The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
label.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef GUI_WIDGETS_LABEL_HPP_INCLUDED
16 #define GUI_WIDGETS_LABEL_HPP_INCLUDED
17 
18 #include "gui/widgets/control.hpp"
19 
22 
23 namespace gui2
24 {
25 
26 // ------------ WIDGET -----------{
27 
28 /** Label showing a text. */
29 class tlabel : public tcontrol
30 {
31 public:
32  tlabel();
33 
34  /** See @ref twidget::can_wrap. */
35  virtual bool can_wrap() const override;
36 
37  /** See @ref tcontrol::get_characters_per_line. */
38  virtual unsigned get_characters_per_line() const override;
39 
40  /** See @ref tcontrol::get_link_aware. */
41  virtual bool get_link_aware() const override;
42 
43  /** See @ref tcontrol::get_link_aware. */
44  virtual std::string get_link_color() const override;
45 
46  /** See @ref tcontrol::set_active. */
47  virtual void set_active(const bool active) override;
48 
49  /** See @ref tcontrol::get_active. */
50  virtual bool get_active() const override;
51 
52  /** See @ref tcontrol::get_state. */
53  virtual unsigned get_state() const override;
54 
55  /** See @ref twidget::disable_click_dismiss. */
56  bool disable_click_dismiss() const override;
57 
58  /***** ***** ***** setters / getters for members ***** ****** *****/
59 
60  void set_can_wrap(const bool wrap)
61  {
62  can_wrap_ = wrap;
63  }
64 
66 
67  void set_link_aware(bool l);
68 
69  void set_link_color(const std::string & color);
70 
71  virtual bool can_mouse_focus() const override { return false; }
72 private:
73  /**
74  * Possible states of the widget.
75  *
76  * Note the order of the states must be the same as defined in settings.hpp.
77  */
78  enum tstate {
82  };
83 
84  void set_state(const tstate state);
85 
86  /**
87  * Current state of the widget.
88  *
89  * The state of the widget determines what to render and how the widget
90  * reacts to certain 'events'.
91  */
93 
94  /** Holds the label can wrap or not. */
95  bool can_wrap_;
96 
97  /**
98  * The maximum number of characters per line.
99  *
100  * The maximum is not an exact maximum, it uses the average character width.
101  */
103 
104  /**
105  * Whether the label is link aware, rendering links with special formatting
106  * and handling click events.
107  */
109 
110  /**
111  * What color links will be rendered in.
112  */
114 
115  /** See @ref tcontrol::get_control_type. */
116  virtual const std::string& get_control_type() const override;
117 
118  /** Inherited from tcontrol. */
119  void load_config_extra();
120 
121  /***** ***** ***** signal handlers ***** ****** *****/
122 
123  /**
124  * Left click signal handler: checks if we clicked on a hyperlink
125  */
126  void signal_handler_left_button_click(const event::tevent event, bool & handled);
127 
128  /**
129  * Right click signal handler: checks if we clicked on a hyperlink, copied to clipboard
130  */
131  void signal_handler_right_button_click(const event::tevent event, bool & handled);
132 };
133 
134 // }---------- DEFINITION ---------{
135 
137 {
138 
139  explicit tlabel_definition(const config& cfg);
140 
142  {
143  explicit tresolution(const config& cfg);
144 
147  };
148 };
149 
150 // }---------- BUILDER -----------{
151 
152 namespace implementation
153 {
154 
156 {
157  tbuilder_label(const config& cfg);
158 
160 
161  twidget* build() const;
162 
163  bool wrap;
164 
166 
167  PangoAlignment text_alignment;
168 };
169 
170 } // namespace implementation
171 
172 // }------------ END --------------
173 
174 } // namespace gui2
175 
176 #endif
std::string link_color_
What color links will be rendered in.
Definition: label.hpp:113
void set_state(const tstate state)
Definition: label.cpp:123
virtual void set_active(const bool active) override
See tcontrol::set_active.
Definition: label.cpp:75
void signal_handler_left_button_click(const event::tevent event, bool &handled)
Left click signal handler: checks if we clicked on a hyperlink.
Definition: label.cpp:152
void set_can_wrap(const bool wrap)
Definition: label.hpp:60
tresolution(const config &cfg)
Definition: label.cpp:264
Label showing a text.
Definition: label.hpp:29
virtual unsigned get_state() const override
See tcontrol::get_state.
Definition: label.cpp:87
Base class of a resolution, contains the common keys for a resolution.
GLdouble l
Definition: glew.h:6966
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
virtual twidget * build() const =0
virtual bool can_wrap() const override
See twidget::can_wrap.
Definition: label.cpp:55
void load_config_extra()
Inherited from tcontrol.
Definition: label.cpp:137
bool can_wrap_
Holds the label can wrap or not.
Definition: label.hpp:95
tevent
The event send to the dispatcher.
Definition: handler.hpp:54
GLuint color
Definition: glew.h:5801
tstate
Possible states of the widget.
Definition: label.hpp:78
unsigned characters_per_line_
The maximum number of characters per line.
Definition: label.hpp:102
virtual bool can_mouse_focus() const override
Whether the mouse move/click event go 'through' this widget.
Definition: label.hpp:71
virtual bool get_link_aware() const override
See tcontrol::get_link_aware.
Definition: label.cpp:65
void set_characters_per_line(const unsigned set_characters_per_line)
Definition: label.cpp:97
tstate state_
Current state of the widget.
Definition: label.hpp:92
tlabel_definition(const config &cfg)
Definition: label.cpp:218
Base class for all visible items.
Definition: control.hpp:34
void set_link_color(const std::string &color)
Definition: label.cpp:113
cl_event event
Definition: glew.h:3070
Base class for all widgets.
Definition: widget.hpp:49
void signal_handler_right_button_click(const event::tevent event, bool &handled)
Right click signal handler: checks if we clicked on a hyperlink, copied to clipboard.
Definition: label.cpp:188
tbuilder_label(const config &cfg)
Definition: label.cpp:316
virtual const std::string & get_control_type() const override
See tcontrol::get_control_type.
Definition: label.cpp:131
void set_link_aware(bool l)
Definition: label.cpp:102
virtual bool get_active() const override
See tcontrol::get_active.
Definition: label.cpp:82
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
virtual unsigned get_characters_per_line() const override
See tcontrol::get_characters_per_line.
Definition: label.cpp:60
GLsizei const GLcharARB ** string
Definition: glew.h:4503
bool link_aware_
Whether the label is link aware, rendering links with special formatting and handling click events...
Definition: label.hpp:108
virtual std::string get_link_color() const override
See tcontrol::get_link_aware.
Definition: label.cpp:70
Contains the implementation details for lexical_cast and shouldn't be used directly.
bool disable_click_dismiss() const override
See twidget::disable_click_dismiss.
Definition: label.cpp:92