bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) { switch (ev.type) { case SDL_KEYDOWN: return handleKeyDown(ev, event); case SDL_KEYUP: return handleKeyUp(ev, event); case SDL_MOUSEMOTION: return handleMouseMotion(ev, event); case SDL_MOUSEBUTTONDOWN: return handleMouseButtonDown(ev, event); case SDL_MOUSEBUTTONUP: return handleMouseButtonUp(ev, event); case SDL_JOYBUTTONDOWN: return handleJoyButtonDown(ev, event); case SDL_JOYBUTTONUP: return handleJoyButtonUp(ev, event); case SDL_JOYAXISMOTION: return handleJoyAxisMotion(ev, event); case SDL_JOYHATMOTION: return handleJoyHatMotion(ev, event); case SDL_VIDEOEXPOSE: if (_graphicsManager) _graphicsManager->notifyVideoExpose(); return false; case SDL_VIDEORESIZE: if (_graphicsManager) { _graphicsManager->notifyResize(ev.resize.w, ev.resize.h); // If the screen changed, send an Common::EVENT_SCREEN_CHANGED int screenID = ((OSystem_SDL *)g_system)->getGraphicsManager()->getScreenChangeID(); if (screenID != _lastScreenID) { _lastScreenID = screenID; event.type = Common::EVENT_SCREEN_CHANGED; return true; } } return false; case SDL_QUIT: event.type = Common::EVENT_QUIT; return true; } return false; }
void ContainerWidget::handleMouseMotion(MouseMotionEvent &event) { auto child = findChildAtPoint(event.getPosition()); if(child) { auto newEvent = event.translatedBy(-child->getPosition()); child->handleMouseMotion(newEvent); event.setHandled(newEvent.wasHandled()); } if(!child) setMouseOverHere(); if(!event.wasHandled()) mouseMotionEvent(event); }
/*! * Handles the mouse motion event. * \param x X screen coordinate * \param y Y screen coordinate * \param state If button is pressed during mouse motion. * \param modKeys State of all modifier keys */ void Menu::mouseMotionEvent(int x, int y, int state, const int modKeys) { handleMouseMotion(x, y, state, modKeys); // Check focus is lost for currently focused widget if (focusedWgId_ != -1) { ActionWidget *pAction = getActionWidget(focusedWgId_); if (!pAction->isMouseOver(x, y) || !pAction->isVisible()) { pAction->handleFocusLost(); focusedWgId_ = -1; } } // See if the mouse is hovering an action widget for (std::list < ActionWidget * >::iterator it = actions_.begin(); it != actions_.end(); it++) { ActionWidget *m = *it; if (!m->isVisible() || !m->isWidgetEnabled()) { // action is not visible or not enabled so it doesn't count continue; } // Mouse is over a widget if (m->isMouseOver(x, y)) { if (m->getId() != focusedWgId_) { // Widget has now the focus : handle the event m->handleFocusGained(); focusedWgId_ = m->getId(); } // Pass the event to the widget m->handleMouseMotion(x, y, state, modKeys); return; } } }
static void handleMouseEvent(const MirMotionEvent motion, int cord_index, _GLFWwindow* window) { switch (motion.action) { case mir_motion_action_down: case mir_motion_action_pointer_down: handleMouseButton(window, GLFW_PRESS, motion.modifiers, motion.button_state); break; case mir_motion_action_up: case mir_motion_action_pointer_up: handleMouseButton(window, GLFW_RELEASE, motion.modifiers, motion.button_state); break; case mir_motion_action_hover_move: case mir_motion_action_move: handleMouseMotion(window, motion.pointer_coordinates[cord_index].x, motion.pointer_coordinates[cord_index].y); break; case mir_motion_action_outside: break; case mir_motion_action_scroll: handleMouseScroll(window, motion.pointer_coordinates[cord_index].hscroll, motion.pointer_coordinates[cord_index].vscroll); break; case mir_motion_action_cancel: case mir_motion_action_hover_enter: case mir_motion_action_hover_exit: break; default: break; } }
void Menu::mouseMotionEvent(int x, int y, int state) { handleMouseMotion(x, y, state); if (hovering_) redrawOptions(); hovering_ = false; for (std::map < Key, MenuText >::iterator it = options_.begin(); it != options_.end(); it++) { MenuText & m = it->second; int width = 300; if (m.text_.size() == 1) width = 30; else width = g_App.fonts().textWidth(m.text_.c_str(), m.size_); if (m.visible_ && x > m.x_ - 2 && x < m.x_ + width && y >= m.y_ - 2 && y < m.y_ + g_App.fonts().textHeight(m.size_) - 2) { g_App.fonts().drawText(m.x_, m.y_, m.text_.c_str(), m.size_, false); hovering_ = true; } } }
bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) { switch (ev.type) { case SDL_KEYDOWN: return handleKeyDown(ev, event); case SDL_KEYUP: return handleKeyUp(ev, event); case SDL_MOUSEMOTION: return handleMouseMotion(ev, event); case SDL_MOUSEBUTTONDOWN: return handleMouseButtonDown(ev, event); case SDL_MOUSEBUTTONUP: return handleMouseButtonUp(ev, event); case SDL_JOYBUTTONDOWN: return handleJoyButtonDown(ev, event); case SDL_JOYBUTTONUP: return handleJoyButtonUp(ev, event); case SDL_JOYAXISMOTION: return handleJoyAxisMotion(ev, event); case SDL_VIDEOEXPOSE: if (_graphicsManager) _graphicsManager->notifyVideoExpose(); return false; case SDL_VIDEORESIZE: if (_graphicsManager) _graphicsManager->notifyResize(ev.resize.w, ev.resize.h); return false; case SDL_QUIT: event.type = Common::EVENT_QUIT; return true; } return false; }
int main(int argc, char *argv[]) { Uint8* keys; int done=0; SM.LoadSound("eerie.wav"); SM.LoadSound("indicator.wav"); SM.LoadSound("static.mp3"); SM.LoadMusic("UNREAL.S3M"); // Create a new OpenGL window with the title "Cone3D Basecode" at // 640x480x32, fullscreen and check for errors along the way if(CreateGLWindow("SDL & OpenGL", 640, 480, 16, 0) == 0){ printf("Could not initalize OpenGL :(\n\n"); KillGLWindow(); return 0; } // Hide the mouse cursor //SDL_ShowCursor(0); // This is the main loop for the entire program and it will run until done==TRUE int changeit = 1; int reset = 1; makeMickey(); while(!done){ // Draw the scene if (changeit == 1) { DrawGLScene(); changeit = 0; } // And poll for events SDL_Event event; while ( SDL_PollEvent(&event) ) { switch (event.type) { case SDL_KEYDOWN: case SDL_KEYUP: handleKey(event.key); break; case SDL_MOUSEMOTION: SDL_PeepEvents (&event,9,SDL_GETEVENT,SDL_MOUSEMOTION); handleMouseMotion(event.motion); if (reset == 1) { xpos = 0; ypos = 0; reset = 0; } //this affects the screen. changeit = 1; break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: handleMouseButtons(event.button); break; case SDL_QUIT: // then we're done and we'll end this program done=1; break; default: break; }// switch }// while // Get the state of the keyboard keys keys = SDL_GetKeyState(NULL); // and check if ESCAPE has been pressed. If so then quit if(keys[SDLK_ESCAPE]) done=1; }// while done // Kill the GL & SDL screens KillGLWindow(); // And quit return 0; }
bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) { switch (ev.type) { case SDL_KEYDOWN: return handleKeyDown(ev, event); case SDL_KEYUP: return handleKeyUp(ev, event); case SDL_MOUSEMOTION: return handleMouseMotion(ev, event); case SDL_MOUSEBUTTONDOWN: return handleMouseButtonDown(ev, event); case SDL_MOUSEBUTTONUP: return handleMouseButtonUp(ev, event); case SDL_JOYBUTTONDOWN: return handleJoyButtonDown(ev, event); case SDL_JOYBUTTONUP: return handleJoyButtonUp(ev, event); case SDL_JOYAXISMOTION: return handleJoyAxisMotion(ev, event); #if SDL_VERSION_ATLEAST(2, 0, 0) case SDL_MOUSEWHEEL: { Sint32 yDir = ev.wheel.y; // HACK: It seems we want the mouse coordinates supplied // with a mouse wheel event. However, SDL2 does not supply // these, thus we use whatever we got last time. It seems // these are always stored in _km.x, _km.y. if (!processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER)) { return false; } if (yDir < 0) { event.type = Common::EVENT_WHEELDOWN; return true; } else if (yDir > 0) { event.type = Common::EVENT_WHEELUP; return true; } else { return false; } } case SDL_TEXTINPUT: { // When we get a TEXTINPUT event it means we got some user input for // which no KEYDOWN exists. SDL 1.2 introduces a "fake" key down+up // in such cases. We will do the same to mimic it's behavior. event.type = Common::EVENT_KEYDOWN; event.kbd = Common::KeyState(Common::KEYCODE_INVALID, convUTF8ToUTF32(ev.text.text), 0); SDLModToOSystemKeyFlags(SDL_GetModState(), event); // Set the scroll lock sticky flag if (_scrollLock) event.kbd.flags |= Common::KBD_SCRL; // Fake a key up when we have a proper ascii value. _queuedFakeKeyUp = (event.kbd.ascii != 0); _fakeKeyUp = event; _fakeKeyUp.type = Common::EVENT_KEYUP; return _queuedFakeKeyUp; } case SDL_WINDOWEVENT: switch (ev.window.event) { case SDL_WINDOWEVENT_EXPOSED: if (_graphicsManager) _graphicsManager->notifyVideoExpose(); return false; // SDL2 documentation indicate that SDL_WINDOWEVENT_SIZE_CHANGED is sent either as a result // of the size being changed by an external event (for example the user resizing the window // or going fullscreen) or a call to the SDL API (for example SDL_SetWindowSize). On the // other hand SDL_WINDOWEVENT_RESIZED is only sent for resize resulting from an external event, // and is always preceded by a SDL_WINDOWEVENT_SIZE_CHANGED event. // We need to handle the programmatic resize as well so that the graphics manager always know // the current size. See comments in SdlWindow::createOrUpdateWindow for details of one case // where we need to call SDL_SetWindowSize and we need the resulting event to be processed. // However if the documentation is correct we can ignore SDL_WINDOWEVENT_RESIZED since when we // get one we should always get a SDL_WINDOWEVENT_SIZE_CHANGED as well. case SDL_WINDOWEVENT_SIZE_CHANGED: //case SDL_WINDOWEVENT_RESIZED: return handleResizeEvent(event, ev.window.data1, ev.window.data2); default: return false; } #else case SDL_VIDEOEXPOSE: if (_graphicsManager) _graphicsManager->notifyVideoExpose(); return false; case SDL_VIDEORESIZE: return handleResizeEvent(event, ev.resize.w, ev.resize.h); #endif case SDL_QUIT: event.type = Common::EVENT_QUIT; return true; } return false; }
bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) { switch (ev.type) { case SDL_KEYDOWN: return handleKeyDown(ev, event); case SDL_KEYUP: return handleKeyUp(ev, event); case SDL_MOUSEMOTION: return handleMouseMotion(ev, event); case SDL_MOUSEBUTTONDOWN: return handleMouseButtonDown(ev, event); case SDL_MOUSEBUTTONUP: return handleMouseButtonUp(ev, event); case SDL_JOYBUTTONDOWN: return handleJoyButtonDown(ev, event); case SDL_JOYBUTTONUP: return handleJoyButtonUp(ev, event); case SDL_JOYAXISMOTION: return handleJoyAxisMotion(ev, event); #if SDL_VERSION_ATLEAST(2, 0, 0) case SDL_MOUSEWHEEL: { Sint32 yDir = ev.wheel.y; #if SDL_VERSION_ATLEAST(2, 0, 4) if (ev.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) { yDir *= -1; } #endif // HACK: It seems we want the mouse coordinates supplied // with a mouse wheel event. However, SDL2 does not supply // these, thus we use whatever we got last time. It seems // these are always stored in _km.x, _km.y. processMouseEvent(event, _km.x, _km.y); if (yDir < 0) { event.type = Common::EVENT_WHEELDOWN; return true; } else if (yDir > 0) { event.type = Common::EVENT_WHEELUP; return true; } else { return false; } } case SDL_TEXTINPUT: { // When we get a TEXTINPUT event it means we got some user input for // which no KEYDOWN exists. SDL 1.2 introduces a "fake" key down+up // in such cases. We will do the same to mimic it's behavior. event.type = Common::EVENT_KEYDOWN; event.kbd = Common::KeyState(Common::KEYCODE_INVALID, convUTF8ToUTF32(ev.text.text), 0); SDLModToOSystemKeyFlags(SDL_GetModState(), event); // Set the scroll lock sticky flag if (_scrollLock) event.kbd.flags |= Common::KBD_SCRL; // Fake a key up when we have a proper ascii value. _queuedFakeKeyUp = (event.kbd.ascii != 0); _fakeKeyUp = event; _fakeKeyUp.type = Common::EVENT_KEYUP; return _queuedFakeKeyUp; } case SDL_WINDOWEVENT: switch (ev.window.event) { case SDL_WINDOWEVENT_EXPOSED: if (_graphicsManager) _graphicsManager->notifyVideoExpose(); return false; case SDL_WINDOWEVENT_RESIZED: return handleResizeEvent(event, ev.window.data1, ev.window.data2); default: return false; } #else case SDL_VIDEOEXPOSE: if (_graphicsManager) _graphicsManager->notifyVideoExpose(); return false; case SDL_VIDEORESIZE: return handleResizeEvent(event, ev.resize.w, ev.resize.h); #endif case SDL_QUIT: event.type = Common::EVENT_QUIT; return true; } return false; }