-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwindow.cpp
More file actions
68 lines (67 loc) · 2.44 KB
/
window.cpp
File metadata and controls
68 lines (67 loc) · 2.44 KB
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
//=============================================================================
// ■ Window
//-----------------------------------------------------------------------------
// A Lua module for managing the application window.
//=============================================================================
namespace Window {
//-------------------------------------------------------------------------
// ● resize(width, height)
//-------------------------------------------------------------------------
int lua_resize(lua_State* L) {
int w = luaL_checkinteger(L, 1);
int h = luaL_checkinteger(L, 2);
SDL_SetWindowSize($window, w, h);
return 0;
}
//-------------------------------------------------------------------------
// ● set_resizable(resizable)
//-------------------------------------------------------------------------
int lua_set_resizable(lua_State* L) {
luaL_checkany(L, 1);
SDL_SetWindowResizable($window, (SDL_bool) lua_toboolean(L, 1));
return 0;
}
//-------------------------------------------------------------------------
// ● set_fullscreen(mode)
// mode: "fullscreen", "borderless" or "windowed"
//-------------------------------------------------------------------------
int lua_set_fullscreen(lua_State* L) {
const char* mode = luaL_checkstring(L, 1);
Uint32 flags;
if (strcmp(mode, "fullscreen") == 0) {
flags = SDL_WINDOW_FULLSCREEN;
} else if (strcmp(mode, "borderless") == 0) {
flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
} else if (strcmp(mode, "windowed") == 0) {
flags = 0;
} else {
return luaL_error(L, "unknown fullscreen mode");
}
if (SDL_SetWindowFullscreen($window, flags) < 0) {
Util::sdlerror(L, "SDL_SetWindowFullscreen() < 0");
}
return 0;
}
//-------------------------------------------------------------------------
// ● set_title(title)
//-------------------------------------------------------------------------
int lua_set_title(lua_State* L) {
const char* text = luaL_checkstring(L, 1);
SDL_SetWindowTitle($window, text);
return 0;
}
//-------------------------------------------------------------------------
// ● init
//-------------------------------------------------------------------------
void init() {
const luaL_reg reg[] = {
{"resize", lua_resize},
{"set_resizable", lua_set_resizable},
{"set_title", lua_set_title},
{"set_fullscreen", lua_set_fullscreen},
{NULL, NULL}
};
luaL_register(L, "Window", reg);
lua_pop(L, 1);
}
}