The Battle for Wesnoth  1.19.5+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  std::string get_linked_group() const
465  {
466  return linked_group_;
467  }
468 
469  /*** *** *** *** *** *** *** *** Members. *** *** *** *** *** *** *** ***/
470 
471 private:
472  /** The x-coordinate of the widget on the screen. */
473  int x_;
474 
475  /** The y-coordinate of the widget on the screen. */
476  int y_;
477 
478  /** The width of the widget. */
479  unsigned width_;
480 
481  /** The height of the widget. */
482  unsigned height_;
483 
484  /**
485  * The best size for the widget.
486  *
487  * When 0,0 the real best size is returned, but in the layout phase a
488  * wrapping or a scrollbar might change the best size for that widget.
489  * This variable holds that best value.
490  *
491  * If the widget size hasn't been changed from the default that
492  * calculate_best_size() returns, layout_size_ is (0,0).
493  */
495 
496 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
497 
498  /**
499  * Debug helper to store last value of get_best_size().
500  *
501  * We're mutable so calls can stay const and this is disabled in
502  * production code.
503  */
504  mutable point last_best_size_;
505 
506 #endif
507 
508  /**
509  * The linked group the widget belongs to.
510  *
511  * @todo For now the linked group is initialized when the layout of the
512  * widget is initialized. The best time to set it would be upon adding the
513  * widget in the window. Need to look whether it is possible in a clean way.
514  * Maybe a signal just prior to showing a window where the widget can do
515  * some of it's on things, would also be nice for widgets that need a
516  * finalizer function.
517  */
518  std::string linked_group_;
519 
520 
521  /***** ***** ***** ***** Drawing functions. ***** ***** ***** *****/
522 
523 public:
524  /**
525  * Calculates the blitting rectangle of the widget.
526  *
527  * The blitting rectangle is the entire widget rectangle.
528  *
529  * @returns The drawing rectangle.
530  */
531  SDL_Rect calculate_blitting_rectangle() const;
532 
533  /**
534  * Calculates the clipping rectangle of the widget.
535  *
536  * The clipping rectangle is used then the @ref redraw_action_ is
537  * @ref redraw_action::partly.
538  *
539  * @returns The clipping rectangle.
540  */
541  SDL_Rect calculate_clipping_rectangle() const;
542 
543  /**
544  * Draws the background of a widget.
545  *
546  * Derived should override @ref impl_draw_background instead of changing
547  * this function.
548  *
549  * @returns False if drawing should be deferred.
550  */
551  bool draw_background();
552 
553  /**
554  * Draws the children of a widget.
555  *
556  * Containers should draw their children when they get this request.
557  *
558  * Derived should override @ref impl_draw_children instead of changing
559  * this function.
560  */
561  void draw_children();
562 
563  /**
564  * Draws the foreground of the widget.
565  *
566  * Some widgets e.g. panel and window have a back and foreground layer this
567  * function requests the drawing of the foreground.
568  *
569  * Derived should override @ref impl_draw_foreground instead of changing
570  * this function.
571  *
572  * @returns False if drawing should be deferred.
573  */
574  bool draw_foreground();
575 
576 private:
577  /** See @ref draw_background. */
578  virtual bool impl_draw_background()
579  {
580  return true;
581  }
582 
583  /** See @ref draw_children. */
584  virtual void impl_draw_children()
585  {
586  }
587 
588  /** See @ref draw_foreground. */
589  virtual bool impl_draw_foreground()
590  {
591  return true;
592  }
593 
594 public:
595  /**
596  * Gets the dirty rectangle of the widget.
597  *
598  * Depending on the @ref redraw_action_ it returns the rectangle this
599  * widget dirties while redrawing.
600  *
601  * @returns The dirty rectangle.
602  */
603  SDL_Rect get_dirty_rectangle() const;
604 
605  /**
606  * Sets the visible rectangle for a widget.
607  *
608  * This function sets the @ref redraw_action_ and the
609  * @ref clipping_rectangle_.
610  *
611  * @param rectangle The visible rectangle in screen coordinates.
612  */
613  virtual void set_visible_rectangle(const SDL_Rect& rectangle);
614 
615  /**
616  * Indicates that this widget should be redrawn.
617  *
618  * This function should be called by widgets whenever their visible
619  * state changes.
620  */
621  void queue_redraw();
622 
623  /**
624  * Indicate that specific region of the screen should be redrawn.
625  *
626  * This is in absolute drawing-space coordinates, and not constrained
627  * to the current widget.
628  */
629  void queue_redraw(const rect& region);
630 
631  /*** *** *** *** *** *** Setters and getters. *** *** *** *** *** ***/
632 
633  void set_visible(const visibility visible);
634  visibility get_visible() const;
635 
637 
638  void set_debug_border_mode(const debug_border debug_border_mode);
639 
640  void set_debug_border_color(const color_t debug_border_color);
641 
642  /*** *** *** *** *** *** *** *** Members. *** *** *** *** *** *** *** ***/
643 
644 private:
645  /** Field for the status of the visibility. */
647 
648  /** Field for the action to do on a drawing request. */
650 
651  /** The clipping rectangle if a widget is partly visible. */
653 
654  /**
655  * Mode for drawing the debug border.
656  *
657  * The debug border is a helper border to determine where a widget is
658  * placed. It is only intended for debugging purposes.
659  */
661 
662  /** The color for the debug border. */
664 
665  void draw_debug_border();
666 
667  /***** ***** ***** ***** Query functions ***** ***** ***** *****/
668 
669 public:
670  /**
671  * Returns the widget at the wanted coordinates.
672  *
673  * @param coordinate The coordinate which should be inside the
674  * widget.
675  * @param must_be_active The widget should be active, not all widgets
676  * have an active flag, those who don't ignore
677  * flag.
678  *
679  * @returns The widget with the id.
680  * @retval nullptr No widget at the wanted coordinate found (or
681  * not active if must_be_active was set).
682  */
683  virtual widget* find_at(const point& coordinate,
684  const bool must_be_active);
685 
686  /** The constant version of @ref find_at. */
687  virtual const widget* find_at(const point& coordinate,
688  const bool must_be_active) const;
689 
690  /**
691  * Returns @em a widget with the wanted id.
692  *
693  * @note Since the id might not be unique inside a container there is no
694  * guarantee which widget is returned.
695  *
696  * @param id The id of the widget to find.
697  * @param must_be_active The widget should be active, not all widgets
698  * have an active flag, those who don't ignore
699  * flag.
700  *
701  * @returns The widget with the id.
702  * @retval nullptr No widget with the id found (or not active if
703  * must_be_active was set).
704  */
705  virtual widget* find(const std::string& id, const bool must_be_active);
706 
707  /** The constant version of @ref find. */
708  virtual const widget* find(const std::string& id,
709  const bool must_be_active) const;
710 
711  /**
712  * Does the widget contain the widget.
713  *
714  * Widgets can be containers which have more widgets inside them, this
715  * function will traverse in those child widgets and tries to find the
716  * wanted widget.
717  *
718  * @param widget Pointer to the widget to find.
719  *
720  * @returns Whether or not the @p widget was found.
721  */
722  virtual bool has_widget(const widget& widget) const;
723 
724  /**
725  * Gets a widget with the wanted id.
726  *
727  * This template function doesn't return a pointer to a generic widget but
728  * returns the wanted type and tests for its existence if required.
729  *
730  * @param id The id of the widget to find.
731  * @param must_be_active The widget should be active, not all widgets
732  * have an active flag, those who don't ignore
733  * flag.
734  * @param must_exist The widget should be exist, the function will
735  * fail if the widget doesn't exist or is
736  * inactive and must be active. Upon failure a
737  * wml_error is thrown.
738  *
739  * @returns The widget with the id.
740  */
741  template <class T>
743  const std::string& id,
744  const bool must_be_active,
745  const bool must_exist)
746  {
747  T* result = dynamic_cast<T*>(this->find(id, must_be_active));
748  VALIDATE(!must_exist || result, missing_widget(id));
749 
750  return result;
751  }
752 
753  template <class T>
755  const std::string& id,
756  const bool must_be_active,
757  const bool must_exist) const
758  {
759  T* result = dynamic_cast<T*>(this->find(id, must_be_active));
760  VALIDATE(!must_exist || result, missing_widget(id));
761 
762  return result;
763  }
764 
765  /**
766  * Gets a widget with the wanted id.
767  *
768  * This template function doesn't return a reference to a generic widget but
769  * returns a reference to the wanted type
770  *
771  * @param id The id of the widget to find.
772  * @param must_be_active The widget should be active, not all widgets
773  * have an active flag, those who don't ignore
774  * flag.
775  *
776  * @returns The widget with the id.
777  */
778  template <class T>
780  const std::string& id,
781  const bool must_be_active = false)
782  {
783  return *(this->find_widget<T>(id, must_be_active, true));
784  }
785 
786  template <class T>
788  const std::string& id,
789  const bool must_be_active = false) const
790  {
791  return *(this->find_widget<T>(id, must_be_active, true));
792  }
793 
794 private:
795  /** See @ref event::dispatcher::is_at. */
796  virtual bool is_at(const point& coordinate) const override;
797 
798  /**
799  * Is the coordinate inside our area.
800  *
801  * Helper for find_at so also looks at our visibility.
802  *
803  * @param coordinate The coordinate which should be inside the
804  * widget.
805  * @param must_be_active The widget should be active, not all widgets
806  * have an active flag, those who don't ignore
807  * flag.
808  *
809  * @returns Status.
810  */
811  bool is_at(const point& coordinate, const bool must_be_active) const;
812 
813  /**
814  * Is the widget and every single one of its parents visible?
815  *
816  * @param widget Widget where to start the check.
817  * @param must_be_active The widget should be active, not all widgets
818  * have an active flag, those who don't ignore
819  * flag.
820  *
821  * @returns Status.
822  */
823  bool recursive_is_visible(const widget* widget, const bool must_be_active) const;
824 
825  /***** ***** ***** ***** Miscellaneous ***** ***** ****** *****/
826 
827 public:
828  /** Does the widget disable easy close? */
829  virtual bool disable_click_dismiss() const = 0;
830 
831  /** Creates a new walker object on the heap. */
833 };
834 
835 } // 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:754
redraw_action redraw_action_
Field for the action to do on a drawing request.
Definition: widget.hpp:649
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:742
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:660
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:473
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:646
virtual ~widget() override
Definition: widget.cpp:77
rect clipping_rectangle_
The clipping rectangle if a widget is partly visible.
Definition: widget.hpp:652
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:663
int get_x() const
Definition: widget.cpp:326
virtual bool impl_draw_foreground()
See draw_foreground.
Definition: widget.hpp:589
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:479
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:787
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:578
int y_
The y-coordinate of the widget on the screen.
Definition: widget.hpp:476
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:779
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:518
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:584
void draw_debug_border()
Definition: widget.cpp:527
point layout_size_
The best size for the widget.
Definition: widget.hpp:494
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:482
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
std::string get_linked_group() const
Definition: widget.hpp:464
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.