1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2004-2009 The Mana World Development Team |
4 |
|
|
* Copyright (C) 2009-2010 The Mana Developers |
5 |
|
|
* Copyright (C) 2011-2019 The ManaPlus Developers |
6 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
7 |
|
|
* Copyright (C) 2009 Aethyra Development Team |
8 |
|
|
* |
9 |
|
|
* This file is part of The ManaPlus Client. |
10 |
|
|
* |
11 |
|
|
* This program is free software; you can redistribute it and/or modify |
12 |
|
|
* it under the terms of the GNU General Public License as published by |
13 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
14 |
|
|
* any later version. |
15 |
|
|
* |
16 |
|
|
* This program is distributed in the hope that it will be useful, |
17 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 |
|
|
* GNU General Public License for more details. |
20 |
|
|
* |
21 |
|
|
* You should have received a copy of the GNU General Public License |
22 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
23 |
|
|
*/ |
24 |
|
|
|
25 |
|
|
#ifndef GUI_WIDGETS_POPUP_H |
26 |
|
|
#define GUI_WIDGETS_POPUP_H |
27 |
|
|
|
28 |
|
|
#include "gui/widgets/container.h" |
29 |
|
|
|
30 |
|
|
#include "listeners/mouselistener.h" |
31 |
|
|
#include "listeners/widgetlistener.h" |
32 |
|
|
|
33 |
|
|
class ImageCollection; |
34 |
|
|
class Skin; |
35 |
|
|
class WindowContainer; |
36 |
|
|
|
37 |
|
|
/** |
38 |
|
|
* A light version of the Window class. Particularly suited for popup type |
39 |
|
|
* functionality that doesn't need to be resized or moved around by the mouse |
40 |
|
|
* once created, but only needs to display some simple content, like a static |
41 |
|
|
* message. |
42 |
|
|
* |
43 |
|
|
* Popups, in general, shouldn't also need to update their content once |
44 |
|
|
* created, although this is not an explicit requirement to use the popup |
45 |
|
|
* class. |
46 |
|
|
* |
47 |
|
|
* \ingroup GUI |
48 |
|
|
*/ |
49 |
|
|
class Popup notfinal : public Container, |
50 |
|
|
public MouseListener, |
51 |
|
|
public WidgetListener |
52 |
|
|
{ |
53 |
|
|
public: |
54 |
|
|
/** |
55 |
|
|
* Constructor. Initializes the title to the given text and hooks |
56 |
|
|
* itself into the popup container. |
57 |
|
|
* |
58 |
|
|
* @param name A human readable name for the popup. Only useful for |
59 |
|
|
* debugging purposes. |
60 |
|
|
* @param skin The location where the Popup's skin XML can be found. |
61 |
|
|
*/ |
62 |
|
|
Popup(const std::string &name, |
63 |
|
|
std::string skin); |
64 |
|
|
|
65 |
|
|
A_DELETE_COPY(Popup) |
66 |
|
|
|
67 |
|
|
/** |
68 |
|
|
* Destructor. Deletes all the added widgets. |
69 |
|
|
*/ |
70 |
|
|
~Popup() override; |
71 |
|
|
|
72 |
|
|
/** |
73 |
|
|
* Sets the window container to be used by new popups. |
74 |
|
|
*/ |
75 |
|
|
static void setWindowContainer(WindowContainer *const windowContainer); |
76 |
|
|
|
77 |
|
|
/** |
78 |
|
|
* Draws the popup. |
79 |
|
|
*/ |
80 |
|
|
void draw(Graphics *const graphics) override A_NONNULL(2); |
81 |
|
|
|
82 |
|
|
void safeDraw(Graphics *const graphics) override A_NONNULL(2); |
83 |
|
|
|
84 |
|
|
/** |
85 |
|
|
* Sets the size of this popup. |
86 |
|
|
*/ |
87 |
|
|
void setContentSize(int width, int height); |
88 |
|
|
|
89 |
|
|
/** |
90 |
|
|
* Sets the location relative to the given widget. |
91 |
|
|
*/ |
92 |
|
|
void setLocationRelativeTo(const Widget *const widget); |
93 |
|
|
|
94 |
|
|
void mouseMoved(MouseEvent &event) override; |
95 |
|
|
|
96 |
|
|
/** |
97 |
|
|
* Sets the minimum width of the popup. |
98 |
|
|
*/ |
99 |
|
|
void setMinWidth(const int width); |
100 |
|
|
|
101 |
|
|
int getMinWidth() const noexcept2 A_WARN_UNUSED |
102 |
|
|
{ return mMinWidth; } |
103 |
|
|
|
104 |
|
|
/** |
105 |
|
|
* Sets the minimum height of the popup. |
106 |
|
|
*/ |
107 |
|
|
void setMinHeight(const int height); |
108 |
|
|
|
109 |
|
|
int getMinHeight() const noexcept2 A_WARN_UNUSED |
110 |
|
|
{ return mMinHeight; } |
111 |
|
|
|
112 |
|
|
/** |
113 |
|
|
* Sets the maximum width of the popup. |
114 |
|
|
*/ |
115 |
|
|
void setMaxWidth(const int width); |
116 |
|
|
|
117 |
|
|
int getMaxWidth() const noexcept2 A_WARN_UNUSED |
118 |
|
|
{ return mMaxWidth; } |
119 |
|
|
|
120 |
|
|
/** |
121 |
|
|
* Sets the minimum height of the popup. |
122 |
|
|
*/ |
123 |
|
|
void setMaxHeight(const int height); |
124 |
|
|
|
125 |
|
|
int getMaxHeight() const noexcept2 A_WARN_UNUSED |
126 |
|
|
{ return mMaxHeight; } |
127 |
|
|
|
128 |
|
|
/** |
129 |
|
|
* Gets the padding of the popup. The padding is the distance between |
130 |
|
|
* the popup border and the content. |
131 |
|
|
* |
132 |
|
|
* @return The padding of the popup. |
133 |
|
|
* @see setPadding |
134 |
|
|
*/ |
135 |
|
|
int getPadding() const noexcept2 A_WARN_UNUSED |
136 |
|
|
{ return mPadding; } |
137 |
|
|
|
138 |
|
|
void setPadding(int padding) noexcept2 |
139 |
|
112 |
{ mPadding = padding; } |
140 |
|
|
|
141 |
|
|
/** |
142 |
|
|
* Sets the name of the popup. This is only useful for debug purposes. |
143 |
|
|
*/ |
144 |
|
|
void setPopupName(const std::string &name) noexcept2 |
145 |
|
|
{ mPopupName = name; } |
146 |
|
|
|
147 |
|
|
const std::string &getPopupName() const noexcept2 |
148 |
|
|
{ return mPopupName; } |
149 |
|
|
|
150 |
|
|
/** |
151 |
|
|
* Schedule this popup for deletion. It will be deleted at the start |
152 |
|
|
* of the next logic update. |
153 |
|
|
*/ |
154 |
|
|
void scheduleDelete(); |
155 |
|
|
|
156 |
|
|
// Inherited from BasicContainer |
157 |
|
|
|
158 |
|
|
Rect getChildrenArea() override; |
159 |
|
|
|
160 |
|
|
/** |
161 |
|
|
* Sets the location to display the popup. Tries to horizontally center |
162 |
|
|
* the popup and provide a vertical buffer between the given point and |
163 |
|
|
* the popup. Prevents the popup from extending off-screen, if |
164 |
|
|
* possible. |
165 |
|
|
*/ |
166 |
|
|
void position(const int x, const int y); |
167 |
|
|
|
168 |
|
|
void hide(); |
169 |
|
|
|
170 |
|
|
void widgetResized(const Event &event) override; |
171 |
|
|
|
172 |
|
|
void widgetMoved(const Event &event) override final; |
173 |
|
|
|
174 |
|
|
bool isPopupVisible() const noexcept2 |
175 |
|
|
{ return mVisible == Visible_true; } |
176 |
|
|
|
177 |
|
|
void postInit() override |
178 |
|
112 |
{ mInit = true; } |
179 |
|
|
|
180 |
|
|
protected: |
181 |
|
|
int mPadding; /**< Holds the padding of the popup. */ |
182 |
|
|
Skin *mSkin; /**< Skin in use by this popup */ |
183 |
|
|
|
184 |
|
|
private: |
185 |
|
|
std::string mPopupName; /**< Name of the popup */ |
186 |
|
|
ImageCollection *mVertexes A_NONNULLPOINTER; |
187 |
|
|
int mMinWidth; /**< Minimum popup width */ |
188 |
|
|
int mMinHeight; /**< Minimum popup height */ |
189 |
|
|
int mMaxWidth; /**< Maximum popup width */ |
190 |
|
|
int mMaxHeight; /**< Maximum popup height */ |
191 |
|
|
bool mInit; |
192 |
|
|
}; |
193 |
|
|
|
194 |
|
|
#endif // GUI_WIDGETS_POPUP_H |