wrap_Window.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /**
  2. * Copyright (c) 2006-2020 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #include "wrap_Window.h"
  21. #include "sdl/Window.h"
  22. namespace love
  23. {
  24. namespace window
  25. {
  26. #define instance() (Module::getInstance<Window>(Module::M_WINDOW))
  27. int w_getDisplayCount(lua_State *L)
  28. {
  29. lua_pushinteger(L, instance()->getDisplayCount());
  30. return 1;
  31. }
  32. int w_getDisplayName(lua_State *L)
  33. {
  34. int index = (int) luaL_checkinteger(L, 1) - 1;
  35. const char *name = nullptr;
  36. luax_catchexcept(L, [&](){ name = instance()->getDisplayName(index); });
  37. lua_pushstring(L, name);
  38. return 1;
  39. }
  40. static const char *settingName(Window::Setting setting)
  41. {
  42. const char *name = nullptr;
  43. Window::getConstant(setting, name);
  44. return name;
  45. }
  46. static int readWindowSettings(lua_State *L, int idx, WindowSettings &settings)
  47. {
  48. luax_checktablefields<Window::Setting>(L, idx, "window setting", Window::getConstant);
  49. lua_getfield(L, idx, settingName(Window::SETTING_FULLSCREEN_TYPE));
  50. if (!lua_isnoneornil(L, -1))
  51. {
  52. const char *typestr = luaL_checkstring(L, -1);
  53. if (!Window::getConstant(typestr, settings.fstype))
  54. return luax_enumerror(L, "fullscreen type", Window::getConstants(settings.fstype), typestr);
  55. }
  56. lua_pop(L, 1);
  57. settings.fullscreen = luax_boolflag(L, idx, settingName(Window::SETTING_FULLSCREEN), settings.fullscreen);
  58. settings.msaa = luax_intflag(L, idx, settingName(Window::SETTING_MSAA), settings.msaa);
  59. settings.stencil = luax_boolflag(L, idx, settingName(Window::SETTING_STENCIL), settings.stencil);
  60. settings.depth = luax_intflag(L, idx, settingName(Window::SETTING_DEPTH), settings.depth);
  61. settings.resizable = luax_boolflag(L, idx, settingName(Window::SETTING_RESIZABLE), settings.resizable);
  62. settings.minwidth = luax_intflag(L, idx, settingName(Window::SETTING_MIN_WIDTH), settings.minwidth);
  63. settings.minheight = luax_intflag(L, idx, settingName(Window::SETTING_MIN_HEIGHT), settings.minheight);
  64. settings.borderless = luax_boolflag(L, idx, settingName(Window::SETTING_BORDERLESS), settings.borderless);
  65. settings.centered = luax_boolflag(L, idx, settingName(Window::SETTING_CENTERED), settings.centered);
  66. settings.display = luax_intflag(L, idx, settingName(Window::SETTING_DISPLAY), settings.display+1) - 1;
  67. settings.usedpiscale = luax_boolflag(L, idx, settingName(Window::SETTING_USE_DPISCALE), settings.usedpiscale);
  68. lua_getfield(L, idx, settingName(Window::SETTING_HIGHDPI));
  69. if (!lua_isnoneornil(L, -1))
  70. {
  71. luax_markdeprecated(L, "window.highdpi", API_FIELD, DEPRECATED_REPLACED, "t.highdpi in love.conf");
  72. bool highdpi = luax_checkboolean(L, -1);
  73. if (!instance()->isOpen())
  74. setHighDPIAllowed(highdpi);
  75. }
  76. lua_pop(L, 1);
  77. lua_getfield(L, idx, settingName(Window::SETTING_VSYNC));
  78. if (lua_isnumber(L, -1))
  79. settings.vsync = (int) lua_tointeger(L, -1);
  80. else if (lua_isboolean(L, -1))
  81. settings.vsync = lua_toboolean(L, -1);
  82. lua_pop(L, 1);
  83. lua_getfield(L, idx, settingName(Window::SETTING_X));
  84. lua_getfield(L, idx, settingName(Window::SETTING_Y));
  85. settings.useposition = !(lua_isnoneornil(L, -2) && lua_isnoneornil(L, -1));
  86. if (settings.useposition)
  87. {
  88. settings.x = (int) luaL_optinteger(L, -2, 0);
  89. settings.y = (int) luaL_optinteger(L, -1, 0);
  90. }
  91. lua_pop(L, 2);
  92. // We don't explicitly set the refresh rate, it's "read-only".
  93. return 0;
  94. }
  95. int w_setMode(lua_State *L)
  96. {
  97. int w = (int) luaL_checkinteger(L, 1);
  98. int h = (int) luaL_checkinteger(L, 2);
  99. if (lua_isnoneornil(L, 3))
  100. {
  101. luax_catchexcept(L, [&](){ luax_pushboolean(L, instance()->setWindow(w, h, nullptr)); });
  102. return 1;
  103. }
  104. // Defaults come from WindowSettings itself.
  105. WindowSettings settings;
  106. readWindowSettings(L, 3, settings);
  107. luax_catchexcept(L,
  108. [&](){ luax_pushboolean(L, instance()->setWindow(w, h, &settings)); }
  109. );
  110. return 1;
  111. }
  112. int w_updateMode(lua_State *L)
  113. {
  114. int w, h;
  115. WindowSettings settings;
  116. instance()->getWindow(w, h, settings);
  117. if (lua_gettop(L) == 0)
  118. return luaL_error(L, "Expected at least one argument");
  119. int idx = 1;
  120. if (lua_isnumber(L, 1))
  121. {
  122. idx = 3;
  123. w = (int) luaL_checkinteger(L, 1);
  124. h = (int) luaL_checkinteger(L, 2);
  125. }
  126. if (!lua_isnoneornil(L, idx))
  127. readWindowSettings(L, idx, settings);
  128. luax_catchexcept(L,
  129. [&](){ luax_pushboolean(L, instance()->setWindow(w, h, &settings)); }
  130. );
  131. return 1;
  132. }
  133. int w_getMode(lua_State *L)
  134. {
  135. int w, h;
  136. WindowSettings settings;
  137. instance()->getWindow(w, h, settings);
  138. lua_pushnumber(L, w);
  139. lua_pushnumber(L, h);
  140. if (lua_istable(L, 1))
  141. lua_pushvalue(L, 1);
  142. else
  143. lua_newtable(L);
  144. const char *fstypestr = "desktop";
  145. Window::getConstant(settings.fstype, fstypestr);
  146. lua_pushstring(L, fstypestr);
  147. lua_setfield(L, -2, settingName(Window::SETTING_FULLSCREEN_TYPE));
  148. luax_pushboolean(L, settings.fullscreen);
  149. lua_setfield(L, -2, settingName(Window::SETTING_FULLSCREEN));
  150. lua_pushinteger(L, settings.vsync);
  151. lua_setfield(L, -2, settingName(Window::SETTING_VSYNC));
  152. lua_pushinteger(L, settings.msaa);
  153. lua_setfield(L, -2, settingName(Window::SETTING_MSAA));
  154. luax_pushboolean(L, settings.stencil);
  155. lua_setfield(L, -2, settingName(Window::SETTING_STENCIL));
  156. lua_pushinteger(L, settings.depth);
  157. lua_setfield(L, -2, settingName(Window::SETTING_DEPTH));
  158. luax_pushboolean(L, settings.resizable);
  159. lua_setfield(L, -2, settingName(Window::SETTING_RESIZABLE));
  160. lua_pushinteger(L, settings.minwidth);
  161. lua_setfield(L, -2, settingName(Window::SETTING_MIN_WIDTH));
  162. lua_pushinteger(L, settings.minheight);
  163. lua_setfield(L, -2, settingName(Window::SETTING_MIN_HEIGHT));
  164. luax_pushboolean(L, settings.borderless);
  165. lua_setfield(L, -2, settingName(Window::SETTING_BORDERLESS));
  166. luax_pushboolean(L, settings.centered);
  167. lua_setfield(L, -2, settingName(Window::SETTING_CENTERED));
  168. // Display index is 0-based internally and 1-based in Lua.
  169. lua_pushinteger(L, settings.display + 1);
  170. lua_setfield(L, -2, settingName(Window::SETTING_DISPLAY));
  171. luax_pushboolean(L, settings.usedpiscale);
  172. lua_setfield(L, -2, settingName(Window::SETTING_USE_DPISCALE));
  173. lua_pushnumber(L, settings.refreshrate);
  174. lua_setfield(L, -2, settingName(Window::SETTING_REFRESHRATE));
  175. lua_pushinteger(L, settings.x);
  176. lua_setfield(L, -2, settingName(Window::SETTING_X));
  177. lua_pushinteger(L, settings.y);
  178. lua_setfield(L, -2, settingName(Window::SETTING_Y));
  179. return 3;
  180. }
  181. int w_isHighDPIAllowed(lua_State *L)
  182. {
  183. luax_pushboolean(L, isHighDPIAllowed());
  184. return 1;
  185. }
  186. int w_getDisplayOrientation(lua_State *L)
  187. {
  188. int displayindex = 0;
  189. if (!lua_isnoneornil(L, 1))
  190. displayindex = (int) luaL_checkinteger(L, 1) - 1;
  191. else
  192. {
  193. int x, y;
  194. instance()->getPosition(x, y, displayindex);
  195. }
  196. const char *orientationstr = nullptr;
  197. if (!Window::getConstant(instance()->getDisplayOrientation(displayindex), orientationstr))
  198. return luaL_error(L, "Unknown display orientation type.");
  199. lua_pushstring(L, orientationstr);
  200. return 1;
  201. }
  202. int w_getFullscreenModes(lua_State *L)
  203. {
  204. int displayindex = 0;
  205. if (!lua_isnoneornil(L, 1))
  206. displayindex = (int) luaL_checkinteger(L, 1) - 1;
  207. else
  208. {
  209. int x, y;
  210. instance()->getPosition(x, y, displayindex);
  211. }
  212. std::vector<Window::WindowSize> modes = instance()->getFullscreenSizes(displayindex);
  213. lua_createtable(L, (int) modes.size(), 0);
  214. for (size_t i = 0; i < modes.size(); i++)
  215. {
  216. lua_pushinteger(L, i + 1);
  217. lua_createtable(L, 0, 2);
  218. // Inner table attribs.
  219. lua_pushinteger(L, modes[i].width);
  220. lua_setfield(L, -2, "width");
  221. lua_pushinteger(L, modes[i].height);
  222. lua_setfield(L, -2, "height");
  223. // Inner table attribs end.
  224. lua_settable(L, -3);
  225. }
  226. return 1;
  227. }
  228. int w_setFullscreen(lua_State *L)
  229. {
  230. bool fullscreen = luax_checkboolean(L, 1);
  231. Window::FullscreenType fstype = Window::FULLSCREEN_MAX_ENUM;
  232. const char *typestr = lua_isnoneornil(L, 2) ? 0 : luaL_checkstring(L, 2);
  233. if (typestr && !Window::getConstant(typestr, fstype))
  234. return luax_enumerror(L, "fullscreen type", Window::getConstants(fstype), typestr);
  235. bool success = false;
  236. luax_catchexcept(L, [&]() {
  237. if (fstype == Window::FULLSCREEN_MAX_ENUM)
  238. success = instance()->setFullscreen(fullscreen);
  239. else
  240. success = instance()->setFullscreen(fullscreen, fstype);
  241. });
  242. luax_pushboolean(L, success);
  243. return 1;
  244. }
  245. int w_getFullscreen(lua_State *L)
  246. {
  247. int w, h;
  248. WindowSettings settings;
  249. instance()->getWindow(w, h, settings);
  250. const char *typestr;
  251. if (!Window::getConstant(settings.fstype, typestr))
  252. luaL_error(L, "Unknown fullscreen type.");
  253. luax_pushboolean(L, settings.fullscreen);
  254. lua_pushstring(L, typestr);
  255. return 2;
  256. }
  257. int w_isOpen(lua_State *L)
  258. {
  259. luax_pushboolean(L, instance()->isOpen());
  260. return 1;
  261. }
  262. int w_close(lua_State *L)
  263. {
  264. luax_catchexcept(L, [&]() { instance()->close(); });
  265. return 0;
  266. }
  267. int w_getDesktopDimensions(lua_State *L)
  268. {
  269. int width = 0, height = 0;
  270. int displayindex = 0;
  271. if (!lua_isnoneornil(L, 1))
  272. displayindex = (int) luaL_checkinteger(L, 1) - 1;
  273. else
  274. {
  275. int x, y;
  276. instance()->getPosition(x, y, displayindex);
  277. }
  278. instance()->getDesktopDimensions(displayindex, width, height);
  279. lua_pushinteger(L, width);
  280. lua_pushinteger(L, height);
  281. return 2;
  282. }
  283. int w_setPosition(lua_State *L)
  284. {
  285. int x = (int) luaL_checkinteger(L, 1);
  286. int y = (int) luaL_checkinteger(L, 2);
  287. int displayindex = 0;
  288. if (!lua_isnoneornil(L, 3))
  289. displayindex = (int) luaL_checkinteger(L, 3) - 1;
  290. else
  291. {
  292. int x_unused, y_unused;
  293. instance()->getPosition(x_unused, y_unused, displayindex);
  294. }
  295. instance()->setPosition(x, y, displayindex);
  296. return 0;
  297. }
  298. int w_getPosition(lua_State *L)
  299. {
  300. int x = 0;
  301. int y = 0;
  302. int displayindex = 0;
  303. instance()->getPosition(x, y, displayindex);
  304. lua_pushinteger(L, x);
  305. lua_pushinteger(L, y);
  306. lua_pushinteger(L, displayindex + 1);
  307. return 3;
  308. }
  309. int w_getSafeArea(lua_State *L)
  310. {
  311. Rect area = instance()->getSafeArea();
  312. lua_pushnumber(L, area.x);
  313. lua_pushnumber(L, area.y);
  314. lua_pushnumber(L, area.w);
  315. lua_pushnumber(L, area.h);
  316. return 4;
  317. }
  318. int w_setIcon(lua_State *L)
  319. {
  320. image::ImageData *i = luax_checktype<image::ImageData>(L, 1);
  321. bool success = false;
  322. luax_catchexcept(L, [&]() { success = instance()->setIcon(i); });
  323. luax_pushboolean(L, success);
  324. return 1;
  325. }
  326. int w_getIcon(lua_State *L)
  327. {
  328. image::ImageData *i = instance()->getIcon();
  329. luax_pushtype(L, i);
  330. return 1;
  331. }
  332. int w_setVSync(lua_State *L)
  333. {
  334. int vsync = 0;
  335. if (lua_type(L, 1) == LUA_TBOOLEAN)
  336. vsync = lua_toboolean(L, 1);
  337. else
  338. vsync = (int)luaL_checkinteger(L, 1);
  339. instance()->setVSync(vsync);
  340. return 0;
  341. }
  342. int w_getVSync(lua_State *L)
  343. {
  344. lua_pushinteger(L, instance()->getVSync());
  345. return 1;
  346. }
  347. int w_setDisplaySleepEnabled(lua_State *L)
  348. {
  349. instance()->setDisplaySleepEnabled(luax_checkboolean(L, 1));
  350. return 0;
  351. }
  352. int w_isDisplaySleepEnabled(lua_State *L)
  353. {
  354. luax_pushboolean(L, instance()->isDisplaySleepEnabled());
  355. return 1;
  356. }
  357. int w_setTitle(lua_State *L)
  358. {
  359. std::string title = luax_checkstring(L, 1);
  360. instance()->setWindowTitle(title);
  361. return 0;
  362. }
  363. int w_getTitle(lua_State *L)
  364. {
  365. luax_pushstring(L, instance()->getWindowTitle());
  366. return 1;
  367. }
  368. int w_hasFocus(lua_State *L)
  369. {
  370. luax_pushboolean(L, instance()->hasFocus());
  371. return 1;
  372. }
  373. int w_hasMouseFocus(lua_State *L)
  374. {
  375. luax_pushboolean(L, instance()->hasMouseFocus());
  376. return 1;
  377. }
  378. int w_isVisible(lua_State *L)
  379. {
  380. luax_pushboolean(L, instance()->isVisible());
  381. return 1;
  382. }
  383. int w_getDPIScale(lua_State *L)
  384. {
  385. lua_pushnumber(L, instance()->getDPIScale());
  386. return 1;
  387. }
  388. int w_getNativeDPIScale(lua_State *L)
  389. {
  390. lua_pushnumber(L, instance()->getNativeDPIScale());
  391. return 1;
  392. }
  393. int w_toPixels(lua_State *L)
  394. {
  395. double wx = luaL_checknumber(L, 1);
  396. if (lua_isnoneornil(L, 2))
  397. {
  398. lua_pushnumber(L, instance()->toPixels(wx));
  399. return 1;
  400. }
  401. double wy = luaL_checknumber(L, 2);
  402. double px = 0.0, py = 0.0;
  403. instance()->toPixels(wx, wy, px, py);
  404. lua_pushnumber(L, px);
  405. lua_pushnumber(L, py);
  406. return 2;
  407. }
  408. int w_fromPixels(lua_State *L)
  409. {
  410. double px = luaL_checknumber(L, 1);
  411. if (lua_isnoneornil(L, 2))
  412. {
  413. lua_pushnumber(L, instance()->fromPixels(px));
  414. return 1;
  415. }
  416. double py = luaL_checknumber(L, 2);
  417. double wx = 0.0, wy = 0.0;
  418. instance()->fromPixels(px, py, wx, wy);
  419. lua_pushnumber(L, wx);
  420. lua_pushnumber(L, wy);
  421. return 2;
  422. }
  423. int w_minimize(lua_State* /*L*/)
  424. {
  425. instance()->minimize();
  426. return 0;
  427. }
  428. int w_maximize(lua_State *)
  429. {
  430. instance()->maximize();
  431. return 0;
  432. }
  433. int w_restore(lua_State *)
  434. {
  435. instance()->restore();
  436. return 0;
  437. }
  438. int w_isMaximized(lua_State *L)
  439. {
  440. luax_pushboolean(L, instance()->isMaximized());
  441. return 1;
  442. }
  443. int w_isMinimized(lua_State *L)
  444. {
  445. luax_pushboolean(L, instance()->isMinimized());
  446. return 1;
  447. }
  448. int w_showMessageBox(lua_State *L)
  449. {
  450. Window::MessageBoxData data = {};
  451. data.type = Window::MESSAGEBOX_INFO;
  452. data.title = luaL_checkstring(L, 1);
  453. data.message = luaL_checkstring(L, 2);
  454. // If we have a table argument, we assume a list of button names, which
  455. // means we should use the more complex message box API.
  456. if (lua_istable(L, 3))
  457. {
  458. size_t numbuttons = luax_objlen(L, 3);
  459. if (numbuttons == 0)
  460. return luaL_error(L, "Must have at least one messagebox button.");
  461. // Array of button names.
  462. for (size_t i = 0; i < numbuttons; i++)
  463. {
  464. lua_rawgeti(L, 3, (int) i + 1);
  465. data.buttons.push_back(luax_checkstring(L, -1));
  466. lua_pop(L, 1);
  467. }
  468. // Optional table entry specifying the button to use when enter is pressed.
  469. lua_getfield(L, 3, "enterbutton");
  470. if (!lua_isnoneornil(L, -1))
  471. data.enterButtonIndex = (int) luaL_checkinteger(L, -1) - 1;
  472. else
  473. data.enterButtonIndex = 0;
  474. lua_pop(L, 1);
  475. // Optional table entry specifying the button to use when esc is pressed.
  476. lua_getfield(L, 3, "escapebutton");
  477. if (!lua_isnoneornil(L, -1))
  478. data.escapeButtonIndex = (int) luaL_checkinteger(L, -1) - 1;
  479. else
  480. data.escapeButtonIndex = (int) data.buttons.size() - 1;
  481. lua_pop(L, 1);
  482. const char *typestr = lua_isnoneornil(L, 4) ? nullptr : luaL_checkstring(L, 4);
  483. if (typestr && !Window::getConstant(typestr, data.type))
  484. return luax_enumerror(L, "messagebox type", Window::getConstants(data.type), typestr);
  485. data.attachToWindow = luax_optboolean(L, 5, true);
  486. int pressedbutton = instance()->showMessageBox(data);
  487. lua_pushinteger(L, pressedbutton + 1);
  488. }
  489. else
  490. {
  491. const char *typestr = lua_isnoneornil(L, 3) ? nullptr : luaL_checkstring(L, 3);
  492. if (typestr && !Window::getConstant(typestr, data.type))
  493. return luax_enumerror(L, "messagebox type", Window::getConstants(data.type), typestr);
  494. data.attachToWindow = luax_optboolean(L, 4, true);
  495. // Display a simple message box.
  496. bool success = instance()->showMessageBox(data.title, data.message, data.type, data.attachToWindow);
  497. luax_pushboolean(L, success);
  498. }
  499. return 1;
  500. }
  501. int w_requestAttention(lua_State *L)
  502. {
  503. bool continuous = luax_optboolean(L, 1, false);
  504. instance()->requestAttention(continuous);
  505. return 0;
  506. }
  507. static const luaL_Reg functions[] =
  508. {
  509. { "getDisplayCount", w_getDisplayCount },
  510. { "getDisplayName", w_getDisplayName },
  511. { "setMode", w_setMode },
  512. { "updateMode", w_updateMode },
  513. { "getMode", w_getMode },
  514. { "isHighDPIAllowed", w_isHighDPIAllowed },
  515. { "getDisplayOrientation", w_getDisplayOrientation },
  516. { "getFullscreenModes", w_getFullscreenModes },
  517. { "setFullscreen", w_setFullscreen },
  518. { "getFullscreen", w_getFullscreen },
  519. { "isOpen", w_isOpen },
  520. { "close", w_close },
  521. { "getDesktopDimensions", w_getDesktopDimensions },
  522. { "setPosition", w_setPosition },
  523. { "getPosition", w_getPosition },
  524. { "getSafeArea", w_getSafeArea },
  525. { "setIcon", w_setIcon },
  526. { "getIcon", w_getIcon },
  527. { "setVSync", w_setVSync },
  528. { "getVSync", w_getVSync },
  529. { "setDisplaySleepEnabled", w_setDisplaySleepEnabled },
  530. { "isDisplaySleepEnabled", w_isDisplaySleepEnabled },
  531. { "setTitle", w_setTitle },
  532. { "getTitle", w_getTitle },
  533. { "hasFocus", w_hasFocus },
  534. { "hasMouseFocus", w_hasMouseFocus },
  535. { "isVisible", w_isVisible },
  536. { "getDPIScale", w_getDPIScale },
  537. { "getNativeDPIScale", w_getNativeDPIScale },
  538. { "toPixels", w_toPixels },
  539. { "fromPixels", w_fromPixels },
  540. { "minimize", w_minimize },
  541. { "maximize", w_maximize },
  542. { "restore", w_restore },
  543. { "isMaximized", w_isMaximized },
  544. { "isMinimized", w_isMinimized },
  545. { "showMessageBox", w_showMessageBox },
  546. { "requestAttention", w_requestAttention },
  547. { 0, 0 }
  548. };
  549. extern "C" int luaopen_love_window(lua_State *L)
  550. {
  551. Window *instance = instance();
  552. if (instance == nullptr)
  553. luax_catchexcept(L, [&](){ instance = new love::window::sdl::Window(); });
  554. else
  555. instance->retain();
  556. WrappedModule w;
  557. w.module = instance;
  558. w.name = "window";
  559. w.type = &Module::type;
  560. w.functions = functions;
  561. w.types = 0;
  562. return luax_register_module(L, w);
  563. }
  564. } // window
  565. } // love