1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "common/system.h"
24 #include "ags/engine/platform/base/sys_main.h"
25 #include "ags/shared/util/geometry.h"
26 #include "ags/shared/util/string.h"
27 
28 namespace AGS3 {
29 
30 namespace ags = AGS::Shared;
31 
32 // ----------------------------------------------------------------------------
33 // INIT / SHUTDOWN
34 // ----------------------------------------------------------------------------
35 
sys_main_init()36 int sys_main_init(/*config*/) {
37 	return 0;
38 }
39 
sys_main_shutdown()40 void sys_main_shutdown() {
41 	sys_window_destroy();
42 }
43 
sys_set_background_mode(bool on)44 void sys_set_background_mode(bool on) {
45 	// TODO: consider if we want any implementation here, and what...
46 }
47 
48 
49 // ----------------------------------------------------------------------------
50 // DISPLAY UTILS
51 // ----------------------------------------------------------------------------
52 #ifdef TODO
53 const int DEFAULT_DISPLAY_INDEX = 0; // TODO: is this always right?
54 #endif
55 
sys_get_desktop_resolution(int & width,int & height)56 int sys_get_desktop_resolution(int &width, int &height) {
57 	// TODO: ScummVM has a hardcoded dummy desktop resolution. See if there's any
58 	// need to change the values, given we're hardcoded for pretend full-screen
59 	width = 9999;
60 	height = 9999;
61 
62 	return 0;
63 }
64 
sys_get_desktop_modes(std::vector<AGS::Engine::DisplayMode> & dms)65 void sys_get_desktop_modes(std::vector<AGS::Engine::DisplayMode> &dms) {
66 #ifdef TODO
67 	SDL_DisplayMode mode;
68 	const int display_id = DEFAULT_DISPLAY_INDEX;
69 	const int count = SDL_GetNumDisplayModes(display_id);
70 	dms.clear();
71 	for (int i = 0; i < count; ++i) {
72 		if (SDL_GetDisplayMode(display_id, i, &mode) != 0) {
73 			SDL_Log("SDL_GetDisplayMode failed: %s", SDL_GetError());
74 			continue;
75 		}
76 		AGS::Engine::DisplayMode dm;
77 		dm.Width = mode.w;
78 		dm.Height = mode.h;
79 		dm.ColorDepth = SDL_BITSPERPIXEL(mode.format);
80 		dm.RefreshRate = mode.refresh_rate;
81 		dms.push_back(dm);
82 	}
83 #endif
84 }
85 
86 
87 // ----------------------------------------------------------------------------
88 // WINDOW UTILS
89 // ----------------------------------------------------------------------------
90 // TODO: support multiple windows? in case we need some for diag purposes etc
91 
92 #ifdef TODO
93 static SDL_Window *window = nullptr;
94 
sys_window_create(const char * window_title,int w,int h,bool windowed,int ex_flags)95 SDL_Window *sys_window_create(const char *window_title, int w, int h, bool windowed, int ex_flags) {
96 	if (window) {
97 		sys_window_destroy();
98 	}
99 	// TODO: support display index selection (?)
100 	// TODO: support separate fullscreen and desktop (borderless fullscreen window) modes
101 	Uint32 flags = SDL_WINDOW_RESIZABLE;
102 	if (!windowed) {
103 		flags |= SDL_WINDOW_FULLSCREEN_DESKTOP/*SDL_WINDOW_FULLSCREEN*/;
104 	}
105 	flags |= ex_flags;
106 	window = SDL_CreateWindow(
107 	             window_title,
108 	             SDL_WINDOWPOS_CENTERED_DISPLAY(DEFAULT_DISPLAY_INDEX),
109 	             SDL_WINDOWPOS_CENTERED_DISPLAY(DEFAULT_DISPLAY_INDEX),
110 	             w,
111 	             h,
112 	             flags
113 	         );
114 	return window;
115 }
116 #else
sys_window_create(const char * window_title,int w,int h,bool windowed,int ex_flags)117 SDL_Window *sys_window_create(const char *window_title, int w, int h, bool windowed, int ex_flags) {
118 	error("TODO: sys_window_create");
119 	return nullptr;
120 }
121 #endif
122 
sys_get_window()123 SDL_Window *sys_get_window() {
124 	//return window;
125 	return nullptr;
126 }
127 
sys_window_set_style(bool windowed)128 void sys_window_set_style(bool windowed) {
129 #ifdef TODO
130 	if (!window) return;
131 	// TODO: support separate fullscreen and desktop (borderless fullscreen window) modes
132 	// TODO: support resizable window later, might need callback for engine and/or gfx renderer
133 	SDL_SetWindowFullscreen(window, windowed ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP);
134 #endif
135 }
136 
sys_window_show_cursor(bool on)137 void sys_window_show_cursor(bool on) {
138 	g_system->showMouse(on);
139 }
140 
sys_window_lock_mouse(bool on)141 bool sys_window_lock_mouse(bool on) {
142 #ifdef TODO
143 	if (!window) return false;
144 	SDL_SetWindowGrab(window, static_cast<SDL_bool>(on));
145 	return on; // TODO: test if successful?
146 #endif
147 	return false;
148 }
149 
sys_window_set_mouse(int x,int y)150 void sys_window_set_mouse(int x, int y) {
151 	g_system->warpMouse(x, y);
152 }
153 
sys_window_destroy()154 void sys_window_destroy() {
155 #ifdef TODO
156 	if (window) {
157 		SDL_DestroyWindow(window);
158 		window = nullptr;
159 	}
160 #endif
161 }
162 
sys_window_set_title(const char * title)163 void sys_window_set_title(const char *title) {
164 	// No implementation in ScummVM
165 }
166 
sys_window_set_icon()167 void sys_window_set_icon() {
168 	// No implementation in ScummVM
169 }
170 
sys_window_set_size(int w,int h,bool center)171 bool sys_window_set_size(int w, int h, bool center) {
172 	error("TODO: sys_window_set_size");
173 	return false;
174 }
175 
176 #if AGS_PLATFORM_OS_WINDOWS
sys_win_get_window()177 void *sys_win_get_window() {
178 	if (!window) return nullptr;
179 	SDL_SysWMinfo wmInfo;
180 	SDL_VERSION(&wmInfo.version);
181 	SDL_GetWindowWMInfo(window, &wmInfo);
182 	HWND hwnd = wmInfo.info.win.window;
183 	return hwnd;
184 }
185 #endif
186 
187 } // namespace AGS3
188