tinySDLGraphicsWindow.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. // Filename: tinySDLGraphicsWindow.cxx
  2. // Created by: drose (24Apr08)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #include "pandabase.h"
  15. #ifdef HAVE_SDL
  16. #include "tinySDLGraphicsWindow.h"
  17. #include "tinyGraphicsStateGuardian.h"
  18. #include "config_tinydisplay.h"
  19. #include "tinySDLGraphicsPipe.h"
  20. #include "mouseButton.h"
  21. #include "keyboardButton.h"
  22. #include "graphicsPipe.h"
  23. TypeHandle TinySDLGraphicsWindow::_type_handle;
  24. ////////////////////////////////////////////////////////////////////
  25. // Function: TinySDLGraphicsWindow::Constructor
  26. // Access: Public
  27. // Description:
  28. ////////////////////////////////////////////////////////////////////
  29. TinySDLGraphicsWindow::
  30. TinySDLGraphicsWindow(GraphicsPipe *pipe,
  31. const string &name,
  32. const FrameBufferProperties &fb_prop,
  33. const WindowProperties &win_prop,
  34. int flags,
  35. GraphicsStateGuardian *gsg,
  36. GraphicsOutput *host) :
  37. GraphicsWindow(pipe, name, fb_prop, win_prop, flags, gsg, host)
  38. {
  39. _screen = NULL;
  40. _frame_buffer = NULL;
  41. _pitch = 0;
  42. update_pixel_factor();
  43. GraphicsWindowInputDevice device =
  44. GraphicsWindowInputDevice::pointer_and_keyboard(this, "keyboard_mouse");
  45. add_input_device(device);
  46. }
  47. ////////////////////////////////////////////////////////////////////
  48. // Function: TinySDLGraphicsWindow::Destructor
  49. // Access: Public, Virtual
  50. // Description:
  51. ////////////////////////////////////////////////////////////////////
  52. TinySDLGraphicsWindow::
  53. ~TinySDLGraphicsWindow() {
  54. }
  55. ////////////////////////////////////////////////////////////////////
  56. // Function: TinySDLGraphicsWindow::begin_frame
  57. // Access: Public, Virtual
  58. // Description: This function will be called within the draw thread
  59. // before beginning rendering for a given frame. It
  60. // should do whatever setup is required, and return true
  61. // if the frame should be rendered, or false if it
  62. // should be skipped.
  63. ////////////////////////////////////////////////////////////////////
  64. bool TinySDLGraphicsWindow::
  65. begin_frame(FrameMode mode, Thread *current_thread) {
  66. begin_frame_spam(mode);
  67. if (_gsg == (GraphicsStateGuardian *)NULL) {
  68. return false;
  69. }
  70. TinyGraphicsStateGuardian *tinygsg;
  71. DCAST_INTO_R(tinygsg, _gsg, false);
  72. tinygsg->_current_frame_buffer = _frame_buffer;
  73. tinygsg->reset_if_new();
  74. _gsg->set_current_properties(&get_fb_properties());
  75. return _gsg->begin_frame(current_thread);
  76. }
  77. ////////////////////////////////////////////////////////////////////
  78. // Function: TinySDLGraphicsWindow::end_frame
  79. // Access: Public, Virtual
  80. // Description: This function will be called within the draw thread
  81. // after rendering is completed for a given frame. It
  82. // should do whatever finalization is required.
  83. ////////////////////////////////////////////////////////////////////
  84. void TinySDLGraphicsWindow::
  85. end_frame(FrameMode mode, Thread *current_thread) {
  86. end_frame_spam(mode);
  87. nassertv(_gsg != (GraphicsStateGuardian *)NULL);
  88. if (mode == FM_render) {
  89. // end_render_texture();
  90. copy_to_textures();
  91. }
  92. _gsg->end_frame(current_thread);
  93. if (mode == FM_render) {
  94. trigger_flip();
  95. if (_one_shot) {
  96. prepare_for_deletion();
  97. }
  98. }
  99. }
  100. ////////////////////////////////////////////////////////////////////
  101. // Function: TinySDLGraphicsWindow::begin_flip
  102. // Access: Public, Virtual
  103. // Description: This function will be called within the draw thread
  104. // after end_frame() has been called on all windows, to
  105. // initiate the exchange of the front and back buffers.
  106. //
  107. // This should instruct the window to prepare for the
  108. // flip at the next video sync, but it should not wait.
  109. //
  110. // We have the two separate functions, begin_flip() and
  111. // end_flip(), to make it easier to flip all of the
  112. // windows at the same time.
  113. ////////////////////////////////////////////////////////////////////
  114. void TinySDLGraphicsWindow::
  115. begin_flip() {
  116. int fb_xsize = get_fb_x_size();
  117. int fb_ysize = get_fb_y_size();
  118. if (fb_xsize == _frame_buffer->xsize) {
  119. // No zooming is necessary--copy directly to the screen.
  120. if (SDL_MUSTLOCK(_screen)) {
  121. if (SDL_LockSurface(_screen) < 0) {
  122. tinydisplay_cat.error()
  123. << "Can't lock screen: " << SDL_GetError() << "\n";
  124. }
  125. }
  126. ZB_copyFrameBuffer(_frame_buffer, _screen->pixels, _pitch);
  127. if (SDL_MUSTLOCK(_screen)) {
  128. SDL_UnlockSurface(_screen);
  129. }
  130. } else {
  131. // Copy to another surface, then scale it onto the screen.
  132. SDL_Surface *temp =
  133. SDL_CreateRGBSurfaceFrom(_frame_buffer->pbuf, _frame_buffer->xsize, _frame_buffer->ysize,
  134. 32, _frame_buffer->linesize, 0xff0000, 0x00ff00, 0x0000ff, 0xff000000);
  135. SDL_SetAlpha(temp, SDL_RLEACCEL, 0);
  136. SDL_BlitSurface(temp, NULL, _screen, NULL);
  137. SDL_FreeSurface(temp);
  138. }
  139. SDL_Flip(_screen);
  140. }
  141. ////////////////////////////////////////////////////////////////////
  142. // Function: TinySDLGraphicsWindow::process_events
  143. // Access: Public, Virtual
  144. // Description: Do whatever processing is necessary to ensure that
  145. // the window responds to user events. Also, honor any
  146. // requests recently made via request_properties()
  147. //
  148. // This function is called only within the window
  149. // thread.
  150. ////////////////////////////////////////////////////////////////////
  151. void TinySDLGraphicsWindow::
  152. process_events() {
  153. GraphicsWindow::process_events();
  154. if (_screen == NULL) {
  155. return;
  156. }
  157. WindowProperties properties;
  158. SDL_Event evt;
  159. ButtonHandle button;
  160. while (SDL_PollEvent(&evt)) {
  161. switch(evt.type) {
  162. case SDL_KEYDOWN:
  163. if (evt.key.keysym.unicode) {
  164. _input_devices[0].keystroke(evt.key.keysym.unicode);
  165. }
  166. button = get_keyboard_button(evt.key.keysym.sym);
  167. if (button != ButtonHandle::none()) {
  168. _input_devices[0].button_down(button);
  169. }
  170. break;
  171. case SDL_KEYUP:
  172. button = get_keyboard_button(evt.key.keysym.sym);
  173. if (button != ButtonHandle::none()) {
  174. _input_devices[0].button_up(button);
  175. }
  176. break;
  177. case SDL_MOUSEBUTTONDOWN:
  178. button = get_mouse_button(evt.button.button);
  179. _input_devices[0].set_pointer_in_window(evt.button.x, evt.button.y);
  180. _input_devices[0].button_down(button);
  181. break;
  182. case SDL_MOUSEBUTTONUP:
  183. button = get_mouse_button(evt.button.button);
  184. _input_devices[0].set_pointer_in_window(evt.button.x, evt.button.y);
  185. _input_devices[0].button_up(button);
  186. break;
  187. case SDL_MOUSEMOTION:
  188. _input_devices[0].set_pointer_in_window(evt.motion.x, evt.motion.y);
  189. break;
  190. case SDL_VIDEORESIZE:
  191. properties.set_size(evt.resize.w, evt.resize.h);
  192. system_changed_properties(properties);
  193. _screen = SDL_SetVideoMode(_properties.get_x_size(), _properties.get_y_size(), 32, _flags);
  194. ZB_resize(_frame_buffer, NULL, _properties.get_x_size(), _properties.get_y_size());
  195. _pitch = _screen->pitch * 32 / _screen->format->BitsPerPixel;
  196. break;
  197. case SDL_QUIT:
  198. // The window was closed by the user.
  199. close_window();
  200. properties.set_open(false);
  201. system_changed_properties(properties);
  202. break;
  203. }
  204. }
  205. }
  206. ////////////////////////////////////////////////////////////////////
  207. // Function: TinySDLGraphicsWindow::set_properties_now
  208. // Access: Public, Virtual
  209. // Description: Applies the requested set of properties to the
  210. // window, if possible, for instance to request a change
  211. // in size or minimization status.
  212. //
  213. // The window properties are applied immediately, rather
  214. // than waiting until the next frame. This implies that
  215. // this method may *only* be called from within the
  216. // window thread.
  217. //
  218. // The return value is true if the properties are set,
  219. // false if they are ignored. This is mainly useful for
  220. // derived classes to implement extensions to this
  221. // function.
  222. ////////////////////////////////////////////////////////////////////
  223. void TinySDLGraphicsWindow::
  224. set_properties_now(WindowProperties &properties) {
  225. GraphicsWindow::set_properties_now(properties);
  226. if (!properties.is_any_specified()) {
  227. // The base class has already handled this case.
  228. return;
  229. }
  230. }
  231. ////////////////////////////////////////////////////////////////////
  232. // Function: TinySDLGraphicsWindow::supports_pixel_zoom
  233. // Access: Published, Virtual
  234. // Description: Returns true if a call to set_pixel_zoom() will be
  235. // respected, false if it will be ignored. If this
  236. // returns false, then get_pixel_factor() will always
  237. // return 1.0, regardless of what value you specify for
  238. // set_pixel_zoom().
  239. //
  240. // This may return false if the underlying renderer
  241. // doesn't support pixel zooming, or if you have called
  242. // this on a DisplayRegion that doesn't have both
  243. // set_clear_color() and set_clear_depth() enabled.
  244. ////////////////////////////////////////////////////////////////////
  245. bool TinySDLGraphicsWindow::
  246. supports_pixel_zoom() const {
  247. return true;
  248. }
  249. ////////////////////////////////////////////////////////////////////
  250. // Function: TinySDLGraphicsWindow::close_window
  251. // Access: Protected, Virtual
  252. // Description: Closes the window right now. Called from the window
  253. // thread.
  254. ////////////////////////////////////////////////////////////////////
  255. void TinySDLGraphicsWindow::
  256. close_window() {
  257. GraphicsWindow::close_window();
  258. }
  259. ////////////////////////////////////////////////////////////////////
  260. // Function: TinySDLGraphicsWindow::open_window
  261. // Access: Protected, Virtual
  262. // Description: Opens the window right now. Called from the window
  263. // thread. Returns true if the window is successfully
  264. // opened, or false if there was a problem.
  265. ////////////////////////////////////////////////////////////////////
  266. bool TinySDLGraphicsWindow::
  267. open_window() {
  268. // GSG Creation/Initialization
  269. TinyGraphicsStateGuardian *tinygsg;
  270. if (_gsg == 0) {
  271. // There is no old gsg. Create a new one.
  272. tinygsg = new TinyGraphicsStateGuardian(_pipe, NULL);
  273. _gsg = tinygsg;
  274. } else {
  275. DCAST_INTO_R(tinygsg, _gsg, false);
  276. }
  277. _flags = SDL_SWSURFACE;
  278. if (_properties.get_fullscreen()) {
  279. _flags |= SDL_FULLSCREEN;
  280. }
  281. if (!_properties.get_fixed_size()) {
  282. _flags |= SDL_RESIZABLE;
  283. }
  284. if (_properties.get_undecorated()) {
  285. _flags |= SDL_NOFRAME;
  286. }
  287. _screen = SDL_SetVideoMode(_properties.get_x_size(), _properties.get_y_size(), 32, _flags);
  288. if (_screen == NULL) {
  289. tinydisplay_cat.error()
  290. << "Video mode set failed.\n";
  291. return false;
  292. }
  293. create_frame_buffer();
  294. if (_frame_buffer == NULL) {
  295. tinydisplay_cat.error()
  296. << "Could not create frame buffer.\n";
  297. return false;
  298. }
  299. tinygsg->_current_frame_buffer = _frame_buffer;
  300. // Now that we have made the context current to a window, we can
  301. // reset the GSG state if this is the first time it has been used.
  302. // (We can't just call reset() when we construct the GSG, because
  303. // reset() requires having a current context.)
  304. tinygsg->reset_if_new();
  305. return true;
  306. }
  307. ////////////////////////////////////////////////////////////////////
  308. // Function: TinySDLGraphicsWindow::create_frame_buffer
  309. // Access: Private
  310. // Description: Creates a suitable frame buffer for the current
  311. // window size.
  312. ////////////////////////////////////////////////////////////////////
  313. void TinySDLGraphicsWindow::
  314. create_frame_buffer() {
  315. if (_frame_buffer != NULL) {
  316. ZB_close(_frame_buffer);
  317. _frame_buffer = NULL;
  318. }
  319. int mode;
  320. switch (_screen->format->BitsPerPixel) {
  321. case 8:
  322. tinydisplay_cat.error()
  323. << "SDL Palettes are currently not supported.\n";
  324. return;
  325. case 16:
  326. mode = ZB_MODE_5R6G5B;
  327. break;
  328. case 24:
  329. mode = ZB_MODE_RGB24;
  330. break;
  331. case 32:
  332. mode = ZB_MODE_RGBA;
  333. break;
  334. default:
  335. return;
  336. }
  337. _frame_buffer = ZB_open(_properties.get_x_size(), _properties.get_y_size(), mode, 0, 0, 0, 0);
  338. _pitch = _screen->pitch * 32 / _screen->format->BitsPerPixel;
  339. }
  340. ////////////////////////////////////////////////////////////////////
  341. // Function: TinySDLGraphicsWindow::get_keyboard_button
  342. // Access: Private, Static
  343. // Description: Maps from an SDL keysym to the corresponding Panda
  344. // ButtonHandle.
  345. ////////////////////////////////////////////////////////////////////
  346. ButtonHandle TinySDLGraphicsWindow::
  347. get_keyboard_button(SDLKey sym) {
  348. switch (sym) {
  349. case SDLK_BACKSPACE: return KeyboardButton::backspace();
  350. case SDLK_TAB: return KeyboardButton::tab();
  351. // case SDLK_CLEAR: return KeyboardButton::clear();
  352. case SDLK_RETURN: return KeyboardButton::enter();
  353. // case SDLK_PAUSE: return KeyboardButton::pause();
  354. case SDLK_ESCAPE: return KeyboardButton::escape();
  355. case SDLK_SPACE: return KeyboardButton::space();
  356. case SDLK_EXCLAIM: return KeyboardButton::ascii_key('!');
  357. case SDLK_QUOTEDBL: return KeyboardButton::ascii_key('"');
  358. case SDLK_HASH: return KeyboardButton::ascii_key('#');
  359. case SDLK_DOLLAR: return KeyboardButton::ascii_key('$');
  360. case SDLK_AMPERSAND: return KeyboardButton::ascii_key('&');
  361. case SDLK_QUOTE: return KeyboardButton::ascii_key('\'');
  362. case SDLK_LEFTPAREN: return KeyboardButton::ascii_key('(');
  363. case SDLK_RIGHTPAREN: return KeyboardButton::ascii_key(')');
  364. case SDLK_ASTERISK: return KeyboardButton::ascii_key('*');
  365. case SDLK_PLUS: return KeyboardButton::ascii_key('+');
  366. case SDLK_COMMA: return KeyboardButton::ascii_key(',');
  367. case SDLK_MINUS: return KeyboardButton::ascii_key('-');
  368. case SDLK_PERIOD: return KeyboardButton::ascii_key('.');
  369. case SDLK_SLASH: return KeyboardButton::ascii_key('/');
  370. case SDLK_0: return KeyboardButton::ascii_key('0');
  371. case SDLK_1: return KeyboardButton::ascii_key('1');
  372. case SDLK_2: return KeyboardButton::ascii_key('2');
  373. case SDLK_3: return KeyboardButton::ascii_key('3');
  374. case SDLK_4: return KeyboardButton::ascii_key('4');
  375. case SDLK_5: return KeyboardButton::ascii_key('5');
  376. case SDLK_6: return KeyboardButton::ascii_key('6');
  377. case SDLK_7: return KeyboardButton::ascii_key('7');
  378. case SDLK_8: return KeyboardButton::ascii_key('8');
  379. case SDLK_9: return KeyboardButton::ascii_key('9');
  380. case SDLK_COLON: return KeyboardButton::ascii_key(':');
  381. case SDLK_SEMICOLON: return KeyboardButton::ascii_key(';');
  382. case SDLK_LESS: return KeyboardButton::ascii_key('<');
  383. case SDLK_EQUALS: return KeyboardButton::ascii_key('=');
  384. case SDLK_GREATER: return KeyboardButton::ascii_key('>');
  385. case SDLK_QUESTION: return KeyboardButton::ascii_key('?');
  386. case SDLK_AT: return KeyboardButton::ascii_key('@');
  387. case SDLK_LEFTBRACKET: return KeyboardButton::ascii_key('[');
  388. case SDLK_BACKSLASH: return KeyboardButton::ascii_key('\\');
  389. case SDLK_RIGHTBRACKET: return KeyboardButton::ascii_key(']');
  390. case SDLK_CARET: return KeyboardButton::ascii_key('^');
  391. case SDLK_UNDERSCORE: return KeyboardButton::ascii_key('_');
  392. case SDLK_BACKQUOTE: return KeyboardButton::ascii_key('`');
  393. case SDLK_a: return KeyboardButton::ascii_key('a');
  394. case SDLK_b: return KeyboardButton::ascii_key('b');
  395. case SDLK_c: return KeyboardButton::ascii_key('c');
  396. case SDLK_d: return KeyboardButton::ascii_key('d');
  397. case SDLK_e: return KeyboardButton::ascii_key('e');
  398. case SDLK_f: return KeyboardButton::ascii_key('f');
  399. case SDLK_g: return KeyboardButton::ascii_key('g');
  400. case SDLK_h: return KeyboardButton::ascii_key('h');
  401. case SDLK_i: return KeyboardButton::ascii_key('i');
  402. case SDLK_j: return KeyboardButton::ascii_key('j');
  403. case SDLK_k: return KeyboardButton::ascii_key('k');
  404. case SDLK_l: return KeyboardButton::ascii_key('l');
  405. case SDLK_m: return KeyboardButton::ascii_key('m');
  406. case SDLK_n: return KeyboardButton::ascii_key('n');
  407. case SDLK_o: return KeyboardButton::ascii_key('o');
  408. case SDLK_p: return KeyboardButton::ascii_key('p');
  409. case SDLK_q: return KeyboardButton::ascii_key('q');
  410. case SDLK_r: return KeyboardButton::ascii_key('r');
  411. case SDLK_s: return KeyboardButton::ascii_key('s');
  412. case SDLK_t: return KeyboardButton::ascii_key('t');
  413. case SDLK_u: return KeyboardButton::ascii_key('u');
  414. case SDLK_v: return KeyboardButton::ascii_key('v');
  415. case SDLK_w: return KeyboardButton::ascii_key('w');
  416. case SDLK_x: return KeyboardButton::ascii_key('x');
  417. case SDLK_y: return KeyboardButton::ascii_key('y');
  418. case SDLK_z: return KeyboardButton::ascii_key('z');
  419. case SDLK_DELETE: return KeyboardButton::del();
  420. case SDLK_KP0: return KeyboardButton::ascii_key('0');
  421. case SDLK_KP1: return KeyboardButton::ascii_key('1');
  422. case SDLK_KP2: return KeyboardButton::ascii_key('2');
  423. case SDLK_KP3: return KeyboardButton::ascii_key('3');
  424. case SDLK_KP4: return KeyboardButton::ascii_key('4');
  425. case SDLK_KP5: return KeyboardButton::ascii_key('5');
  426. case SDLK_KP6: return KeyboardButton::ascii_key('6');
  427. case SDLK_KP7: return KeyboardButton::ascii_key('7');
  428. case SDLK_KP8: return KeyboardButton::ascii_key('8');
  429. case SDLK_KP9: return KeyboardButton::ascii_key('9');
  430. case SDLK_KP_PERIOD: return KeyboardButton::ascii_key('.');
  431. case SDLK_KP_DIVIDE: return KeyboardButton::ascii_key('/');
  432. case SDLK_KP_MULTIPLY: return KeyboardButton::ascii_key('*');
  433. case SDLK_KP_MINUS: return KeyboardButton::ascii_key('-');
  434. case SDLK_KP_PLUS: return KeyboardButton::ascii_key('+');
  435. case SDLK_KP_ENTER: return KeyboardButton::enter();
  436. case SDLK_KP_EQUALS: return KeyboardButton::ascii_key('=');
  437. case SDLK_UP: return KeyboardButton::up();
  438. case SDLK_DOWN: return KeyboardButton::down();
  439. case SDLK_RIGHT: return KeyboardButton::right();
  440. case SDLK_LEFT: return KeyboardButton::left();
  441. case SDLK_INSERT: return KeyboardButton::insert();
  442. case SDLK_HOME: return KeyboardButton::home();
  443. case SDLK_END: return KeyboardButton::end();
  444. case SDLK_PAGEUP: return KeyboardButton::page_up();
  445. case SDLK_PAGEDOWN: return KeyboardButton::page_down();
  446. case SDLK_F1: return KeyboardButton::f1();
  447. case SDLK_F2: return KeyboardButton::f2();
  448. case SDLK_F3: return KeyboardButton::f3();
  449. case SDLK_F4: return KeyboardButton::f4();
  450. case SDLK_F5: return KeyboardButton::f5();
  451. case SDLK_F6: return KeyboardButton::f6();
  452. case SDLK_F7: return KeyboardButton::f7();
  453. case SDLK_F8: return KeyboardButton::f8();
  454. case SDLK_F9: return KeyboardButton::f9();
  455. case SDLK_F10: return KeyboardButton::f10();
  456. case SDLK_F11: return KeyboardButton::f11();
  457. case SDLK_F12: return KeyboardButton::f12();
  458. case SDLK_F13: return KeyboardButton::f13();
  459. case SDLK_F14: return KeyboardButton::f14();
  460. case SDLK_F15: return KeyboardButton::f15();
  461. // case SDLK_NUMLOCK: return KeyboardButton::numlock();
  462. // case SDLK_CAPSLOCK: return KeyboardButton::capslock();
  463. // case SDLK_SCROLLOCK: return KeyboardButton::scrollock();
  464. case SDLK_RSHIFT: return KeyboardButton::rshift();
  465. case SDLK_LSHIFT: return KeyboardButton::lshift();
  466. case SDLK_RCTRL: return KeyboardButton::rcontrol();
  467. case SDLK_LCTRL: return KeyboardButton::lcontrol();
  468. case SDLK_RALT: return KeyboardButton::ralt();
  469. case SDLK_LALT: return KeyboardButton::lalt();
  470. case SDLK_RMETA: return KeyboardButton::ralt();
  471. case SDLK_LMETA: return KeyboardButton::lalt();
  472. // case SDLK_LSUPER: return KeyboardButton::left();
  473. // case SDLK_RSUPER: return KeyboardButton::right();
  474. // case SDLK_MODE: return KeyboardButton::mode();
  475. case SDLK_HELP: return KeyboardButton::help();
  476. // case SDLK_PRINT: return KeyboardButton::print-screen();
  477. // case SDLK_SYSREQ: return KeyboardButton::SysRq();
  478. // case SDLK_BREAK: return KeyboardButton::break();
  479. // case SDLK_MENU: return KeyboardButton::menu();
  480. // case SDLK_POWER: return KeyboardButton::power();
  481. // case SDLK_EURO: return KeyboardButton::euro();
  482. }
  483. tinydisplay_cat.info()
  484. << "unhandled keyboard button " << sym << "\n";
  485. return ButtonHandle::none();
  486. }
  487. ////////////////////////////////////////////////////////////////////
  488. // Function: TinySDLGraphicsWindow::get_mouse_button
  489. // Access: Private, Static
  490. // Description: Maps from an SDL mouse button index to the
  491. // corresponding Panda ButtonHandle.
  492. ////////////////////////////////////////////////////////////////////
  493. ButtonHandle TinySDLGraphicsWindow::
  494. get_mouse_button(Uint8 button) {
  495. switch (button) {
  496. case SDL_BUTTON_LEFT:
  497. return MouseButton::one();
  498. case SDL_BUTTON_MIDDLE:
  499. return MouseButton::two();
  500. case SDL_BUTTON_RIGHT:
  501. return MouseButton::three();
  502. case SDL_BUTTON_WHEELUP:
  503. return MouseButton::wheel_up();
  504. case SDL_BUTTON_WHEELDOWN:
  505. return MouseButton::wheel_down();
  506. }
  507. tinydisplay_cat.info()
  508. << "unhandled mouse button " << button << "\n";
  509. return ButtonHandle::none();
  510. }
  511. #endif // HAVE_SDL