Event.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /**
  2. * Copyright (c) 2006-2015 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 "Event.h"
  21. #include "keyboard/Keyboard.h"
  22. #include "mouse/Mouse.h"
  23. #include "joystick/JoystickModule.h"
  24. #include "joystick/sdl/Joystick.h"
  25. #include "graphics/Graphics.h"
  26. #include "window/Window.h"
  27. #include "common/Exception.h"
  28. #include "common/config.h"
  29. #include <cmath>
  30. namespace love
  31. {
  32. namespace event
  33. {
  34. namespace sdl
  35. {
  36. // SDL reports mouse coordinates in the window coordinate system in OS X, but
  37. // we want them in pixel coordinates (may be different with high-DPI enabled.)
  38. static void windowToPixelCoords(double *x, double *y)
  39. {
  40. window::Window *window = Module::getInstance<window::Window>(Module::M_WINDOW);
  41. if (window && x)
  42. *x = window->toPixels(*x);
  43. if (window && y)
  44. *y = window->toPixels(*y);
  45. }
  46. const char *Event::getName() const
  47. {
  48. return "love.event.sdl";
  49. }
  50. Event::Event()
  51. {
  52. if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0)
  53. throw love::Exception("%s", SDL_GetError());
  54. }
  55. Event::~Event()
  56. {
  57. SDL_QuitSubSystem(SDL_INIT_EVENTS);
  58. }
  59. void Event::pump()
  60. {
  61. SDL_Event e;
  62. while (SDL_PollEvent(&e))
  63. {
  64. Message *msg = convert(e);
  65. if (msg)
  66. {
  67. push(msg);
  68. msg->release();
  69. }
  70. }
  71. }
  72. Message *Event::wait()
  73. {
  74. SDL_Event e;
  75. if (SDL_WaitEvent(&e) != 1)
  76. return nullptr;
  77. return convert(e);
  78. }
  79. void Event::clear()
  80. {
  81. SDL_Event e;
  82. while (SDL_PollEvent(&e))
  83. {
  84. // Do nothing with 'e' ...
  85. }
  86. love::event::Event::clear();
  87. }
  88. Message *Event::convert(const SDL_Event &e) const
  89. {
  90. Message *msg = NULL;
  91. love::keyboard::Keyboard *kb = 0;
  92. love::keyboard::Keyboard::Key key;
  93. love::mouse::Mouse::Button button;
  94. Variant *arg1, *arg2, *arg3, *arg4;
  95. const char *txt;
  96. std::map<SDL_Keycode, love::keyboard::Keyboard::Key>::const_iterator keyit;
  97. switch (e.type)
  98. {
  99. case SDL_KEYDOWN:
  100. if (e.key.repeat)
  101. {
  102. kb = Module::getInstance<love::keyboard::Keyboard>(Module::M_KEYBOARD);
  103. if (kb && !kb->hasKeyRepeat())
  104. break;
  105. }
  106. keyit = keys.find(e.key.keysym.sym);
  107. if (keyit != keys.end())
  108. key = keyit->second;
  109. else
  110. key = love::keyboard::Keyboard::KEY_UNKNOWN;
  111. if (!love::keyboard::Keyboard::getConstant(key, txt))
  112. txt = "unknown";
  113. arg1 = new Variant(txt, strlen(txt));
  114. arg2 = new Variant(e.key.repeat != 0);
  115. msg = new Message("keypressed", arg1, arg2);
  116. arg1->release();
  117. arg2->release();
  118. break;
  119. case SDL_KEYUP:
  120. keyit = keys.find(e.key.keysym.sym);
  121. if (keyit != keys.end())
  122. key = keyit->second;
  123. else
  124. key = love::keyboard::Keyboard::KEY_UNKNOWN;
  125. if (!love::keyboard::Keyboard::getConstant(key, txt))
  126. txt = "unknown";
  127. arg1 = new Variant(txt, strlen(txt));
  128. msg = new Message("keyreleased", arg1);
  129. arg1->release();
  130. break;
  131. case SDL_TEXTINPUT:
  132. txt = e.text.text;
  133. arg1 = new Variant(txt, strlen(txt));
  134. msg = new Message("textinput", arg1);
  135. arg1->release();
  136. break;
  137. case SDL_TEXTEDITING:
  138. txt = e.edit.text;
  139. arg1 = new Variant(txt, strlen(txt));
  140. arg2 = new Variant((double) e.edit.start);
  141. arg3 = new Variant((double) e.edit.length);
  142. msg = new Message("textedit", arg1, arg2, arg3);
  143. arg1->release();
  144. arg2->release();
  145. arg3->release();
  146. break;
  147. case SDL_MOUSEMOTION:
  148. {
  149. double x = (double) e.motion.x;
  150. double y = (double) e.motion.y;
  151. double xrel = (double) e.motion.xrel;
  152. double yrel = (double) e.motion.yrel;
  153. windowToPixelCoords(&x, &y);
  154. windowToPixelCoords(&xrel, &yrel);
  155. arg1 = new Variant(x);
  156. arg2 = new Variant(y);
  157. arg3 = new Variant(xrel);
  158. arg4 = new Variant(yrel);
  159. msg = new Message("mousemoved", arg1, arg2, arg3, arg4);
  160. arg1->release();
  161. arg2->release();
  162. arg3->release();
  163. arg4->release();
  164. }
  165. break;
  166. case SDL_MOUSEBUTTONDOWN:
  167. case SDL_MOUSEBUTTONUP:
  168. if (buttons.find(e.button.button, button) && mouse::Mouse::getConstant(button, txt))
  169. {
  170. double x = (double) e.button.x;
  171. double y = (double) e.button.y;
  172. windowToPixelCoords(&x, &y);
  173. arg1 = new Variant(x);
  174. arg2 = new Variant(y);
  175. arg3 = new Variant(txt, strlen(txt));
  176. msg = new Message((e.type == SDL_MOUSEBUTTONDOWN) ?
  177. "mousepressed" : "mousereleased",
  178. arg1, arg2, arg3);
  179. arg1->release();
  180. arg2->release();
  181. arg3->release();
  182. }
  183. break;
  184. case SDL_MOUSEWHEEL:
  185. if (e.wheel.y != 0)
  186. {
  187. button = (e.wheel.y > 0) ? mouse::Mouse::BUTTON_WHEELUP : mouse::Mouse::BUTTON_WHEELDOWN;
  188. if (!love::mouse::Mouse::getConstant(button, txt))
  189. break;
  190. int mx, my;
  191. double dmx, dmy;
  192. SDL_GetMouseState(&mx, &my);
  193. dmx = (double) mx;
  194. dmy = (double) my;
  195. windowToPixelCoords(&dmx, &dmy);
  196. arg1 = new Variant(dmx);
  197. arg2 = new Variant(dmy);
  198. arg3 = new Variant(txt, strlen(txt));
  199. msg = new Message("mousepressed", arg1, arg2, arg3);
  200. arg1->release();
  201. arg2->release();
  202. arg3->release();
  203. }
  204. break;
  205. case SDL_JOYBUTTONDOWN:
  206. case SDL_JOYBUTTONUP:
  207. case SDL_JOYAXISMOTION:
  208. case SDL_JOYBALLMOTION:
  209. case SDL_JOYHATMOTION:
  210. case SDL_JOYDEVICEADDED:
  211. case SDL_JOYDEVICEREMOVED:
  212. case SDL_CONTROLLERBUTTONDOWN:
  213. case SDL_CONTROLLERBUTTONUP:
  214. case SDL_CONTROLLERAXISMOTION:
  215. msg = convertJoystickEvent(e);
  216. break;
  217. case SDL_WINDOWEVENT:
  218. msg = convertWindowEvent(e);
  219. break;
  220. case SDL_DROPFILE:
  221. SDL_free(e.drop.file);
  222. break;
  223. case SDL_QUIT:
  224. msg = new Message("quit");
  225. break;
  226. default:
  227. break;
  228. }
  229. return msg;
  230. }
  231. Message *Event::convertJoystickEvent(const SDL_Event &e) const
  232. {
  233. joystick::JoystickModule *joymodule = Module::getInstance<joystick::JoystickModule>(Module::M_JOYSTICK);
  234. if (!joymodule)
  235. return 0;
  236. Message *msg = 0;
  237. Proxy proxy;
  238. love::joystick::Joystick::Hat hat;
  239. love::joystick::Joystick::GamepadButton padbutton;
  240. love::joystick::Joystick::GamepadAxis padaxis;
  241. Variant *arg1, *arg2, *arg3;
  242. const char *txt;
  243. switch (e.type)
  244. {
  245. case SDL_JOYBUTTONDOWN:
  246. case SDL_JOYBUTTONUP:
  247. proxy.flags = JOYSTICK_JOYSTICK_T;
  248. proxy.data = joymodule->getJoystickFromID(e.jbutton.which);
  249. if (!proxy.data)
  250. break;
  251. arg1 = new Variant(JOYSTICK_JOYSTICK_ID, (void *) &proxy);
  252. arg2 = new Variant((double)(e.jbutton.button+1));
  253. msg = new Message((e.type == SDL_JOYBUTTONDOWN) ?
  254. "joystickpressed" : "joystickreleased",
  255. arg1, arg2);
  256. arg1->release();
  257. arg2->release();
  258. break;
  259. case SDL_JOYAXISMOTION:
  260. {
  261. proxy.flags = JOYSTICK_JOYSTICK_T;
  262. proxy.data = joymodule->getJoystickFromID(e.jaxis.which);
  263. if (!proxy.data)
  264. break;
  265. arg1 = new Variant(JOYSTICK_JOYSTICK_ID, (void *) &proxy);
  266. arg2 = new Variant((double)(e.jaxis.axis+1));
  267. float value = joystick::Joystick::clampval(e.jaxis.value / 32768.0f);
  268. arg3 = new Variant((double) value);
  269. msg = new Message("joystickaxis", arg1, arg2, arg3);
  270. arg1->release();
  271. arg2->release();
  272. arg3->release();
  273. }
  274. break;
  275. case SDL_JOYHATMOTION:
  276. if (!joystick::sdl::Joystick::getConstant(e.jhat.value, hat) || !joystick::Joystick::getConstant(hat, txt))
  277. break;
  278. proxy.flags = JOYSTICK_JOYSTICK_T;
  279. proxy.data = joymodule->getJoystickFromID(e.jhat.which);
  280. if (!proxy.data)
  281. break;
  282. arg1 = new Variant(JOYSTICK_JOYSTICK_ID, (void *) &proxy);
  283. arg2 = new Variant((double)(e.jhat.hat+1));
  284. arg3 = new Variant(txt, strlen(txt));
  285. msg = new Message("joystickhat", arg1, arg2, arg3);
  286. arg1->release();
  287. arg2->release();
  288. arg3->release();
  289. break;
  290. case SDL_CONTROLLERBUTTONDOWN:
  291. case SDL_CONTROLLERBUTTONUP:
  292. if (!joystick::sdl::Joystick::getConstant((SDL_GameControllerButton) e.cbutton.button, padbutton))
  293. break;
  294. if (!joystick::Joystick::getConstant(padbutton, txt))
  295. break;
  296. proxy.flags = JOYSTICK_JOYSTICK_T;
  297. proxy.data = joymodule->getJoystickFromID(e.cbutton.which);
  298. if (!proxy.data)
  299. break;
  300. arg1 = new Variant(JOYSTICK_JOYSTICK_ID, (void *) &proxy);
  301. arg2 = new Variant(txt, strlen(txt));
  302. msg = new Message(e.type == SDL_CONTROLLERBUTTONDOWN ?
  303. "gamepadpressed" : "gamepadreleased", arg1, arg2);
  304. arg1->release();
  305. arg2->release();
  306. break;
  307. case SDL_CONTROLLERAXISMOTION:
  308. if (joystick::sdl::Joystick::getConstant((SDL_GameControllerAxis) e.caxis.axis, padaxis))
  309. {
  310. if (!joystick::Joystick::getConstant(padaxis, txt))
  311. break;
  312. proxy.flags = JOYSTICK_JOYSTICK_T;
  313. proxy.data = joymodule->getJoystickFromID(e.caxis.which);
  314. if (!proxy.data)
  315. break;
  316. arg1 = new Variant(JOYSTICK_JOYSTICK_ID, (void *) &proxy);
  317. arg2 = new Variant(txt, strlen(txt));
  318. float value = joystick::Joystick::clampval(e.caxis.value / 32768.0f);
  319. arg3 = new Variant((double) value);
  320. msg = new Message("gamepadaxis", arg1, arg2, arg3);
  321. arg1->release();
  322. arg2->release();
  323. arg3->release();
  324. }
  325. break;
  326. case SDL_JOYDEVICEADDED:
  327. // jdevice.which is the joystick device index.
  328. proxy.data = joymodule->addJoystick(e.jdevice.which);
  329. proxy.flags = JOYSTICK_JOYSTICK_T;
  330. if (proxy.data)
  331. {
  332. arg1 = new Variant(JOYSTICK_JOYSTICK_ID, (void *) &proxy);
  333. msg = new Message("joystickadded", arg1);
  334. arg1->release();
  335. }
  336. break;
  337. case SDL_JOYDEVICEREMOVED:
  338. // jdevice.which is the joystick instance ID now.
  339. proxy.data = joymodule->getJoystickFromID(e.jdevice.which);
  340. proxy.flags = JOYSTICK_JOYSTICK_T;
  341. if (proxy.data)
  342. {
  343. joymodule->removeJoystick((joystick::Joystick *) proxy.data);
  344. arg1 = new Variant(JOYSTICK_JOYSTICK_ID, (void *) &proxy);
  345. msg = new Message("joystickremoved", arg1);
  346. arg1->release();
  347. }
  348. break;
  349. default:
  350. break;
  351. }
  352. return msg;
  353. }
  354. Message *Event::convertWindowEvent(const SDL_Event &e) const
  355. {
  356. Message *msg = 0;
  357. Variant *arg1, *arg2, *arg3, *arg4;
  358. window::Window *win = 0;
  359. if (e.type != SDL_WINDOWEVENT)
  360. return 0;
  361. switch (e.window.event)
  362. {
  363. case SDL_WINDOWEVENT_FOCUS_GAINED:
  364. case SDL_WINDOWEVENT_FOCUS_LOST:
  365. // Users won't expect the screensaver to activate if a game is in
  366. // focus. Also, joystick input may not delay the screensaver timer.
  367. if (e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
  368. SDL_DisableScreenSaver();
  369. else
  370. SDL_EnableScreenSaver();
  371. arg1 = new Variant(e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED);
  372. msg = new Message("focus", arg1);
  373. arg1->release();
  374. break;
  375. case SDL_WINDOWEVENT_ENTER:
  376. case SDL_WINDOWEVENT_LEAVE:
  377. arg1 = new Variant(e.window.event == SDL_WINDOWEVENT_ENTER);
  378. msg = new Message("mousefocus", arg1);
  379. arg1->release();
  380. break;
  381. case SDL_WINDOWEVENT_SHOWN:
  382. case SDL_WINDOWEVENT_HIDDEN:
  383. arg1 = new Variant(e.window.event == SDL_WINDOWEVENT_SHOWN);
  384. msg = new Message("visible", arg1);
  385. arg1->release();
  386. break;
  387. case SDL_WINDOWEVENT_RESIZED:
  388. win = Module::getInstance<window::Window>(Module::M_WINDOW);
  389. if (win)
  390. {
  391. int px_w = e.window.data1;
  392. int px_h = e.window.data2;
  393. // FIXME: disabled in Linux for runtime SDL 2.0.0 compatibility.
  394. #if SDL_VERSION_ATLEAST(2,0,1) && !defined(LOVE_LINUX)
  395. SDL_Window *sdlwin = SDL_GetWindowFromID(e.window.windowID);
  396. if (sdlwin)
  397. SDL_GL_GetDrawableSize(sdlwin, &px_w, &px_h);
  398. #endif
  399. win->onWindowResize(e.window.data1, e.window.data2);
  400. graphics::Graphics *gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
  401. if (gfx)
  402. gfx->setViewportSize(px_w, px_h);
  403. arg1 = new Variant((double) px_w);
  404. arg2 = new Variant((double) px_h);
  405. arg3 = new Variant((double) e.window.data1);
  406. arg4 = new Variant((double) e.window.data2);
  407. msg = new Message("resize", arg1, arg2, arg3, arg4);
  408. arg1->release();
  409. arg2->release();
  410. arg3->release();
  411. arg4->release();
  412. }
  413. break;
  414. }
  415. return msg;
  416. }
  417. std::map<SDL_Keycode, love::keyboard::Keyboard::Key> Event::createKeyMap()
  418. {
  419. using love::keyboard::Keyboard;
  420. std::map<SDL_Keycode, Keyboard::Key> k;
  421. k[SDLK_UNKNOWN] = Keyboard::KEY_UNKNOWN;
  422. k[SDLK_RETURN] = Keyboard::KEY_RETURN;
  423. k[SDLK_ESCAPE] = Keyboard::KEY_ESCAPE;
  424. k[SDLK_BACKSPACE] = Keyboard::KEY_BACKSPACE;
  425. k[SDLK_TAB] = Keyboard::KEY_TAB;
  426. k[SDLK_SPACE] = Keyboard::KEY_SPACE;
  427. k[SDLK_EXCLAIM] = Keyboard::KEY_EXCLAIM;
  428. k[SDLK_QUOTEDBL] = Keyboard::KEY_QUOTEDBL;
  429. k[SDLK_HASH] = Keyboard::KEY_HASH;
  430. k[SDLK_DOLLAR] = Keyboard::KEY_DOLLAR;
  431. k[SDLK_AMPERSAND] = Keyboard::KEY_AMPERSAND;
  432. k[SDLK_QUOTE] = Keyboard::KEY_QUOTE;
  433. k[SDLK_LEFTPAREN] = Keyboard::KEY_LEFTPAREN;
  434. k[SDLK_RIGHTPAREN] = Keyboard::KEY_RIGHTPAREN;
  435. k[SDLK_ASTERISK] = Keyboard::KEY_ASTERISK;
  436. k[SDLK_PLUS] = Keyboard::KEY_PLUS;
  437. k[SDLK_COMMA] = Keyboard::KEY_COMMA;
  438. k[SDLK_MINUS] = Keyboard::KEY_MINUS;
  439. k[SDLK_PERIOD] = Keyboard::KEY_PERIOD;
  440. k[SDLK_SLASH] = Keyboard::KEY_SLASH;
  441. k[SDLK_0] = Keyboard::KEY_0;
  442. k[SDLK_1] = Keyboard::KEY_1;
  443. k[SDLK_2] = Keyboard::KEY_2;
  444. k[SDLK_3] = Keyboard::KEY_3;
  445. k[SDLK_4] = Keyboard::KEY_4;
  446. k[SDLK_5] = Keyboard::KEY_5;
  447. k[SDLK_6] = Keyboard::KEY_6;
  448. k[SDLK_7] = Keyboard::KEY_7;
  449. k[SDLK_8] = Keyboard::KEY_8;
  450. k[SDLK_9] = Keyboard::KEY_9;
  451. k[SDLK_COLON] = Keyboard::KEY_COLON;
  452. k[SDLK_SEMICOLON] = Keyboard::KEY_SEMICOLON;
  453. k[SDLK_LESS] = Keyboard::KEY_LESS;
  454. k[SDLK_EQUALS] = Keyboard::KEY_EQUALS;
  455. k[SDLK_GREATER] = Keyboard::KEY_GREATER;
  456. k[SDLK_QUESTION] = Keyboard::KEY_QUESTION;
  457. k[SDLK_AT] = Keyboard::KEY_AT;
  458. k[SDLK_LEFTBRACKET] = Keyboard::KEY_LEFTBRACKET;
  459. k[SDLK_BACKSLASH] = Keyboard::KEY_BACKSLASH;
  460. k[SDLK_RIGHTBRACKET] = Keyboard::KEY_RIGHTBRACKET;
  461. k[SDLK_CARET] = Keyboard::KEY_CARET;
  462. k[SDLK_UNDERSCORE] = Keyboard::KEY_UNDERSCORE;
  463. k[SDLK_BACKQUOTE] = Keyboard::KEY_BACKQUOTE;
  464. k[SDLK_a] = Keyboard::KEY_A;
  465. k[SDLK_b] = Keyboard::KEY_B;
  466. k[SDLK_c] = Keyboard::KEY_C;
  467. k[SDLK_d] = Keyboard::KEY_D;
  468. k[SDLK_e] = Keyboard::KEY_E;
  469. k[SDLK_f] = Keyboard::KEY_F;
  470. k[SDLK_g] = Keyboard::KEY_G;
  471. k[SDLK_h] = Keyboard::KEY_H;
  472. k[SDLK_i] = Keyboard::KEY_I;
  473. k[SDLK_j] = Keyboard::KEY_J;
  474. k[SDLK_k] = Keyboard::KEY_K;
  475. k[SDLK_l] = Keyboard::KEY_L;
  476. k[SDLK_m] = Keyboard::KEY_M;
  477. k[SDLK_n] = Keyboard::KEY_N;
  478. k[SDLK_o] = Keyboard::KEY_O;
  479. k[SDLK_p] = Keyboard::KEY_P;
  480. k[SDLK_q] = Keyboard::KEY_Q;
  481. k[SDLK_r] = Keyboard::KEY_R;
  482. k[SDLK_s] = Keyboard::KEY_S;
  483. k[SDLK_t] = Keyboard::KEY_T;
  484. k[SDLK_u] = Keyboard::KEY_U;
  485. k[SDLK_v] = Keyboard::KEY_V;
  486. k[SDLK_w] = Keyboard::KEY_W;
  487. k[SDLK_x] = Keyboard::KEY_X;
  488. k[SDLK_y] = Keyboard::KEY_Y;
  489. k[SDLK_z] = Keyboard::KEY_Z;
  490. k[SDLK_CAPSLOCK] = Keyboard::KEY_CAPSLOCK;
  491. k[SDLK_F1] = Keyboard::KEY_F1;
  492. k[SDLK_F2] = Keyboard::KEY_F2;
  493. k[SDLK_F3] = Keyboard::KEY_F3;
  494. k[SDLK_F4] = Keyboard::KEY_F4;
  495. k[SDLK_F5] = Keyboard::KEY_F5;
  496. k[SDLK_F6] = Keyboard::KEY_F6;
  497. k[SDLK_F7] = Keyboard::KEY_F7;
  498. k[SDLK_F8] = Keyboard::KEY_F8;
  499. k[SDLK_F9] = Keyboard::KEY_F9;
  500. k[SDLK_F10] = Keyboard::KEY_F10;
  501. k[SDLK_F11] = Keyboard::KEY_F11;
  502. k[SDLK_F12] = Keyboard::KEY_F12;
  503. k[SDLK_PRINTSCREEN] = Keyboard::KEY_PRINTSCREEN;
  504. k[SDLK_SCROLLLOCK] = Keyboard::KEY_SCROLLLOCK;
  505. k[SDLK_PAUSE] = Keyboard::KEY_PAUSE;
  506. k[SDLK_INSERT] = Keyboard::KEY_INSERT;
  507. k[SDLK_HOME] = Keyboard::KEY_HOME;
  508. k[SDLK_PAGEUP] = Keyboard::KEY_PAGEUP;
  509. k[SDLK_DELETE] = Keyboard::KEY_DELETE;
  510. k[SDLK_END] = Keyboard::KEY_END;
  511. k[SDLK_PAGEDOWN] = Keyboard::KEY_PAGEDOWN;
  512. k[SDLK_RIGHT] = Keyboard::KEY_RIGHT;
  513. k[SDLK_LEFT] = Keyboard::KEY_LEFT;
  514. k[SDLK_DOWN] = Keyboard::KEY_DOWN;
  515. k[SDLK_UP] = Keyboard::KEY_UP;
  516. k[SDLK_NUMLOCKCLEAR] = Keyboard::KEY_NUMLOCKCLEAR;
  517. k[SDLK_KP_DIVIDE] = Keyboard::KEY_KP_DIVIDE;
  518. k[SDLK_KP_MULTIPLY] = Keyboard::KEY_KP_MULTIPLY;
  519. k[SDLK_KP_MINUS] = Keyboard::KEY_KP_MINUS;
  520. k[SDLK_KP_PLUS] = Keyboard::KEY_KP_PLUS;
  521. k[SDLK_KP_ENTER] = Keyboard::KEY_KP_ENTER;
  522. k[SDLK_KP_0] = Keyboard::KEY_KP_0;
  523. k[SDLK_KP_1] = Keyboard::KEY_KP_1;
  524. k[SDLK_KP_2] = Keyboard::KEY_KP_2;
  525. k[SDLK_KP_3] = Keyboard::KEY_KP_3;
  526. k[SDLK_KP_4] = Keyboard::KEY_KP_4;
  527. k[SDLK_KP_5] = Keyboard::KEY_KP_5;
  528. k[SDLK_KP_6] = Keyboard::KEY_KP_6;
  529. k[SDLK_KP_7] = Keyboard::KEY_KP_7;
  530. k[SDLK_KP_8] = Keyboard::KEY_KP_8;
  531. k[SDLK_KP_9] = Keyboard::KEY_KP_9;
  532. k[SDLK_KP_PERIOD] = Keyboard::KEY_KP_PERIOD;
  533. k[SDLK_KP_COMMA] = Keyboard::KEY_KP_COMMA;
  534. k[SDLK_KP_EQUALS] = Keyboard::KEY_KP_EQUALS;
  535. k[SDLK_APPLICATION] = Keyboard::KEY_APPLICATION;
  536. k[SDLK_POWER] = Keyboard::KEY_POWER;
  537. k[SDLK_F13] = Keyboard::KEY_F13;
  538. k[SDLK_F14] = Keyboard::KEY_F14;
  539. k[SDLK_F15] = Keyboard::KEY_F15;
  540. k[SDLK_F16] = Keyboard::KEY_F16;
  541. k[SDLK_F17] = Keyboard::KEY_F17;
  542. k[SDLK_F18] = Keyboard::KEY_F18;
  543. k[SDLK_F19] = Keyboard::KEY_F19;
  544. k[SDLK_F20] = Keyboard::KEY_F20;
  545. k[SDLK_F21] = Keyboard::KEY_F21;
  546. k[SDLK_F22] = Keyboard::KEY_F22;
  547. k[SDLK_F23] = Keyboard::KEY_F23;
  548. k[SDLK_F24] = Keyboard::KEY_F24;
  549. k[SDLK_EXECUTE] = Keyboard::KEY_EXECUTE;
  550. k[SDLK_HELP] = Keyboard::KEY_HELP;
  551. k[SDLK_MENU] = Keyboard::KEY_MENU;
  552. k[SDLK_SELECT] = Keyboard::KEY_SELECT;
  553. k[SDLK_STOP] = Keyboard::KEY_STOP;
  554. k[SDLK_AGAIN] = Keyboard::KEY_AGAIN;
  555. k[SDLK_UNDO] = Keyboard::KEY_UNDO;
  556. k[SDLK_CUT] = Keyboard::KEY_CUT;
  557. k[SDLK_COPY] = Keyboard::KEY_COPY;
  558. k[SDLK_PASTE] = Keyboard::KEY_PASTE;
  559. k[SDLK_FIND] = Keyboard::KEY_FIND;
  560. k[SDLK_MUTE] = Keyboard::KEY_MUTE;
  561. k[SDLK_VOLUMEUP] = Keyboard::KEY_VOLUMEUP;
  562. k[SDLK_VOLUMEDOWN] = Keyboard::KEY_VOLUMEDOWN;
  563. k[SDLK_ALTERASE] = Keyboard::KEY_ALTERASE;
  564. k[SDLK_SYSREQ] = Keyboard::KEY_SYSREQ;
  565. k[SDLK_CANCEL] = Keyboard::KEY_CANCEL;
  566. k[SDLK_CLEAR] = Keyboard::KEY_CLEAR;
  567. k[SDLK_PRIOR] = Keyboard::KEY_PRIOR;
  568. k[SDLK_RETURN2] = Keyboard::KEY_RETURN2;
  569. k[SDLK_SEPARATOR] = Keyboard::KEY_SEPARATOR;
  570. k[SDLK_OUT] = Keyboard::KEY_OUT;
  571. k[SDLK_OPER] = Keyboard::KEY_OPER;
  572. k[SDLK_CLEARAGAIN] = Keyboard::KEY_CLEARAGAIN;
  573. k[SDLK_THOUSANDSSEPARATOR] = Keyboard::KEY_THOUSANDSSEPARATOR;
  574. k[SDLK_DECIMALSEPARATOR] = Keyboard::KEY_DECIMALSEPARATOR;
  575. k[SDLK_CURRENCYUNIT] = Keyboard::KEY_CURRENCYUNIT;
  576. k[SDLK_CURRENCYSUBUNIT] = Keyboard::KEY_CURRENCYSUBUNIT;
  577. k[SDLK_LCTRL] = Keyboard::KEY_LCTRL;
  578. k[SDLK_LSHIFT] = Keyboard::KEY_LSHIFT;
  579. k[SDLK_LALT] = Keyboard::KEY_LALT;
  580. k[SDLK_LGUI] = Keyboard::KEY_LGUI;
  581. k[SDLK_RCTRL] = Keyboard::KEY_RCTRL;
  582. k[SDLK_RSHIFT] = Keyboard::KEY_RSHIFT;
  583. k[SDLK_RALT] = Keyboard::KEY_RALT;
  584. k[SDLK_RGUI] = Keyboard::KEY_RGUI;
  585. k[SDLK_MODE] = Keyboard::KEY_MODE;
  586. k[SDLK_AUDIONEXT] = Keyboard::KEY_AUDIONEXT;
  587. k[SDLK_AUDIOPREV] = Keyboard::KEY_AUDIOPREV;
  588. k[SDLK_AUDIOSTOP] = Keyboard::KEY_AUDIOSTOP;
  589. k[SDLK_AUDIOPLAY] = Keyboard::KEY_AUDIOPLAY;
  590. k[SDLK_AUDIOMUTE] = Keyboard::KEY_AUDIOMUTE;
  591. k[SDLK_MEDIASELECT] = Keyboard::KEY_MEDIASELECT;
  592. k[SDLK_WWW] = Keyboard::KEY_WWW;
  593. k[SDLK_MAIL] = Keyboard::KEY_MAIL;
  594. k[SDLK_CALCULATOR] = Keyboard::KEY_CALCULATOR;
  595. k[SDLK_COMPUTER] = Keyboard::KEY_COMPUTER;
  596. k[SDLK_AC_SEARCH] = Keyboard::KEY_APP_SEARCH;
  597. k[SDLK_AC_HOME] = Keyboard::KEY_APP_HOME;
  598. k[SDLK_AC_BACK] = Keyboard::KEY_APP_BACK;
  599. k[SDLK_AC_FORWARD] = Keyboard::KEY_APP_FORWARD;
  600. k[SDLK_AC_STOP] = Keyboard::KEY_APP_STOP;
  601. k[SDLK_AC_REFRESH] = Keyboard::KEY_APP_REFRESH;
  602. k[SDLK_AC_BOOKMARKS] = Keyboard::KEY_APP_BOOKMARKS;
  603. k[SDLK_BRIGHTNESSDOWN] = Keyboard::KEY_BRIGHTNESSDOWN;
  604. k[SDLK_BRIGHTNESSUP] = Keyboard::KEY_BRIGHTNESSUP;
  605. k[SDLK_DISPLAYSWITCH] = Keyboard::KEY_DISPLAYSWITCH;
  606. k[SDLK_KBDILLUMTOGGLE] = Keyboard::KEY_KBDILLUMTOGGLE;
  607. k[SDLK_KBDILLUMDOWN] = Keyboard::KEY_KBDILLUMDOWN;
  608. k[SDLK_KBDILLUMUP] = Keyboard::KEY_KBDILLUMUP;
  609. k[SDLK_EJECT] = Keyboard::KEY_EJECT;
  610. k[SDLK_SLEEP] = Keyboard::KEY_SLEEP;
  611. return k;
  612. }
  613. std::map<SDL_Keycode, love::keyboard::Keyboard::Key> Event::keys = Event::createKeyMap();
  614. EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM>::Entry Event::buttonEntries[] =
  615. {
  616. { love::mouse::Mouse::BUTTON_LEFT, SDL_BUTTON_LEFT},
  617. { love::mouse::Mouse::BUTTON_MIDDLE, SDL_BUTTON_MIDDLE},
  618. { love::mouse::Mouse::BUTTON_RIGHT, SDL_BUTTON_RIGHT},
  619. { love::mouse::Mouse::BUTTON_X1, SDL_BUTTON_X1},
  620. { love::mouse::Mouse::BUTTON_X2, SDL_BUTTON_X2},
  621. };
  622. EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM> Event::buttons(Event::buttonEntries, sizeof(Event::buttonEntries));
  623. } // sdl
  624. } // event
  625. } // love