void CL_TreeView_Silver::update_scrollbar(bool resize) { int max_height = treeview->get_items_height(); int component_height = treeview->get_client_area()->get_height(); if(max_height > component_height) { if(visible_scrollbar == false) { visible_scrollbar = true; treeview->add_child(scrollbar, false); if(resize) on_resize(0, 0); } scrollbar->set_max_value(max_height - component_height + 1); scrollbar->set_value(0); } else { if(visible_scrollbar) { visible_scrollbar = false; scrollbar->set_range(0, 0); scrollbar->set_value(0); treeview->remove_child(scrollbar); if(resize) on_resize(0, 0); } } }
CL_Window_Silver::CL_Window_Silver( CL_Window *window, CL_StyleManager_Silver *style) : CL_ComponentStyle(window), window(window), button_close(0), button_maximize(0), button_minimize(0), button_help(0), style(style), titlebar_height(22) { CL_ResourceManager *resources = style->get_resources(); font = new CL_Font("Window/font", resources); font_disabled = new CL_Font("Window/font_disabled", resources); // Make the window movable by dragging titlebar move_handler = new CL_ComponentMoveHandler(window); // Make the window resizable by dragging corner resize_handler = new CL_ComponentResizeHandler(window); CL_Window::TitlebarButtons buttons = window->get_titlebar_buttons_enum(); // Create a close button on the titlebar if(buttons & CL_Window::close_button) { button_close = add_titlebar_button("Window/surface_close", "Window/surface_close", "Window/surface_close_disabled", resources); slots.connect(button_close->sig_clicked(), this, &CL_Window_Silver::on_close_button_clicked); } // Create a maximize button on the titlebar if(buttons & CL_Window::maximize_button) { button_maximize = add_titlebar_button("Window/surface_maximize", "Window/surface_maximize", "Window/surface_maximize_disabled", resources); slots.connect(button_maximize->sig_clicked(), this, &CL_Window_Silver::on_maximize_button_clicked); } // Create a minimize button on the titlebar if(buttons & CL_Window::minimize_button) { button_minimize = add_titlebar_button("Window/surface_minimize", "Window/surface_minimize", "Window/surface_minimize_disabled", resources); slots.connect(button_minimize->sig_clicked(), this, &CL_Window_Silver::on_minimize_button_clicked); } // Create a help button on the titlebar if(buttons & CL_Window::help_button) { button_help = add_titlebar_button("Window/surface_help", "Window/surface_help", "Window/surface_help_disabled", resources); slots.connect(button_help->sig_clicked(), this, &CL_Window_Silver::on_help_button_clicked); } slots.connect(window->sig_paint(), this, &CL_Window_Silver::on_paint); slots.connect(window->sig_resize(), this, &CL_Window_Silver::on_resize); on_resize(0,0); }
/// Summary: Delegate events to internal functions. /// Remarks: Called automatically by the event manager. This subroutine is essentially an extension of the SDL /// message loop. void cx::engine::environment::delegate( SDL_Event event ) { // Call the correct function based on the type of event. switch (event.type) { case SDL_VIDEORESIZE: on_resize( event ); break; } }
void widget::position(const point& p) { if (rect_.p1() != p) { rect_.position(p); on_resize(); } }
void widget::height(int val) { if (height() != val) { rect_.height(val); on_resize(); } }
void widget::width(int val) { if (width() != val) { rect_.width(val); on_resize(); } }
// wrap the rectangle interface, emitting on_resize as appropriate // FIXME: should we always call redraw too when we resize? void widget::rect(const rectangle& rect) { if (rect_ != rect) { rect_ = rect; on_resize(); } }
static int check_resize (pingobj_t *ping) /* {{{ */ { int need_resize = 0; while (42) { int key = wgetch (stdscr); if (key == ERR) break; else if (key == KEY_RESIZE) need_resize = 1; } if (need_resize) return (on_resize (ping)); else return (0); } /* }}} int check_resize */
CL_TreeView_Silver::CL_TreeView_Silver( CL_TreeView *treeview, CL_StyleManager_Silver *style) : CL_ComponentStyle(treeview), treeview(treeview), style(style) { CL_ResourceManager *resources = style->get_resources(); font = new CL_Font("TreeView/font", resources); CL_Component *client_area = treeview->get_client_area(); client_area->set_clipping(true); // Create a vertical scrollbar scrollbar = new CL_ScrollBar(false, treeview); visible_scrollbar = true; // Create the header component header_area = new CL_Component(treeview); // Connect the dots slots.connect(treeview->sig_paint(), this, &CL_TreeView_Silver::on_paint); slots.connect(header_area->sig_paint(), this, &CL_TreeView_Silver::on_paint_header); slots.connect(client_area->sig_paint(), this, &CL_TreeView_Silver::on_paint_client); slots.connect(treeview->sig_paint_node(), this, &CL_TreeView_Silver::on_paint_node); slots.connect(client_area->sig_mouse_down(), this, &CL_TreeView_Silver::on_mouse_down); slots.connect(treeview->sig_resize(), this, &CL_TreeView_Silver::on_resize); slots.connect(treeview->sig_item_added(), this, &CL_TreeView_Silver::on_item_changed); slots.connect(treeview->sig_item_removed(), this, &CL_TreeView_Silver::on_item_changed); slots.connect(treeview->sig_item_expanded(), this, &CL_TreeView_Silver::on_item_changed); slots.connect(treeview->sig_item_collapsed(), this, &CL_TreeView_Silver::on_item_changed); slots.connect(treeview->sig_column_added(), this, &CL_TreeView_Silver::on_column_added); slots.connect(treeview->sig_column_removed(), this, &CL_TreeView_Silver::on_column_removed); slots.connect(treeview->sig_clear(), this, &CL_TreeView_Silver::on_clear); // Make sure we're arranged properly on_resize(0,0); }
Raytracer::Raytracer(u16 w, u16 h) : width(w) , height(h) { on_resize(width, height); }
static int event_loop() { int result = 0; SDL_Event event; while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: fs_log("intercepted SDL_QUIT\n"); fs_ml_quit(); continue; #ifdef USE_SDL2 case SDL_WINDOWEVENT: // printf("SDL_WINDOWEVENT...\n"); if (event.window.event == SDL_WINDOWEVENT_RESIZED) { on_resize(event.window.data1, event.window.data2); } else if (event.window.event == SDL_WINDOWEVENT_CLOSE) { event.type = SDL_QUIT; SDL_PushEvent(&event); } continue; #else case SDL_VIDEORESIZE: on_resize(event.resize.w, event.resize.h); continue; case SDL_ACTIVEEVENT: //fs_log("got active event %d %d %d %d\n", event.active.state, // SDL_APPMOUSEFOCUS, SDL_APPINPUTFOCUS, SDL_APPACTIVE); if ((event.active.state & SDL_APPINPUTFOCUS)) { if (event.active.gain) { fs_log("got keyboard focus\n"); // just got keyboard focus -- clearing modifier states fs_ml_clear_keyboard_modifier_state(); if (g_fs_ml_had_input_grab) { fs_log("- had input grab, re-acquiring\n"); fs_ml_grab_input(1, 1); g_fs_ml_had_input_grab = 0; } if (g_fs_ml_was_fullscreen) { if (!g_fs_emu_video_fullscreen) { fs_log("- was in fullsreen mode before (switching)\n"); fs_ml_toggle_fullscreen(); } g_fs_ml_was_fullscreen = 0; } } else { fs_log("lost keyboard focus\n"); if (fs_ml_has_input_grab()) { fs_log("- releasing input grab\n"); fs_ml_grab_input(0, 1); g_fs_ml_had_input_grab = 1; } else { fs_log("- did not have input grab\n"); //g_fs_ml_had_input_grab = 0; } } } continue; #endif case SDL_KEYDOWN: case SDL_KEYUP: if (g_debug_input) { fs_log("SDL key sym %d mod %d scancode %d state %d\n", event.key.keysym.sym, event.key.keysym.mod, event.key.keysym.scancode, event.key.state); } if (event.key.keysym.sym == 0 && event.key.keysym.scancode == 0) { // ignore "ghost key" seen on OS X which without this // specific check will cause the A key to be mysteriously // pressed. if (g_debug_input) { fs_log("- ignored key with keysym 0 and scancode 0\n"); } continue; } /* if (event.key.keysym.sym == SDLK_F12) { g_f12_state = event.key.state ? FS_ML_KEY_MOD_F12 : 0; printf("-- g_f12_state is %d\n", g_f12_state); } else if (event.key.keysym.sym == SDLK_F11) { g_f11_state = event.key.state ? FS_ML_KEY_MOD_F11 : 0; } */ const Uint8* key_state; int num_keys; #ifdef USE_SDL2 key_state = SDL_GetKeyboardState(&num_keys); g_f11_state = key_state[SDL_SCANCODE_F11] ? FS_ML_KEY_MOD_F11 : 0; g_f12_state = key_state[SDL_SCANCODE_F12] ? FS_ML_KEY_MOD_F12 : 0; // printf("%d %d\n", g_f11_state, g_f12_state); #else key_state = SDL_GetKeyState(&num_keys); g_f11_state = key_state[SDLK_F11] ? FS_ML_KEY_MOD_F11 : 0; g_f12_state = key_state[SDLK_F12] ? FS_ML_KEY_MOD_F12 : 0; #endif int key = -1; #ifdef USE_SDL2 if (event.key.keysym.scancode <= LAST_SDL2_SCANCODE) { key = g_sdl2_keys[event.key.keysym.scancode]; } #else if (0) { } #endif #if defined(MACOSX) #ifdef USE_SDL2 #else else if (event.key.keysym.sym == SDLK_LSHIFT) { key = SDLK_LSHIFT; } else if (event.key.keysym.sym == SDLK_LCTRL) { key = SDLK_LCTRL; } else if (event.key.keysym.sym == SDLK_LALT) { key = SDLK_LALT; } else if (event.key.keysym.sym == SDLK_LMETA) { key = SDLK_LSUPER; } else if (event.key.keysym.sym == SDLK_RMETA) { key = SDLK_RSUPER; } else if (event.key.keysym.sym == SDLK_RALT) { key = SDLK_RALT; } else if (event.key.keysym.sym == SDLK_RCTRL) { key = SDLK_RCTRL; } else if (event.key.keysym.sym == SDLK_RSHIFT) { key = SDLK_RSHIFT; } else if (event.key.keysym.sym == SDLK_CAPSLOCK) { key = SDLK_CAPSLOCK; } #endif #elif defined(WINDOWS) #else else if (event.key.keysym.sym == SDLK_MODE) { key = SDLK_RALT; } #endif else { key = fs_ml_scancode_to_key(event.key.keysym.scancode); } #ifdef USE_SDL2 if (0) { // the below trick does not currently work for SDL2, as // there is no mapping yet for translated keys } #else if (g_f12_state || g_f11_state) { // leave translated key code in keysym } #endif else if (key >= 0) { if (g_debug_input) { fs_log("- key code set to %d (was %d) based on " "scancode %d\n", key, event.key.keysym.sym, event.key.keysym.scancode); } event.key.keysym.sym = key; } int mod = event.key.keysym.mod; if (mod & KMOD_LSHIFT || mod & KMOD_RSHIFT) { event.key.keysym.mod |= KMOD_SHIFT; } if (mod & KMOD_LALT || mod & KMOD_RALT) { //mod & ~(KMOD_LALT | KMOD_RALT); event.key.keysym.mod |= KMOD_ALT; } if (mod & KMOD_LCTRL || mod & KMOD_RCTRL) { event.key.keysym.mod |= KMOD_CTRL; } if (mod & KMOD_LMETA || mod & KMOD_RMETA) { event.key.keysym.mod |= KMOD_META; } // filter out other modidifers event.key.keysym.mod &= (KMOD_SHIFT | KMOD_ALT | KMOD_CTRL | KMOD_META); // add F11/F12 state event.key.keysym.mod |= g_f11_state | g_f12_state; //printf("%d %d %d %d\n", event.key.keysym.mod, // KMOD_ALT, KMOD_LALT, KMOD_RALT); break; //case SDL_MOUSEBUTTONDOWN: // printf("--- mousebutton down ---\n"); } fs_ml_event *new_event = NULL; #if !defined(USE_SDL2) fs_ml_event *new_event_2 = NULL; #endif if (event.type == SDL_KEYDOWN) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_KEYDOWN; new_event->key.keysym.sym = event.key.keysym.sym; new_event->key.keysym.mod = event.key.keysym.mod; #ifdef USE_SDL2 // SDL2 sends its own text input events #else if (event.key.keysym.unicode && event.key.keysym.unicode < 128) { // FIXME: only supporting ASCII for now.. new_event_2 = fs_ml_alloc_event(); new_event_2->type = FS_ML_TEXTINPUT; new_event_2->text.text[0] = event.key.keysym.unicode; new_event_2->text.text[1] = '\0'; } #endif new_event->key.state = event.key.state; } else if (event.type == SDL_KEYUP) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_KEYUP; new_event->key.keysym.sym = event.key.keysym.sym; new_event->key.keysym.mod = event.key.keysym.mod; new_event->key.state = event.key.state; } else if (event.type == SDL_JOYBUTTONDOWN) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_JOYBUTTONDOWN; new_event->jbutton.which = g_fs_ml_first_joystick_index + \ event.jbutton.which; new_event->jbutton.button = event.jbutton.button; new_event->jbutton.state = event.jbutton.state; } else if (event.type == SDL_JOYBUTTONUP) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_JOYBUTTONUP; new_event->jbutton.which = g_fs_ml_first_joystick_index + \ event.jbutton.which; new_event->jbutton.button = event.jbutton.button; new_event->jbutton.state = event.jbutton.state; } else if (event.type == SDL_JOYAXISMOTION) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_JOYAXISMOTION; new_event->jaxis.which = g_fs_ml_first_joystick_index + \ event.jaxis.which; new_event->jaxis.axis = event.jaxis.axis; new_event->jaxis.value = event.jaxis.value; } else if (event.type == SDL_JOYHATMOTION) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_JOYHATMOTION; new_event->jhat.which = g_fs_ml_first_joystick_index + \ event.jhat.which; new_event->jhat.hat = event.jhat.hat; new_event->jhat.value = event.jhat.value; } else if (event.type == SDL_MOUSEMOTION) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_MOUSEMOTION; new_event->motion.device = g_fs_ml_first_mouse_index; new_event->motion.xrel = event.motion.xrel; new_event->motion.yrel = event.motion.yrel; /* Absolute window coordinates */ new_event->motion.x = event.motion.x; new_event->motion.y = event.motion.y; //printf("ISREL %d\n", SDL_GetRelativeMouseMode()); if (g_debug_input) { fs_log("SDL mouse event x: %4d y: %4d xrel: %4d yrel: %4d\n", event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel); } } else if (event.type == SDL_MOUSEBUTTONDOWN) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_MOUSEBUTTONDOWN; new_event->button.device = g_fs_ml_first_mouse_index; new_event->button.button = event.button.button; #ifdef MACOSX if (new_event->button.button == 1) { int mod = SDL_GetModState(); if (mod & KMOD_ALT) { new_event->button.button = 2; } else if (mod & KMOD_CTRL) { new_event->button.button = 3; } } #endif new_event->button.state = event.button.state; } else if (event.type == SDL_MOUSEBUTTONUP) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_MOUSEBUTTONUP; new_event->button.device = g_fs_ml_first_mouse_index; new_event->button.button = event.button.button; #ifdef MACOSX if (new_event->button.button == 1) { int mod = SDL_GetModState(); if (mod & KMOD_ALT) { new_event->button.button = 2; } else if (mod & KMOD_CTRL) { new_event->button.button = 3; } } #endif new_event->button.state = event.button.state; } #ifdef USE_SDL2 else if (event.type == SDL_MOUSEWHEEL) { /* if (event.wheel.which == SDL_TOUCH_MOUSEID) { } */ if (event.wheel.y) { if (g_debug_input) { fs_log("SDL mouse event y-scroll: %4d\n", event.wheel.y); } new_event = fs_ml_alloc_event(); new_event->type = FS_ML_MOUSEBUTTONDOWN; if (event.wheel.y > 0) { new_event->button.button = FS_ML_BUTTON_WHEELUP; } else { new_event->button.button = FS_ML_BUTTON_WHEELDOWN; } new_event->button.device = g_fs_ml_first_mouse_index; new_event->button.state = 1; } } else if (event.type == SDL_TEXTINPUT) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_TEXTINPUT; memcpy(&(new_event->text.text), &(event.text.text), MIN(TEXTINPUTEVENT_TEXT_SIZE, SDL_TEXTINPUTEVENT_TEXT_SIZE)); new_event->text.text[TEXTINPUTEVENT_TEXT_SIZE - 1] = 0; } #endif if (new_event) { fs_ml_post_event(new_event); } #if !defined(USE_SDL2) if (new_event_2) { fs_ml_post_event(new_event_2); } #endif } return result; }
//------------------------------------------------------------------------ bool platform_support::init(unsigned width, unsigned height, unsigned flags) { if(m_specific->m_sys_format == pix_format_undefined) { return false; } m_window_flags = flags; // application EventTypeSpec eventType; EventHandlerUPP handlerUPP; eventType.eventClass = kEventClassApplication; eventType.eventKind = kEventAppQuit; handlerUPP = NewEventHandlerUPP(DoAppQuit); InstallApplicationEventHandler (handlerUPP, 1, &eventType, nil, nil); eventType.eventClass = kEventClassMouse; eventType.eventKind = kEventMouseDown; handlerUPP = NewEventHandlerUPP(DoMouseDown); InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); eventType.eventKind = kEventMouseUp; handlerUPP = NewEventHandlerUPP(DoMouseUp); InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); eventType.eventKind = kEventMouseDragged; handlerUPP = NewEventHandlerUPP(DoMouseDragged); InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); eventType.eventClass = kEventClassKeyboard; eventType.eventKind = kEventRawKeyDown; handlerUPP = NewEventHandlerUPP(DoKeyDown); InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); eventType.eventKind = kEventRawKeyUp; handlerUPP = NewEventHandlerUPP(DoKeyUp); InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); eventType.eventKind = kEventRawKeyRepeat; handlerUPP = NewEventHandlerUPP(DoKeyDown); // 'key repeat' is translated to 'key down' InstallApplicationEventHandler (handlerUPP, 1, &eventType, this, nil); WindowAttributes windowAttrs; Rect bounds; // window windowAttrs = kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowStandardHandlerAttribute; SetRect (&bounds, 0, 0, width, height); OffsetRect (&bounds, 100, 100); CreateNewWindow (kDocumentWindowClass, windowAttrs, &bounds, &m_specific->m_window); if(m_specific->m_window == nil) { return false; } // I assume the text is ASCII. // Change to kCFStringEncodingMacRoman, kCFStringEncodingISOLatin1, kCFStringEncodingUTF8 or what else you need. SetWindowTitleWithCFString (m_specific->m_window, CFStringCreateWithCStringNoCopy (nil, m_caption, kCFStringEncodingASCII, nil)); eventType.eventClass = kEventClassWindow; eventType.eventKind = kEventWindowClose; handlerUPP = NewEventHandlerUPP(DoWindowClose); InstallWindowEventHandler (m_specific->m_window, handlerUPP, 1, &eventType, this, NULL); eventType.eventKind = kEventWindowDrawContent; handlerUPP = NewEventHandlerUPP(DoWindowDrawContent); InstallWindowEventHandler (m_specific->m_window, handlerUPP, 1, &eventType, this, NULL); // Periodic task // Instead of an idle function I use the Carbon event timer. // You may decide to change the wait value which is currently 50 milliseconds. EventLoopRef mainLoop; EventLoopTimerUPP timerUPP; EventLoopTimerRef theTimer; mainLoop = GetMainEventLoop(); timerUPP = NewEventLoopTimerUPP (DoPeriodicTask); InstallEventLoopTimer (mainLoop, 0, 50 * kEventDurationMillisecond, timerUPP, this, &theTimer); m_specific->create_pmap(width, height, &m_rbuf_window); m_initial_width = width; m_initial_height = height; on_init(); on_resize(width, height); m_specific->m_redraw_flag = true; ShowWindow (m_specific->m_window); SetPortWindowPort (m_specific->m_window); return true; }
//------------------------------------------------------------------------ bool platform_support::init(unsigned width, unsigned height, unsigned flags) { m_window_flags = flags; unsigned wflags = MEMDC_FLAG_SWSURFACE; if(m_window_flags & window_hw_buffer) { wflags = MEMDC_FLAG_HWSURFACE; } /* if(m_window_flags & window_resize) { wflags |= GAL_RESIZABLE; } */ //SDL_WM_SetCaption(m_caption, 0); if(m_specific->m_surf_window) DeleteMemDC(m_specific->m_surf_window); #if 0 printf("init memdc: w=%d, h=%d, m_bpp=%d, wflags=%d\n", width, height, m_bpp, wflags); printf("init memdc: m_rmask=%x, m_gmask=%x, m_bmask=%x, m_amask=%x\n", m_specific->m_rmask, m_specific->m_gmask, m_specific->m_bmask, m_specific->m_amask); #endif m_specific->m_surf_window = CreateMemDC( width, height, m_bpp, wflags, m_specific->m_rmask, m_specific->m_gmask, m_specific->m_bmask, m_specific->m_amask); if(m_specific->m_surf_window == 0) { fprintf(stderr, "Unable to create image buffer %dx%d %d bpp: %s\n", width, height, m_bpp, //SDL_GetError()); "failed"); return false; } int pitch = width * (m_bpp/8); //printf("init, pitch=%d\n", pitch); #if 0 m_rbuf_window.attach((unsigned char*)PIXEL(SURFACE(m_specific->m_surf_window)), width, height, m_flip_y ? -pitch:pitch); #else m_rbuf_window.attach((unsigned char*)LockDC(m_specific->m_surf_window, NULL, NULL, NULL, NULL), width, height, m_flip_y ? -pitch:pitch); #endif if(!m_specific->m_initialized) { m_initial_width = width; m_initial_height = height; on_init(); m_specific->m_initialized = true; } on_resize(m_rbuf_window.width(), m_rbuf_window.height()); m_specific->m_update_flag = true; return true; }
void GraphicsCanvas::resizeEvent(QResizeEvent *event) { on_resize(event); }
static int event_loop() { int result = 0; SDL_Event event; while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: fs_log("intercepted SDL_QUIT\n"); fs_ml_quit(); continue; case SDL_VIDEORESIZE: on_resize(event.resize.w, event.resize.h); continue; case SDL_ACTIVEEVENT: //fs_log("got active event %d %d %d %d\n", event.active.state, // SDL_APPMOUSEFOCUS, SDL_APPINPUTFOCUS, SDL_APPACTIVE); if ((event.active.state & SDL_APPINPUTFOCUS)) { if (event.active.gain) { fs_log("got keyboard focus\n"); // just got keyboard focus -- clearing modifier states fs_ml_clear_keyboard_modifier_state(); if (g_fs_ml_had_input_grab) { fs_log("- had input grab, re-acquiring\n"); fs_ml_grab_input(1, 1); g_fs_ml_had_input_grab = 0; } if (g_fs_ml_was_fullscreen) { if (!g_fs_emu_video_fullscreen) { fs_log("- was in fullsreen mode before (switching)\n"); fs_ml_toggle_fullscreen(); } g_fs_ml_was_fullscreen = 0; } } else { fs_log("lost keyboard focus\n"); if (fs_ml_has_input_grab()) { fs_log("- releasing input grab\n"); fs_ml_grab_input(0, 1); g_fs_ml_had_input_grab = 1; } else { fs_log("- did not have input grab\n"); //g_fs_ml_had_input_grab = 0; } } } continue; case SDL_KEYDOWN: case SDL_KEYUP: if (g_debug_keys) { fs_log("SDL key sym %d mod %d scancode %d state %d\n", event.key.keysym.sym, event.key.keysym.mod, event.key.keysym.scancode, event.key.state); } int key = -1; if (0) { } #ifdef MACOSX else if (event.key.keysym.sym == SDLK_LSHIFT) { key = SDLK_LSHIFT; } else if (event.key.keysym.sym == SDLK_LCTRL) { key = SDLK_LCTRL; } else if (event.key.keysym.sym == SDLK_LALT) { key = SDLK_LALT; } else if (event.key.keysym.sym == SDLK_LMETA) { key = SDLK_LSUPER; } else if (event.key.keysym.sym == SDLK_RMETA) { key = SDLK_RSUPER; } else if (event.key.keysym.sym == SDLK_RALT) { key = SDLK_RALT; } else if (event.key.keysym.sym == SDLK_RCTRL) { key = SDLK_RCTRL; } else if (event.key.keysym.sym == SDLK_RSHIFT) { key = SDLK_RSHIFT; } else if (event.key.keysym.sym == SDLK_CAPSLOCK) { key = SDLK_CAPSLOCK; } #endif else { key = fs_ml_scancode_to_key(event.key.keysym.scancode); } if (key >= 0) { event.key.keysym.sym = key; } int mod = event.key.keysym.mod; if (mod & KMOD_LSHIFT || mod & KMOD_RSHIFT) { event.key.keysym.mod |= KMOD_SHIFT; } if (mod & KMOD_LALT || mod & KMOD_RALT) { //mod & ~(KMOD_LALT | KMOD_RALT); event.key.keysym.mod |= KMOD_ALT; } if (mod & KMOD_LCTRL || mod & KMOD_RCTRL) { event.key.keysym.mod |= KMOD_CTRL; } if (mod & KMOD_LMETA || mod & KMOD_RMETA) { event.key.keysym.mod |= KMOD_META; } // filter out other modidifers event.key.keysym.mod &= (KMOD_SHIFT | KMOD_ALT | KMOD_CTRL | KMOD_META); //printf("%d %d %d %d\n", event.key.keysym.mod, // KMOD_ALT, KMOD_LALT, KMOD_RALT); break; //case SDL_MOUSEBUTTONDOWN: // printf("--- mousebutton down ---\n"); } fs_ml_event *new_event = fs_ml_alloc_event(); *new_event = event; fs_ml_post_event(new_event); } return result; }
void title_screen::pre_show(window& win) { win.set_click_dismiss(false); win.set_enter_disabled(true); win.set_escape_disabled(true); // Each time the dialog shows, we set this to false redraw_background_ = false; #ifdef DEBUG_TOOLTIP win.connect_signal<event::SDL_MOUSE_MOTION>( std::bind(debug_tooltip, std::ref(win), _3, _5), event::dispatcher::front_child); #endif win.connect_signal<event::SDL_VIDEO_RESIZE>(std::bind(&title_screen::on_resize, this, std::ref(win))); // // General hotkeys // win.register_hotkey(hotkey::TITLE_SCREEN__RELOAD_WML, [](event::dispatcher& w, hotkey::HOTKEY_COMMAND) { dynamic_cast<window&>(w).set_retval(RELOAD_GAME_DATA); return true; }); win.register_hotkey(hotkey::HOTKEY_FULLSCREEN, std::bind(fullscreen, std::ref(win.video()))); win.register_hotkey(hotkey::LUA_CONSOLE, std::bind(&launch_lua_console, std::ref(win))); // // Background and logo images // if(game_config::images::game_title.empty()) { ERR_CF << "No title image defined" << std::endl; } win.get_canvas()[0].set_variable("title_image", variant(game_config::images::game_title)); if(game_config::images::game_title_background.empty()) { ERR_CF << "No title background image defined" << std::endl; } win.get_canvas()[0].set_variable("background_image", variant(game_config::images::game_title_background)); find_widget<image>(&win, "logo-bg", false).set_image(game_config::images::game_logo_background); find_widget<image>(&win, "logo", false).set_image(game_config::images::game_logo); // // Version string // const std::string version_string = formatter() << ("Version") << " " << game_config::revision; if(label* version_label = find_widget<label>(&win, "revision_number", false, false)) { version_label->set_label(version_string); } win.get_canvas()[0].set_variable("revision_number", variant(version_string)); // // Tip-of-the-day browser // multi_page& tip_pages = find_widget<multi_page>(&win, "tips", false); std::vector<game_tip> tips(settings::get_tips()); if(tips.empty()) { WRN_CF << "There are no tips of day available." << std::endl; } for(const auto& tip : tips) { string_map widget; std::map<std::string, string_map> page; widget["use_markup"] = "true"; widget["label"] = tip.text(); page.emplace("tip", widget); widget["label"] = tip.source(); page.emplace("source", widget); tip_pages.add_page(page); } update_tip(win, true); register_button(win, "next_tip", hotkey::TITLE_SCREEN__NEXT_TIP, std::bind(&title_screen::update_tip, this, std::ref(win), true)); register_button(win, "previous_tip", hotkey::TITLE_SCREEN__PREVIOUS_TIP, std::bind(&title_screen::update_tip, this, std::ref(win), false)); // // Help // register_button(win, "help", hotkey::HOTKEY_HELP, [this](window&) { help::help_manager help_manager(&game_config_manager::get()->game_config()); help::show_help(game_.video()); }); // // About // register_button(win, "about", hotkey::HOTKEY_NULL, std::bind(&game_version::display, std::ref(win.video()))); // // Tutorial // register_button(win, "tutorial", hotkey::TITLE_SCREEN__TUTORIAL, [this](window& w) { game_.set_tutorial(); w.set_retval(LAUNCH_GAME); }); // // Campaign // register_button(win, "campaign", hotkey::TITLE_SCREEN__CAMPAIGN, [this](window& w) { try{ if(game_.new_campaign()) { w.set_retval(LAUNCH_GAME); } } catch (const config::error& e) { gui2::show_error_message(game_.video(), e.what()); } }); // // Multiplayer // register_button(win, "multiplayer", hotkey::TITLE_SCREEN__MULTIPLAYER, [this](window& w) { while(true) { gui2::dialogs::mp_method_selection dlg; dlg.show(game_.video()); if(dlg.get_retval() != gui2::window::OK) { return; } const int res = dlg.get_choice(); if(res == 2 && preferences::mp_server_warning_disabled() < 2) { if(!gui2::dialogs::mp_host_game_prompt::execute(game_.video())) { continue; } } switch(res) { case 0: game_.select_mp_server(preferences::server_list().front().address); w.set_retval(MP_CONNECT); break; case 1: game_.select_mp_server(""); w.set_retval(MP_CONNECT); break; case 2: game_.select_mp_server("localhost"); w.set_retval(MP_HOST); break; case 3: w.set_retval(MP_LOCAL); break; } return; } }); // // Load game // register_button(win, "load", hotkey::HOTKEY_LOAD_GAME, [this](window& w) { if(game_.load_game()) { w.set_retval(LAUNCH_GAME); } else { game_.clear_loaded_game(); } }); // // Addons // register_button(win, "addons", hotkey::TITLE_SCREEN__ADDONS, [this](window&) { // NOTE: we need the help_manager to get access to the Add-ons section in the game help! help::help_manager help_manager(&game_config_manager::get()->game_config()); if(manage_addons(game_.video())) { game_config_manager::get()->reload_changed_game_config(); } }); // // Editor // register_button(win, "editor", hotkey::TITLE_SCREEN__EDITOR, [&](window& w) { w.set_retval(MAP_EDITOR); }); // // Cores // register_button(win, "cores", hotkey::TITLE_SCREEN__CORES, [this](window&) { int current = 0; std::vector<config> cores; for(const config& core : game_config_manager::get()->game_config().child_range("core")) { cores.push_back(core); if(core["id"] == preferences::core_id()) { current = cores.size() - 1; } } gui2::dialogs::core_selection core_dlg(cores, current); if(core_dlg.show(game_.video())) { const std::string& core_id = cores[core_dlg.get_choice()]["id"]; preferences::set_core_id(core_id); game_config_manager::get()->reload_changed_game_config(); } }); if(game_config_manager::get()->game_config().child_range("core").size() <= 1) { find_widget<button>(&win, "cores", false).set_visible(window::visibility::invisible); } // // Language // register_button(win, "language", hotkey::HOTKEY_LANGUAGE, [this](window& w) { try { if(game_.change_language()) { t_string::reset_translations(); ::image::flush_cache(); on_resize(w); } } catch(std::runtime_error& e) { gui2::show_error_message(game_.video(), e.what()); } }); // // Preferences // register_button(win, "preferences", hotkey::HOTKEY_PREFERENCES, [this](window&) { game_.show_preferences(); }); // // Credits // register_button(win, "credits", hotkey::TITLE_SCREEN__CREDITS, [&](window& w) { w.set_retval(SHOW_ABOUT); }); // // Quit // register_button(win, "quit", hotkey::HOTKEY_QUIT_TO_DESKTOP, [&](window& w) { w.set_retval(QUIT_GAME); }); // // Debug clock // register_button(win, "clock", hotkey::HOTKEY_NULL, std::bind(&title_screen::show_debug_clock_window, this, std::ref(win.video()))); find_widget<button>(&win, "clock", false).set_visible(show_debug_clock_button ? widget::visibility::visible : widget::visibility::invisible); }
//------------------------------------------------------------------------ bool platform_support::init(unsigned width, unsigned height, unsigned flags) { ERROR_PRINT("platform_support::init %d,%d\n", width, height); m_window_flags = flags; int wflags = 0; if(m_specific->m_texture) SDL_DestroyTexture(m_specific->m_texture); if(m_specific->m_renderer) SDL_DestroyRenderer(m_specific->m_renderer); if(m_specific->m_surface) SDL_FreeSurface(m_specific->m_surface); //if(m_specific->m_mwindow) SDL_DestroyWindow(m_specific->m_mwindow); m_specific->m_texture = 0; m_specific->m_renderer = 0; m_specific->m_surface = 0; //m_specific->m_mwindow = 0; if(m_window_flags & window_resize) { wflags |= SDL_WINDOW_RESIZABLE; } if(m_window_flags & window_fullscreen) { wflags |= SDL_WINDOW_FULLSCREEN; #ifdef __ANDROID__DISABLED width = Android_ScreenWidth; height = Android_ScreenHeight; #endif #ifdef __ANDROID__ if (m_window_flags & window_keep_aspect_ratio) { width = (double)Android_ScreenWidth/Android_ScreenHeight*height; width_factor = (double)width/Android_ScreenWidth; hight_factor = (double)height/Android_ScreenHeight; } #endif } DEBUG_PRINT("platform_support::init %d,%d,%d", width, height, wflags); int numRendDrv = SDL_GetNumRenderDrivers(); DEBUG_PRINT("num rend drv %d\n", numRendDrv); for (int i = 0; i < numRendDrv; i++) { SDL_RendererInfo info; SDL_GetRenderDriverInfo(i, &info); DEBUG_PRINT("index %i, %s, flags %x, texture formats %x\n", i, info.name, info.flags, info.texture_formats[0]); } if (!m_specific->m_mwindow) { m_specific->m_mwindow = SDL_CreateWindow(m_caption, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, wflags); } if (m_specific->m_mwindow == 0) { ERROR_PRINT( "Unable to create %dx%d %d bpp window: %s\n", width, height, m_bpp, SDL_GetError()); return false; } m_specific->m_surface = SDL_CreateRGBSurface(0, width, height, m_bpp, m_specific->m_rmask, m_specific->m_gmask, m_specific->m_bmask, m_specific->m_amask); DEBUG_PRINT("surface at %p", m_specific->m_surface); if(m_specific->m_surface == 0) { ERROR_PRINT( "Unable to create image buffer %dx%d %d bpp: %s\n", width, height, m_bpp, SDL_GetError()); return false; } m_specific->m_renderer = SDL_CreateRenderer(m_specific->m_mwindow, -1, 0); if(m_specific->m_renderer == 0) { ERROR_PRINT( "Unable to create renderer: %s\n", SDL_GetError()); return false; } { SDL_RendererInfo info; SDL_GetRendererInfo(m_specific->m_renderer, &info); DEBUG_PRINT("Current, %s, flags %x, texture formats %x, %x\n", info.name, info.flags, SDL_PIXELFORMAT_ARGB8888, info.texture_formats[0]); } m_specific->m_texture = SDL_CreateTexture( m_specific->m_renderer, m_specific->m_pformat, SDL_TEXTUREACCESS_STREAMING, width, height); if(m_specific->m_renderer == 0) { ERROR_PRINT( "Unable to create texture: %s\n", SDL_GetError()); return false; } void* pixels; int pitch; if (SDL_LockTexture(m_specific->m_texture, NULL, &pixels, &pitch) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock texture: %s\n", SDL_GetError()); } m_rbuf_window.attach((unsigned char*)pixels, width, height, m_flip_y ? -pitch : pitch); if (!m_specific->m_initialized) { m_initial_width = width; m_initial_height = height; on_init(); m_specific->m_initialized = true; } on_resize(m_rbuf_window.width(), m_rbuf_window.height()); m_specific->m_update_flag = true; return true; }
int fs_ml_event_loop(void) { // printf("fs_ml_event_loop\n"); int result = 0; SDL_Event event; while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: fs_log("Received SDL_QUIT\n"); fs_ml_quit(); #ifdef FSE_DRIVERS printf("returning 1 from fs_ml_event_loop\n"); result = 1; #endif continue; case SDL_WINDOWEVENT: if (event.window.event == SDL_WINDOWEVENT_RESIZED) { on_resize(event.window.data1, event.window.data2); } else if (event.window.event == SDL_WINDOWEVENT_CLOSE) { event.type = SDL_QUIT; SDL_PushEvent(&event); } else if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { if (g_grab_input_on_activate) { fs_log("Window focus gained - grabbing input\n"); g_grab_input_on_activate = false; fs_ml_set_input_grab(true); #ifdef MACOSX } else if (fs_ml_input_grab()) { /* Input grab could be "lost" due to Cmd+Tab */ fs_log("[INPUT] Forcing re-grab of input on macOS\n"); fs_ml_set_input_grab(false); fs_ml_set_input_grab(true); #endif } } continue; case SDL_KEYDOWN: case SDL_KEYUP: if (g_fs_log_input) { fs_log("SDL key sym %d mod %d scancode %d state %d repeat %d\n", event.key.keysym.sym, event.key.keysym.mod, event.key.keysym.scancode, event.key.state, event.key.repeat); } if (event.key.repeat) { continue; } if (event.key.keysym.sym == 0 && event.key.keysym.scancode == 0) { /* ignore "ghost key" seen on OS X which without this * specific check will cause the A key to be mysteriously * pressed. */ if (g_fs_log_input) { fs_log("- ignored key with keysym 0 and scancode 0\n"); } continue; } /* if (event.key.keysym.sym == SDLK_F12) { g_f12_state = event.key.state ? FS_ML_KEY_MOD_F12 : 0; printf("-- g_f12_state is %d\n", g_f12_state); } else if (event.key.keysym.sym == SDLK_F11) { g_f11_state = event.key.state ? FS_ML_KEY_MOD_F11 : 0; } */ const Uint8* key_state; int num_keys; key_state = SDL_GetKeyboardState(&num_keys); g_f11_state = key_state[SDL_SCANCODE_F11] ? FS_ML_KEY_MOD_F11 : 0; g_f12_state = key_state[SDL_SCANCODE_F12] ? FS_ML_KEY_MOD_F12 : 0; int key = -1; if (event.key.keysym.scancode <= LAST_SDL2_SCANCODE) { key = g_sdl2_keys[event.key.keysym.scancode]; } #if defined(MACOSX) #elif defined(WINDOWS) #else else if (event.key.keysym.sym == SDLK_MODE) { key = SDLK_RALT; } #endif else { key = fs_ml_scancode_to_key(event.key.keysym.scancode); } #ifdef USE_SDL2 if (0) { // the below trick does not currently work for SDL2, as // there is no mapping yet for translated keys } #else if (g_f12_state || g_f11_state) { // leave translated key code in keysym } #endif else if (key >= 0) { if (g_fs_log_input) { fs_log("- key code set to %d (was %d) based on " "scancode %d\n", key, event.key.keysym.sym, event.key.keysym.scancode); } event.key.keysym.sym = key; } int mod = event.key.keysym.mod; if (mod & KMOD_LSHIFT || mod & KMOD_RSHIFT) event.key.keysym.mod |= KMOD_SHIFT; #if 0 if (mod & KMOD_LALT || mod & KMOD_RALT) event.key.keysym.mod |= KMOD_ALT; #endif if (mod & KMOD_LCTRL || mod & KMOD_RCTRL) event.key.keysym.mod |= KMOD_CTRL; #if 0 if (mod & KMOD_LMETA || mod & KMOD_RMETA) event.key.keysym.mod |= KMOD_META; #endif /* Filter out other modidifers */ event.key.keysym.mod &= KMOD_SHIFT | KMOD_ALT | KMOD_CTRL | KMOD_META; /* Add F11/F12 modifier state */ event.key.keysym.mod |= g_f11_state | g_f12_state; //printf("%d %d %d %d\n", event.key.keysym.mod, // KMOD_ALT, KMOD_LALT, KMOD_RALT); break; //case SDL_MOUSEBUTTONDOWN: // printf("--- mousebutton down ---\n"); } fs_ml_event *new_event = NULL; if (event.type == SDL_KEYDOWN) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_KEYDOWN; new_event->key.keysym.sym = event.key.keysym.sym; new_event->key.keysym.mod = event.key.keysym.mod; new_event->key.state = event.key.state; } else if (event.type == SDL_KEYUP) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_KEYUP; new_event->key.keysym.sym = event.key.keysym.sym; new_event->key.keysym.mod = event.key.keysym.mod; new_event->key.state = event.key.state; } else if (event.type == SDL_JOYBUTTONDOWN) { if (g_fs_log_input) { fs_log("SDL_JOYBUTTONDOWN which %d button %d state %d\n", event.jbutton.which, event.jbutton.button, event.jbutton.state); } new_event = fs_ml_alloc_event(); new_event->type = FS_ML_JOYBUTTONDOWN; new_event->jbutton.which = \ g_fs_ml_sdl_joystick_index_map[event.jbutton.which]; new_event->jbutton.button = event.jbutton.button; new_event->jbutton.state = event.jbutton.state; } else if (event.type == SDL_JOYBUTTONUP) { if (g_fs_log_input) { fs_log("SDL_JOYBUTTONUP which %d button %d state %d\n", event.jbutton.which, event.jbutton.button, event.jbutton.state); } new_event = fs_ml_alloc_event(); new_event->type = FS_ML_JOYBUTTONUP; new_event->jbutton.which = \ g_fs_ml_sdl_joystick_index_map[event.jbutton.which]; new_event->jbutton.button = event.jbutton.button; new_event->jbutton.state = event.jbutton.state; } else if (event.type == SDL_JOYAXISMOTION) { /* Not logging axis motion, too much noise */ new_event = fs_ml_alloc_event(); new_event->type = FS_ML_JOYAXISMOTION; new_event->jaxis.which = \ g_fs_ml_sdl_joystick_index_map[event.jaxis.which]; new_event->jaxis.axis = event.jaxis.axis; new_event->jaxis.value = event.jaxis.value; } else if (event.type == SDL_JOYHATMOTION) { if (g_fs_log_input) { fs_log("SDL_JOYHATMOTION which %d hat %d value %d\n", event.jhat.which, event.jhat.hat, event.jhat.value); } new_event = fs_ml_alloc_event(); new_event->type = FS_ML_JOYHATMOTION; new_event->jhat.which = \ g_fs_ml_sdl_joystick_index_map[event.jhat.which]; new_event->jhat.hat = event.jhat.hat; new_event->jhat.value = event.jhat.value; } else if (event.type == SDL_MOUSEMOTION) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_MOUSEMOTION; new_event->motion.device = g_fs_ml_first_mouse_index; new_event->motion.xrel = event.motion.xrel; new_event->motion.yrel = event.motion.yrel; /* Absolute window coordinates */ new_event->motion.x = event.motion.x; new_event->motion.y = event.motion.y; //printf("ISREL %d\n", SDL_GetRelativeMouseMode()); if (g_fs_log_input) { fs_log("SDL mouse event x: %4d y: %4d xrel: %4d yrel: %4d\n", event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel); } } else if (event.type == SDL_MOUSEBUTTONDOWN) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_MOUSEBUTTONDOWN; new_event->button.device = g_fs_ml_first_mouse_index; new_event->button.button = event.button.button; #ifdef MACOSX if (new_event->button.button == 1) { int mod = SDL_GetModState(); if (mod & KMOD_ALT) { new_event->button.button = 2; } else if (mod & KMOD_CTRL) { new_event->button.button = 3; } } #endif new_event->button.state = event.button.state; } else if (event.type == SDL_MOUSEBUTTONUP) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_MOUSEBUTTONUP; new_event->button.device = g_fs_ml_first_mouse_index; new_event->button.button = event.button.button; #ifdef MACOSX if (new_event->button.button == 1) { int mod = SDL_GetModState(); if (mod & KMOD_ALT) { new_event->button.button = 2; } else if (mod & KMOD_CTRL) { new_event->button.button = 3; } } #endif new_event->button.state = event.button.state; } else if (event.type == SDL_MOUSEWHEEL) { /* if (event.wheel.which == SDL_TOUCH_MOUSEID) { } */ if (event.wheel.y) { if (g_fs_log_input) { fs_log("SDL mouse event y-scroll: %4d\n", event.wheel.y); } new_event = fs_ml_alloc_event(); new_event->type = FS_ML_MOUSEBUTTONDOWN; if (event.wheel.y > 0) { new_event->button.button = FS_ML_BUTTON_WHEELUP; } else { new_event->button.button = FS_ML_BUTTON_WHEELDOWN; } new_event->button.device = g_fs_ml_first_mouse_index; new_event->button.state = 1; } } else if (event.type == SDL_TEXTINPUT) { new_event = fs_ml_alloc_event(); new_event->type = FS_ML_TEXTINPUT; memcpy(&(new_event->text.text), &(event.text.text), MIN(TEXTINPUTEVENT_TEXT_SIZE, SDL_TEXTINPUTEVENT_TEXT_SIZE)); new_event->text.text[TEXTINPUTEVENT_TEXT_SIZE - 1] = 0; } if (new_event) { fs_ml_post_event(new_event); } } return result; }
//------------------------------------------------------------------------ int platform_support::run() { SDL_Event event; bool ev_flag = false; for(;;) { if(m_specific->m_update_flag) { on_draw(); update_window(); m_specific->m_update_flag = false; } ev_flag = false; if(m_wait_mode) { SDL_WaitEvent(&event); ev_flag = true; } else { if(SDL_PollEvent(&event)) { ev_flag = true; } else { on_idle(); } } if(ev_flag) { if(event.type == SDL_QUIT) { break; } int y; unsigned flags = 0; switch (event.type) { int event_x; int event_y; case SDL_WINDOWEVENT: switch (event.window.event) { case SDL_WINDOWEVENT_RESIZED: ERROR_PRINT("SDL_WINDOWEVENT_RESIZED %d,%d\n", event.window.data1, event.window.data2); #ifndef __ANDROID__ if(!init(event.window.data1, event.window.data2, m_window_flags)) return false; on_resize(m_rbuf_window.width(), m_rbuf_window.height()); trans_affine_resizing(event.window.data1, event.window.data2); #endif m_specific->m_update_flag = true; break; default: DEBUG_PRINT("unknown win event type %d\n", event.window.event); break; } break; case SDL_APP_DIDENTERFOREGROUND: DEBUG_PRINT("SDL_APP_DIDENTERFOREGROUND"); enter_foreground(); break; case SDL_APP_WILLENTERFOREGROUND: DEBUG_PRINT("SDL_APP_WILLENTERFOREGROUND"); break; case SDL_APP_DIDENTERBACKGROUND: DEBUG_PRINT("SDL_APP_DIDENTERBACKGROUND"); enter_background(); break; case SDL_APP_WILLENTERBACKGROUND: DEBUG_PRINT("SDL_APP_WILLENTERBACKGROUND"); break; case SDL_KEYDOWN: { flags = 0; if(event.key.keysym.mod & KMOD_SHIFT) flags |= kbd_shift; if(event.key.keysym.mod & KMOD_CTRL) flags |= kbd_ctrl; bool left = false; bool up = false; bool right = false; bool down = false; switch(event.key.keysym.sym) { case key_left: left = true; break; case key_up: up = true; break; case key_right: right = true; break; case key_down: down = true; break; } if(m_ctrls.on_arrow_keys(left, right, down, up)) { on_ctrl_change(); force_redraw(); } else { on_key(m_specific->m_cur_x, m_specific->m_cur_y, event.key.keysym.sym, flags); } } break; case SDL_MOUSEMOTION: event_x = (double)event.button.x*width_factor; event_y = (double)event.button.y*hight_factor; y = m_flip_y ? m_rbuf_window.height() - event_y : event_y; m_specific->m_cur_x = event_x; m_specific->m_cur_y = y; flags = 0; if(event.motion.state & SDL_BUTTON_LMASK) flags |= mouse_left; if(event.motion.state & SDL_BUTTON_RMASK) flags |= mouse_right; if(m_ctrls.on_mouse_move(m_specific->m_cur_x, m_specific->m_cur_y, (flags & mouse_left) != 0)) { on_ctrl_change(); force_redraw(); } else { on_mouse_move(m_specific->m_cur_x, m_specific->m_cur_y, flags); } SDL_Event eventtrash; while (SDL_PeepEvents(&eventtrash, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION)!=0){;} break; case SDL_MOUSEBUTTONDOWN: event_x = (double)event.button.x*width_factor; event_y = (double)event.button.y*hight_factor; DEBUG_PRINT("mouse down: %d,%d %d,%d\n", event.button.x,event.button.y, event_x,event_y); y = m_flip_y ? m_rbuf_window.height() - event_y : event_y; m_specific->m_cur_x = event_x; m_specific->m_cur_y = y; flags = 0; DEBUG_PRINT("mouse down: %d,%d w %d,%d\n", event_x,y, m_rbuf_window.width(), m_rbuf_window.height()); switch(event.button.button) { case SDL_BUTTON_LEFT: { flags = mouse_left; if(m_ctrls.on_mouse_button_down(m_specific->m_cur_x, m_specific->m_cur_y)) { m_ctrls.set_cur(m_specific->m_cur_x, m_specific->m_cur_y); on_ctrl_change(); force_redraw(); } else { if(m_ctrls.in_rect(m_specific->m_cur_x, m_specific->m_cur_y)) { if(m_ctrls.set_cur(m_specific->m_cur_x, m_specific->m_cur_y)) { on_ctrl_change(); force_redraw(); } } else { on_mouse_button_down(m_specific->m_cur_x, m_specific->m_cur_y, flags); } } } break; case SDL_BUTTON_RIGHT: DEBUG_PRINT("SDL_BUTTON_RIGHT"); flags = mouse_right; on_mouse_button_down(m_specific->m_cur_x, m_specific->m_cur_y, flags); break; } //switch(event.button.button) break; case SDL_MOUSEBUTTONUP: event_x = (double)event.button.x*width_factor; event_y = (double)event.button.y*hight_factor; y = m_flip_y ? m_rbuf_window.height() - event_y : event_y; m_specific->m_cur_x = event_x; m_specific->m_cur_y = y; flags = 0; if(m_ctrls.on_mouse_button_up(m_specific->m_cur_x, m_specific->m_cur_y)) { on_ctrl_change(); force_redraw(); } on_mouse_button_up(m_specific->m_cur_x, m_specific->m_cur_y, flags); break; case SDL_MOUSEWHEEL: break; case SDL_FINGERDOWN: case SDL_FINGERUP: case SDL_FINGERMOTION: DEBUG_PRINT("Finger: x=%f, y=%f dx=%f, dy=%f, %d\n", event.tfinger.x, event.tfinger.y, event.tfinger.dx, event.tfinger.dy, (int)event.tfinger.fingerId); on_touch_event( event.tfinger.x, m_flip_y ? 1-event.tfinger.y: event.tfinger.y, event.tfinger.dx, event.tfinger.dy, (int)event.tfinger.fingerId, !(event.type == SDL_FINGERUP)); break; case SDL_MULTIGESTURE: DEBUG_PRINT("Multi Gesture: x = %f, y = %f, dAng = %f, dR = %f numDownTouch = %i\n", event.mgesture.x, event.mgesture.y, event.mgesture.dTheta, event.mgesture.dDist, event.mgesture.numFingers); on_multi_gesture( event.mgesture.x, event.mgesture.y, event.mgesture.dTheta, event.mgesture.dDist, event.mgesture.numFingers); break; default: DEBUG_PRINT("unknown event type %d\n", event.type); break; } } } return 0; }
LRESULT Window::on_message(HWND _hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: return on_create() ? 0 : -1; break; case WM_DESTROY: if (on_destroy()) return 0; break; case WM_CLOSE: if (on_close()) /* true returned: message was handled */ return 0; break; case WM_SIZE: if (on_resize(LOWORD(lParam), HIWORD(lParam))) return 0; break; case WM_MOUSEMOVE: if (on_mouse_move(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam)) return 0; break; case WM_LBUTTONDOWN: XCSoarInterface::InterfaceTimeoutReset(); if (on_mouse_down(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_LBUTTONUP: XCSoarInterface::InterfaceTimeoutReset(); if (on_mouse_up(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_LBUTTONDBLCLK: XCSoarInterface::InterfaceTimeoutReset(); if (on_mouse_double(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; #ifdef WM_MOUSEWHEEL case WM_MOUSEWHEEL: XCSoarInterface::InterfaceTimeoutReset(); if (on_mouse_wheel(GET_WHEEL_DELTA_WPARAM(wParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; #endif case WM_KEYDOWN: XCSoarInterface::InterfaceTimeoutReset(); if (on_key_down(wParam)) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_KEYUP: XCSoarInterface::InterfaceTimeoutReset(); if (on_key_up(wParam)) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_COMMAND: XCSoarInterface::InterfaceTimeoutReset(); if (on_command(LOWORD(wParam), HIWORD(wParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_SETFOCUS: if (on_setfocus()) return 0; break; case WM_KILLFOCUS: if (on_killfocus()) return 0; break; case WM_TIMER: if (on_timer(wParam)) return 0; break; } if (message >= WM_USER && message <= 0x7FFF && on_user(message - WM_USER)) return 0; return on_unhandled_message(_hWnd, message, wParam, lParam); }
//------------------------------------------------------------------------ int platform_support::run() { SDL_Event event; bool ev_flag = false; for(;;) { if(m_specific->m_update_flag) { on_draw(); update_window(); m_specific->m_update_flag = false; } ev_flag = false; if(m_wait_mode) { SDL_WaitEvent(&event); ev_flag = true; } else { if(SDL_PollEvent(&event)) { ev_flag = true; } else { on_idle(); } } if(ev_flag) { if(event.type == SDL_QUIT) { break; } int y; unsigned flags = 0; switch (event.type) { case SDL_VIDEORESIZE: if(!init(event.resize.w, event.resize.h, m_window_flags)) return false; on_resize(m_rbuf_window.width(), m_rbuf_window.height()); trans_affine_resizing(event.resize.w, event.resize.h); m_specific->m_update_flag = true; break; case SDL_KEYDOWN: { flags = 0; if(event.key.keysym.mod & KMOD_SHIFT) flags |= kbd_shift; if(event.key.keysym.mod & KMOD_CTRL) flags |= kbd_ctrl; bool left = false; bool up = false; bool right = false; bool down = false; switch(event.key.keysym.sym) { case key_left: left = true; break; case key_up: up = true; break; case key_right: right = true; break; case key_down: down = true; break; } if(m_ctrls.on_arrow_keys(left, right, down, up)) { on_ctrl_change(); force_redraw(); } else { on_key(m_specific->m_cur_x, m_specific->m_cur_y, event.key.keysym.sym, flags); } } break; case SDL_MOUSEMOTION: y = m_flip_y ? m_rbuf_window.height() - event.motion.y : event.motion.y; m_specific->m_cur_x = event.motion.x; m_specific->m_cur_y = y; flags = 0; if(event.motion.state & SDL_BUTTON(1)) flags |= mouse_left; if(event.motion.state & SDL_BUTTON(3)) flags |= mouse_right; if(m_ctrls.on_mouse_move(m_specific->m_cur_x, m_specific->m_cur_y, (flags & mouse_left) != 0)) { on_ctrl_change(); force_redraw(); } else { on_mouse_move(m_specific->m_cur_x, m_specific->m_cur_y, flags); } SDL_Event eventtrash; while (SDL_PeepEvents(&eventtrash, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION))!=0){;} break; case SDL_MOUSEBUTTONDOWN: y = m_flip_y ? m_rbuf_window.height() - event.motion.y : event.motion.y; m_specific->m_cur_x = event.motion.x; m_specific->m_cur_y = y; flags = 0; if(event.button.button == SDL_BUTTON_LEFT) flags = mouse_left; if(event.button.button == SDL_BUTTON_RIGHT) flags = mouse_right; if(flags & mouse_left) { if(m_ctrls.on_mouse_button_down(m_specific->m_cur_x, m_specific->m_cur_y)) { m_ctrls.set_cur(m_specific->m_cur_x, m_specific->m_cur_y); on_ctrl_change(); force_redraw(); } else { if(m_ctrls.in_rect(m_specific->m_cur_x, m_specific->m_cur_y)) { if(m_ctrls.set_cur(m_specific->m_cur_x, m_specific->m_cur_y)) { on_ctrl_change(); force_redraw(); } } else { on_mouse_button_down(m_specific->m_cur_x, m_specific->m_cur_y, flags); } } } if(flags & mouse_right) { on_mouse_button_down(m_specific->m_cur_x, m_specific->m_cur_y, flags); } break; case SDL_MOUSEBUTTONUP: y = m_flip_y ? m_rbuf_window.height() - event.motion.y : event.motion.y; m_specific->m_cur_x = event.motion.x; m_specific->m_cur_y = y; flags = 0; if(m_ctrls.on_mouse_button_up(m_specific->m_cur_x, m_specific->m_cur_y)) { on_ctrl_change(); force_redraw(); } on_mouse_button_up(m_specific->m_cur_x, m_specific->m_cur_y, flags); break; } } } return 0; }
//------------------------------------------------------------------------ bool platform_support::init(unsigned width, unsigned height, unsigned flags) { m_window_flags = flags; unsigned wflags = SDL_SWSURFACE; if(m_window_flags & window_hw_buffer) { wflags = SDL_HWSURFACE; } if(m_window_flags & window_resize) { wflags |= SDL_RESIZABLE; } if(m_specific->m_surf_screen) SDL_FreeSurface(m_specific->m_surf_screen); m_specific->m_surf_screen = SDL_SetVideoMode(width, height, m_bpp, wflags); if(m_specific->m_surf_screen == 0) { fprintf(stderr, "Unable to set %dx%d %d bpp video: %s\n", width, height, m_bpp, ::SDL_GetError()); return false; } SDL_WM_SetCaption(m_caption, 0); if(m_specific->m_surf_window) SDL_FreeSurface(m_specific->m_surf_window); m_specific->m_surf_window = SDL_CreateRGBSurface(SDL_HWSURFACE, m_specific->m_surf_screen->w, m_specific->m_surf_screen->h, m_specific->m_surf_screen->format->BitsPerPixel, m_specific->m_rmask, m_specific->m_gmask, m_specific->m_bmask, m_specific->m_amask); if(m_specific->m_surf_window == 0) { fprintf(stderr, "Unable to create image buffer %dx%d %d bpp: %s\n", width, height, m_bpp, SDL_GetError()); return false; } m_rbuf_window.attach((unsigned char*)m_specific->m_surf_window->pixels, m_specific->m_surf_window->w, m_specific->m_surf_window->h, m_flip_y ? -m_specific->m_surf_window->pitch : m_specific->m_surf_window->pitch); if(!m_specific->m_initialized) { m_initial_width = width; m_initial_height = height; on_init(); m_specific->m_initialized = true; } on_resize(m_rbuf_window.width(), m_rbuf_window.height()); m_specific->m_update_flag = true; return true; }
//------------------------------------------------------------------------ bool platform_support::init(unsigned width, unsigned height, unsigned flags) { if( m_specific->m_ftype == RGBFB_NONE ) { message("Unsupported mode requested."); return false; } m_window_flags = flags; m_specific->m_idcmp_hook = reinterpret_cast<Hook*>( IExec->AllocSysObjectTags(ASOT_HOOK, ASOHOOK_Entry, handle_idcmp, ASOHOOK_Data, this, TAG_END)); if ( m_specific->m_idcmp_hook == 0 ) { return false; } m_specific->m_window_obj = IIntuition->NewObject(WindowClass, 0, WA_Title, m_caption, WA_AutoAdjustDClip, TRUE, WA_InnerWidth, width, WA_InnerHeight, height, WA_Activate, TRUE, WA_SmartRefresh, TRUE, WA_NoCareRefresh, TRUE, WA_CloseGadget, TRUE, WA_DepthGadget, TRUE, WA_SizeGadget, (flags & agg::window_resize) ? TRUE : FALSE, WA_DragBar, TRUE, WA_AutoAdjust, TRUE, WA_ReportMouse, TRUE, WA_RMBTrap, TRUE, WA_MouseQueue, 1, WA_IDCMP, IDCMP_NEWSIZE | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_RAWKEY | IDCMP_INTUITICKS, WINDOW_IDCMPHook, m_specific->m_idcmp_hook, WINDOW_IDCMPHookBits, IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_RAWKEY, TAG_END); if ( m_specific->m_window_obj == 0 ) { return false; } Object* obj = reinterpret_cast<Object*>(m_specific->m_window_obj); m_specific->m_window = reinterpret_cast<Window*>(IIntuition->IDoMethod(obj, WM_OPEN)); if ( m_specific->m_window == 0 ) { return false; } RGBFTYPE ftype = static_cast<RGBFTYPE>(IP96->p96GetBitMapAttr( m_specific->m_window->RPort->BitMap, P96BMA_RGBFORMAT)); switch ( ftype ) { case RGBFB_A8R8G8B8: case RGBFB_B8G8R8A8: case RGBFB_R5G6B5PC: break; default: message("Unsupported screen mode.\n"); return false; } if ( !m_specific->make_bitmap() ) { return false; } m_initial_width = width; m_initial_height = height; on_init(); on_resize(width, height); force_redraw(); return true; }
LRESULT Window::on_message(HWND _hWnd, UINT message, WPARAM wParam, LPARAM lParam) { if (IsEmbedded() && !IsAltair()) { /* some older iPaqs such as the H3900 send only WM_KEYUP for VK_APP*, but never VK_KEYDOWN; the hx4700 has an additional set of undocumented key codes (0xca..0xcd) for the APP keys, but sends WM_KEYUP/VK_APP* additionally; the following rules hopefully catch all of these obscurities */ if (message == WM_KEYUP && wParam >= 0x80) /* convert to WM_KEYDOWN to make all handlers catch it */ message = WM_KEYDOWN; else if (message == WM_KEYDOWN && wParam >= 0x80) /* ignore the real WM_KEYDOWN, just in case it really happens */ return 0; } switch (message) { case WM_CREATE: on_create(); return 0; case WM_DESTROY: on_destroy(); return 0; case WM_CLOSE: if (on_close()) /* true returned: message was handled */ return 0; break; case WM_SIZE: on_resize(LOWORD(lParam), HIWORD(lParam)); return 0; case WM_MOUSEMOVE: if (on_mouse_move(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam)) return 0; break; case WM_LBUTTONDOWN: if (on_mouse_down(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_LBUTTONUP: if (on_mouse_up(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_LBUTTONDBLCLK: if (!double_clicks) /* instead of disabling CS_DBLCLKS (which would affect all instances of a window class), we just translate WM_LBUTTONDBLCLK to WM_LBUTTONDOWN here; this even works for built-in window class such as BUTTON */ return on_message(_hWnd, WM_LBUTTONDOWN, wParam, lParam); if (on_mouse_double(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; #ifdef WM_MOUSEWHEEL case WM_MOUSEWHEEL: if (on_mouse_wheel(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), GET_WHEEL_DELTA_WPARAM(wParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; #endif case WM_KEYDOWN: if (on_key_down(::TranscodeKey(wParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_KEYUP: if (on_key_up(::TranscodeKey(wParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_COMMAND: if (on_command(LOWORD(wParam), HIWORD(wParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_CANCELMODE: if (on_cancel_mode()) return 0; break; case WM_SETFOCUS: on_setfocus(); return 0; case WM_KILLFOCUS: on_killfocus(); return 0; case WM_TIMER: if (on_timer(*(WindowTimer *)wParam)) return 0; break; case WM_PAINT: if (custom_painting) { PaintCanvas canvas(*this); on_paint(canvas, canvas.get_dirty()); return 0; } break; case WM_GETDLGCODE: if (on_key_check(wParam)) return DLGC_WANTMESSAGE; break; } if (message >= WM_USER && message <= 0x7FFF && on_user(message - WM_USER)) return 0; return on_unhandled_message(_hWnd, message, wParam, lParam); }