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