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