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