The Battle for Wesnoth  1.19.8+dev
window.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 /**
17  * @file
18  * This file contains the window object, this object is a top level container
19  * which has the event management as well.
20  */
21 
22 #pragma once
23 
24 #include "formula/callable.hpp"
25 #include "formula/function.hpp"
29 #include "gui/widgets/panel.hpp"
30 #include "gui/widgets/retval.hpp"
31 
32 #include "sdl/texture.hpp"
33 
34 #include <functional>
35 #include <map>
36 #include <memory>
37 #include <string>
38 #include <vector>
39 
40 
41 namespace gui2
42 {
43 
44 class widget;
45 namespace event { struct message; }
46 
47 // ------------ WIDGET -----------{
48 
49 namespace dialogs { class modal_dialog; }
50 
51 namespace event
52 {
53 class distributor;
54 } // namespace event
55 
56 /**
57  * base class of top level items, the only item which needs to store the final canvases to draw on.
58  * A window is a kind of panel see the panel for which fields exist.
59  */
60 class window : public panel, public top_level_drawable
61 {
62  friend class debug_layout_graph;
63  friend struct window_implementation;
65  friend class pane;
66 
67 public:
68  explicit window(const builder_window::window_resolution& definition);
69 
70  virtual ~window();
71 
72  /**
73  * Returns the instance of a window.
74  *
75  * @param handle The instance id of the window.
76  *
77  * @returns The window or nullptr.
78  */
79  static window* window_instance(const unsigned handle);
80 
81  /** Gets the retval for the default buttons. */
82  static retval get_retval_by_id(const std::string& id);
83 
84  /**
85  * Shows the window, running an event loop until it should close.
86  *
87  * @param auto_close_timeout The time in ms after which the window will
88  * automatically close, if 0 it doesn't close.
89  * @note the timeout is a minimum time and
90  * there's no guarantee about how fast it closes
91  * after the minimum.
92  *
93  * @returns The close code of the window, predefined
94  * values are listed in retval.
95  */
96  int show(unsigned auto_close_timeout = 0);
97 
98  /**
99  * Shows the window as a tooltip.
100  *
101  * A tooltip can't be interacted with and is just shown.
102  *
103  * @todo implement @p auto_close_timeout.
104  *
105  * @p auto_close_timeout The time in ms after which the window will
106  * automatically close, if 0 it doesn't close.
107  * @note the timeout is a minimum time and
108  * there's no guarantee about how fast it closes
109  * after the minimum.
110  */
111  void show_tooltip(/*const unsigned auto_close_timeout = 0*/);
112 
113  /**
114  * Shows the window non modal.
115  *
116  * A tooltip can be interacted with unlike the tooltip.
117  *
118  * @todo implement @p auto_close_timeout.
119  *
120  * @p auto_close_timeout The time in ms after which the window will
121  * automatically close, if 0 it doesn't close.
122  * @note the timeout is a minimum time and
123  * there's no guarantee about how fast it closes
124  * after the minimum.
125  */
126  void show_non_modal(/*const unsigned auto_close_timeout = 0*/);
127 
128  /**
129  * Draws the window.
130  *
131  * This routine draws the window if needed, it's called from the event
132  * handler. This is done by a drawing event. When a window is shown it
133  * manages an SDL timer which fires a drawing event every X milliseconds,
134  * that event calls this routine. Don't call it manually.
135  */
136  void draw();
137 
138  /** Hides the window. It will not draw until it is shown again. */
139  void hide();
140 
141  /**
142  * Lays out the window.
143  *
144  * This part does the pre and post processing for the actual layout
145  * algorithm.
146  *
147  * See @ref layout_algorithm for more information.
148  *
149  * This is also called by draw_manager to finalize screen layout.
150  */
151  virtual void layout() override;
152 
153  /** Ensure the window's internal render buffer is up-to-date.
154  *
155  * This renders the window to an off-screen texture, which is then
156  * copied to the screen during expose().
157  */
158  virtual void render() override;
159 
160 private:
161  /** The internal render buffer used by render() and expose(). */
163 
164  /** The part of the window (if any) currently marked for rerender. */
166 
167  /** Parts of the window (if any) with rendering deferred to next frame */
168  std::vector<rect> deferred_regions_;
169 
170  /** Ensure render textures are valid and correct. */
171  void update_render_textures();
172 
173 public:
174  /**
175  * Called by draw_manager when it believes a redraw is necessary.
176  * Can be called multiple times per vsync.
177  */
178  virtual bool expose(const rect& region) override;
179 
180  /** The current draw location of the window, on the screen. */
181  virtual rect screen_location() override;
182 
183  /**
184  * Queue a rerender of the internal render buffer.
185  *
186  * This does not request a repaint. Ordinarily use queue_redraw()
187  * on a widget, which will call this automatically.
188  *
189  * @param region The region to rerender in screen coordinates.
190  */
191  void queue_rerender(const rect& region);
192  void queue_rerender();
193 
194  /**
195  * Defer rendering of a particular region to next frame.
196  *
197  * This is used for blur, which must render the region underneath once
198  * before rendering the blur.
199  *
200  * @param region The region to defer in screen coordinates.
201  */
202  void defer_region(const rect& region);
203 
204  /** The status of the window. */
205  enum class status {
206  NEW, /**< The window is new and not yet shown. */
207  SHOWING, /**< The window is being shown. */
208  REQUEST_CLOSE, /**< The window has been requested to be closed but still needs to evaluate the request. */
209  CLOSED /**< The window has been closed. */
210  };
211 
212  /**
213  * Requests to close the window.
214  *
215  * This request is not always honored immediately, and so callers must account for the window remaining open.
216  * For example, when overriding draw_manager's update() method.
217  */
218  void close()
219  {
221  }
222 
223  /**
224  * Helper class to block invalidate_layout.
225  *
226  * Some widgets can handling certain layout aspects without help. For
227  * example a listbox can handle hiding and showing rows without help but
228  * setting the visibility calls invalidate_layout(). When this blocker is
229  * Instantiated the call to invalidate_layout() becomes a nop.
230  *
231  * @note The class can't be used recursively.
232  */
234  {
235  public:
238 
239  private:
241  };
242 
243  /** Is invalidate_layout blocked, see invalidate_layout_blocker. */
245  {
247  }
248 
249  /**
250  * Updates the size of the window.
251  *
252  * If the window has automatic placement set this function recalculates the
253  * window. To be used after creation and after modification or items which
254  * can have different sizes eg listboxes.
255  */
256  void invalidate_layout();
257 
258  /** See @ref widget::find_at. */
259  virtual widget* find_at(const point& coordinate,
260  const bool must_be_active) override;
261 
262  /** See @ref widget::find_at. */
263  virtual const widget* find_at(const point& coordinate,
264  const bool must_be_active) const override;
265 
266  /** Inherited from widget. */
268  {
269  return owner_;
270  }
271 
272  /** See @ref widget::find. */
273  widget* find(const std::string_view id, const bool must_be_active) override;
274 
275  /** See @ref widget::find. */
276  const widget* find(const std::string_view id, const bool must_be_active) const override;
277 
278 #if 0
279  /** @todo Implement these functions. */
280  /**
281  * Register a widget that prevents easy closing.
282  *
283  * Duplicate registration are ignored. See click_dismiss_ for more info.
284  *
285  * @param id The id of the widget to register.
286  */
287  void add_click_dismiss_blocker(const std::string& id);
288 
289  /**
290  * Unregister a widget the prevents easy closing.
291  *
292  * Removing a non registered id is allowed but will do nothing. See
293  * click_dismiss_ for more info.
294  *
295  * @param id The id of the widget to register.
296  */
297  void remove_click_dismiss_blocker(const std::string& id);
298 #endif
299 
300  /**
301  * Does the window close easily?
302  *
303  * The behavior can change at run-time, but that might cause oddities
304  * with the easy close button (when one is needed).
305  *
306  * @returns Whether or not the window closes easily.
307  */
308  bool does_click_dismiss() const
309  {
311  }
312 
313  /**
314  * Disable the enter key.
315  *
316  * This is added to block dialogs from being closed automatically.
317  *
318  * @todo this function should be merged with the hotkey support once
319  * that has been added.
320  */
321  void set_enter_disabled(const bool enter_disabled)
322  {
323  enter_disabled_ = enter_disabled;
324  }
325 
326  /**
327  * Disable the escape key.
328  *
329  * This is added to block dialogs from being closed automatically.
330  *
331  * @todo this function should be merged with the hotkey support once
332  * that has been added.
333  */
334  void set_escape_disabled(const bool escape_disabled)
335  {
336  escape_disabled_ = escape_disabled;
337  }
338 
339  /**
340  * Initializes a linked size group.
341  *
342  * Note at least one of fixed_width or fixed_height must be true.
343  *
344  * @param id The id of the group.
345  * @param fixed_width Does the group have a fixed width?
346  * @param fixed_height Does the group have a fixed height?
347  *
348  * @returns True if successful, false otherwise.
349  */
350  bool init_linked_size_group(const std::string& id,
351  const bool fixed_width,
352  const bool fixed_height);
353 
354  /**
355  * Is the linked size group defined for this window?
356  *
357  * @param id The id of the group.
358  *
359  * @returns True if defined, false otherwise.
360  */
361  bool has_linked_size_group(const std::string& id);
362 
363  /**
364  * Adds a widget to a linked size group.
365  *
366  * The group needs to exist, which is done by calling
367  * init_linked_size_group. A widget may only be member of one group.
368  * @todo Untested if a new widget is added after showing the widgets.
369  *
370  * @param id The id of the group.
371  * @param widget The widget to add to the group.
372  */
373  void add_linked_widget(const std::string& id, widget* widget);
374 
375  /**
376  * Removes a widget from a linked size group.
377  *
378  * The group needs to exist, which is done by calling
379  * init_linked_size_group. If the widget is no member of the group the
380  * function does nothing.
381  *
382  * @param id The id of the group.
383  * @param widget The widget to remove from the group.
384  */
385  void remove_linked_widget(const std::string& id, const widget* widget);
386 
387  /***** ***** ***** setters / getters for members ***** ****** *****/
388 
389  /**
390  * Sets there return value of the window.
391  *
392  * @param retval The return value for the window.
393  * @param close_window Close the window after setting the value.
394  */
395  void set_retval(const int retval, const bool close_window = true)
396  {
397  retval_ = retval;
398  if(close_window)
399  close();
400  }
401 
403  {
404  return retval_;
405  }
406 
408  {
409  owner_ = owner;
410  }
411 
413  {
415  }
416 
417  bool get_need_layout() const
418  {
419  return need_layout_;
420  }
421 
422  void set_variable(const std::string& key, const wfl::variant& value)
423  {
424  variables_.add(key, value);
425  queue_redraw();
426  }
427 
428  point get_linked_size(std::string_view group_id) const
429  {
430  if(auto it = linked_size_.find(group_id); it != linked_size_.end()) {
431  return { it->second.width, it->second.height };
432  } else {
433  return { -1, -1 };
434  }
435  }
436 
437  enum class exit_hook {
438  always,
439  ok_only,
440  };
441 
442  /**
443  * Sets the window's exit hook.
444  *
445  * A window will only close if the given function returns true under the specified mode.
446  */
447  template<typename Func>
448  void set_exit_hook(exit_hook mode, const Func& hook)
449  {
450  switch(mode) {
451  case exit_hook::always:
452  exit_hook_ = hook;
453  break;
454 
455  case exit_hook::ok_only:
456  exit_hook_ = [this, hook] { return get_retval() != OK || hook(); };
457  break;
458 
459  default:
460  break;
461  }
462  }
463 
464  enum class show_mode {
465  none,
466  modal,
467  modeless,
468  tooltip
469  };
470 
471 private:
472  /** The status of the window. */
474 
475  /**
476  * The mode in which the window is shown.
477  *
478  * This is used to determine whether or not to remove the tip.
479  */
481 
482  // return value of the window, 0 default.
483  int retval_;
484 
485  /** The dialog that owns the window. */
487 
488  /**
489  * When set the form needs a full layout redraw cycle.
490  *
491  * This happens when either a widget changes it's size or visibility or
492  * the window is resized.
493  */
495 
496  /** The variables of the canvas. */
498 
499  /** Is invalidate_layout blocked, see invalidate_layout_blocker. */
501 
502  /** Avoid drawing the window. */
503  bool hidden_;
504 
505  /** Do we wish to place the widget automatically? */
507 
508  /**
509  * Sets the horizontal placement.
510  *
511  * Only used if automatic_placement_ is true.
512  * The value should be a grid placement flag.
513  */
514  const unsigned horizontal_placement_;
515 
516  /**
517  * Sets the vertical placement.
518  *
519  * Only used if automatic_placement_ is true.
520  * The value should be a grid placement flag.
521  */
522  const unsigned vertical_placement_;
523 
524  /** The maximum width if automatic_placement_ is true. */
526 
527  /** The maximum height if automatic_placement_ is true. */
529 
530  /** The formula to calculate the x value of the dialog. */
532 
533  /** The formula to calculate the y value of the dialog. */
535 
536  /** The formula to calculate the width of the dialog. */
538 
539  /** The formula to calculate the height of the dialog. */
541 
542  /** The formula to determine whether the size is good. */
544 
545  /** The formula definitions available for the calculation formulas. */
547 
548  /** The settings for the tooltip. */
550 
551  /** The settings for the helptip. */
553 
554  /**
555  * Do we want to have easy close behavior?
556  *
557  * Easy closing means that whenever a mouse click is done the dialog will
558  * be closed. The widgets in the window may override this behavior by
559  * registering themselves as blockers. This is tested by the function
560  * disable_click_dismiss().
561  *
562  * The handling of easy close is done in the window, in order to do so a
563  * window either needs a click_dismiss or an ok button. Both will be hidden
564  * when not needed and when needed first the ok is tried and then the
565  * click_dismiss button. this allows adding a click_dismiss button to the
566  * window definition and use the ok from the window instance.
567  *
568  * @todo After testing the click dismiss feature it should be documented in
569  * the wiki.
570  */
572 
573  /** Disable the enter key see our setter for more info. */
575 
576  /** Disable the escape key see our setter for more info. */
578 
579  /**
580  * Helper struct to force widgets the have the same size.
581  *
582  * Widget which are linked will get the same width and/or height. This
583  * can especially be useful for listboxes, but can also be used for other
584  * applications.
585  */
586  struct linked_size
587  {
588  linked_size(const bool width = false, const bool height = false)
589  : widgets(), width(width ? 0 : -1), height(height ? 0 : -1)
590  {
591  }
592 
593  /** The widgets linked. */
594  std::vector<widget*> widgets;
595 
596  /** The current width of all widgets in the group, -1 if the width is not linked. */
597  int width;
598 
599  /** The current height of all widgets in the group, -1 if the height is not linked. */
600  int height;
601  };
602 
603  /** List of the widgets, whose size are linked together. */
604  std::map<std::string, linked_size, std::less<>> linked_size_;
605 
606  /** List of widgets in the tabbing order. */
607  std::vector<widget*> tab_order;
608 
609  /**
610  * Layouts the linked widgets.
611  *
612  * See @ref layout_algorithm for more information.
613  */
614  void layout_linked_widgets();
615 
616  /**
617  * Handles a mouse click event for dismissing the dialog.
618  *
619  * @param mouse_button_mask The SDL_BUTTON mask for the button used to
620  * dismiss the click. If the caller is from the
621  * keyboard code the value should be 0.
622  *
623  * @return Whether the event should be considered as
624  * handled.
625  */
626  bool click_dismiss(const int mouse_button_mask);
627 
628  /**
629  * The state of the mouse button.
630  *
631  * When click dismissing a dialog in the past the DOWN event was used.
632  * This lead to a bug [1]. The obvious change was to switch to the UP
633  * event, this lead to another bug; the dialog was directly dismissed.
634  * Since the game map code uses the UP and DOWN event to select a unit
635  * there is no simple solution.
636  *
637  * Upon entry this value stores the mouse button state at entry. When a
638  * button is DOWN and goes UP that button does \em not trigger a dismissal
639  * of the dialog, instead that button's down state is removed from this
640  * variable. Therefore the next UP event does dismiss the dialog.
641  *
642  * [1] https://gna.org/bugs/index.php?18970
643  */
645 
646 public:
647  /** Static type getter that does not rely on the widget being constructed. */
648  static const std::string& type();
649 
650 private:
651  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
652  virtual const std::string& get_control_type() const override;
653 
654  /**
655  * In how many consecutive frames the window has changed. This is used to
656  * detect the situation where the title screen changes in every frame,
657  * forcing all other windows to redraw everything all the time.
658  */
659  unsigned int consecutive_changed_frames_ = 0u;
660 
661  /** Schedules windows on top of us (if any) to redraw. */
662  void redraw_windows_on_top() const;
663 
664  /**
665  * Finishes the initialization of the grid.
666  *
667  * @param content_grid The new contents for the content grid.
668  */
669  void finalize(const builder_grid& content_grid);
670 
671 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
672  std::unique_ptr<debug_layout_graph> debug_layout_;
673 
674 public:
675  /** wrapper for debug_layout_graph::generate_dot_file. */
676  void generate_dot_file(const std::string& generator, const unsigned domain);
677 
678 private:
679 #else
680  void generate_dot_file(const std::string&, const unsigned)
681  {
682  }
683 #endif
684 
685  std::unique_ptr<event::distributor> event_distributor_;
686 
687 public:
688  /** Gets a reference to the window's distributor to allow some state peeking. */
690  {
691  return *event_distributor_;
692  }
693 
694  /** Returns the dialog mode for this window. */
695  show_mode mode() const
696  {
697  return show_mode_;
698  }
699 
700  // mouse and keyboard_capture should be renamed and stored in the
701  // dispatcher. Chaining probably should remain exclusive to windows.
702  void mouse_capture(const bool capture = true);
704 
705  /**
706  * Adds the widget to the keyboard chain.
707  *
708  * @todo rename to keyboard_add_to_chain.
709  * @param widget The widget to add to the chain. The widget
710  * should be valid widget, which hasn't been
711  * added to the chain yet.
712  */
714 
715  /**
716  * Remove the widget from the keyboard chain.
717  *
718  * @todo rename to keyboard_remove_from_chain.
719  *
720  * @param widget The widget to be removed from the chain.
721  */
723 
724  /**
725  * Add the widget to the tabbing order
726  * @param widget The widget to be added to the tabbing order
727  * @param at A hint for where to place the widget in the tabbing order
728  */
729  void add_to_tab_order(widget* widget, int at = -1);
730 
731 private:
732  /***** ***** ***** signal handlers ***** ****** *****/
733 
735  bool& handled,
736  const point& new_size);
737 
738  /**
739  * The handler for the click dismiss mouse 'event'.
740  *
741  * @param event See @ref event::dispatcher::fire.
742  * @param handled See @ref event::dispatcher::fire.
743  * @param halt See @ref event::dispatcher::fire.
744  * @param mouse_button_mask Forwared to @ref click_dismiss.
745  */
747  bool& handled,
748  bool& halt,
749  const int mouse_button_mask);
750 
752  bool& handled,
753  const SDL_Keycode key,
754  const SDL_Keymod mod,
755  bool handle_tab);
756 
758  bool& handled,
759  const event::message& message);
760 
762  bool& handled,
763  const event::message& message);
764 
766  bool& handled);
767 
769 
770  std::function<bool()> exit_hook_;
771 };
772 
773 // }---------- DEFINITION ---------{
774 
776 {
777  explicit window_definition(const config& cfg);
778 
780  {
781  explicit resolution(const config& cfg);
782 
784  };
785 };
786 
787 // }------------ END --------------
788 
789 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:158
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
Main class to show messages to the user.
Definition: message.hpp:36
Abstract base class for all modal dialogs.
At the moment two kinds of tips are known:
Definition: tooltip.cpp:41
The event handler class for the widget library.
Basic template class to generate new items.
A pane is a container where new members can be added and removed during run-time.
Definition: pane.hpp:41
A top-level drawable item (TLD), such as a window.
Base class for all widgets.
Definition: widget.hpp:55
void queue_redraw()
Indicates that this widget should be redrawn.
Definition: widget.cpp:464
friend class window
Definition: widget.hpp:57
Helper class to block invalidate_layout.
Definition: window.hpp:234
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:61
void set_enter_disabled(const bool enter_disabled)
Disable the enter key.
Definition: window.hpp:321
bool need_layout_
When set the form needs a full layout redraw cycle.
Definition: window.hpp:494
void set_retval(const int retval, const bool close_window=true)
Sets there return value of the window.
Definition: window.hpp:395
show_mode mode() const
Returns the dialog mode for this window.
Definition: window.hpp:695
const unsigned vertical_placement_
Sets the vertical placement.
Definition: window.hpp:522
bool invalidate_layout_blocked_
Is invalidate_layout blocked, see invalidate_layout_blocker.
Definition: window.hpp:500
typed_formula< bool > reevaluate_best_size_
The formula to determine whether the size is good.
Definition: window.hpp:543
typed_formula< unsigned > maximum_width_
The maximum width if automatic_placement_ is true.
Definition: window.hpp:525
void remove_from_keyboard_chain(widget *widget)
Remove the widget from the keyboard chain.
Definition: window.cpp:1205
void keyboard_capture(widget *widget)
Definition: window.cpp:1193
void invalidate_layout()
Updates the size of the window.
Definition: window.cpp:752
void add_to_keyboard_chain(widget *widget)
Adds the widget to the keyboard chain.
Definition: window.cpp:1199
void signal_handler_message_show_tooltip(const event::ui_event event, bool &handled, const event::message &message)
Definition: window.cpp:1327
void mouse_capture(const bool capture=true)
Definition: window.cpp:1187
typed_formula< unsigned > maximum_height_
The maximum height if automatic_placement_ is true.
Definition: window.hpp:528
virtual rect screen_location() override
The current draw location of the window, on the screen.
Definition: window.cpp:731
void update_render_textures()
Ensure render textures are valid and correct.
Definition: window.cpp:634
void show_tooltip()
Shows the window as a tooltip.
Definition: window.cpp:423
int mouse_button_state_
The state of the mouse button.
Definition: window.hpp:644
point get_linked_size(std::string_view group_id) const
Definition: window.hpp:428
void hide()
Hides the window.
Definition: window.cpp:618
void show_non_modal()
Shows the window non modal.
Definition: window.cpp:455
std::unique_ptr< event::distributor > event_distributor_
Definition: window.hpp:685
void signal_handler_sdl_video_resize(const event::ui_event event, bool &handled, const point &new_size)
Definition: window.cpp:1227
virtual ~window()
Definition: window.cpp:371
unsigned int consecutive_changed_frames_
In how many consecutive frames the window has changed.
Definition: window.hpp:659
std::map< std::string, linked_size, std::less<> > linked_size_
List of the widgets, whose size are linked together.
Definition: window.hpp:604
static window * window_instance(const unsigned handle)
Returns the instance of a window.
Definition: window.cpp:405
void close()
Requests to close the window.
Definition: window.hpp:218
status
The status of the window.
Definition: window.hpp:205
@ CLOSED
The window has been closed.
@ NEW
The window is new and not yet shown.
@ SHOWING
The window is being shown.
@ REQUEST_CLOSE
The window has been requested to be closed but still needs to evaluate the request.
builder_window::window_resolution::tooltip_info tooltip_
The settings for the tooltip.
Definition: window.hpp:549
bool invalidate_layout_blocked() const
Is invalidate_layout blocked, see invalidate_layout_blocker.
Definition: window.hpp:244
void signal_handler_sdl_key_down(const event::ui_event event, bool &handled, const SDL_Keycode key, const SDL_Keymod mod, bool handle_tab)
Definition: window.cpp:1261
virtual void layout() override
Lays out the window.
Definition: window.cpp:824
void signal_handler_message_show_helptip(const event::ui_event event, bool &handled, const event::message &message)
Definition: window.cpp:1341
dialogs::modal_dialog * dialog()
Inherited from widget.
Definition: window.hpp:267
void layout_linked_widgets()
Layouts the linked widgets.
Definition: window.cpp:1024
show_mode show_mode_
The mode in which the window is shown.
Definition: window.hpp:480
std::vector< widget * > tab_order
List of widgets in the tabbing order.
Definition: window.hpp:607
typed_formula< unsigned > h_
The formula to calculate the height of the dialog.
Definition: window.hpp:540
widget * find(const std::string_view id, const bool must_be_active) override
See widget::find.
Definition: window.cpp:769
int show(unsigned auto_close_timeout=0)
Shows the window, running an event loop until it should close.
Definition: window.cpp:489
rect awaiting_rerender_
The part of the window (if any) currently marked for rerender.
Definition: window.hpp:165
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
void signal_handler_request_placement(const event::ui_event event, bool &handled)
Definition: window.cpp:1355
friend class debug_layout_graph
Definition: window.hpp:62
bool escape_disabled_
Disable the escape key see our setter for more info.
Definition: window.hpp:577
bool does_click_dismiss() const
Does the window close easily?
Definition: window.hpp:308
void signal_handler_close_window()
Definition: window.cpp:1365
bool click_dismiss_
Do we want to have easy close behavior?
Definition: window.hpp:571
void redraw_windows_on_top() const
Schedules windows on top of us (if any) to redraw.
void set_escape_disabled(const bool escape_disabled)
Disable the escape key.
Definition: window.hpp:334
void add_linked_widget(const std::string &id, widget *widget)
Adds a widget to a linked size group.
Definition: window.cpp:792
void defer_region(const rect &region)
Defer rendering of a particular region to next frame.
Definition: window.cpp:682
const unsigned horizontal_placement_
Sets the horizontal placement.
Definition: window.hpp:514
void queue_rerender()
Definition: window.cpp:668
static retval get_retval_by_id(const std::string &id)
Gets the retval for the default buttons.
Definition: window.cpp:410
bool get_need_layout() const
Definition: window.hpp:417
void set_click_dismiss(const bool click_dismiss)
Definition: window.hpp:412
void add_to_tab_order(widget *widget, int at=-1)
Add the widget to the tabbing order.
Definition: window.cpp:1211
const bool automatic_placement_
Do we wish to place the widget automatically?
Definition: window.hpp:506
void finalize(const builder_grid &content_grid)
Finishes the initialization of the grid.
Definition: window.cpp:1083
void set_exit_hook(exit_hook mode, const Func &hook)
Sets the window's exit hook.
Definition: window.hpp:448
int get_retval()
Definition: window.hpp:402
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
builder_window::window_resolution::tooltip_info helptip_
The settings for the helptip.
Definition: window.hpp:552
std::function< bool()> exit_hook_
Definition: window.hpp:770
std::vector< rect > deferred_regions_
Parts of the window (if any) with rendering deferred to next frame.
Definition: window.hpp:168
bool hidden_
Avoid drawing the window.
Definition: window.hpp:503
bool click_dismiss(const int mouse_button_mask)
Handles a mouse click event for dismissing the dialog.
Definition: window.cpp:1070
typed_formula< unsigned > x_
The formula to calculate the x value of the dialog.
Definition: window.hpp:531
typed_formula< unsigned > y_
The formula to calculate the y value of the dialog.
Definition: window.hpp:534
void set_variable(const std::string &key, const wfl::variant &value)
Definition: window.hpp:422
void generate_dot_file(const std::string &, const unsigned)
Definition: window.hpp:680
virtual bool expose(const rect &region) override
Called by draw_manager when it believes a redraw is necessary.
Definition: window.cpp:710
wfl::map_formula_callable variables_
The variables of the canvas.
Definition: window.hpp:497
void remove_linked_widget(const std::string &id, const widget *widget)
Removes a widget from a linked size group.
Definition: window.cpp:806
void signal_handler_click_dismiss(const event::ui_event event, bool &handled, bool &halt, const int mouse_button_mask)
The handler for the click dismiss mouse 'event'.
Definition: window.cpp:1242
const event::distributor & get_distributor() const
Gets a reference to the window's distributor to allow some state peeking.
Definition: window.hpp:689
bool enter_disabled_
Disable the enter key see our setter for more info.
Definition: window.hpp:574
virtual void render() override
Ensure the window's internal render buffer is up-to-date.
Definition: window.cpp:688
dialogs::modal_dialog * owner_
The dialog that owns the window.
Definition: window.hpp:486
bool init_linked_size_group(const std::string &id, const bool fixed_width, const bool fixed_height)
Initializes a linked size group.
Definition: window.cpp:780
void draw()
Draws the window.
Definition: window.cpp:591
typed_formula< unsigned > w_
The formula to calculate the width of the dialog.
Definition: window.hpp:537
wfl::function_symbol_table functions_
The formula definitions available for the calculation formulas.
Definition: window.hpp:546
void set_owner(dialogs::modal_dialog *owner)
Definition: window.hpp:407
status status_
The status of the window.
Definition: window.hpp:473
virtual widget * find_at(const point &coordinate, const bool must_be_active) override
See widget::find_at.
Definition: window.cpp:758
texture render_buffer_
The internal render buffer used by render() and expose().
Definition: window.hpp:162
bool has_linked_size_group(const std::string &id)
Is the linked size group defined for this window?
Definition: window.cpp:787
Wrapper class to encapsulate creation and management of an SDL_Texture.
Definition: texture.hpp:33
map_formula_callable & add(const std::string &key, const variant &value)
Definition: callable.hpp:253
Various uncategorised dialogs.
ui_event
The event sent to the dispatcher.
Definition: handler.hpp:115
Generic file dialog.
std::shared_ptr< builder_grid > builder_grid_ptr
retval
Default window/dialog return values.
Definition: retval.hpp:30
@ OK
Dialog was closed with the OK button.
Definition: retval.hpp:35
std::shared_ptr< halo_record > handle
Definition: halo.hpp:31
static std::string at(const std::string &file, int line)
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
Helper struct to store information about the tips.
The message callbacks hold a reference to a message.
Definition: message.hpp:46
Helper struct to force widgets the have the same size.
Definition: window.hpp:587
int height
The current height of all widgets in the group, -1 if the height is not linked.
Definition: window.hpp:600
linked_size(const bool width=false, const bool height=false)
Definition: window.hpp:588
int width
The current width of all widgets in the group, -1 if the width is not linked.
Definition: window.hpp:597
std::vector< widget * > widgets
The widgets linked.
Definition: window.hpp:594
window_definition(const config &cfg)
Definition: window.cpp:1372
Helper to implement private functions without modifying the header.
Holds a 2D point.
Definition: point.hpp:25
An abstract description of a rectangle with integer coordinates.
Definition: rect.hpp:49