forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaseui.cpp
121 lines (100 loc) · 3.34 KB
/
baseui.cpp
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
/*
* 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/>.
*/
// Headers
#include "baseui.h"
#include "bitmap.h"
#include "player.h"
#if USE_SDL==2
# include "platform/sdl/sdl2_ui.h"
#elif USE_SDL==1
# include "platform/sdl/sdl_ui.h"
#elif USE_LIBRETRO
# include "platform/libretro/ui.h"
#elif defined(__3DS__)
# include "platform/3ds/ui.h"
#elif defined(__vita__)
# include "platform/psvita/ui.h"
#elif defined(__SWITCH__)
# include "platform/switch/ui.h"
#endif
std::shared_ptr<BaseUi> DisplayUi;
std::shared_ptr<BaseUi> BaseUi::CreateUi(long width, long height, const Game_Config& cfg) {
#if USE_SDL==2
return std::make_shared<Sdl2Ui>(width, height, cfg);
#elif USE_SDL==1
return std::make_shared<SdlUi>(width, height, cfg);
#elif defined(PLAYER_UI)
return std::make_shared<PLAYER_UI>(width, height, cfg);
#else
# error cannot create UI
#endif
}
BaseUi::BaseUi(const Game_Config& cfg)
{
keys.reset();
vcfg = cfg.video;
auto fps_limit = vcfg.fps_limit.Get();
frame_limit = (fps_limit == 0 ? Game_Clock::duration(0) : Game_Clock::TimeStepFromFps(fps_limit));
}
BitmapRef BaseUi::CaptureScreen() {
BitmapRef capture = Bitmap::Create(main_surface->width(), main_surface->height(), false);
capture->BlitFast(0, 0, *main_surface, main_surface->GetRect(), Opacity::Opaque());
return capture;
}
void BaseUi::CleanDisplay() {
main_surface->Clear();
}
void BaseUi::SetGameResolution(GameResolution resolution) {
vcfg.game_resolution.Set(resolution);
}
Game_ConfigVideo BaseUi::GetConfig() const {
Game_ConfigVideo cfg = vcfg;
cfg.Hide();
vGetConfig(cfg);
Rect metrics = GetWindowMetrics();
cfg.window_x.Set(metrics.x);
cfg.window_y.Set(metrics.y);
cfg.window_width.Set(metrics.width);
cfg.window_height.Set(metrics.height);
if (cfg.fullscreen.IsOptionVisible()) {
cfg.fps_render_window.SetLocked(cfg.fullscreen.Get());
if (cfg.fps_render_window.IsLocked()) {
cfg.fps_render_window.SetDescription("This options requires to be in windowed mode");
}
}
if (cfg.vsync.IsOptionVisible()
&& cfg.vsync.Get()) {
cfg.fps_limit.SetLocked(true);
cfg.fps_limit.SetDescription("This option requires V-Sync to be disabled");
}
if (cfg.fullscreen.IsOptionVisible()
&& cfg.fullscreen.Get()) {
cfg.window_zoom.SetLocked(true);
cfg.window_zoom.SetDescription("This option requires to be in windowed mode");
}
if (Player::has_custom_resolution) {
cfg.game_resolution.SetLocked(true);
cfg.game_resolution.SetDescription("This game uses a custom resolution");
}
return cfg;
}
bool BaseUi::ChangeDisplaySurfaceResolution(int new_width, int new_height) {
if (new_width == current_display_mode.width && new_height == current_display_mode.height) {
return true;
}
return vChangeDisplaySurfaceResolution(new_width, new_height);
}