The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
control.cpp
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 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
17 #include "control.hpp"
18 
19 #include "font.hpp"
20 #include "formula/string_utils.hpp"
22 #include "gui/core/log.hpp"
24 #include "gui/dialogs/tip.hpp"
25 #include "gui/widgets/settings.hpp"
26 #include "gui/widgets/window.hpp"
27 #include "marked-up_text.hpp"
28 #include "hotkey/hotkey_item.hpp"
29 #include "formatter.hpp"
30 #include "gettext.hpp"
31 #include "wml_exception.hpp"
32 
33 #include "utils/functional.hpp"
34 
35 #include <iomanip>
36 
37 #define LOG_SCOPE_HEADER \
38  "tcontrol(" + get_control_type() + ") [" + id() + "] " + __func__
39 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
40 
41 namespace gui2
42 {
43 
44 // ------------ WIDGET -----------{
45 
46 tcontrol::tcontrol(const unsigned canvas_count)
47  : definition_("default")
48  , label_()
49  , use_markup_(false)
50  , use_tooltip_on_label_overflow_(true)
51  , tooltip_()
52  , help_message_()
53  , canvas_(canvas_count)
54  , config_(nullptr)
55  , renderer_()
56  , text_maximum_width_(0)
57  , text_alignment_(PANGO_ALIGN_LEFT)
58  , shrunken_(false)
59 {
60  connect_signal<event::SHOW_TOOLTIP>(std::bind(
61  &tcontrol::signal_handler_show_tooltip, this, _2, _3, _5));
62 
63  connect_signal<event::SHOW_HELPTIP>(std::bind(
64  &tcontrol::signal_handler_show_helptip, this, _2, _3, _5));
65 
66  connect_signal<event::NOTIFY_REMOVE_TOOLTIP>(std::bind(
68 }
69 
71  const unsigned canvas_count,
72  const std::string& control_type)
73  : twidget(builder)
74  , definition_(builder.definition)
75  , label_(builder.label)
76  , use_markup_(false)
77  , use_tooltip_on_label_overflow_(builder.use_tooltip_on_label_overflow)
78  , tooltip_(builder.tooltip)
79  , help_message_(builder.help)
80  , canvas_(canvas_count)
81  , config_(nullptr)
82  , renderer_()
83  , text_maximum_width_(0)
84  , text_alignment_(PANGO_ALIGN_LEFT)
85  , shrunken_(false)
86 {
87  definition_load_configuration(control_type);
88 
89  connect_signal<event::SHOW_TOOLTIP>(std::bind(
90  &tcontrol::signal_handler_show_tooltip, this, _2, _3, _5));
91 
92  connect_signal<event::SHOW_HELPTIP>(std::bind(
93  &tcontrol::signal_handler_show_helptip, this, _2, _3, _5));
94 
95  connect_signal<event::NOTIFY_REMOVE_TOOLTIP>(std::bind(
97 }
98 
100 {
101  /** @todo document this feature on the wiki. */
102  /** @todo do we need to add the debug colors here as well? */
103  string_map::const_iterator itor = data.find("id");
104  if(itor != data.end()) {
105  set_id(itor->second);
106  }
107 
108  itor = data.find("linked_group");
109  if(itor != data.end()) {
110  set_linked_group(itor->second);
111  }
112 
113  itor = data.find("label");
114  if(itor != data.end()) {
115  set_label(itor->second);
116  }
117 
118  itor = data.find("tooltip");
119  if(itor != data.end()) {
120  set_tooltip(itor->second);
121  }
122 
123  itor = data.find("help");
124  if(itor != data.end()) {
125  set_help_message(itor->second);
126  }
127 
128  itor = data.find("use_markup");
129  if(itor != data.end()) {
130  set_use_markup(utils::string_bool(itor->second));
131  }
132 
133  itor = data.find("text_alignment");
134  if(itor != data.end()) {
136  }
137 }
138 
140 {
142 }
143 
145 {
146  return new iterator::walker::twidget(*this);
147 }
148 
150 {
151  assert(config_);
152 
153  tpoint result(config_->min_width, config_->min_height);
154 
155  DBG_GUI_L << LOG_HEADER << " result " << result << ".\n";
156  return result;
157 }
158 
160 {
161  assert(config_);
162 
163  tpoint result(config_->default_width, config_->default_height);
164 
165  DBG_GUI_L << LOG_HEADER << " result " << result << ".\n";
166  return result;
167 }
168 
170 {
171  assert(config_);
172 
173  tpoint result(config_->max_width, config_->max_height);
174 
175  DBG_GUI_L << LOG_HEADER << " result " << result << ".\n";
176  return result;
177 }
178 
180 {
181  return 0;
182 }
183 
185 {
186  return false;
187 }
188 
190 {
191  return "#ffff00";
192 }
193 
194 void tcontrol::layout_initialise(const bool full_initialisation)
195 {
196  // Inherited.
197  twidget::layout_initialise(full_initialisation);
198 
199  if(full_initialisation) {
200  shrunken_ = false;
201  }
202 }
203 
204 void tcontrol::request_reduce_width(const unsigned maximum_width)
205 {
206  assert(config_);
207 
208  if(!label_.empty() && can_wrap()) {
209 
211  tpoint(0, 0),
212  tpoint(maximum_width - config_->text_extra_width, 0));
213 
214  size.x += config_->text_extra_width;
215  size.y += config_->text_extra_height;
216 
217  set_layout_size(size);
218 
219  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_)
220  << "' maximum_width " << maximum_width << " result " << size
221  << ".\n";
222 
223  } else {
224  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_)
225  << "' failed; either no label or wrapping not allowed.\n";
226  }
227 }
228 
230 {
231  assert(config_);
232  if(label_.empty()) {
233  DBG_GUI_L << LOG_HEADER << " empty label return default.\n";
234  return get_config_default_size();
235  }
236 
237  const tpoint minimum = get_config_default_size();
238  const tpoint maximum = get_config_maximum_size();
239 
240  /**
241  * @todo The value send should subtract the border size
242  * and read it after calculation to get the proper result.
243  */
244  tpoint result = get_best_text_size(minimum, maximum);
245  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_)
246  << "' result " << result << ".\n";
247  return result;
248 }
249 
250 void tcontrol::place(const tpoint& origin, const tpoint& size)
251 {
252  // resize canvasses
253  for(auto & canvas : canvas_)
254  {
255  canvas.set_width(size.x);
256  canvas.set_height(size.y);
257  }
258 
259  // Note we assume that the best size has been queried but otherwise it
260  // should return false.
262  && tooltip_.empty()) {
263 
265  }
266 
267  // inherited
268  twidget::place(origin, size);
269 
270  // update the state of the canvas after the sizes have been set.
271  update_canvas();
272 }
273 
275 {
276  if(!config()) {
277 
279 
281  }
282 }
283 
284 twidget* tcontrol::find_at(const tpoint& coordinate, const bool must_be_active)
285 {
286  return (twidget::find_at(coordinate, must_be_active)
287  && (!must_be_active || get_active()))
288  ? this
289  : nullptr;
290 }
291 
292 const twidget* tcontrol::find_at(const tpoint& coordinate,
293  const bool must_be_active) const
294 {
295  return (twidget::find_at(coordinate, must_be_active)
296  && (!must_be_active || get_active()))
297  ? this
298  : nullptr;
299 }
300 
301 twidget* tcontrol::find(const std::string& id, const bool must_be_active)
302 {
303  return (twidget::find(id, must_be_active)
304  && (!must_be_active || get_active()))
305  ? this
306  : nullptr;
307 }
308 
309 const twidget* tcontrol::find(const std::string& id, const bool must_be_active)
310  const
311 {
312  return (twidget::find(id, must_be_active)
313  && (!must_be_active || get_active()))
314  ? this
315  : nullptr;
316 }
317 
318 void tcontrol::set_definition(const std::string& definition)
319 {
320  assert(!config());
321  definition_ = definition;
322  load_config();
323  assert(config());
324 
325 #ifdef GUI2_EXPERIMENTAL_LISTBOX
326  init();
327 #endif
328 }
329 
330 void tcontrol::set_label(const t_string& label)
331 {
332  if(label == label_) {
333  return;
334  }
335 
336  label_ = label;
337  set_layout_size(tpoint(0, 0));
338  update_canvas();
339  set_is_dirty(true);
340 }
341 
342 void tcontrol::set_use_markup(bool use_markup)
343 {
344  if(use_markup == use_markup_) {
345  return;
346  }
347 
348  use_markup_ = use_markup;
349  update_canvas();
350  set_is_dirty(true);
351 }
352 
353 void tcontrol::set_text_alignment(const PangoAlignment text_alignment)
354 {
355  if(text_alignment_ == text_alignment) {
356  return;
357  }
358 
359  text_alignment_ = text_alignment;
360  update_canvas();
361  set_is_dirty(true);
362 }
363 
365 {
366  const int max_width = get_text_maximum_width();
367  const int max_height = get_text_maximum_height();
368 
369  // set label in canvases
370  for(auto & canvas : canvas_)
371  {
372  canvas.set_variable("text", variant(label_));
373  canvas.set_variable("text_markup", variant(use_markup_));
374  canvas.set_variable("text_link_aware", variant(get_link_aware()));
375  canvas.set_variable("text_link_color", variant(get_link_color()));
376  canvas.set_variable("text_alignment",
378  canvas.set_variable("text_maximum_width", variant(max_width));
379  canvas.set_variable("text_maximum_height", variant(max_height));
380  canvas.set_variable("text_wrap_mode",
381  variant(can_wrap() ? PANGO_ELLIPSIZE_NONE
382  : PANGO_ELLIPSIZE_END));
383  canvas.set_variable("text_characters_per_line",
385  }
386 }
387 
389 {
390  assert(config_);
391 
393  : get_width() - config_->text_extra_width;
394 }
395 
397 {
398  assert(config_);
399 
400  return get_height() - config_->text_extra_height;
401 }
402 
404  int x_offset,
405  int y_offset)
406 {
407  DBG_GUI_D << LOG_HEADER << " label '" << debug_truncate(label_) << "' size "
408  << get_rectangle() << ".\n";
409 
410  canvas(get_state()).blit(frame_buffer,
411  calculate_blitting_rectangle(x_offset, y_offset));
412 }
413 
415  ,
416  int /*x_offset*/
417  ,
418  int /*y_offset*/)
419 {
420  /* DO NOTHING */
421 }
422 
424 {
425  assert(!config());
426 
427  set_config(get_control(control_type, definition_));
428  if(canvas().size() != config()->state.size())
429  {
430  // TODO: Some widgets (toggle panel, toggle button) have a variable canvas count which is determined by its definition.
431  // I think we should remove the canvas_count from tcontrols constructor and always read it from the definition.
432  LOG_GUI_L << "Corrected canvas count to " << config()->state.size();
433  canvas() = std::vector<tcanvas>(config()->state.size());
434  }
435  for(size_t i = 0; i < canvas().size(); ++i) {
436  canvas(i) = config()->state[i].canvas;
437  }
438 
439  update_canvas();
440 }
441 
443  const tpoint& maximum_size) const
444 {
446 
447  assert(!label_.empty());
448 
449  const tpoint border(config_->text_extra_width, config_->text_extra_height);
450  tpoint size = minimum_size - border;
451 
454 
456 
457  renderer_.set_family_class(config_->text_font_family);
458  renderer_.set_font_size(config_->text_font_size);
459  renderer_.set_font_style(config_->text_font_style);
461 
462  // Try with the minimum wanted size.
463  const int maximum_width = text_maximum_width_ != 0 ? text_maximum_width_
464  : maximum_size.x;
465 
466  renderer_.set_maximum_width(maximum_width);
467 
468  if(can_wrap()) {
469  renderer_.set_ellipse_mode(PANGO_ELLIPSIZE_NONE);
470  }
471 
473  if(get_characters_per_line() != 0 && !can_wrap()) {
474  WRN_GUI_L
475  << LOG_HEADER << " Limited the number of characters per line, "
476  << "but wrapping is not set, output may not be as expected.\n";
477  }
478 
479  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_)
480  << "' status: "
481  << " minimum_size " << minimum_size << " maximum_size "
482  << maximum_size << " text_maximum_width_ " << text_maximum_width_
483  << " can_wrap " << can_wrap() << " characters_per_line "
484  << get_characters_per_line() << " truncated "
485  << renderer_.is_truncated() << " renderer size "
486  << renderer_.get_size() << ".\n";
487 
488  // If doesn't fit try the maximum.
489  if(renderer_.is_truncated() && !can_wrap()) {
490  // FIXME if maximum size is defined we should look at that
491  // but also we don't adjust for the extra text space yet!!!
492  const tpoint maximum_size(config_->max_width, config_->max_height);
493  renderer_.set_maximum_width(maximum_size.x ? maximum_size.x - border.x
494  : -1);
495  }
496 
497  size = renderer_.get_size() + border;
498 
499  if(size.x < minimum_size.x) {
500  size.x = minimum_size.x;
501  }
502 
503  if(size.y < minimum_size.y) {
504  size.y = minimum_size.y;
505  }
506 
507  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_)
508  << "' result " << size << ".\n";
509  return size;
510 }
511 
513  bool& handled,
514  const tpoint& location)
515 {
516  DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
517 
518  if(!tooltip_.empty()) {
520  if(!help_message_.empty()) {
521  utils::string_map symbols;
522  symbols["hotkey"] = hotkey::get_names(
524  hotkey::GLOBAL__HELPTIP).command);
525 
528  }
529 
530  event::tmessage_show_tooltip message(tip, location);
531  handled = fire(event::MESSAGE_SHOW_TOOLTIP, *this, message);
532  }
533 }
534 
536  bool& handled,
537  const tpoint& location)
538 {
539  DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
540 
541  if(!help_message_.empty()) {
542  event::tmessage_show_helptip message(help_message_, location);
543  handled = fire(event::MESSAGE_SHOW_HELPTIP, *this, message);
544  }
545 }
546 
548  bool& handled)
549 {
550  DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
551 
552  /*
553  * This makes the class know the tip code rather intimately. An
554  * alternative is to add a message to the window to remove the tip.
555  * Might be done later.
556  */
557  tip::remove();
558 
559  handled = true;
560 }
561 
562 std::string tcontrol::get_label_token(const gui2::tpoint & position, const char * delim) const
563 {
564  return renderer_.get_token(position, delim);
565 }
566 
568 {
569  return renderer_.get_link(position);
570 }
571 
572 // }---------- BUILDER -----------{
573 
574 /*WIKI
575  * @page = GUIWidgetInstanceWML
576  * @order = 1_widget
577  *
578  * = Widget =
579  * @begin{parent}{name="generic/"}
580  * @begin{tag}{name="widget_instance"}{min="0"}{max="-1"}
581  * All widgets placed in the cell have some values in common:
582  * @begin{table}{config}
583  * id & string & "" & This value is used for the engine to
584  * identify 'special' items. This means that
585  * for example a text_box can get the proper
586  * initial value. This value should be
587  * unique or empty. Those special values are
588  * documented at the window definition that
589  * uses them. NOTE items starting with an
590  * underscore are used for composed widgets
591  * and these should be unique per composed
592  * widget. $
593  *
594  * definition & string & "default" &
595  * The id of the widget definition to use.
596  * This way it's possible to select a
597  * specific version of the widget e.g. a
598  * title label when the label is used as
599  * title. $
600  *
601  * linked_group & string & "" & The linked group the control belongs
602  * to. $
603  *
604  * label & t_string & "" & Most widgets have some text associated
605  * with them, this field contain the value
606  * of that text. Some widgets use this value
607  * for other purposes, this is documented
608  * at the widget. E.g. an image uses the
609  * filename in this field. $
610  *
611  * tooltip & t_string & "" & If you hover over a widget a while (the
612  * time it takes can differ per widget) a
613  * short help can show up.This defines the
614  * text of that message. This field may not
615  * be empty when 'help' is set. $
616  *
617  *
618  * help & t_string & "" & If you hover over a widget and press F10
619  * (or the key the user defined for the help
620  * tip) a help message can show up. This
621  * help message might be the same as the
622  * tooltip but in general (if used) this
623  * message should show more help. This
624  * defines the text of that message. $
625  *
626  * use_tooltip_on_label_overflow & bool & true &
627  * If the text on the label is truncated and
628  * the tooltip is empty the label can be
629  * used for the tooltip. If this variable is
630  * set to true this will happen. $
631  *
632  * debug_border_mode & unsigned & 0 &
633  * The mode for showing the debug border.
634  * This border shows the area reserved for
635  * a widget. This function is only meant
636  * for debugging and might not be
637  * available in all Wesnoth binaries.
638  * Available modes:
639  * @* 0 no border.
640  * @* 1 1 pixel border.
641  * @* 2 floodfill the widget area. $
642  *
643  * debug_border_color & color & "" & The color of the debug border. $
644  * @end{table}
645  * @end{tag}{name="widget_instance"}
646  * @end{parent}{name="generic/"}
647  */
648 
649 namespace implementation
650 {
651 
653  : tbuilder_widget(cfg)
654  , definition(cfg["definition"])
655  , label(cfg["label"].t_str())
656  , tooltip(cfg["tooltip"].t_str())
657  , help(cfg["help"].t_str())
658  , use_tooltip_on_label_overflow(true)
659 {
660  if(definition.empty()) {
661  definition = "default";
662  }
663 
665  help.empty() || !tooltip.empty(),
666  _("Found a widget with a helptip and without a tooltip."),
667  (formatter() << "id '" << id << "' label '" << label
668  << "' helptip '" << help << "'.").str());
669 
670 
671  DBG_GUI_P << "Window builder: found control with id '" << id
672  << "' and definition '" << definition << "'.\n";
673 }
674 
676 {
677  assert(control);
678 
679  control->set_id(id);
680  control->set_definition(definition);
681  control->set_linked_group(linked_group);
682  control->set_label(label);
683  control->set_tooltip(tooltip);
684  control->set_help_message(help);
686 #ifndef LOW_MEM
689 #endif
690 }
691 
692 twidget* tbuilder_control::build(const treplacements& /*replacements*/) const
693 {
694  return build();
695 }
696 
697 } // namespace implementation
698 
699 // }------------ END --------------
700 
701 } // namespace gui2
Define the common log macros for the gui toolkit.
tpoint get_config_default_size() const
Gets the default size as defined in the config.
Definition: control.cpp:159
std::string encode_text_alignment(const PangoAlignment alignment)
Converts a text alignment to its string representation.
Definition: helper.cpp:107
unsigned get_width() const
Definition: widget.cpp:294
#define DBG_GUI_P
Definition: log.hpp:69
virtual void impl_draw_background(surface &frame_buffer, int x_offset, int y_offset) override
See twidget::impl_draw_background.
Definition: control.cpp:403
Request for somebody to show the tooltip based on the data send.
Definition: handler.hpp:160
virtual void impl_draw_foreground(surface &frame_buffer, int x_offset, int y_offset) override
See twidget::impl_draw_foreground.
Definition: control.cpp:414
#define LOG_GUI_L
Definition: log.hpp:59
void signal_handler_show_tooltip(const event::tevent event, bool &handled, const tpoint &location)
Definition: control.cpp:512
ttext & set_alignment(const PangoAlignment alignment)
Definition: text.cpp:524
std::string interpolate_variables_into_string(const std::string &str, const string_map *const symbols)
Function which will interpolate variables, starting with '$' in the string 'str' with the equivalent ...
#define DBG_GUI_L
Definition: log.hpp:58
tformula< PangoAlignment > text_alignment_
The alignment of the text.
Definition: canvas.cpp:1262
ttext & set_link_aware(bool b)
Definition: text.cpp:546
void set_config(tresolution_definition_ptr config)
Definition: control.hpp:308
virtual bool can_wrap() const
Can the widget wrap.
Definition: widget.cpp:211
virtual unsigned get_characters_per_line() const
Returns the number of characters per line.
Definition: control.cpp:179
ttext & set_font_style(const unsigned font_style)
Definition: text.cpp:418
Contains the info needed to instantiate a widget.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
twidget * find(const std::string &id, const bool must_be_active) override
See twidget::find.
Definition: control.cpp:301
virtual void load_config_extra()
Load class dependent config settings.
Definition: control.hpp:405
virtual const std::string & get_control_type() const =0
Returns the control_type of the control.
tresolution_definition_ptr config()
Definition: control.hpp:299
bool is_truncated() const
Has the text been truncated?
Definition: text.cpp:197
This file contains the window object, this object is a top level container which has the event manage...
tvisible::scoped_enum get_visible() const
Definition: widget.cpp:471
#define WRN_GUI_L
Definition: log.hpp:60
virtual void request_reduce_width(const unsigned maximum_width) override
See twidget::request_reduce_width.
Definition: control.cpp:204
virtual void set_label(const t_string &label)
Definition: control.cpp:330
lg::log_domain log_gui_layout("gui/layout")
Definition: log.hpp:57
ttext & set_font_size(const unsigned font_size)
Definition: text.cpp:406
int text_maximum_width_
The maximum width for the text in a control.
Definition: control.hpp:488
ttext & set_maximum_width(int width)
Definition: text.cpp:446
PangoAlignment decode_text_alignment(const std::string &alignment)
Converts a text alignment string to a text alignment.
Definition: helper.cpp:92
ttext & set_link_color(const std::string &color)
Definition: text.cpp:556
void set_help_message(const t_string &help_message)
Definition: control.hpp:276
#define VALIDATE_WITH_DEV_MESSAGE(cond, message, dev_message)
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
void set_is_dirty(const bool is_dirty)
Definition: widget.cpp:435
virtual void layout_initialise(const bool full_initialisation)
How the layout engine works.
Definition: widget.cpp:162
virtual unsigned get_state() const =0
Returns the id of the state.
#define LOG_SCOPE_HEADER
Definition: control.cpp:37
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
void init_control(tcontrol *control) const
Definition: control.cpp:675
std::string definition
Parameters for the control.
Definition: control.hpp:530
#define DBG_GUI_D
Definition: log.hpp:29
virtual void set_use_markup(bool use_markup)
Definition: control.cpp:342
virtual twidget * build() const =0
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
GLuint64EXT * result
Definition: glew.h:10727
std::map< std::string, t_string > string_map
std::string get_link(const gui2::tpoint &position) const
Checks if position points to a character in a link in the text, returns it if so, empty string otherw...
Definition: text.cpp:311
tpoint get_config_maximum_size() const
Gets the best size as defined in the config.
Definition: control.cpp:169
tpoint get_best_text_size(const tpoint &minimum_size, const tpoint &maximum_size=tpoint(0, 0)) const
Gets the best size for a text.
Definition: control.cpp:442
t_string tooltip_
Tooltip text.
Definition: control.hpp:368
std::string get_label_token(const gui2::tpoint &position, const char *delimiters=" \n\r\t") const
Exposes font::ttext::get_token, for the text label of this control.
Definition: control.cpp:562
This file contains the settings handling of the widget library.
bool fire(const tevent event, twidget &target)
Fires an event which has no extra parameters.
Definition: dispatcher.cpp:144
void remove()
Removes a tip.
Definition: tip.cpp:167
std::ostringstream wrapper.
Definition: formatter.hpp:32
t_string has_helptip_message
Definition: settings.cpp:63
int y
y coordinate.
Definition: point.hpp:34
void set_layout_size(const tpoint &size)
Definition: widget.cpp:304
Request for somebody to show the helptip based on the data send.
Definition: handler.hpp:170
int get_text_maximum_width() const
Returns the maximum width available for the text.
Definition: control.cpp:388
gui2::tpoint get_size() const
Returns the size needed for the text.
Definition: text.cpp:190
This file contains the defintions for the gui2::event::tmessage class.
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
Definition: control.cpp:250
#define log_scope2(domain, description)
Definition: log.hpp:186
ttext & set_characters_per_line(const unsigned characters_per_line)
Definition: text.cpp:479
void set_id(const std::string &id)
Definition: widget.cpp:97
void load_config()
Loads the configuration of the widget.
Definition: control.cpp:274
const t_string & label() const
Definition: control.hpp:248
virtual void place(const tpoint &origin, const tpoint &size)
Places the widget.
Definition: widget.cpp:233
tevent
The event send to the dispatcher.
Definition: handler.hpp:54
void set_use_tooltip_on_label_overflow(const bool use_tooltip=true)
Definition: control.hpp:243
bool shrunken_
Is the widget smaller as it's best size?
Definition: control.hpp:494
void set_tooltip(const t_string &tooltip)
Definition: control.hpp:265
bool init()
Initializes the gui subsystems.
Definition: helper.cpp:37
tresolution_definition_ptr get_control(const std::string &control_type, const std::string &definition)
Definition: settings.cpp:576
tresolution_definition_ptr config_
Contains the pointer to the configuration.
Definition: control.hpp:397
A walker for a gui2::tcontrol.
font::ttext renderer_
Contains a helper cache for the rendering.
Definition: control.hpp:485
std::map< std::string, t_string > string_map
Definition: generator.hpp:23
PangoAlignment text_alignment_
The alignment of the text in a control.
Definition: control.hpp:491
Encapsulates the map of the game.
Definition: location.hpp:38
int x
x coordinate.
Definition: point.hpp:31
std::string definition_
The definition is the id of that widget class.
Definition: control.hpp:347
virtual void update_canvas()
Updates the canvas(ses).
Definition: control.cpp:364
tpoint get_config_minimum_size() const
Gets the minimum size as defined in the config.
Definition: control.cpp:149
static ttip & tip()
Definition: tip.cpp:123
The user sets the widget visible, that means:
Definition: widget.hpp:79
std::string get_token(const gui2::tpoint &position, const char *delimiters=" \n\r\t") const
Gets the largest collection of characters, including the token at position, and not including any cha...
Definition: text.cpp:279
std::map< std::string, tfilter >::iterator itor
Definition: filter.cpp:199
#define DBG_GUI_E
Definition: log.hpp:35
std::vector< tcanvas > canvas_
Holds all canvas objects for a control.
Definition: control.hpp:386
void set_debug_border_colour(const unsigned debug_border_colour)
Definition: widget.cpp:489
std::string debug_truncate(const std::string &text)
Returns a truncated version of the text.
Definition: helper.cpp:157
virtual iterator::twalker_ * create_walker() override
See twidget::create_walker.
Definition: control.cpp:144
bool use_markup_
Use markup for the label?
Definition: control.hpp:353
unsigned get_height() const
Definition: widget.cpp:299
void signal_handler_show_helptip(const event::tevent event, bool &handled, const tpoint &location)
Definition: control.cpp:535
size_t i
Definition: function.cpp:1057
Holds a 2D point.
Definition: point.hpp:24
SDL_Rect calculate_blitting_rectangle(const int x_offset, const int y_offset)
Calculates the blitting rectangle of the widget.
Definition: widget.cpp:321
void definition_load_configuration(const std::string &control_type)
Loads the configuration of the widget.
Definition: control.cpp:423
std::vector< tcanvas > & canvas()
Definition: control.hpp:282
bool string_bool(const std::string &str, bool def)
Convert no, false, off, 0, 0.0 to false, empty to def, and others to true.
std::string get_names(std::string id)
Returns a comma-separated string of hotkey names.
void signal_handler_notify_remove_tooltip(const event::tevent event, bool &handled)
Definition: control.cpp:547
virtual bool get_link_aware() const
Returns whether the label should be link_aware, in in rendering and in searching for links with get_l...
Definition: control.cpp:184
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active)
Returns the widget at the wanted coordinates.
Definition: widget.cpp:547
Base class for all visible items.
Definition: control.hpp:34
GLint GLint GLsizei GLsizei GLsizei GLint border
Definition: glew.h:1222
bool disable_click_dismiss() const override
See twidget::disable_click_dismiss.
Definition: control.cpp:139
GLsizeiptr size
Definition: glew.h:1649
bool use_tooltip_on_label_overflow_
If the text doesn't fit on the label should the text be used as tooltip?
Definition: control.hpp:360
t_string label_
Contain the non-editable text associated with control.
Definition: control.hpp:350
void set_text_alignment(const PangoAlignment text_alignment)
Definition: control.cpp:353
cl_event event
Definition: glew.h:3070
int get_text_maximum_height() const
Returns the maximum height available for the text.
Definition: control.cpp:396
virtual void set_members(const string_map &data)
Sets the members of the control.
Definition: control.cpp:99
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
Definition: control.cpp:284
Base class for all widgets.
Definition: widget.hpp:49
ttext & set_family_class(font::family_class fclass)
Definition: text.cpp:395
std::string get_label_link(const gui2::tpoint &position) const
Definition: control.cpp:567
tcontrol(const unsigned canvas_count)
Definition: control.cpp:46
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
virtual std::string get_link_color() const
Returns the color string to be used with links.
Definition: control.cpp:189
bool set_text(const std::string &text, const bool markedup)
Sets the text to render.
Definition: text.cpp:360
Definition: help.cpp:57
void set_definition(const std::string &definition)
Sets the definition.
Definition: control.cpp:318
The walker abstract base class.
Definition: walker.hpp:27
std::map< std::string, boost::intrusive_ptr< tbuilder_widget > > treplacements
The replacements type is used to define replacement types.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
SDL_Rect get_rectangle() const
Gets the bounding rectangle of the widget on the screen.
Definition: widget.cpp:279
virtual bool get_active() const =0
Gets the active state of the control.
void set_debug_border_mode(const unsigned debug_border_mode)
Definition: widget.cpp:484
virtual void layout_initialise(const bool full_initialisation) override
See twidget::layout_initialise.
Definition: control.cpp:194
virtual twidget * find(const std::string &id, const bool must_be_active)
Returns a widget with the wanted id.
Definition: widget.cpp:558
#define LOG_HEADER
Definition: control.cpp:39
GLsizei const GLcharARB ** string
Definition: glew.h:4503
t_string help_message_
Tooltip text.
Definition: control.hpp:376
bool empty() const
Definition: tstring.hpp:166
ttext & set_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
Definition: text.cpp:510
Contains the implementation details for lexical_cast and shouldn't be used directly.
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
Definition: control.cpp:229
static const hotkey_command & get_command_by_command(HOTKEY_COMMAND command)
the execute_command argument was changed from HOTKEY_COMMAND to hotkey_command, to be able to call it...
void set_linked_group(const std::string &linked_group)
Definition: widget.cpp:314