15 #include "pandabase.h" 19 #include "tinySDLGraphicsWindow.h" 20 #include "tinyGraphicsStateGuardian.h" 21 #include "config_tinydisplay.h" 22 #include "tinySDLGraphicsPipe.h" 23 #include "mouseButton.h" 24 #include "keyboardButton.h" 25 #include "graphicsPipe.h" 27 TypeHandle TinySDLGraphicsWindow::_type_handle;
34 TinySDLGraphicsWindow::
42 GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host)
47 update_pixel_factor();
51 add_input_device(device);
59 TinySDLGraphicsWindow::
60 ~TinySDLGraphicsWindow() {
72 bool TinySDLGraphicsWindow::
73 begin_frame(FrameMode mode,
Thread *current_thread) {
74 begin_frame_spam(mode);
80 DCAST_INTO_R(tinygsg, _gsg,
false);
82 tinygsg->_current_frame_buffer = _frame_buffer;
85 _gsg->set_current_properties(&get_fb_properties());
86 return _gsg->begin_frame(current_thread);
96 void TinySDLGraphicsWindow::
97 end_frame(FrameMode mode,
Thread *current_thread) {
101 if (mode == FM_render) {
106 _gsg->end_frame(current_thread);
108 if (mode == FM_render) {
123 void TinySDLGraphicsWindow::
130 int fb_xsize = get_fb_x_size();
131 int fb_ysize = get_fb_y_size();
133 if (fb_xsize == _frame_buffer->xsize) {
135 if (SDL_MUSTLOCK(_screen)) {
136 if (SDL_LockSurface(_screen) < 0) {
137 tinydisplay_cat.error()
138 <<
"Can't lock screen: " << SDL_GetError() <<
"\n";
141 ZB_copyFrameBuffer(_frame_buffer, _screen->pixels, _pitch);
143 if (SDL_MUSTLOCK(_screen)) {
144 SDL_UnlockSurface(_screen);
150 SDL_CreateRGBSurfaceFrom(_frame_buffer->pbuf, _frame_buffer->xsize, _frame_buffer->ysize,
151 32, _frame_buffer->linesize, 0xff0000, 0x00ff00, 0x0000ff, 0xff000000);
152 SDL_SetAlpha(temp, SDL_RLEACCEL, 0);
153 SDL_BlitSurface(temp, NULL, _screen, NULL);
154 SDL_FreeSurface(temp);
171 void TinySDLGraphicsWindow::
175 if (_screen == NULL) {
183 while (SDL_PollEvent(&evt)) {
186 if (evt.key.keysym.unicode) {
187 _input_devices[0].keystroke(evt.key.keysym.unicode);
189 button = get_keyboard_button(evt.key.keysym.sym);
191 _input_devices[0].button_down(button);
196 button = get_keyboard_button(evt.key.keysym.sym);
198 _input_devices[0].button_up(button);
202 case SDL_MOUSEBUTTONDOWN:
203 button = get_mouse_button(evt.button.button);
204 _input_devices[0].set_pointer_in_window(evt.button.x, evt.button.y);
205 _input_devices[0].button_down(button);
208 case SDL_MOUSEBUTTONUP:
209 button = get_mouse_button(evt.button.button);
210 _input_devices[0].set_pointer_in_window(evt.button.x, evt.button.y);
211 _input_devices[0].button_up(button);
214 case SDL_MOUSEMOTION:
215 _input_devices[0].set_pointer_in_window(evt.motion.x, evt.motion.y);
218 case SDL_VIDEORESIZE:
219 properties.
set_size(evt.resize.w, evt.resize.h);
220 system_changed_properties(properties);
221 _screen = SDL_SetVideoMode(_properties.get_x_size(), _properties.get_y_size(), 32, _flags);
222 ZB_resize(_frame_buffer, NULL, _properties.get_x_size(), _properties.get_y_size());
223 _pitch = _screen->pitch * 32 / _screen->format->BitsPerPixel;
230 system_changed_properties(properties);
253 void TinySDLGraphicsWindow::
276 bool TinySDLGraphicsWindow::
277 supports_pixel_zoom()
const {
287 void TinySDLGraphicsWindow::
289 GraphicsWindow::close_window();
299 bool TinySDLGraphicsWindow::
310 DCAST_INTO_R(tinygsg, _gsg,
false);
313 _flags = SDL_SWSURFACE;
314 if (_properties.get_fullscreen()) {
315 _flags |= SDL_FULLSCREEN;
317 if (!_properties.get_fixed_size()) {
318 _flags |= SDL_RESIZABLE;
320 if (_properties.get_undecorated()) {
321 _flags |= SDL_NOFRAME;
323 _screen = SDL_SetVideoMode(_properties.get_x_size(), _properties.get_y_size(), 32, _flags);
325 if (_screen == NULL) {
326 tinydisplay_cat.error()
327 <<
"Video mode set failed.\n";
331 create_frame_buffer();
332 if (_frame_buffer == NULL) {
333 tinydisplay_cat.error()
334 <<
"Could not create frame buffer.\n";
338 tinygsg->_current_frame_buffer = _frame_buffer;
355 void TinySDLGraphicsWindow::
356 create_frame_buffer() {
357 if (_frame_buffer != NULL) {
358 ZB_close(_frame_buffer);
359 _frame_buffer = NULL;
363 switch (_screen->format->BitsPerPixel) {
365 tinydisplay_cat.error()
366 <<
"SDL Palettes are currently not supported.\n";
370 mode = ZB_MODE_5R6G5B;
373 mode = ZB_MODE_RGB24;
383 _frame_buffer = ZB_open(_properties.get_x_size(), _properties.get_y_size(), mode, 0, 0, 0, 0);
385 _pitch = _screen->pitch * 32 / _screen->format->BitsPerPixel;
395 get_keyboard_button(SDLKey sym) {
397 case SDLK_BACKSPACE:
return KeyboardButton::backspace();
398 case SDLK_TAB:
return KeyboardButton::tab();
400 case SDLK_RETURN:
return KeyboardButton::enter();
402 case SDLK_ESCAPE:
return KeyboardButton::escape();
403 case SDLK_SPACE:
return KeyboardButton::space();
467 case SDLK_DELETE:
return KeyboardButton::del();
483 case SDLK_KP_ENTER:
return KeyboardButton::enter();
485 case SDLK_UP:
return KeyboardButton::up();
486 case SDLK_DOWN:
return KeyboardButton::down();
487 case SDLK_RIGHT:
return KeyboardButton::right();
488 case SDLK_LEFT:
return KeyboardButton::left();
489 case SDLK_INSERT:
return KeyboardButton::insert();
490 case SDLK_HOME:
return KeyboardButton::home();
491 case SDLK_END:
return KeyboardButton::end();
492 case SDLK_PAGEUP:
return KeyboardButton::page_up();
493 case SDLK_PAGEDOWN:
return KeyboardButton::page_down();
494 case SDLK_F1:
return KeyboardButton::f1();
495 case SDLK_F2:
return KeyboardButton::f2();
496 case SDLK_F3:
return KeyboardButton::f3();
497 case SDLK_F4:
return KeyboardButton::f4();
498 case SDLK_F5:
return KeyboardButton::f5();
499 case SDLK_F6:
return KeyboardButton::f6();
500 case SDLK_F7:
return KeyboardButton::f7();
501 case SDLK_F8:
return KeyboardButton::f8();
502 case SDLK_F9:
return KeyboardButton::f9();
503 case SDLK_F10:
return KeyboardButton::f10();
504 case SDLK_F11:
return KeyboardButton::f11();
505 case SDLK_F12:
return KeyboardButton::f12();
506 case SDLK_F13:
return KeyboardButton::f13();
507 case SDLK_F14:
return KeyboardButton::f14();
508 case SDLK_F15:
return KeyboardButton::f15();
512 case SDLK_RSHIFT:
return KeyboardButton::rshift();
513 case SDLK_LSHIFT:
return KeyboardButton::lshift();
514 case SDLK_RCTRL:
return KeyboardButton::rcontrol();
515 case SDLK_LCTRL:
return KeyboardButton::lcontrol();
516 case SDLK_RALT:
return KeyboardButton::ralt();
517 case SDLK_LALT:
return KeyboardButton::lalt();
518 case SDLK_RMETA:
return KeyboardButton::ralt();
519 case SDLK_LMETA:
return KeyboardButton::lalt();
523 case SDLK_HELP:
return KeyboardButton::help();
531 tinydisplay_cat.info()
532 <<
"unhandled keyboard button " << sym <<
"\n";
544 get_mouse_button(Uint8 button) {
546 case SDL_BUTTON_LEFT:
549 case SDL_BUTTON_MIDDLE:
552 case SDL_BUTTON_RIGHT:
555 case SDL_BUTTON_WHEELUP:
558 case SDL_BUTTON_WHEELDOWN:
561 tinydisplay_cat.info()
562 <<
"unhandled mouse button " << button <<
"\n";
bool is_any_specified() const
Returns true if any properties have been specified, false otherwise.
virtual void process_events()
Do whatever processing is necessary to ensure that the window responds to user events.
virtual void end_flip()
This function will be called within the draw thread after begin_flip() has been called on all windows...
virtual void set_properties_now(WindowProperties &properties)
Applies the requested set of properties to the window, if possible, for instance to request a change ...
bool reset_if_new()
Calls reset() to initialize the GSG, but only if it hasn't been called yet.
void set_size(const LVector2i &size)
Specifies the requested size of the window, in pixels.
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
A container for the various kinds of properties we might ask to have on a graphics window before we o...
An object to create GraphicsOutputs that share a particular 3-D API.
This is a base class for the various different classes that represent the result of a frame of render...
A thread; that is, a lightweight process.
Encapsulates all the communication with a particular instance of a given rendering backend...
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
void set_open(bool open)
Specifies whether the window should be open.
An interface to the TinyPanda software rendering code within this module.