The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
popup.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef GUI_DIALOGS_POPUP_HPP_INCLUDED
16 #define GUI_DIALOGS_POPUP_HPP_INCLUDED
17 
18 #include <string>
19 
20 class CVideo;
21 
22 namespace gui2
23 {
24 
25 class twindow;
26 
27 /**
28  * The popup class shows windows that are shown non-modal.
29  *
30  * At the moment these windows also don't capture the mouse and keyboard so can
31  * only be used for things like tooltips. This behavior might change later.
32  */
33 class tpopup
34 {
35  /**
36  * Special helper function to get the id of the window.
37  *
38  * This is used in the unit tests, but these implementation details
39  * shouldn't be used in the normal code.
40  */
42 
43  /**
44  * Special helper function for the unit test to the the window.
45  *
46  * This is used in the unit tests, but these implementation details
47  * shouldn't be used in the normal code.
48  */
49  friend twindow* unit_test_window(const tpopup& dialog);
50 
51 public:
52  tpopup();
53 
54  virtual ~tpopup();
55 
56  /**
57  * Shows the window.
58  *
59  * @param video The video which contains the surface to draw
60  * upon.
61  * @param allow_interaction Does the dialog allow interaction?
62  * * true a non modal window is shown
63  * * false a tooltip window is shown
64  * @param auto_close_time The time in ms after which the dialog will
65  * automatically close, if 0 it doesn't close.
66  * @note the timeout is a minimum time and
67  * there's no guarantee about how fast it closes
68  * after the minimum.
69  */
70  void show(CVideo& video,
71  const bool allow_interaction = false,
72  const unsigned auto_close_time = 0);
73 
74 
75  /**
76  * Hides the window.
77  *
78  * The hiding also destroys the window. It is save to call the function
79  * when the window is not shown.
80  */
81  void hide();
82 
83 private:
84  /** The window, used in show. */
86 
87  /** The id of the window to build. */
88  virtual const std::string& window_id() const = 0;
89 
90  /**
91  * Builds the window.
92  *
93  * Every dialog shows it's own kind of window, this function should return
94  * the window to show.
95  *
96  * @param video The video which contains the surface to draw
97  * upon.
98  * @returns The window to show.
99  */
100  twindow* build_window(CVideo& video) const;
101 
102  /**
103  * Actions to be taken directly after the window is build.
104  *
105  * @param video The video which contains the surface to draw
106  * upon.
107  * @param window The window just created.
108  */
109  virtual void post_build(twindow& window);
110 
111  /**
112  * Actions to be taken before showing the window.
113  *
114  * @param video The video which contains the surface to draw
115  * upon.
116  * @param window The window to be shown.
117  */
118  virtual void pre_show(twindow& window);
119 };
120 
121 } // namespace gui2
122 
123 #endif
twindow * window_
The window, used in show.
Definition: popup.hpp:85
Definition: video.hpp:58
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
friend std::string unit_test_mark_popup_as_tested(const tpopup &dialog)
Special helper function to get the id of the window.
Definition: test_gui2.cpp:116
void show(CVideo &video, const bool allow_interaction=false, const unsigned auto_close_time=0)
Shows the window.
Definition: popup.cpp:34
twindow * build_window(CVideo &video) const
Builds the window.
Definition: popup.cpp:66
virtual const std::string & window_id() const =0
The id of the window to build.
The popup class shows windows that are shown non-modal.
Definition: popup.hpp:33
friend twindow * unit_test_window(const tpopup &dialog)
Special helper function for the unit test to the the window.
Definition: test_gui2.cpp:125
void hide()
Hides the window.
Definition: popup.cpp:57
virtual void pre_show(twindow &window)
Actions to be taken before showing the window.
Definition: popup.cpp:76
virtual void post_build(twindow &window)
Actions to be taken directly after the window is build.
Definition: popup.cpp:71
virtual ~tpopup()
Definition: popup.cpp:29
GLsizei const GLcharARB ** string
Definition: glew.h:4503