void button::handle_event(const SDL_Event& event) { if (hidden() || !enabled()) return; STATE start_state = state_; if (!mouse_locked()) { switch(event.type) { case SDL_MOUSEBUTTONDOWN: mouse_down(event.button); break; case SDL_MOUSEBUTTONUP: mouse_up(event.button); break; case SDL_MOUSEMOTION: mouse_motion(event.motion); break; default: return; } } if (start_state != state_) set_dirty(true); }
void c3arcball_mouse_motion( c3arcballp a, int x, int y) { mouse_motion(x, y, 0, 0, 0); }
// SDL doesn't use callbacks, so we must check the events ourselves void main_loop() { SDL_Event event; SDL_Event prev_event; int retval; for(;;) { // We can wait on an event (as we are doing here), or we can poll for // events and, if there are no events waiting to be processed, we can // call our idle function. This allows for a slightly more versatile // event handler than with a callback-based approach, as with GLUT. if(!SDL_WaitEvent(&event)) continue; event_switch: switch(event.type) { case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: mouse_button(event.button.button, event.button.state, event.button.x, event.button.y); break; case SDL_MOUSEMOTION: // This is a hack to keep the motion from being so jumpy on // slow cards do { prev_event = event; retval = SDL_PollEvent(&event); } while(retval != 0 && event.type == SDL_MOUSEMOTION); if(retval != 0) { // SDL_PushEvent(&event); // event = prev_event; mouse_motion(prev_event.motion.state, prev_event.motion.x, prev_event.motion.y); goto event_switch; } mouse_motion(event.motion.state, event.motion.x, event.motion.y); break; case SDL_KEYUP: keyfunc(event.key.keysym.sym); break; case SDL_VIDEORESIZE: set_window_size(event.resize.w, event.resize.h); break; case SDL_QUIT: return; } } }
void mouse_handler_base::mouse_update(const bool browse) { int x, y; SDL_GetMouseState(&x,&y); mouse_motion(x, y, browse, true); // mouse_motion(x_, y_, browse, true); }
void tmouse_motion::signal_handler_sdl_mouse_motion( const event::tevent event , bool& handled , const tpoint& coordinate) { if(signal_handler_sdl_mouse_motion_entered_) { return; } tlock lock(signal_handler_sdl_mouse_motion_entered_); DBG_GUI_E << LOG_HEADER << event << ".\n"; if(mouse_captured_) { assert(mouse_focus_); if(!owner_.fire(event, *mouse_focus_, coordinate)) { mouse_motion(mouse_focus_, coordinate); } } else { twidget* mouse_over = owner_.find_at(coordinate, true); if(mouse_over) { DBG_GUI_E << LOG_HEADER << "Firing: " << event << ".\n"; if(owner_.fire(event, *mouse_over, coordinate)) { return; } } if(!mouse_focus_ && mouse_over) { mouse_enter(mouse_over); } else if (mouse_focus_ && !mouse_over) { mouse_leave(); } else if(mouse_focus_ && mouse_focus_ == mouse_over) { mouse_motion(mouse_over, coordinate); } else if(mouse_focus_ && mouse_over) { // moved from one widget to the next mouse_leave(); mouse_enter(mouse_over); } else { assert(!mouse_focus_ && !mouse_over); } } handled = true; }
void slider::handle_event(const SDL_Event& event) { gui::widget::handle_event(event); if (!enabled() || hidden()) return; STATE start_state = state_; switch(event.type) { case SDL_MOUSEBUTTONUP: if (!mouse_locked()) { bool on = sdl::point_in_rect(event.button.x, event.button.y, slider_area()); state_ = on ? ACTIVE : NORMAL; } break; case SDL_MOUSEBUTTONDOWN: if (!mouse_locked()) mouse_down(event.button); break; case SDL_MOUSEMOTION: if (!mouse_locked()) mouse_motion(event.motion); break; case SDL_KEYDOWN: if(focus(&event) && allow_key_events()) { //allow_key_events is used by zoom_sliders to disable left-right key press, which is buggy for them const SDL_Keysym& key = reinterpret_cast<const SDL_KeyboardEvent&>(event).keysym; const int c = key.sym; if(c == SDLK_LEFT) { sound::play_UI_sound(game_config::sounds::slider_adjust); set_value(value_ - increment_); } else if(c == SDLK_RIGHT) { sound::play_UI_sound(game_config::sounds::slider_adjust); set_value(value_ + increment_); } } break; case SDL_MOUSEWHEEL: if (!mouse_locked()) mouse_wheel(event.wheel); break; default: return; } if (start_state != state_) set_dirty(true); }
void OVR_SDL2_app::dispatch(SDL_Event& e) { switch (e.type) { case SDL_KEYDOWN: keyboard(e.key.keysym.scancode, true, (e.key.repeat != 0)); break; case SDL_KEYUP: keyboard(e.key.keysym.scancode, false, (e.key.repeat != 0)); break; case SDL_MOUSEBUTTONDOWN: mouse_button(e.button.button, true); break; case SDL_MOUSEBUTTONUP: mouse_button(e.button.button, false); break; case SDL_MOUSEMOTION: mouse_motion(e.motion.xrel, e.motion.yrel); break; case SDL_MOUSEWHEEL: mouse_wheel(e.wheel.x, e.wheel.y); break; case SDL_CONTROLLERAXISMOTION: game_axis(e.caxis.which, e.caxis.axis, e.caxis.value / 32768.f); break; case SDL_CONTROLLERBUTTONDOWN: game_button(e.caxis.which, e.cbutton.button, true); break; case SDL_CONTROLLERBUTTONUP: game_button(e.caxis.which, e.cbutton.button, false); break; case SDL_CONTROLLERDEVICEADDED: game_connect(e.cdevice.which, true); break; case SDL_CONTROLLERDEVICEREMOVED: game_connect(e.cdevice.which, false); break; case SDL_QUIT: running = false; break; } }
int main(int argc, char **argv) { int mbn, prev_mx = -1, prev_my = -1, prev_mbn = 0; if(parse_args(argc, argv) == -1) { return 1; } if(init() == -1) { return 1; } reset_timer(); for(;;) { if(kbhit()) { if(keyb(getch()) == 0) { break; } } mbn = read_mouse(&mx, &my); if(mbn != prev_mbn) { mouse_button(mbn, mx, my); prev_mbn = mbn; } if(mx != prev_mx || my != prev_my) { if(mbn) { mouse_motion(mx, my); } prev_mx = mx; prev_my = my; } redraw(); } shutdown(); print_perf(); return 0; }
// ------------------------------------------------------------- mouse_drag --- void mouse_drag( int x, int y ) { static int _x=-1, _y=-1; if( (_x == -1) && (_y == -1) ) { _x = x; _y = y; return; } int dy = y - _y; if (dy < 0) { viewport.zoom *= 1.05; } else { viewport.zoom /= 1.05; } _x = x; _y = y; mouse_motion(x,y); }
void slider::handle_event(const SDL_Event& event) { if (!enabled() || hidden()) return; STATE start_state = state_; switch(event.type) { case SDL_MOUSEBUTTONUP: if (!mouse_locked()) state_ = NORMAL; break; case SDL_MOUSEBUTTONDOWN: if (!mouse_locked()) mouse_down(event.button); break; case SDL_MOUSEMOTION: if (!mouse_locked()) mouse_motion(event.motion); break; case SDL_KEYDOWN: if(focus(&event)) { const SDL_keysym& key = reinterpret_cast<const SDL_KeyboardEvent&>(event).keysym; const int c = key.sym; if(c == SDLK_LEFT) { sound::play_UI_sound(game_config::sounds::slider_adjust); set_value(value_ - increment_); } else if(c == SDLK_RIGHT) { sound::play_UI_sound(game_config::sounds::slider_adjust); set_value(value_ + increment_); } } break; default: return; } if (start_state != state_) set_dirty(true); }
void motion(int x, int y) { mouse_motion(x, y); }
void mouse_handler_base::mouse_update(const bool browse, map_location loc) { int x, y; SDL_GetMouseState(&x,&y); mouse_motion(x, y, browse, true, loc); }
void mouse_handler_base::mouse_motion_event(const SDL_MouseMotionEvent& event, const bool browse) { mouse_motion(event.x,event.y, browse); }
void EventHandler::handle_events() { SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_VIDEORESIZE: resize_window(event.resize.w, event.resize.h); break; case SDL_JOYAXISMOTION: joystick_motion(&event.jaxis); break; case SDL_JOYBUTTONDOWN: if (nJoystickDlg) joystickDlg->joystickDlgButton(&event.jbutton); else joystick_button(&event.jbutton); break; case SDL_MOUSEMOTION: /** * GUI_MOUSE_MOTION_WORKAROUND * The GUI sometimes returns that it used the event, although it is not visible anymore! * Therefore we need to check whether it is visible at all. * Where it works: * -ESC to show GUI * -open dialog (for example video) * -close dialog * -ESC to hide GUI * Everything is fine, the mouse-motions are not used by the GUI. * -ESC to show GUI * -toggle something from the menu bar (for example Verbosity) * -ESC to hide GUI * Now the GUI still uses the mouse motions, although it is invisible! */ if (Global::TXInterface->inputMethod() == T_TX_Interface::eIM_mouse) { // always update the mouse interface mouse_motion(&event.motion); if (Global::gui) Global::gui->mouseMotionHandler(event.motion.x, event.motion.y); } else if (!Global::gui || !Global::gui->isVisible() || !Global::gui->mouseMotionHandler(event.motion.x, event.motion.y)) { // GUI did not use the event, pass it to the simulation itself mouse_motion(&event.motion); } break; case SDL_MOUSEBUTTONDOWN: #if TEST_WITHOUT_JOYSTICK > 0 if (nJoystickDlg && event.button.button != SDL_BUTTON_LEFT) { SDL_JoyButtonEvent jevent; jevent.type = SDL_JOYBUTTONDOWN; jevent.state = SDL_PRESSED; jevent.which = 0; switch (event.button.button) { case SDL_BUTTON_MIDDLE: jevent.button = 0; break; case SDL_BUTTON_RIGHT: jevent.button = 1; break; default: jevent.button = 2; break; } joystickDlg->joystickDlgButton(&jevent); } #endif if (!Global::gui || !Global::gui->mouseButtonDownHandler(event.button.button, event.button.x, event.button.y)) { // GUI did not use the event, pass it to the simulation itself mouse_button(&event.button); } break; case SDL_MOUSEBUTTONUP: if (Global::gui) Global::gui->mouseButtonUpHandler(event.button.button, event.button.x, event.button.y); break; case SDL_KEYDOWN: if (!Global::gui || !Global::gui->keyDownEventHandler(event.key.keysym)) { // GUI did not use the event, pass it to the simulation itself key_down(&event.key.keysym); } break; case SDL_KEYUP: if (Global::gui) Global::gui->keyUpEventHandler(event.key.keysym); break; case SDL_QUIT: if (Global::gui) Global::gui->doQuitDialog(); else Global::Simulation->quit(); break; } } }
void Arcball::mouse_motion(int x, int y) { mouse_motion(x, y, 0, 0, 0); }