forked from twig33/ynoclient
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbaseui.h
316 lines (251 loc) · 6.64 KB
/
baseui.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EP_BASEUI_H
#define EP_BASEUI_H
// Headers
#include <string>
#include <bitset>
#include "system.h"
#include "color.h"
#include "font.h"
#include "point.h"
#include "rect.h"
#include "keys.h"
#include "game_config.h"
#include "game_clock.h"
#ifdef SUPPORT_AUDIO
struct AudioInterface;
#endif
/**
* BaseUi base abstract class.
*/
class BaseUi {
public:
/**
* Virtual Destructor.
*/
virtual ~BaseUi() {}
/**
* Creates a new BaseUi.
*
* @param width display client width.
* @param height display client height.
* @param cfg video config options
*/
static std::shared_ptr<BaseUi> CreateUi(long width, long height, const Game_ConfigVideo& cfg);
/**
* Toggles fullscreen.
*/
virtual void ToggleFullscreen() = 0;
/**
* Toggles zoom.
*/
virtual void ToggleZoom() = 0;
/**
* Processes events queue.
*/
virtual void ProcessEvents() = 0;
/**
* Cleans video buffer.
*/
void CleanDisplay();
/**
* Updates video buffer.
*/
virtual void UpdateDisplay() = 0;
/**
* Gets a copy of the display surface.
*
* @return bitmap a copy of the display surface.
*/
BitmapRef CaptureScreen();
/**
* Clipboard text content.
*/
virtual std::string getClipboardText();
virtual void setClipboardText(std::string text);
/**
* Sets display title.
*
* @param title title string.
*/
virtual void SetTitle(const std::string &title) = 0;
/**
* Sets if the cursor should be shown.
*
* @param flag cursor visibility flag.
* @return previous state.
*/
virtual bool ShowCursor(bool flag) = 0;
/**
* Gets if fullscreen mode is active.
*
* @return whether fullscreen mode is active.
*/
bool IsFullscreen() const;
#ifdef SUPPORT_AUDIO
/**
* Returns audio instance.
*
* @return audio implementation.
*/
virtual AudioInterface& GetAudio() = 0;
#endif
/**
* Gets client width size.
*
* @return client width size.
*/
long GetWidth() const;
/**
* Gets client height size.
*
* @return client height size.
*/
long GetHeight() const;
/**
* Gets whether mouse is hovering the display.
*
* @return whether mouse is hovering the display.
*/
bool GetMouseFocus() const;
/**
* @return mouse position.
*/
Point GetMousePosition() const;
BitmapRef const& GetDisplaySurface() const;
BitmapRef& GetDisplaySurface();
typedef std::bitset<Input::Keys::KEYS_COUNT> KeyStatus;
/**
* Gets vector with the all keys pressed states.
*
* @returns vector with the all keys pressed states.
*/
KeyStatus& GetKeyStates();
std::string FetchTextInputBuffer(); // text input buffer for in-game chat
/** @return true if the display manages the framerate */
bool IsFrameRateSynchronized() const;
/** @return true if we should render the fps counter to the screen */
bool RenderFps() const;
/** @return true if we should render the fps counter to the title bar */
bool ShowFpsOnTitle() const;
/** Toggle whether we should show fps */
void ToggleShowFps();
/**
* @return the minimum amount of time each physical frame should take.
* If the UI manages time (i.e.) vsync, will return a 0 duration.
*/
Game_Clock::duration GetFrameLimit() const;
protected:
/**
* Protected Constructor. Use CreateBaseUi instead.
*/
explicit BaseUi(const Game_ConfigVideo& cfg);
void SetFrameRateSynchronized(bool value);
void SetIsFullscreen(bool value);
/**
* Display mode data struct.
*/
struct DisplayMode {
int zoom = 0;
int width = 0;
int height = 0;
uint32_t flags = 0;
uint8_t bpp = 0;
bool effective = false;
bool vsync = false;
};
/** Current display mode. */
DisplayMode current_display_mode;
KeyStatus keys;
std::string textInputBuffer; // text input buffer for in-game chat
/** Surface used for zoom. */
BitmapRef main_surface;
/** Mouse position on screen relative to the window. */
Point mouse_pos;
/** Color for display background. */
Color back_color = Color{ 0, 0, 0, 255 };
/** Mouse hovering the window flag. */
bool mouse_focus = false;
/** The frames per second limit */
int fps_limit = Game_Clock::GetTargetGameFps();
/** The amount of time each frame should take, based on fps limit */
Game_Clock::duration frame_limit = Game_Clock::GetTargetGameTimeStep();
/** Cursor visibility flag. */
bool cursor_visible = false;
/** Ui manages frame rate externally */
bool external_frame_rate = false;
/** Whether UI is currently fullscreen */
bool is_fullscreen = false;
/** Whether we will show fps counter the screen */
bool show_fps = false;
/** If we will render fps on the screen even in windowed mode */
bool fps_render_window = false;
};
/** Global DisplayUi variable. */
extern std::shared_ptr<BaseUi> DisplayUi;
inline bool BaseUi::IsFrameRateSynchronized() const {
return external_frame_rate;
}
inline void BaseUi::SetFrameRateSynchronized(bool value) {
external_frame_rate = value;
}
inline bool BaseUi::IsFullscreen() const {
return is_fullscreen;
}
inline void BaseUi::SetIsFullscreen(bool fs) {
is_fullscreen = fs;
}
inline BaseUi::KeyStatus& BaseUi::GetKeyStates() {
return keys;
}
inline std::string BaseUi::FetchTextInputBuffer() {
std::string val = textInputBuffer;
textInputBuffer = ""; // reset buffer when fetching
return val;
}
inline BitmapRef const& BaseUi::GetDisplaySurface() const {
return main_surface;
}
inline BitmapRef& BaseUi::GetDisplaySurface() {
return main_surface;
}
inline long BaseUi::GetWidth() const {
return current_display_mode.width;
}
inline long BaseUi::GetHeight() const {
return current_display_mode.height;
}
inline bool BaseUi::GetMouseFocus() const {
return mouse_focus;
}
inline Point BaseUi::GetMousePosition() const {
return mouse_pos;
}
inline bool BaseUi::RenderFps() const {
return show_fps && (IsFullscreen() || fps_render_window);
}
inline bool BaseUi::ShowFpsOnTitle() const {
return show_fps;
}
inline void BaseUi::ToggleShowFps() {
show_fps = !show_fps;
}
inline Game_Clock::duration BaseUi::GetFrameLimit() const {
return IsFrameRateSynchronized() ? Game_Clock::duration(0) : frame_limit;
}
#endif