bool init_scaler( unsigned int new_scaler, bool fullscreen ) { int w = scalers[new_scaler].width, h = scalers[new_scaler].height; int bpp = can_init_scaler(new_scaler, fullscreen); /*int flags = SDL_SWSURFACE | SDL_HWPALETTE | (fullscreen ? SDL_FULLSCREEN : 0); if (bpp == 0) return false; SDL_Surface *const surface = SDL_SetVideoMode(w, h, bpp, flags);*/ SDL_Surface *const surface = SDLSingleton::GetInstance()->GetSurface(); if (surface == NULL) { fprintf(stderr, "error: failed to initialize video mode %dx%dx%d: %s\n", w, h, bpp, SDL_GetError()); return false; } w = surface->w; h = surface->h; bpp = surface->format->BitsPerPixel; printf("initialized video: %dx%dx%d\n", w, h, bpp); scaler = new_scaler; fullscreen_enabled = fullscreen; switch (bpp) { case 32: scaler_function = scalers[scaler].scaler32; break; case 16: scaler_function = scalers[scaler].scaler16; break; case 8: scaler_function = scalers[scaler].scaler8; break; default: scaler_function = NULL; break; } if (scaler_function == NULL) { assert(false); return false; } input_grab(); JE_showVGA(); return true; }
void app_quit( void ) { // in case the window isn't in the foreground // we'd end up with a huge black spot from being previously covered render_flip(&render_info); // release mouse so they can interact with message box input_grab( false ); // ask them to confirm clossing if(Msg("Are you sure you want to exit?") ) { // user wants to quit // let our code know we're quitting and not failing // let the message reach DefWindowProc so it calls CloseWindow CleanUpAndPostQuit(); return; } // let them click to get focus again if( ! render_info.fullscreen ) input_grab( true ); }
static void text_entry_button_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t button, enum wl_pointer_button_state state, void *data) { struct text_entry *entry = data; struct rectangle allocation; struct editor *editor; int32_t x, y; uint32_t result; widget_get_allocation(entry->widget, &allocation); input_get_position(input, &x, &y); x -= allocation.x + text_offset_left; y -= allocation.y + text_offset_left; editor = window_get_user_data(entry->window); if (button == BTN_LEFT) { entry->button_pressed = (state == WL_POINTER_BUTTON_STATE_PRESSED); if (state == WL_POINTER_BUTTON_STATE_PRESSED) input_grab(input, entry->widget, button); else input_ungrab(input); } if (text_entry_has_preedit(entry)) { result = text_entry_try_invoke_preedit_action(entry, x, y, button, state); if (result) return; } if (state == WL_POINTER_BUTTON_STATE_PRESSED) { struct wl_seat *seat = input_get_seat(input); text_entry_activate(entry, seat); editor->active_entry = entry; text_entry_set_cursor_position(entry, x, y, true); } }
void service_SDL_events( JE_boolean clear_new ) { SDL_Event ev; if (clear_new) newkey = newmouse = false; while (SDL_PollEvent(&ev)) { switch (ev.type) { case SDL_MOUSEMOTION: mouse_x = ev.motion.x * vga_width / scalers[scaler].width; mouse_y = ev.motion.y * vga_height / scalers[scaler].height; break; case SDL_KEYDOWN: if (ev.key.keysym.mod & KMOD_CTRL) { /* <ctrl><bksp> emergency kill */ if (ev.key.keysym.sym == SDLK_BACKSPACE) { puts("\n\n\nCtrl+Backspace pressed. Doing emergency quit.\n"); SDL_Quit(); exit(1); } /* <ctrl><f10> toggle input grab */ if (ev.key.keysym.sym == SDLK_F10) { input_grab_enabled = !input_grab_enabled; input_grab(); break; } } if (ev.key.keysym.mod & KMOD_ALT) { /* <alt><enter> toggle fullscreen */ if (ev.key.keysym.sym == SDLK_RETURN) { #ifdef __BLACKBERRY__ if (!init_scaler()) { exit(EXIT_FAILURE); } #else if (!init_scaler(scaler, !fullscreen_enabled) && // try new fullscreen state !init_any_scaler(!fullscreen_enabled) && // try any scaler in new fullscreen state !init_scaler(scaler, fullscreen_enabled)) // revert on fail { exit(EXIT_FAILURE); } #endif break; } /* <alt><tab> disable input grab and fullscreen */ if (ev.key.keysym.sym == SDLK_TAB) { input_grab_enabled = false; input_grab(); #ifdef __BLACKBERRY__ if (!init_scaler()) { exit(EXIT_FAILURE); } #else if (!init_scaler(scaler, false) && // try windowed !init_any_scaler(false) && // try any scaler windowed !init_scaler(scaler, fullscreen_enabled)) // revert on fail { exit(EXIT_FAILURE); } #endif break; } } newkey = true; lastkey_sym = ev.key.keysym.sym; lastkey_mod = ev.key.keysym.mod; lastkey_char = ev.key.keysym.unicode; keydown = true; return; case SDL_KEYUP: keydown = false; return; case SDL_MOUSEBUTTONDOWN: if(has_mouse) { if (!input_grabbed) { input_grab_enabled = !input_grab_enabled; input_grab(); break; } } /* no break */ case SDL_MOUSEBUTTONUP: if(has_mouse) { if (ev.type == SDL_MOUSEBUTTONDOWN) { newmouse = true; lastmouse_but = ev.button.button; lastmouse_x = ev.button.x * vga_width / scalers[scaler].width; lastmouse_y = ev.button.y * vga_height / scalers[scaler].height; mousedown = true; } else { mousedown = false; } switch (ev.button.button) { case SDL_BUTTON_LEFT: mouse_pressed[0] = mousedown; break; case SDL_BUTTON_RIGHT: mouse_pressed[1] = mousedown; break; case SDL_BUTTON_MIDDLE: mouse_pressed[2] = mousedown; break; } } break; case SDL_QUIT: /* TODO: Call the cleanup code here. */ #ifdef __BLACKBERRY__ JE_tyrianHalt(0); #else exit(0); #endif break; } } }
void service_SDL_events( JE_boolean clear_new ) { SDL_Event ev; if (clear_new) newkey = newmouse = false; while (SDL_PollEvent(&ev)) { switch (ev.type) { case SDL_ACTIVEEVENT: if (ev.active.state == SDL_APPINPUTFOCUS && !ev.active.gain) input_grab(false); break; case SDL_MOUSEMOTION: mouse_x = ev.motion.x * vga_width / scalers[scaler].width; mouse_y = ev.motion.y * vga_height / scalers[scaler].height; break; case SDL_KEYDOWN: if (handle_pause_key && ev.key.keysym.sym == SDLK_PAUSE) { JE_boolean superPause_save = superPause; superPause = true; JE_pauseGame(); superPause = superPause_save; break; } if (ev.key.keysym.mod & KMOD_CTRL) { /* <ctrl><bksp> emergency kill */ if (ev.key.keysym.sym == SDLK_BACKSPACE) { puts("\n\n\nCtrl+Backspace pressed. Doing emergency quit.\n"); SDL_Quit(); exit(1); } /* <ctrl><f10> toggle input grab */ if (ev.key.keysym.sym == SDLK_F10) { input_grab(!input_grab_enabled); break; } } if (ev.key.keysym.mod & KMOD_ALT) { /* <alt><enter> toggle fullscreen */ if (ev.key.keysym.sym == SDLK_RETURN) { if (!init_scaler(scaler, !fullscreen_enabled) && // try new fullscreen state !init_any_scaler(!fullscreen_enabled) && // try any scaler in new fullscreen state !init_scaler(scaler, fullscreen_enabled)) // revert on fail { exit(EXIT_FAILURE); } break; } /* <alt><tab> disable input grab and fullscreen */ if (ev.key.keysym.sym == SDLK_TAB) { if (!init_scaler(scaler, false) && // try windowed !init_any_scaler(false) && // try any scaler windowed !init_scaler(scaler, fullscreen_enabled)) // revert on fail { exit(EXIT_FAILURE); } input_grab(false); break; } } keysactive[ev.key.keysym.sym] = 1; newkey = true; lastkey_sym = ev.key.keysym.sym; lastkey_mod = ev.key.keysym.mod; lastkey_char = ev.key.keysym.unicode; keydown = true; return; case SDL_KEYUP: keysactive[ev.key.keysym.sym] = 0; keydown = false; return; case SDL_MOUSEBUTTONDOWN: if (!input_grab_enabled) { input_grab(true); break; } // intentional fall-though case SDL_MOUSEBUTTONUP: if (ev.type == SDL_MOUSEBUTTONDOWN) { newmouse = true; lastmouse_but = ev.button.button; lastmouse_x = ev.button.x * vga_width / scalers[scaler].width; lastmouse_y = ev.button.y * vga_height / scalers[scaler].height; mousedown = true; } else { mousedown = false; } switch (ev.button.button) { case SDL_BUTTON_LEFT: mouse_pressed[0] = mousedown; break; case SDL_BUTTON_RIGHT: mouse_pressed[1] = mousedown; break; case SDL_BUTTON_MIDDLE: mouse_pressed[2] = mousedown; break; } break; case SDL_QUIT: /* TODO: Call the cleanup code here. */ exit(0); break; } } }
bool init_scaler( unsigned int new_scaler, bool fullscreen ) #endif { const SDL_VideoInfo *info = SDL_GetVideoInfo(); const int screen_w = info->current_w; // Z10: 1280 const int screen_h = info->current_h; // Z10: 768 #ifdef __BLACKBERRY__ bool fullscreen = true; unsigned int new_scaler = 0; while (new_scaler < scalers_count && (scalers[new_scaler].width != screen_w || scalers[new_scaler].height != screen_h)) { new_scaler++; } if (scalers_count == new_scaler) { new_scaler = scalers_count - 1; } int bpp = 32; int w = scalers[new_scaler].width; int h = scalers[new_scaler].height; #else int bpp = can_init_scaler(new_scaler, fullscreen); #endif int flags = SDL_SWSURFACE | SDL_HWPALETTE | (fullscreen ? SDL_FULLSCREEN : 0); if (bpp == 0) return false; SDL_Surface * const surface = SDL_SetVideoMode(w, h, bpp, flags); if (surface == NULL) { fprintf(stderr, "error: failed to initialize video mode %dx%dx%d: %s\n", w, h, bpp, SDL_GetError()); return false; } w = surface->w; h = surface->h; bpp = surface->format->BitsPerPixel; fprintf(stderr, "initialized video: %dx%dx%d\n", w, h, bpp); scaler = new_scaler; fullscreen_enabled = fullscreen; switch (bpp) { case 32: scaler_function = scalers[scaler].scaler32; break; case 16: scaler_function = scalers[scaler].scaler16; break; case 8: scaler_function = scalers[scaler].scaler8; break; default: scaler_function = NULL; break; } if (scaler_function == NULL) { assert(false); return false; } input_grab(); JE_showVGA(); return true; }
void app_active( SDL_ActiveEvent * active ) #endif { // DebugPrintf("window active state set to: %s\n",(active->gain?"true":"false")); // since sdl 2 can support more than one type of event we want to explicitly check both gained/lost state #if SDL_VERSION_ATLEAST(2,0,0) bool gained = window -> event == SDL_WINDOWEVENT_FOCUS_GAINED; bool lost = window -> event == SDL_WINDOWEVENT_FOCUS_LOST; bool resized = window -> event == SDL_WINDOWEVENT_RESIZED; bool exposed = window -> event == SDL_WINDOWEVENT_EXPOSED; #else bool gained = active -> gain; bool lost = ! gained; #endif if( lost ) input_grab( false ); if( gained ) { // fullscreen always has exclusive inputs if( render_info.fullscreen ) { input_grab(true); } // window mode else { // only grab inputs if we are playing and not in menu if( !CurrentMenu && MyGameStatus == STATUS_Normal ) input_grab(true); else input_grab(false); } RenderModeReset(); } #if SDL_VERSION_ATLEAST(2,0,0) if( resized ) app_resize( window ); if( exposed ) render_flip(&render_info); #endif #if !SDL_VERSION_ATLEAST(2,0,0) switch( active->state ) { case SDL_APPMOUSEFOCUS: // mouse //DebugPrintf("Mouse event\n"); break; case SDL_APPINPUTFOCUS: // keyboard //DebugPrintf("keyboard event\n"); break; case SDL_APPACTIVE: // minimize/iconified //DebugPrintf("Iconify event\n"); break; } #endif }