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