1 /*
2 * This file is part of EasyRPG Player.
3 *
4 * EasyRPG Player is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * EasyRPG Player is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef EP_WINDOW_H
19 #define EP_WINDOW_H
20
21 // Headers
22 #include "system.h"
23 #include "drawable.h"
24 #include "rect.h"
25
26 /**
27 * Window class.
28 */
29 class Window : public Drawable {
30 public:
31 Window(Drawable::Flags flags = Drawable::Flags::Default);
32
33 void Draw(Bitmap& dst) override;
34
35 void Update();
36 BitmapRef const& GetWindowskin() const;
37 void SetWindowskin(BitmapRef const& nwindowskin);
38 BitmapRef GetContents() const;
39 void SetContents(BitmapRef const& ncontents);
40 bool GetStretch() const;
41 void SetStretch(bool nstretch);
42 Rect const& GetCursorRect() const;
43 void SetCursorRect(Rect const& ncursor_rect);
44 bool GetActive() const;
45 void SetActive(bool nactive);
46 bool GetPause() const;
47 void SetPause(bool npause);
48 bool GetUpArrow() const;
49 void SetUpArrow(bool nup_arrow);
50 bool GetDownArrow() const;
51 void SetDownArrow(bool ndown_arrow);
52 bool GetLeftArrow() const;
53 void SetLeftArrow(bool nleft_arrow);
54 bool GetRightArrow() const;
55 void SetRightArrow(bool nright_arrow);
56 int GetX() const;
57 void SetX(int nx);
58 int GetY() const;
59 void SetY(int ny);
60 int GetWidth() const;
61 void SetWidth(int nwidth);
62 int GetHeight() const;
63 void SetHeight(int nheight);
64 int GetOx() const;
65 void SetOx(int nox);
66 int GetOy() const;
67 void SetOy(int noy);
68 int GetBorderX() const;
69 void SetBorderX(int nox);
70 int GetBorderY() const;
71 void SetBorderY(int noy);
72 int GetOpacity() const;
73 void SetOpacity(int nopacity);
74 int GetBackOpacity() const;
75 void SetBackOpacity(int nback_opacity);
76 int GetContentsOpacity() const;
77 void SetContentsOpacity(int ncontents_opacity);
78 void SetOpenAnimation(int frames);
79 void SetCloseAnimation(int frames);
80
81 bool IsOpening() const;
82 bool IsClosing() const;
83 bool IsOpeningOrClosing() const;
84
85 protected:
86 virtual bool IsSystemGraphicUpdateAllowed() const;
87
88 unsigned long ID;
89 BitmapRef windowskin, contents;
90 bool stretch = true;
91 Rect cursor_rect;
92 bool active = true;
93 bool closing = false;
94 bool up_arrow = false;
95 bool down_arrow = false;
96 bool left_arrow = false;
97 bool right_arrow = false;
98 int x = 0;
99 int y = 0;
100 int width = 0;
101 int height = 0;
102 int ox = 0;
103 int oy = 0;
104 int border_x = 8;
105 int border_y = 8;
106 int opacity = 255;
107 int back_opacity = 255;
108 int contents_opacity = 255;
109
110 private:
111 BitmapRef
112 background, frame_down,
113 frame_up, frame_left, frame_right, cursor1, cursor2;
114
115 void RefreshBackground();
116 void RefreshFrame();
117 void RefreshCursor();
118
119 bool background_needs_refresh;
120 bool frame_needs_refresh;
121 bool cursor_needs_refresh;
122 bool pause = false;
123
124 int cursor_frame = 0;
125 int pause_frame = 0;
126 int animation_frames = 0;
127 double animation_count = 0.0;
128 double animation_increment = 0.0;
129 };
130
IsOpening()131 inline bool Window::IsOpening() const {
132 return animation_frames > 0 && !closing;
133 }
134
IsClosing()135 inline bool Window::IsClosing() const {
136 return animation_frames > 0 && closing;
137 }
138
IsOpeningOrClosing()139 inline bool Window::IsOpeningOrClosing() const {
140 return animation_frames > 0;
141 }
142
GetWindowskin()143 inline BitmapRef const& Window::GetWindowskin() const {
144 return windowskin;
145 }
146
GetContents()147 inline BitmapRef Window::GetContents() const {
148 return contents;
149 }
150
SetContents(BitmapRef const & ncontents)151 inline void Window::SetContents(BitmapRef const& ncontents) {
152 contents = ncontents;
153 }
154
GetStretch()155 inline bool Window::GetStretch() const {
156 return stretch;
157 }
158
GetCursorRect()159 inline Rect const& Window::GetCursorRect() const {
160 return cursor_rect;
161 }
162
GetActive()163 inline bool Window::GetActive() const {
164 return active;
165 }
166
SetActive(bool nactive)167 inline void Window::SetActive(bool nactive) {
168 active = nactive;
169 }
170
GetPause()171 inline bool Window::GetPause() const {
172 return pause;
173 }
174
SetPause(bool npause)175 inline void Window::SetPause(bool npause) {
176 pause = npause;
177 pause_frame = 0;
178 }
179
GetUpArrow()180 inline bool Window::GetUpArrow() const {
181 return up_arrow;
182 }
183
SetUpArrow(bool nup_arrow)184 inline void Window::SetUpArrow(bool nup_arrow) {
185 up_arrow = nup_arrow;
186 }
187
GetDownArrow()188 inline bool Window::GetDownArrow() const {
189 return down_arrow;
190 }
191
SetDownArrow(bool ndown_arrow)192 inline void Window::SetDownArrow(bool ndown_arrow) {
193 down_arrow = ndown_arrow;
194 }
195
GetLeftArrow()196 inline bool Window::GetLeftArrow() const {
197 return left_arrow;
198 }
199
SetLeftArrow(bool nleft_arrow)200 inline void Window::SetLeftArrow(bool nleft_arrow) {
201 left_arrow = nleft_arrow;
202 }
203
GetRightArrow()204 inline bool Window::GetRightArrow() const {
205 return right_arrow;
206 }
207
SetRightArrow(bool nright_arrow)208 inline void Window::SetRightArrow(bool nright_arrow) {
209 right_arrow = nright_arrow;
210 }
211
GetX()212 inline int Window::GetX() const {
213 return x;
214 }
215
SetX(int nx)216 inline void Window::SetX(int nx) {
217 x = nx;
218 }
219
GetY()220 inline int Window::GetY() const {
221 return y;
222 }
223
SetY(int ny)224 inline void Window::SetY(int ny) {
225 y = ny;
226 }
227
GetWidth()228 inline int Window::GetWidth() const {
229 return width;
230 }
231
GetHeight()232 inline int Window::GetHeight() const {
233 return height;
234 }
235
GetOx()236 inline int Window::GetOx() const {
237 return ox;
238 }
239
SetOx(int nox)240 inline void Window::SetOx(int nox) {
241 ox = nox;
242 }
243
GetOy()244 inline int Window::GetOy() const {
245 return oy;
246 }
247
SetOy(int noy)248 inline void Window::SetOy(int noy) {
249 oy = noy;
250 }
251
GetBorderX()252 inline int Window::GetBorderX() const {
253 return border_x;
254 }
255
SetBorderX(int x)256 inline void Window::SetBorderX(int x) {
257 border_x = x;
258 }
259
GetBorderY()260 inline int Window::GetBorderY() const {
261 return border_y;
262 }
263
SetBorderY(int y)264 inline void Window::SetBorderY(int y) {
265 border_y = y;
266 }
267
GetOpacity()268 inline int Window::GetOpacity() const {
269 return opacity;
270 }
271
SetOpacity(int nopacity)272 inline void Window::SetOpacity(int nopacity) {
273 opacity = nopacity;
274 }
275
GetBackOpacity()276 inline int Window::GetBackOpacity() const {
277 return back_opacity;
278 }
279
SetBackOpacity(int nback_opacity)280 inline void Window::SetBackOpacity(int nback_opacity) {
281 back_opacity = nback_opacity;
282 }
283
GetContentsOpacity()284 inline int Window::GetContentsOpacity() const {
285 return contents_opacity;
286 }
287
SetContentsOpacity(int ncontents_opacity)288 inline void Window::SetContentsOpacity(int ncontents_opacity) {
289 contents_opacity = ncontents_opacity;
290 }
291
IsSystemGraphicUpdateAllowed()292 inline bool Window::IsSystemGraphicUpdateAllowed() const {
293 return !IsClosing();
294 }
295
296 #endif
297