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