Debian Codegraph @

CorsixTH/Src/sdl_wm.cpp

raw
1 /*
2 Copyright (c) 2009 Peter "Corsix" Cawley
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23 #include "lua.hpp"
24 #include "th_lua.h"
25 #ifdef CORSIX_TH_USE_WIN32_SDK
26 #include <SDL_syswm.h>
27 #include <windows.h>
28
29 #include "../resource.h"
30 #endif
31 #include <SDL_mouse.h>
32
33 #include <array>
34
35 namespace {
36
37 int l_set_icon_win32(lua_State* L) {
38 // Hack to set the window icon from the EXE resource under Windows.
39 // Does nothing (and returns false) on other platforms.
40
41 lua_pushboolean(L, 0);
42 #if 0
43 // XXX: Doesn't work any more, since window is inside renderer. Move to renderer.
44 SDL_SysWMinfo oWindowInfo;
45 oWindowInfo.version.major = SDL_MAJOR_VERSION;
46 oWindowInfo.version.minor = SDL_MINOR_VERSION;
47 oWindowInfo.version.patch = SDL_PATCHLEVEL;
48 if(SDL_GetWindowWMInfo(window,&oWindowInfo) == 1)
49 {
50 HWND hWindow = oWindowInfo.info.win.window;
51 HICON hIcon = LoadIcon((HINSTANCE)GetModuleHandle(nullptr), (LPCTSTR)IDI_CORSIXTH);
52 SetClassLongPtr(hWindow, GCLP_HICON, (LONG_PTR)hIcon);
53 SetClassLongPtr(hWindow, GCLP_HICONSM, (LONG_PTR)hIcon);
54 lua_pushboolean(L, 1);
55 }
56 #endif
57 return 1;
58 }
59
60 int l_show_cursor(lua_State* L) {
61 SDL_ShowCursor(lua_toboolean(L, 1));
62 return 0;
63 }
64
65 constexpr std::array<struct luaL_Reg, 3> sdl_wmlib{
66 {{"setIconWin32", l_set_icon_win32},
67 {"showCursor", l_show_cursor},
68 {nullptr, nullptr}}};
69
70 } // namespace
71
72 int luaopen_sdl_wm(lua_State* L) {
73 lua_newtable(L);
74 luaT_setfuncs(L, sdl_wmlib.data());
75
76 return 1;
77 }