The Battle for Wesnoth  1.19.4+dev
widget.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2024
3  by Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "color.hpp"
21 #include "gui/widgets/helper.hpp"
22 #include "scripting/lua_ptr.hpp"
23 #include "sdl/point.hpp"
24 #include "sdl/rect.hpp"
25 #include "wml_exception.hpp"
26 
27 #include <string>
28 
29 
30 namespace gui2
31 {
32 /* Data format used by styled_widget::set_members to set settings for a single widget. */
33 using widget_item = std::map<std::string, t_string>;
34 
35 /* Indexes multiple @ref widget_item maps by widget ID. */
36 using widget_data = std::map<std::string, widget_item>;
37 
38 struct builder_widget;
39 class window;
40 class grid;
41 
42 namespace iteration
43 {
44 using walker_ptr = std::unique_ptr<class walker_base>;
45 } // namespace iteration
46 
47 /**
48  * Base class for all widgets.
49  *
50  * From this abstract all other widgets should derive. It contains the minimal
51  * info needed for a real widget and some pure abstract functions which need to
52  * be implemented by classes deriving from this class.
53  */
54 class widget : public event_executor, public event::dispatcher, public enable_lua_ptr<widget>
55 {
56  friend class debug_layout_graph;
57  friend class window; // needed for modifying the layout_size.
58 
59 
60  /***** ***** ***** ***** ***** Types. ***** ***** ***** ***** *****/
61 
62 public:
63  /** Visibility settings done by the user. */
64  enum class visibility
65  {
66  /**
67  * The user sets the widget visible, that means:
68  * * The widget is visible.
69  * * @ref find_at always 'sees' the widget (the active flag is
70  * tested later).
71  * * The widget (if active) handles events (and sends events to
72  * its children).
73  * * The widget is drawn.
74  */
75  visible,
76 
77  /**
78  * The user sets the widget hidden, that means:
79  * * The widget is invisible but keeps its size.
80  * * @ref find_at 'sees' the widget if active is @c false.
81  * * The widget doesn't handle events (and doesn't send events to
82  * its children).
83  */
84  hidden,
85 
86  /**
87  * The user set the widget invisible, that means:
88  * * The widget is invisible and its grid cell has size 0,0.
89  * * @ref find_at never 'sees' the widget.
90  * * The widget doesn't handle events (and doesn't send events to
91  * its children).
92  */
93  invisible
94  };
95 
96  /**
97  * Visibility set by the engine.
98  *
99  * This state only will be used if @ref visible_ is @ref visibility::visible
100  * depending on this state the widget might not be visible after all.
101  */
102  enum class redraw_action
103  {
104  // TODO: draw_manager/hwaccel - are these still useful?
105  /**
106  * The widget is fully visible.
107  *
108  * The widget should be drawn. The entire widget's rectangle
109  * should be redrawn.
110  */
111  full,
112 
113  /**
114  * The widget is partly visible.
115  *
116  * The should be drawn. The rectangle to redraw in determined
117  * by @ref clipping_rectangle_
118  */
119  partly,
120 
121  /**
122  * The widget is not visible.
123  *
124  * The widget should not be drawn.
125  */
126  none
127  };
128 
129  enum class debug_border {
130  /** No border. */
131  none,
132  /** Single-pixel outline. */
133  outline,
134  /** Flood-filled rectangle. */
135  fill,
136  };
137 
138  /***** ***** ***** Constructor and destructor. ***** ***** *****/
139 
140 public:
141  widget(const widget&) = delete;
142  widget& operator=(const widget&) = delete;
143 
144  /** @deprecated use the second overload. */
145  widget();
146 
147  /**
148  * Constructor.
149  *
150  * @param builder The builder object with the settings for the
151  * object.
152  */
153  explicit widget(const builder_widget& builder);
154 
155  virtual ~widget() override;
156 
157 
158  /***** ***** ***** ***** ID functions. ***** ***** ***** *****/
159 
160 public:
161  /*** *** *** *** *** *** Setters and getters. *** *** *** *** *** ***/
162 
163  void set_id(const std::string& id);
164  const std::string& id() const;
165 
166  /*** *** *** *** *** *** *** *** Members. *** *** *** *** *** *** *** ***/
167 
168 private:
169  /**
170  * The id is the unique name of the widget in a certain context.
171  *
172  * This is needed for certain widgets so the engine knows which widget is
173  * which. E.g. it knows which button is pressed and thus which engine action
174  * is connected to the button. This doesn't mean that the id is unique in a
175  * window, e.g. a listbox can have the same id for every row.
176  */
177  std::string id_;
178 
179 
180  /***** ***** ***** ***** Parent functions ***** ***** ***** *****/
181 
182 public:
183  /**
184  * Get the parent window.
185  *
186  * @returns Pointer to parent window.
187  * @retval nullptr No parent window found.
188  */
189  window* get_window();
190 
191  /** The constant version of @ref get_window. */
192  const window* get_window() const;
193 
194  /**
195  * Get the parent grid.
196  *
197  * @returns Pointer to parent grid.
198  * @retval nullptr No parent grid found.
199  */
201  const grid* get_parent_grid() const;
202 
203  /*** *** *** *** *** *** Setters and getters. *** *** *** *** *** ***/
204 
205  void set_parent(widget* parent);
206  widget* parent();
207 
208  /*** *** *** *** *** *** *** *** Members. *** *** *** *** *** *** *** ***/
209 
210 private:
211  /**
212  * The parent widget.
213  *
214  * If the widget has a parent it contains a pointer to the parent, else it
215  * is set to @c nullptr.
216  */
218 
219 
220  /***** ***** ***** ***** Size and layout functions. ***** ***** ***** *****/
221 
222 public:
223  /**
224  * How the layout engine works.
225  *
226  * Every widget has a member @ref layout_size_ which holds the best size in
227  * the current layout phase. When the windows starts the layout phase it
228  * calls @ref layout_initialize which resets this value.
229  *
230  * Every widget has two function to get the best size. @ref get_best_size
231  * tests whether layout_size_ is set and if so returns that value otherwise
232  * it calls @ref calculate_best_size so the size can be updated.
233  *
234  * During the layout phase some functions can modify layout_size_ so the
235  * next call to @ref get_best_size returns the currently best size. This
236  * means that after the layout phase @ref get_best_size still returns this
237  * value.
238  */
239 
240  /**
241  * Initialises the layout phase.
242  *
243  * Clears the initial best size for the widgets.
244  *
245  * See @ref layout_algorithm for more information.
246  *
247  * @param full_initialization For widgets with scrollbars it hides them
248  * unless the mode is
249  * scrollbar_mode::ALWAYS_VISIBLE. For
250  * other widgets this flag is a @em NOP.
251  */
252  virtual void layout_initialize(const bool full_initialization);
253 
254  /**
255  * Tries to reduce the width of a widget.
256  *
257  * This function tries to do it 'friendly' and only use scrollbars or
258  * tries to wrap the widget.
259  *
260  * See @ref layout_algorithm for more information.
261  *
262  * @param maximum_width The wanted maximum width.
263  */
264  virtual void request_reduce_width(const unsigned maximum_width) = 0;
265 
266  /**
267  * Tries to reduce the width of a widget.
268  *
269  * This function does it more aggressively and should only be used when
270  * using scrollbars and wrapping failed.
271  *
272  * @todo Make pure virtual.
273  *
274  * See @ref layout_algorithm for more information.
275  *
276  * @param maximum_width The wanted maximum width.
277  */
278  virtual void demand_reduce_width(const unsigned maximum_width);
279 
280  /**
281  * Tries to reduce the height of a widget.
282  *
283  * This function tries to do it 'friendly' and only use scrollbars.
284  *
285  * @todo Make pure virtual.
286  *
287  * See @ref layout_algorithm for more information.
288  *
289  * @param maximum_height The wanted maximum height.
290  */
291  virtual void request_reduce_height(const unsigned maximum_height);
292 
293  /**
294  * Tries to reduce the height of a widget.
295  *
296  * This function does it more aggressively and should only be used when
297  * using scrollbars failed.
298  *
299  * @todo Make pure virtual.
300  *
301  * See @ref layout_algorithm for more information.
302  *
303  * @param maximum_height The wanted maximum height.
304  */
305  virtual void demand_reduce_height(const unsigned maximum_height);
306 
307  /**
308  * Gets the best size for the widget.
309  *
310  * During the layout phase a best size will be determined, several stages
311  * might change the best size. This function will return the currently best
312  * size as determined during the layout phase.
313  *
314  * @returns The best size for the widget.
315  */
316  point get_best_size() const;
317 
318 private:
319  /**
320  * Calculates the best size.
321  *
322  * This function calculates the best size and ignores the current values in
323  * the layout phase. Note containers can call the @ref get_best_size() of
324  * their children since it is meant to update itself.
325  *
326  * @returns The best size for the widget.
327  */
328  virtual point calculate_best_size() const = 0;
329 
330 public:
331  /**
332  * Whether the mouse move/click event go 'through' this widget.
333  */
334  virtual bool can_mouse_focus() const { return true; }
335  /**
336  * Can the widget wrap.
337  *
338  * When a widget can wrap it can reduce its width by increasing its
339  * height. When a layout is too wide it should first try to wrap and if
340  * that fails it should check the vertical scrollbar status. After wrapping
341  * the height might (probably will) change so the layout engine needs to
342  * recalculate the height after wrapping.
343  */
344  virtual bool can_wrap() const;
345 
346  /**
347  * Sets the origin of the widget.
348  *
349  * This function can be used to move the widget without triggering a
350  * redraw. The location is an absolute position, if a relative move is
351  * required use @ref move.
352  *
353  * @param origin The new origin.
354  */
355  virtual void set_origin(const point& origin);
356 
357  /**
358  * Sets the size of the widget.
359  *
360  * This version is meant to resize a widget, since the origin isn't
361  * modified. This can be used if a widget needs to change its size and the
362  * layout will be fixed later.
363  *
364  * @param size The size of the widget.
365  */
366  virtual void set_size(const point& size);
367 
368  /**
369  * Places the widget.
370  *
371  * This function is normally called by a layout function to do the
372  * placement of a widget.
373  *
374  * @param origin The position of top left of the widget.
375  * @param size The size of the widget.
376  */
377  virtual void place(const point& origin, const point& size);
378 
379  /**
380  * Moves a widget.
381  *
382  * This function can be used to move the widget without queueing a redraw.
383  *
384  * @todo Implement the function to all derived classes.
385  *
386  * @param x_offset The amount of pixels to move the widget in
387  * the x-direction.
388  * @param y_offset The amount of pixels to move the widget in
389  * the y-direction.
390  */
391  virtual void move(const int x_offset, const int y_offset);
392 
393  /**
394  * Sets the horizontal alignment of the widget within its parent grid.
395  *
396  * @param alignment The new alignment.
397  */
398  virtual void set_horizontal_alignment(const std::string& alignment);
399 
400  /**
401  * Sets the horizontal alignment of the widget within its parent grid.
402  *
403  * @param alignment The new alignment.
404  */
405  virtual void set_vertical_alignment(const std::string& alignment);
406 
407  /**
408  * Allows a widget to update its children.
409  *
410  * Before the window is populating the dirty list the widgets can update
411  * their content, which allows delayed initialization. This delayed
412  * initialization is only allowed if the widget resizes itself, not when
413  * being placed.
414  */
415  virtual void layout_children();
416 
417  /**
418  * Returns the screen origin of the widget.
419  *
420  * @returns The origin of the widget.
421  */
422  point get_origin() const;
423 
424  /**
425  * Returns the size of the widget.
426  *
427  * @returns The size of the widget.
428  */
429  point get_size() const;
430 
431  /**
432  * Gets the bounding rectangle of the widget on the screen.
433  *
434  * @returns The bounding rectangle of the widget.
435  */
436  rect get_rectangle() const;
437 
438  /*** *** *** *** *** *** Setters and getters. *** *** *** *** *** ***/
439 
440  int get_x() const;
441 
442  int get_y() const;
443 
444  unsigned get_width() const;
445 
446  unsigned get_height() const;
447 
448 protected:
449  void set_layout_size(const point& size);
450  const point& layout_size() const;
451 
452  /**
453  * Throws away @ref layout_size_.
454  *
455  * Use with care: this function does not recurse to child widgets.
456  *
457  * See @ref layout_algorithm for more information.
458  */
460 
461 public:
462  void set_linked_group(const std::string& linked_group);
463 
464  /*** *** *** *** *** *** *** *** Members. *** *** *** *** *** *** *** ***/
465 
466 private:
467  /** The x-coordinate of the widget on the screen. */
468  int x_;
469 
470  /** The y-coordinate of the widget on the screen. */
471  int y_;
472 
473  /** The width of the widget. */
474  unsigned width_;
475 
476  /** The height of the widget. */
477  unsigned height_;
478 
479  /**
480  * The best size for the widget.
481  *
482  * When 0,0 the real best size is returned, but in the layout phase a
483  * wrapping or a scrollbar might change the best size for that widget.
484  * This variable holds that best value.
485  *
486  * If the widget size hasn't been changed from the default that
487  * calculate_best_size() returns, layout_size_ is (0,0).
488  */
490 
491 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
492 
493  /**
494  * Debug helper to store last value of get_best_size().
495  *
496  * We're mutable so calls can stay const and this is disabled in
497  * production code.
498  */
499  mutable point last_best_size_;
500 
501 #endif
502 
503  /**
504  * The linked group the widget belongs to.
505  *
506  * @todo For now the linked group is initialized when the layout of the
507  * widget is initialized. The best time to set it would be upon adding the
508  * widget in the window. Need to look whether it is possible in a clean way.
509  * Maybe a signal just prior to showing a window where the widget can do
510  * some of it's on things, would also be nice for widgets that need a
511  * finalizer function.
512  */
513  std::string linked_group_;
514 
515 
516  /***** ***** ***** ***** Drawing functions. ***** ***** ***** *****/
517 
518 public:
519  /**
520  * Calculates the blitting rectangle of the widget.
521  *
522  * The blitting rectangle is the entire widget rectangle.
523  *
524  * @returns The drawing rectangle.
525  */
526  SDL_Rect calculate_blitting_rectangle() const;
527 
528  /**
529  * Calculates the clipping rectangle of the widget.
530  *
531  * The clipping rectangle is used then the @ref redraw_action_ is
532  * @ref redraw_action::partly.
533  *
534  * @returns The clipping rectangle.
535  */
536  SDL_Rect calculate_clipping_rectangle() const;
537 
538  /**
539  * Draws the background of a widget.
540  *
541  * Derived should override @ref impl_draw_background instead of changing
542  * this function.
543  *
544  * @returns False if drawing should be deferred.
545  */
546  bool draw_background();
547 
548  /**
549  * Draws the children of a widget.
550  *
551  * Containers should draw their children when they get this request.
552  *
553  * Derived should override @ref impl_draw_children instead of changing
554  * this function.
555  */
556  void draw_children();
557 
558  /**
559  * Draws the foreground of the widget.
560  *
561  * Some widgets e.g. panel and window have a back and foreground layer this
562  * function requests the drawing of the foreground.
563  *
564  * Derived should override @ref impl_draw_foreground instead of changing
565  * this function.
566  *
567  * @returns False if drawing should be deferred.
568  */
569  bool draw_foreground();
570 
571 private:
572  /** See @ref draw_background. */
573  virtual bool impl_draw_background()
574  {
575  return true;
576  }
577 
578  /** See @ref draw_children. */
579  virtual void impl_draw_children()
580  {
581  }
582 
583  /** See @ref draw_foreground. */
584  virtual bool impl_draw_foreground()
585  {
586  return true;
587  }
588 
589 public:
590  /**
591  * Gets the dirty rectangle of the widget.
592  *
593  * Depending on the @ref redraw_action_ it returns the rectangle this
594  * widget dirties while redrawing.
595  *
596  * @returns The dirty rectangle.
597  */
598  SDL_Rect get_dirty_rectangle() const;
599 
600  /**
601  * Sets the visible rectangle for a widget.
602  *
603  * This function sets the @ref redraw_action_ and the
604  * @ref clipping_rectangle_.
605  *
606  * @param rectangle The visible rectangle in screen coordinates.
607  */
608  virtual void set_visible_rectangle(const SDL_Rect& rectangle);
609 
610  /**
611  * Indicates that this widget should be redrawn.
612  *
613  * This function should be called by widgets whenever their visible
614  * state changes.
615  */
616  void queue_redraw();
617 
618  /**
619  * Indicate that specific region of the screen should be redrawn.
620  *
621  * This is in absolute drawing-space coordinates, and not constrained
622  * to the current widget.
623  */
624  void queue_redraw(const rect& region);
625 
626  /*** *** *** *** *** *** Setters and getters. *** *** *** *** *** ***/
627 
628  void set_visible(const visibility visible);
629  visibility get_visible() const;
630 
632 
633  void set_debug_border_mode(const debug_border debug_border_mode);
634 
635  void set_debug_border_color(const color_t debug_border_color);
636 
637  /*** *** *** *** *** *** *** *** Members. *** *** *** *** *** *** *** ***/
638 
639 private:
640  /** Field for the status of the visibility. */
642 
643  /** Field for the action to do on a drawing request. */
645 
646  /** The clipping rectangle if a widget is partly visible. */
648 
649  /**
650  * Mode for drawing the debug border.
651  *
652  * The debug border is a helper border to determine where a widget is
653  * placed. It is only intended for debugging purposes.
654  */
656 
657  /** The color for the debug border. */
659 
660  void draw_debug_border();
661 
662  /***** ***** ***** ***** Query functions ***** ***** ***** *****/
663 
664 public:
665  /**
666  * Returns the widget at the wanted coordinates.
667  *
668  * @param coordinate The coordinate which should be inside the
669  * widget.
670  * @param must_be_active The widget should be active, not all widgets
671  * have an active flag, those who don't ignore
672  * flag.
673  *
674  * @returns The widget with the id.
675  * @retval nullptr No widget at the wanted coordinate found (or
676  * not active if must_be_active was set).
677  */
678  virtual widget* find_at(const point& coordinate,
679  const bool must_be_active);
680 
681  /** The constant version of @ref find_at. */
682  virtual const widget* find_at(const point& coordinate,
683  const bool must_be_active) const;
684 
685  /**
686  * Returns @em a widget with the wanted id.
687  *
688  * @note Since the id might not be unique inside a container there is no
689  * guarantee which widget is returned.
690  *
691  * @param id The id of the widget to find.
692  * @param must_be_active The widget should be active, not all widgets
693  * have an active flag, those who don't ignore
694  * flag.
695  *
696  * @returns The widget with the id.
697  * @retval nullptr No widget with the id found (or not active if
698  * must_be_active was set).
699  */
700  virtual widget* find(const std::string& id, const bool must_be_active);
701 
702  /** The constant version of @ref find. */
703  virtual const widget* find(const std::string& id,
704  const bool must_be_active) const;
705 
706  /**
707  * Does the widget contain the widget.
708  *
709  * Widgets can be containers which have more widgets inside them, this
710  * function will traverse in those child widgets and tries to find the
711  * wanted widget.
712  *
713  * @param widget Pointer to the widget to find.
714  *
715  * @returns Whether or not the @p widget was found.
716  */
717  virtual bool has_widget(const widget& widget) const;
718 
719  /**
720  * Gets a widget with the wanted id.
721  *
722  * This template function doesn't return a pointer to a generic widget but
723  * returns the wanted type and tests for its existence if required.
724  *
725  * @param id The id of the widget to find.
726  * @param must_be_active The widget should be active, not all widgets
727  * have an active flag, those who don't ignore
728  * flag.
729  * @param must_exist The widget should be exist, the function will
730  * fail if the widget doesn't exist or is
731  * inactive and must be active. Upon failure a
732  * wml_error is thrown.
733  *
734  * @returns The widget with the id.
735  */
736  template <class T>
738  const std::string& id,
739  const bool must_be_active,
740  const bool must_exist)
741  {
742  T* result = dynamic_cast<T*>(this->find(id, must_be_active));
743  VALIDATE(!must_exist || result, missing_widget(id));
744 
745  return result;
746  }
747 
748  template <class T>
750  const std::string& id,
751  const bool must_be_active,
752  const bool must_exist) const
753  {
754  T* result = dynamic_cast<T*>(this->find(id, must_be_active));
755  VALIDATE(!must_exist || result, missing_widget(id));
756 
757  return result;
758  }
759 
760  /**
761  * Gets a widget with the wanted id.
762  *
763  * This template function doesn't return a reference to a generic widget but
764  * returns a reference to the wanted type
765  *
766  * @param id The id of the widget to find.
767  * @param must_be_active The widget should be active, not all widgets
768  * have an active flag, those who don't ignore
769  * flag.
770  *
771  * @returns The widget with the id.
772  */
773  template <class T>
775  const std::string& id,
776  const bool must_be_active = false)
777  {
778  return *(this->find_widget<T>(id, must_be_active, true));
779  }
780 
781  template <class T>
783  const std::string& id,
784  const bool must_be_active = false) const
785  {
786  return *(this->find_widget<T>(id, must_be_active, true));
787  }
788 
789 private:
790  /** See @ref event::dispatcher::is_at. */
791  virtual bool is_at(const point& coordinate) const override;
792 
793  /**
794  * Is the coordinate inside our area.
795  *
796  * Helper for find_at so also looks at our visibility.
797  *
798  * @param coordinate The coordinate which should be inside the
799  * widget.
800  * @param must_be_active The widget should be active, not all widgets
801  * have an active flag, those who don't ignore
802  * flag.
803  *
804  * @returns Status.
805  */
806  bool is_at(const point& coordinate, const bool must_be_active) const;
807 
808  /**
809  * Is the widget and every single one of its parents visible?
810  *
811  * @param widget Widget where to start the check.
812  * @param must_be_active The widget should be active, not all widgets
813  * have an active flag, those who don't ignore
814  * flag.
815  *
816  * @returns Status.
817  */
818  bool recursive_is_visible(const widget* widget, const bool must_be_active) const;
819 
820  /***** ***** ***** ***** Miscellaneous ***** ***** ****** *****/
821 
822 public:
823  /** Does the widget disable easy close? */
824  virtual bool disable_click_dismiss() const = 0;
825 
826  /** Creates a new walker object on the heap. */
828 };
829 
830 } // namespace gui2
Base class for event handling.
Definition: dispatcher.hpp:150
Event execution calls.
Base container class.
Definition: grid.hpp:32
Base class for all widgets.
Definition: widget.hpp:55
virtual iteration::walker_ptr create_walker()=0
Creates a new walker object on the heap.
const point & layout_size() const
Definition: widget.cpp:351
virtual void demand_reduce_width(const unsigned maximum_width)
Tries to reduce the width of a widget.
Definition: widget.cpp:188
void set_layout_size(const point &size)
Definition: widget.cpp:346
grid * get_parent_grid()
Get the parent grid.
Definition: widget.cpp:145
NOT_DANGLING const T * find_widget(const std::string &id, const bool must_be_active, const bool must_exist) const
Definition: widget.hpp:749
redraw_action redraw_action_
Field for the action to do on a drawing request.
Definition: widget.hpp:644
bool draw_foreground()
Draws the foreground of the widget.
Definition: widget.cpp:423
point get_best_size() const
Gets the best size for the widget.
Definition: widget.cpp:203
NOT_DANGLING T * find_widget(const std::string &id, const bool must_be_active, const bool must_exist)
Gets a widget with the wanted id.
Definition: widget.hpp:737
void clear_layout_size()
Throws away layout_size_.
Definition: widget.hpp:459
virtual void place(const point &origin, const point &size)
Places the widget.
Definition: widget.cpp:248
debug_border debug_border_mode_
Mode for drawing the debug border.
Definition: widget.hpp:655
void set_visible(const visibility visible)
Definition: widget.cpp:479
virtual bool disable_click_dismiss() const =0
Does the widget disable easy close?
void set_id(const std::string &id)
Definition: widget.cpp:98
int x_
The x-coordinate of the widget on the screen.
Definition: widget.hpp:468
virtual void demand_reduce_height(const unsigned maximum_height)
Tries to reduce the height of a widget.
Definition: widget.cpp:198
virtual void layout_children()
Allows a widget to update its children.
Definition: widget.cpp:306
visibility visible_
Field for the status of the visibility.
Definition: widget.hpp:641
virtual ~widget() override
Definition: widget.cpp:77
rect clipping_rectangle_
The clipping rectangle if a widget is partly visible.
Definition: widget.hpp:647
virtual void layout_initialize(const bool full_initialization)
How the layout engine works.
Definition: widget.cpp:177
SDL_Rect get_dirty_rectangle() const
Gets the dirty rectangle of the widget.
Definition: widget.cpp:445
void set_linked_group(const std::string &linked_group)
Definition: widget.cpp:356
void queue_redraw()
Indicates that this widget should be redrawn.
Definition: widget.cpp:464
widget * parent_
The parent widget.
Definition: widget.hpp:217
visibility get_visible() const
Definition: widget.cpp:506
point get_origin() const
Returns the screen origin of the widget.
Definition: widget.cpp:311
color_t debug_border_color_
The color for the debug border.
Definition: widget.hpp:658
int get_x() const
Definition: widget.cpp:326
virtual bool impl_draw_foreground()
See draw_foreground.
Definition: widget.hpp:584
virtual widget * find(const std::string &id, const bool must_be_active)
Returns a widget with the wanted id.
Definition: widget.cpp:560
virtual bool can_mouse_focus() const
Whether the mouse move/click event go 'through' this widget.
Definition: widget.hpp:334
unsigned width_
The width of the widget.
Definition: widget.hpp:474
unsigned get_width() const
Definition: widget.cpp:336
int get_y() const
Definition: widget.cpp:331
void set_parent(widget *parent)
Definition: widget.cpp:165
virtual point calculate_best_size() const =0
Calculates the best size.
point get_size() const
Returns the size of the widget.
Definition: widget.cpp:316
void draw_children()
Draws the children of a widget.
Definition: widget.cpp:402
virtual void move(const int x_offset, const int y_offset)
Moves a widget.
Definition: widget.cpp:274
bool draw_background()
Draws the background of a widget.
Definition: widget.cpp:381
virtual bool has_widget(const widget &widget) const
Does the widget contain the widget.
Definition: widget.cpp:571
friend class debug_layout_graph
Definition: widget.hpp:56
virtual void set_origin(const point &origin)
Sets the origin of the widget.
Definition: widget.cpp:230
unsigned get_height() const
Definition: widget.cpp:341
const std::string & id() const
Definition: widget.cpp:110
window * get_window()
Get the parent window.
Definition: widget.cpp:117
NOT_DANGLING const T & find_widget(const std::string &id, const bool must_be_active=false) const
Definition: widget.hpp:782
bool recursive_is_visible(const widget *widget, const bool must_be_active) const
Is the widget and every single one of its parents visible?
Definition: widget.cpp:581
virtual bool impl_draw_background()
See draw_background.
Definition: widget.hpp:573
int y_
The y-coordinate of the widget on the screen.
Definition: widget.hpp:471
virtual void set_horizontal_alignment(const std::string &alignment)
Sets the horizontal alignment of the widget within its parent grid.
Definition: widget.cpp:280
std::string id_
The id is the unique name of the widget in a certain context.
Definition: widget.hpp:177
NOT_DANGLING T & find_widget(const std::string &id, const bool must_be_active=false)
Gets a widget with the wanted id.
Definition: widget.hpp:774
visibility
Visibility settings done by the user.
Definition: widget.hpp:65
@ visible
The user sets the widget visible, that means:
@ invisible
The user set the widget invisible, that means:
@ hidden
The user sets the widget hidden, that means:
virtual void request_reduce_width(const unsigned maximum_width)=0
Tries to reduce the width of a widget.
SDL_Rect calculate_blitting_rectangle() const
Calculates the blitting rectangle of the widget.
Definition: widget.cpp:363
SDL_Rect calculate_clipping_rectangle() const
Calculates the clipping rectangle of the widget.
Definition: widget.cpp:368
std::string linked_group_
The linked group the widget belongs to.
Definition: widget.hpp:513
widget(const widget &)=delete
void set_debug_border_mode(const debug_border debug_border_mode)
Definition: widget.cpp:517
redraw_action get_drawing_action() const
Definition: widget.cpp:511
rect get_rectangle() const
Gets the bounding rectangle of the widget on the screen.
Definition: widget.cpp:321
virtual void impl_draw_children()
See draw_children.
Definition: widget.hpp:579
void draw_debug_border()
Definition: widget.cpp:527
point layout_size_
The best size for the widget.
Definition: widget.hpp:489
widget & operator=(const widget &)=delete
@ outline
Single-pixel outline.
@ fill
Flood-filled rectangle.
virtual widget * find_at(const point &coordinate, const bool must_be_active)
Returns the widget at the wanted coordinates.
Definition: widget.cpp:549
void set_debug_border_color(const color_t debug_border_color)
Definition: widget.cpp:522
unsigned height_
The height of the widget.
Definition: widget.hpp:477
virtual void set_size(const point &size)
Sets the size of the widget.
Definition: widget.cpp:236
virtual void request_reduce_height(const unsigned maximum_height)
Tries to reduce the height of a widget.
Definition: widget.cpp:193
virtual bool can_wrap() const
Can the widget wrap.
Definition: widget.cpp:225
virtual bool is_at(const point &coordinate) const override
See event::dispatcher::is_at.
Definition: widget.cpp:576
redraw_action
Visibility set by the engine.
Definition: widget.hpp:103
@ none
The widget is not visible.
@ partly
The widget is partly visible.
@ full
The widget is fully visible.
virtual void set_visible_rectangle(const SDL_Rect &rectangle)
Sets the visible rectangle for a widget.
Definition: widget.cpp:451
widget * parent()
Definition: widget.cpp:170
virtual void set_vertical_alignment(const std::string &alignment)
Sets the horizontal alignment of the widget within its parent grid.
Definition: widget.cpp:293
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:61
#define NOT_DANGLING
Definition: global.hpp:65
void point(int x, int y)
Draw a single point.
Definition: draw.cpp:202
std::unique_ptr< class walker_base > walker_ptr
Definition: widget.hpp:44
Generic file dialog.
t_string missing_widget(const std::string &id)
Returns a default error message if a mandatory widget is omitted.
Definition: helper.cpp:120
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:36
std::map< std::string, t_string > widget_item
Definition: widget.hpp:33
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:85
Contains the SDL_Rect helper code.
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:59
Contains the info needed to instantiate a widget.
Holds a 2D point.
Definition: point.hpp:25
An abstract description of a rectangle with integer coordinates.
Definition: rect.hpp:47
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE(cond, message)
The macro to use for the validation of WML.