Panda3D

tinySDLGraphicsWindow.cxx

00001 // Filename: tinySDLGraphicsWindow.cxx
00002 // Created by:  drose (24Apr08)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "pandabase.h"
00016 
00017 #ifdef HAVE_SDL
00018 
00019 #include "tinySDLGraphicsWindow.h"
00020 #include "tinyGraphicsStateGuardian.h"
00021 #include "config_tinydisplay.h"
00022 #include "tinySDLGraphicsPipe.h"
00023 #include "mouseButton.h"
00024 #include "keyboardButton.h"
00025 #include "graphicsPipe.h"
00026 
00027 TypeHandle TinySDLGraphicsWindow::_type_handle;
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: TinySDLGraphicsWindow::Constructor
00031 //       Access: Public
00032 //  Description:
00033 ////////////////////////////////////////////////////////////////////
00034 TinySDLGraphicsWindow::
00035 TinySDLGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, 
00036                       const string &name,
00037                       const FrameBufferProperties &fb_prop,
00038                       const WindowProperties &win_prop,
00039                       int flags,
00040                       GraphicsStateGuardian *gsg,
00041                       GraphicsOutput *host) :
00042   GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host)
00043 {
00044   _screen = NULL;
00045   _frame_buffer = NULL;
00046   _pitch = 0;
00047   update_pixel_factor();
00048 
00049   GraphicsWindowInputDevice device =
00050     GraphicsWindowInputDevice::pointer_and_keyboard(this, "keyboard_mouse");
00051   add_input_device(device);
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: TinySDLGraphicsWindow::Destructor
00056 //       Access: Public, Virtual
00057 //  Description:
00058 ////////////////////////////////////////////////////////////////////
00059 TinySDLGraphicsWindow::
00060 ~TinySDLGraphicsWindow() {
00061 }
00062 
00063 ////////////////////////////////////////////////////////////////////
00064 //     Function: TinySDLGraphicsWindow::begin_frame
00065 //       Access: Public, Virtual
00066 //  Description: This function will be called within the draw thread
00067 //               before beginning rendering for a given frame.  It
00068 //               should do whatever setup is required, and return true
00069 //               if the frame should be rendered, or false if it
00070 //               should be skipped.
00071 ////////////////////////////////////////////////////////////////////
00072 bool TinySDLGraphicsWindow::
00073 begin_frame(FrameMode mode, Thread *current_thread) {
00074   begin_frame_spam(mode);
00075   if (_gsg == (GraphicsStateGuardian *)NULL) {
00076     return false;
00077   }
00078 
00079   TinyGraphicsStateGuardian *tinygsg;
00080   DCAST_INTO_R(tinygsg, _gsg, false);
00081 
00082   tinygsg->_current_frame_buffer = _frame_buffer;
00083   tinygsg->reset_if_new();
00084   
00085   _gsg->set_current_properties(&get_fb_properties());
00086   return _gsg->begin_frame(current_thread);
00087 }
00088 
00089 ////////////////////////////////////////////////////////////////////
00090 //     Function: TinySDLGraphicsWindow::end_frame
00091 //       Access: Public, Virtual
00092 //  Description: This function will be called within the draw thread
00093 //               after rendering is completed for a given frame.  It
00094 //               should do whatever finalization is required.
00095 ////////////////////////////////////////////////////////////////////
00096 void TinySDLGraphicsWindow::
00097 end_frame(FrameMode mode, Thread *current_thread) {
00098   end_frame_spam(mode);
00099   nassertv(_gsg != (GraphicsStateGuardian *)NULL);
00100 
00101   if (mode == FM_render) {
00102     // end_render_texture();
00103     copy_to_textures();
00104   }
00105 
00106   _gsg->end_frame(current_thread);
00107 
00108   if (mode == FM_render) {
00109     trigger_flip();
00110     if (_one_shot) {
00111       prepare_for_deletion();
00112     }
00113   }
00114 }
00115 
00116 ////////////////////////////////////////////////////////////////////
00117 //     Function: TinySDLGraphicsWindow::begin_flip
00118 //       Access: Public, Virtual
00119 //  Description: This function will be called within the draw thread
00120 //               after end_frame() has been called on all windows, to
00121 //               initiate the exchange of the front and back buffers.
00122 //
00123 //               This should instruct the window to prepare for the
00124 //               flip at the next video sync, but it should not wait.
00125 //
00126 //               We have the two separate functions, begin_flip() and
00127 //               end_flip(), to make it easier to flip all of the
00128 //               windows at the same time.
00129 ////////////////////////////////////////////////////////////////////
00130 void TinySDLGraphicsWindow::
00131 begin_flip() {
00132   int fb_xsize = get_fb_x_size();
00133   int fb_ysize = get_fb_y_size();
00134 
00135   if (fb_xsize == _frame_buffer->xsize) {
00136     // No zooming is necessary--copy directly to the screen.
00137     if (SDL_MUSTLOCK(_screen)) {
00138       if (SDL_LockSurface(_screen) < 0) {
00139         tinydisplay_cat.error()
00140           << "Can't lock screen: " << SDL_GetError() << "\n";
00141       }
00142     }
00143     ZB_copyFrameBuffer(_frame_buffer, _screen->pixels, _pitch);
00144     
00145     if (SDL_MUSTLOCK(_screen)) {
00146       SDL_UnlockSurface(_screen); 
00147     }
00148 
00149   } else {
00150     // Copy to another surface, then scale it onto the screen.
00151     SDL_Surface *temp = 
00152       SDL_CreateRGBSurfaceFrom(_frame_buffer->pbuf, _frame_buffer->xsize, _frame_buffer->ysize,
00153                                32, _frame_buffer->linesize, 0xff0000, 0x00ff00, 0x0000ff, 0xff000000);
00154     SDL_SetAlpha(temp, SDL_RLEACCEL, 0);
00155     SDL_BlitSurface(temp, NULL, _screen, NULL);
00156     SDL_FreeSurface(temp);
00157   }
00158 
00159   SDL_Flip(_screen);
00160 }
00161 
00162 ////////////////////////////////////////////////////////////////////
00163 //     Function: TinySDLGraphicsWindow::process_events
00164 //       Access: Public, Virtual
00165 //  Description: Do whatever processing is necessary to ensure that
00166 //               the window responds to user events.  Also, honor any
00167 //               requests recently made via request_properties()
00168 //
00169 //               This function is called only within the window
00170 //               thread.
00171 ////////////////////////////////////////////////////////////////////
00172 void TinySDLGraphicsWindow::
00173 process_events() {
00174   GraphicsWindow::process_events();
00175 
00176   if (_screen == NULL) {
00177     return;
00178   }
00179 
00180   WindowProperties properties;
00181 
00182   SDL_Event evt;
00183   ButtonHandle button;
00184   while (SDL_PollEvent(&evt)) {
00185     switch(evt.type) {
00186     case SDL_KEYDOWN:
00187       if (evt.key.keysym.unicode) {
00188         _input_devices[0].keystroke(evt.key.keysym.unicode);
00189       }
00190       button = get_keyboard_button(evt.key.keysym.sym);
00191       if (button != ButtonHandle::none()) {
00192         _input_devices[0].button_down(button);
00193       }
00194       break;
00195 
00196     case SDL_KEYUP:
00197       button = get_keyboard_button(evt.key.keysym.sym);
00198       if (button != ButtonHandle::none()) {
00199         _input_devices[0].button_up(button);
00200       }
00201       break;
00202 
00203     case SDL_MOUSEBUTTONDOWN:
00204       button = get_mouse_button(evt.button.button);
00205       _input_devices[0].set_pointer_in_window(evt.button.x, evt.button.y);
00206       _input_devices[0].button_down(button);
00207       break;
00208 
00209     case SDL_MOUSEBUTTONUP:
00210       button = get_mouse_button(evt.button.button);
00211       _input_devices[0].set_pointer_in_window(evt.button.x, evt.button.y);
00212       _input_devices[0].button_up(button);
00213       break;
00214 
00215     case SDL_MOUSEMOTION:
00216       _input_devices[0].set_pointer_in_window(evt.motion.x, evt.motion.y);
00217       break;
00218      
00219     case SDL_VIDEORESIZE:
00220       properties.set_size(evt.resize.w, evt.resize.h);
00221       system_changed_properties(properties);
00222       _screen = SDL_SetVideoMode(_properties.get_x_size(), _properties.get_y_size(), 32, _flags);
00223       ZB_resize(_frame_buffer, NULL, _properties.get_x_size(), _properties.get_y_size());
00224       _pitch = _screen->pitch * 32 / _screen->format->BitsPerPixel;
00225       break;
00226       
00227     case SDL_QUIT:
00228       // The window was closed by the user.
00229       close_window();
00230       properties.set_open(false);
00231       system_changed_properties(properties);
00232       break;
00233     }
00234   }
00235 }
00236 
00237 ////////////////////////////////////////////////////////////////////
00238 //     Function: TinySDLGraphicsWindow::set_properties_now
00239 //       Access: Public, Virtual
00240 //  Description: Applies the requested set of properties to the
00241 //               window, if possible, for instance to request a change
00242 //               in size or minimization status.
00243 //
00244 //               The window properties are applied immediately, rather
00245 //               than waiting until the next frame.  This implies that
00246 //               this method may *only* be called from within the
00247 //               window thread.
00248 //
00249 //               The return value is true if the properties are set,
00250 //               false if they are ignored.  This is mainly useful for
00251 //               derived classes to implement extensions to this
00252 //               function.
00253 ////////////////////////////////////////////////////////////////////
00254 void TinySDLGraphicsWindow::
00255 set_properties_now(WindowProperties &properties) {
00256   GraphicsWindow::set_properties_now(properties);
00257   if (!properties.is_any_specified()) {
00258     // The base class has already handled this case.
00259     return;
00260   }
00261 }
00262 
00263 ////////////////////////////////////////////////////////////////////
00264 //     Function: TinySDLGraphicsWindow::supports_pixel_zoom
00265 //       Access: Published, Virtual
00266 //  Description: Returns true if a call to set_pixel_zoom() will be
00267 //               respected, false if it will be ignored.  If this
00268 //               returns false, then get_pixel_factor() will always
00269 //               return 1.0, regardless of what value you specify for
00270 //               set_pixel_zoom().
00271 //
00272 //               This may return false if the underlying renderer
00273 //               doesn't support pixel zooming, or if you have called
00274 //               this on a DisplayRegion that doesn't have both
00275 //               set_clear_color() and set_clear_depth() enabled.
00276 ////////////////////////////////////////////////////////////////////
00277 bool TinySDLGraphicsWindow::
00278 supports_pixel_zoom() const {
00279   return true;
00280 }
00281 
00282 ////////////////////////////////////////////////////////////////////
00283 //     Function: TinySDLGraphicsWindow::close_window
00284 //       Access: Protected, Virtual
00285 //  Description: Closes the window right now.  Called from the window
00286 //               thread.
00287 ////////////////////////////////////////////////////////////////////
00288 void TinySDLGraphicsWindow::
00289 close_window() {
00290   GraphicsWindow::close_window();
00291 }
00292 
00293 ////////////////////////////////////////////////////////////////////
00294 //     Function: TinySDLGraphicsWindow::open_window
00295 //       Access: Protected, Virtual
00296 //  Description: Opens the window right now.  Called from the window
00297 //               thread.  Returns true if the window is successfully
00298 //               opened, or false if there was a problem.
00299 ////////////////////////////////////////////////////////////////////
00300 bool TinySDLGraphicsWindow::
00301 open_window() {
00302 
00303   // GSG Creation/Initialization
00304   TinyGraphicsStateGuardian *tinygsg;
00305   if (_gsg == 0) {
00306     // There is no old gsg.  Create a new one.
00307     tinygsg = new TinyGraphicsStateGuardian(_engine, _pipe, NULL);
00308     _gsg = tinygsg;
00309 
00310   } else {
00311     DCAST_INTO_R(tinygsg, _gsg, false);
00312   }
00313 
00314   _flags = SDL_SWSURFACE;
00315   if (_properties.get_fullscreen()) {
00316     _flags |= SDL_FULLSCREEN;
00317   }
00318   if (!_properties.get_fixed_size()) {
00319     _flags |= SDL_RESIZABLE;
00320   }
00321   if (_properties.get_undecorated()) {
00322     _flags |= SDL_NOFRAME;
00323   }
00324   _screen = SDL_SetVideoMode(_properties.get_x_size(), _properties.get_y_size(), 32, _flags);
00325 
00326   if (_screen == NULL) {
00327     tinydisplay_cat.error()
00328       << "Video mode set failed.\n";
00329     return false;
00330   }
00331 
00332   create_frame_buffer();
00333   if (_frame_buffer == NULL) {
00334     tinydisplay_cat.error()
00335       << "Could not create frame buffer.\n";
00336     return false;
00337   }
00338 
00339   tinygsg->_current_frame_buffer = _frame_buffer;
00340 
00341   // Now that we have made the context current to a window, we can
00342   // reset the GSG state if this is the first time it has been used.
00343   // (We can't just call reset() when we construct the GSG, because
00344   // reset() requires having a current context.)
00345   tinygsg->reset_if_new();
00346 
00347   return true;
00348 }
00349 
00350 ////////////////////////////////////////////////////////////////////
00351 //     Function: TinySDLGraphicsWindow::create_frame_buffer
00352 //       Access: Private
00353 //  Description: Creates a suitable frame buffer for the current
00354 //               window size.
00355 ////////////////////////////////////////////////////////////////////
00356 void TinySDLGraphicsWindow::
00357 create_frame_buffer() {
00358   if (_frame_buffer != NULL) {
00359     ZB_close(_frame_buffer);
00360     _frame_buffer = NULL;
00361   }
00362 
00363   int mode;
00364   switch (_screen->format->BitsPerPixel) {
00365   case  8:
00366     tinydisplay_cat.error()
00367       << "SDL Palettes are currently not supported.\n";
00368     return;
00369 
00370   case 16:
00371     mode = ZB_MODE_5R6G5B;
00372     break;
00373   case 24:
00374     mode = ZB_MODE_RGB24;
00375     break;
00376   case 32:
00377     mode = ZB_MODE_RGBA;
00378     break;
00379 
00380   default:
00381     return;
00382   }
00383 
00384   _frame_buffer = ZB_open(_properties.get_x_size(), _properties.get_y_size(), mode, 0, 0, 0, 0);
00385 
00386   _pitch = _screen->pitch * 32 / _screen->format->BitsPerPixel;
00387 }
00388 
00389 ////////////////////////////////////////////////////////////////////
00390 //     Function: TinySDLGraphicsWindow::get_keyboard_button
00391 //       Access: Private, Static
00392 //  Description: Maps from an SDL keysym to the corresponding Panda
00393 //               ButtonHandle.
00394 ////////////////////////////////////////////////////////////////////
00395 ButtonHandle TinySDLGraphicsWindow::
00396 get_keyboard_button(SDLKey sym) {
00397   switch (sym) {
00398   case SDLK_BACKSPACE: return KeyboardButton::backspace();
00399   case SDLK_TAB: return KeyboardButton::tab();
00400     //  case SDLK_CLEAR: return KeyboardButton::clear();
00401   case SDLK_RETURN: return KeyboardButton::enter();
00402     //  case SDLK_PAUSE: return KeyboardButton::pause();
00403   case SDLK_ESCAPE: return KeyboardButton::escape();
00404   case SDLK_SPACE: return KeyboardButton::space();
00405   case SDLK_EXCLAIM: return KeyboardButton::ascii_key('!');
00406   case SDLK_QUOTEDBL: return KeyboardButton::ascii_key('"');
00407   case SDLK_HASH: return KeyboardButton::ascii_key('#');
00408   case SDLK_DOLLAR: return KeyboardButton::ascii_key('$');
00409   case SDLK_AMPERSAND: return KeyboardButton::ascii_key('&');
00410   case SDLK_QUOTE: return KeyboardButton::ascii_key('\'');
00411   case SDLK_LEFTPAREN: return KeyboardButton::ascii_key('(');
00412   case SDLK_RIGHTPAREN: return KeyboardButton::ascii_key(')');
00413   case SDLK_ASTERISK: return KeyboardButton::ascii_key('*');
00414   case SDLK_PLUS: return KeyboardButton::ascii_key('+');
00415   case SDLK_COMMA: return KeyboardButton::ascii_key(',');
00416   case SDLK_MINUS: return KeyboardButton::ascii_key('-');
00417   case SDLK_PERIOD: return KeyboardButton::ascii_key('.');
00418   case SDLK_SLASH: return KeyboardButton::ascii_key('/');
00419   case SDLK_0: return KeyboardButton::ascii_key('0');
00420   case SDLK_1: return KeyboardButton::ascii_key('1');
00421   case SDLK_2: return KeyboardButton::ascii_key('2');
00422   case SDLK_3: return KeyboardButton::ascii_key('3');
00423   case SDLK_4: return KeyboardButton::ascii_key('4');
00424   case SDLK_5: return KeyboardButton::ascii_key('5');
00425   case SDLK_6: return KeyboardButton::ascii_key('6');
00426   case SDLK_7: return KeyboardButton::ascii_key('7');
00427   case SDLK_8: return KeyboardButton::ascii_key('8');
00428   case SDLK_9: return KeyboardButton::ascii_key('9');
00429   case SDLK_COLON: return KeyboardButton::ascii_key(':');
00430   case SDLK_SEMICOLON: return KeyboardButton::ascii_key(';');
00431   case SDLK_LESS: return KeyboardButton::ascii_key('<');
00432   case SDLK_EQUALS: return KeyboardButton::ascii_key('=');
00433   case SDLK_GREATER: return KeyboardButton::ascii_key('>');
00434   case SDLK_QUESTION: return KeyboardButton::ascii_key('?');
00435   case SDLK_AT: return KeyboardButton::ascii_key('@');
00436   case SDLK_LEFTBRACKET: return KeyboardButton::ascii_key('[');
00437   case SDLK_BACKSLASH: return KeyboardButton::ascii_key('\\');
00438   case SDLK_RIGHTBRACKET: return KeyboardButton::ascii_key(']');
00439   case SDLK_CARET: return KeyboardButton::ascii_key('^');
00440   case SDLK_UNDERSCORE: return KeyboardButton::ascii_key('_');
00441   case SDLK_BACKQUOTE: return KeyboardButton::ascii_key('`');
00442   case SDLK_a: return KeyboardButton::ascii_key('a');
00443   case SDLK_b: return KeyboardButton::ascii_key('b');
00444   case SDLK_c: return KeyboardButton::ascii_key('c');
00445   case SDLK_d: return KeyboardButton::ascii_key('d');
00446   case SDLK_e: return KeyboardButton::ascii_key('e');
00447   case SDLK_f: return KeyboardButton::ascii_key('f');
00448   case SDLK_g: return KeyboardButton::ascii_key('g');
00449   case SDLK_h: return KeyboardButton::ascii_key('h');
00450   case SDLK_i: return KeyboardButton::ascii_key('i');
00451   case SDLK_j: return KeyboardButton::ascii_key('j');
00452   case SDLK_k: return KeyboardButton::ascii_key('k');
00453   case SDLK_l: return KeyboardButton::ascii_key('l');
00454   case SDLK_m: return KeyboardButton::ascii_key('m');
00455   case SDLK_n: return KeyboardButton::ascii_key('n');
00456   case SDLK_o: return KeyboardButton::ascii_key('o');
00457   case SDLK_p: return KeyboardButton::ascii_key('p');
00458   case SDLK_q: return KeyboardButton::ascii_key('q');
00459   case SDLK_r: return KeyboardButton::ascii_key('r');
00460   case SDLK_s: return KeyboardButton::ascii_key('s');
00461   case SDLK_t: return KeyboardButton::ascii_key('t');
00462   case SDLK_u: return KeyboardButton::ascii_key('u');
00463   case SDLK_v: return KeyboardButton::ascii_key('v');
00464   case SDLK_w: return KeyboardButton::ascii_key('w');
00465   case SDLK_x: return KeyboardButton::ascii_key('x');
00466   case SDLK_y: return KeyboardButton::ascii_key('y');
00467   case SDLK_z: return KeyboardButton::ascii_key('z');
00468   case SDLK_DELETE: return KeyboardButton::del();
00469   case SDLK_KP0: return KeyboardButton::ascii_key('0');
00470   case SDLK_KP1: return KeyboardButton::ascii_key('1');
00471   case SDLK_KP2: return KeyboardButton::ascii_key('2');
00472   case SDLK_KP3: return KeyboardButton::ascii_key('3');
00473   case SDLK_KP4: return KeyboardButton::ascii_key('4');
00474   case SDLK_KP5: return KeyboardButton::ascii_key('5');
00475   case SDLK_KP6: return KeyboardButton::ascii_key('6');
00476   case SDLK_KP7: return KeyboardButton::ascii_key('7');
00477   case SDLK_KP8: return KeyboardButton::ascii_key('8');
00478   case SDLK_KP9: return KeyboardButton::ascii_key('9');
00479   case SDLK_KP_PERIOD: return KeyboardButton::ascii_key('.');
00480   case SDLK_KP_DIVIDE: return KeyboardButton::ascii_key('/');
00481   case SDLK_KP_MULTIPLY: return KeyboardButton::ascii_key('*');
00482   case SDLK_KP_MINUS: return KeyboardButton::ascii_key('-');
00483   case SDLK_KP_PLUS: return KeyboardButton::ascii_key('+');
00484   case SDLK_KP_ENTER: return KeyboardButton::enter();
00485   case SDLK_KP_EQUALS: return KeyboardButton::ascii_key('=');
00486   case SDLK_UP: return KeyboardButton::up();
00487   case SDLK_DOWN: return KeyboardButton::down();
00488   case SDLK_RIGHT: return KeyboardButton::right();
00489   case SDLK_LEFT: return KeyboardButton::left();
00490   case SDLK_INSERT: return KeyboardButton::insert();
00491   case SDLK_HOME: return KeyboardButton::home();
00492   case SDLK_END: return KeyboardButton::end();
00493   case SDLK_PAGEUP: return KeyboardButton::page_up();
00494   case SDLK_PAGEDOWN: return KeyboardButton::page_down();
00495   case SDLK_F1: return KeyboardButton::f1();
00496   case SDLK_F2: return KeyboardButton::f2();
00497   case SDLK_F3: return KeyboardButton::f3();
00498   case SDLK_F4: return KeyboardButton::f4();
00499   case SDLK_F5: return KeyboardButton::f5();
00500   case SDLK_F6: return KeyboardButton::f6();
00501   case SDLK_F7: return KeyboardButton::f7();
00502   case SDLK_F8: return KeyboardButton::f8();
00503   case SDLK_F9: return KeyboardButton::f9();
00504   case SDLK_F10: return KeyboardButton::f10();
00505   case SDLK_F11: return KeyboardButton::f11();
00506   case SDLK_F12: return KeyboardButton::f12();
00507   case SDLK_F13: return KeyboardButton::f13();
00508   case SDLK_F14: return KeyboardButton::f14();
00509   case SDLK_F15: return KeyboardButton::f15();
00510     //  case SDLK_NUMLOCK: return KeyboardButton::numlock();
00511     //  case SDLK_CAPSLOCK: return KeyboardButton::capslock();
00512     //  case SDLK_SCROLLOCK: return KeyboardButton::scrollock();
00513   case SDLK_RSHIFT: return KeyboardButton::rshift();
00514   case SDLK_LSHIFT: return KeyboardButton::lshift();
00515   case SDLK_RCTRL: return KeyboardButton::rcontrol();
00516   case SDLK_LCTRL: return KeyboardButton::lcontrol();
00517   case SDLK_RALT: return KeyboardButton::ralt();
00518   case SDLK_LALT: return KeyboardButton::lalt();
00519   case SDLK_RMETA: return KeyboardButton::ralt();
00520   case SDLK_LMETA: return KeyboardButton::lalt();
00521     //  case SDLK_LSUPER: return KeyboardButton::left();
00522     //  case SDLK_RSUPER: return KeyboardButton::right();
00523     //  case SDLK_MODE: return KeyboardButton::mode();
00524   case SDLK_HELP: return KeyboardButton::help();
00525     //  case SDLK_PRINT: return KeyboardButton::print-screen();
00526     //  case SDLK_SYSREQ: return KeyboardButton::SysRq();
00527     //  case SDLK_BREAK: return KeyboardButton::break();
00528     //  case SDLK_MENU: return KeyboardButton::menu();
00529     //  case SDLK_POWER: return KeyboardButton::power();
00530     //  case SDLK_EURO: return KeyboardButton::euro();
00531   }
00532   tinydisplay_cat.info()
00533     << "unhandled keyboard button " << sym << "\n";
00534 
00535   return ButtonHandle::none();
00536 }
00537 
00538 ////////////////////////////////////////////////////////////////////
00539 //     Function: TinySDLGraphicsWindow::get_mouse_button
00540 //       Access: Private, Static
00541 //  Description: Maps from an SDL mouse button index to the
00542 //               corresponding Panda ButtonHandle.
00543 ////////////////////////////////////////////////////////////////////
00544 ButtonHandle TinySDLGraphicsWindow::
00545 get_mouse_button(Uint8 button) {
00546   switch (button) {
00547   case SDL_BUTTON_LEFT:
00548     return MouseButton::one();
00549 
00550   case SDL_BUTTON_MIDDLE:
00551     return MouseButton::two();
00552 
00553   case SDL_BUTTON_RIGHT:
00554     return MouseButton::three();
00555 
00556   case SDL_BUTTON_WHEELUP:
00557     return MouseButton::wheel_up();
00558 
00559   case SDL_BUTTON_WHEELDOWN:
00560     return MouseButton::wheel_down();
00561   }
00562   tinydisplay_cat.info()
00563     << "unhandled mouse button " << button << "\n";
00564 
00565   return ButtonHandle::none();
00566 }
00567 
00568 #endif  // HAVE_SDL
 All Classes Functions Variables Enumerations