void CInput::processMouse(SDL_Event& ev) { #if SDL_VERSION_ATLEAST(1, 3, 0) SDL_Rect screenRect; if(SDL_GetDisplayBounds(0, &screenRect) == 0) { // transform mouse coordinates // WARNING: I don't really understand that. It's probably somehow iPhoneRotateScreen + SDL stuff. ev.button.y -= screenRect.h - 200; } #endif // NOTE: The ev.button.which / the multitouch support was removed in SDL 1.3 trunk // with changeset 4465:3e69e077cb95 on May09. It is planned to add a real multitouch API // at some later time (maybe Aug2010). // As long as we don't have that, we must use the old SDL 1.3 revision 4464. switch(ev.type) { case SDL_MOUSEBUTTONDOWN: processMouse(ev.button.x, ev.button.y, true, ev.button.which); break; case SDL_MOUSEBUTTONUP: processMouse(ev.button.x, ev.button.y, false, ev.button.which); break; case SDL_MOUSEMOTION: processMouse(ev.motion.x - ev.motion.xrel, ev.motion.y - ev.motion.yrel, false, ev.motion.which); processMouse(ev.motion.x, ev.motion.y, true, ev.motion.which); break; } }
void Window::run() //timestep { double time; //not used for now, but useful for later when I need time in my scene const double timestep = 1 / 60.0f; //for an ideal 60FPS double lastTime = glfwGetTime(); while (!glfwWindowShouldClose(window)) { double currentTime = glfwGetTime(); double frameTime = currentTime - lastTime; if(frameTime > timestep) { glfwPollEvents(); processKeys(); processMouse(); scene->processKeys(keyboard); scene->processMouse(mouse); scene->update(); scene->render(); glfwSwapBuffers(window); lastTime = glfwGetTime(); } } }
static void processEvent(const SDL_Event& event) { if (videoEventFilter(event)) return; if (keyboardBindingFilter(event)) return; int key = 0; int x, y, xnew, ynew; switch (event.type) { case SDL_KEYDOWN: key = event.key.keysym.sym; if (Config.action[key]) S9xDoAction(Config.action[key]); joypads[0] |= getJoyMask(Config.joypad1Mapping, key); joypads[1] |= getJoyMask(Config.joypad2Mapping, key); checkOther(Config.joypad1Mapping, key ); checkOther(Config.joypad2Mapping, key ); break; case SDL_KEYUP: key = event.key.keysym.sym; joypads[0] &= ~getJoyMask(Config.joypad1Mapping, key); joypads[1] &= ~getJoyMask(Config.joypad2Mapping, key); break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: x = event.button.x; y = event.button.y; // We interpret mouse input differently depending on orientation if ( orientation != ORIENTATION_PORTRAIT ) { // XXX: Make this not magical y = 320 - event.button.x; x = event.button.y; } processMouse(x, y, (event.button.state == SDL_PRESSED)); break; case SDL_MOUSEMOTION: xnew = event.motion.x; ynew = event.motion.y; x = xnew - event.motion.xrel; y = ynew - event.motion.yrel; // We interpret mouse input differently depending on orientation if ( orientation != ORIENTATION_PORTRAIT ) { // XXX: Make this not magical ynew = 320 - event.motion.x; xnew = event.motion.y; x = xnew - event.motion.yrel; y = ynew + event.motion.xrel; } processMouseMotion(x, y, xnew, ynew); break; // case SDL_QUIT: // Config.running = false; // break; } }
void CInput::processMouse(SDL_Event& ev) { SDL_Rect screenRect; //SDL_Touch* touch = SDL_GetTouch(ev.tfinger.touchId); SDL_Finger* touch = SDL_GetTouchFinger(ev.tfinger.touchId, 0); int x, y, dx, dy, w, h; if(SDL_GetDisplayBounds(0, &screenRect) == 0) { w = screenRect.w; h = screenRect.h; } if(touch == NULL) return; //The touch has been removed //float fx = ((float)ev.tfinger.x)/touch->xres; //float fy = ((float)ev.tfinger.y)/touch->yres; float fx = ((float)ev.tfinger.x)/touch->x; float fy = ((float)ev.tfinger.y)/touch->y; x = (int)(fx*w); y = (int)(fy*h); switch(ev.type) { case SDL_FINGERDOWN: processMouse(x, y, true, ev.tfinger.fingerId); break; case SDL_FINGERUP: processMouse(x, y, false, ev.tfinger.fingerId); break; case SDL_FINGERMOTION: //float fdx = ((float)ev.tfinger.dx)/touch->xres; //float fdy = ((float)ev.tfinger.dy)/touch->yres; float fdx = ((float)ev.tfinger.dx)/touch->x; float fdy = ((float)ev.tfinger.dy)/touch->y; dx = (int)(fdx*w); dy = (int)(fdy*h); processMouse(x - dx, y - dy, false, ev.tfinger.fingerId); processMouse(x, y, true, ev.tfinger.fingerId); break; } //#endif }
//! called if an event happened. bool CGUIEditBox::OnEvent(const SEvent& event) { #ifndef SERVER_ONLY if (isEnabled()) { switch(event.EventType) { case EET_GUI_EVENT: if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) { if (event.GUIEvent.Caller == this) { MouseMarking = false; setTextMarkers(0,0); } #ifdef _IRR_COMPILE_WITH_X11_DEVICE_ CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(irr_driver->getDevice()); dl->setIMEEnable(false); #endif } #ifdef _IRR_COMPILE_WITH_X11_DEVICE_ else if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED) { CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(irr_driver->getDevice()); dl->setIMEEnable(true); dl->setIMELocation(calculateICPos()); } #endif break; #if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) case EET_IMPUT_METHOD_EVENT: if (processIMEEvent(event)) return true; break; #endif case EET_KEY_INPUT_EVENT: if (processKey(event)) return true; break; case EET_MOUSE_INPUT_EVENT: if (processMouse(event)) return true; break; default: break; } } #endif return IGUIElement::OnEvent(event); }
void runInput() { #ifndef NO_GUI if (!video.sdlStarted) return; #endif processKeys(); #ifndef NO_GUI processMouse(); #endif }
bool GLBoxSelector::eventFilter(QObject *watched, QEvent *event) { if (!hidden && watched == glw) { QResizeEvent *re; QMouseEvent *me; QPaintEvent *pe; if ((re=dynamic_cast<QResizeEvent *>(event))) { QSize s = re->size(); resized(s.width(), s.height()); } else if ((me=dynamic_cast<QMouseEvent *>(event))) { if (enabled) processMouse(me); } else if ((pe=dynamic_cast<QPaintEvent *>(event))) { //draw(); } } return false; // don't filter event }
/** * Check whether we clicked in the window */ void Arcball::mouseButtonCallbackImpl(GLFWwindow * window, int button, int action, int mods) { processMouse(button, action); double x, y; glfwGetCursorPos(window, &x, &y); m_clicked = m_mouse[GLFW_MOUSE_BUTTON_LEFT]; if(m_clicked){ m_prevPos = toScreenCoord(x, y); } else { m_dragging = false; m_prevTrans = m_currTrans; } }
/** * \brief Called every logic cycle. This triggers the events that occur and process them trough various functions */ void CInput::pollEvents() { // copy all the input of the last poll to a space for checking pressing or holding a button memcpy(last_immediate_keytable, immediate_keytable, KEYTABLE_SIZE*sizeof(char)); for(int i=0 ; i<MAX_COMMANDS ; i++) for(int j=0 ; j<NUM_INPUTS ; j++) InputCommand[j][i].lastactive = InputCommand[j][i].active; // While there's an event to handle while( SDL_PollEvent( &Event ) ) { switch( Event.type ) { case SDL_QUIT: g_pLogFile->textOut("SDL: Got quit event!"); m_exit = true; break; case SDL_KEYDOWN: processKeys(1); break; case SDL_KEYUP: processKeys(0); break; case SDL_JOYAXISMOTION: processJoystickAxis(); break; case SDL_JOYBUTTONDOWN: processJoystickButton(1); break; case SDL_JOYBUTTONUP: processJoystickButton(0); break; #ifdef MOUSEWRAPPER case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: case SDL_MOUSEMOTION: processMouse(Event); break; #endif case SDL_VIDEORESIZE: CRect newSize(Event.resize.w, Event.resize.h); g_pVideoDriver->mp_VideoEngine->resizeDisplayScreen(newSize); break; } } #ifdef MOUSEWRAPPER // Handle mouse emulation layer processMouse(); #endif for(unsigned int i = 0; i < KEYTABLE_SIZE; ++i) firsttime_immediate_keytable[i] = !last_immediate_keytable[i] && immediate_keytable[i]; for(int i=0 ; i<MAX_COMMANDS ; i++) for(int j=0 ; j<NUM_INPUTS ; j++) InputCommand[j][i].firsttimeactive = !InputCommand[j][i].lastactive && InputCommand[j][i].active; #ifndef MOUSEWRAPPER // TODO: I'm not sure, if that should go here... // Check, if LALT+ENTER was pressed if((getHoldedKey(KALT)) && getPressedKey(KENTER)) { bool value; value = g_pVideoDriver->getFullscreen(); value = !value; g_pLogFile->textOut(GREEN,"Fullscreen mode triggered by user!<br>"); g_pVideoDriver->isFullscreen(value); // initialize/activate all drivers g_pVideoDriver->stop(); g_pLogFile->ftextOut("Restarting graphics driver...<br>"); if ( g_pVideoDriver->applyMode() && g_pVideoDriver->start() ) { g_pLogFile->ftextOut(PURPLE, "Toggled Fullscreen quick shortcut...<br>"); } else { value = !value; g_pLogFile->ftextOut(PURPLE, "Couldn't change the resolution, Rolling back...<br>"); g_pVideoDriver->applyMode(); g_pVideoDriver->start(); } if(value) g_pVideoDriver->AddConsoleMsg("Fullscreen enabled"); else g_pVideoDriver->AddConsoleMsg("Fullscreen disabled"); g_pInput->flushAll(); } // Check, if LALT+Q or LALT+F4 was pressed if(getHoldedKey(KALT) && (getPressedKey(KF4) || getPressedKey(KQ)) ) { g_pLogFile->textOut("User exit request!"); m_exit = true; } #endif #if defined(WIZ) || defined(GP2X) WIZ_AdjustVolume( volume_direction ); #endif // Fix up settings if everything gets messed up if (g_pInput->getHoldedKey(KF) && g_pInput->getHoldedKey(KI) && g_pInput->getHoldedKey(KX)) { g_pSettings->loadDefaultGraphicsCfg(); g_pSettings->saveDrvCfg(); g_pVideoDriver->stop(); g_pVideoDriver->start(); } }
/** * \brief Called every logic cycle. This triggers the events that occur and process them through various functions */ void CInput::pollEvents() { // Semaphore SDL_SemWait( pollSem ); if(remapper.mappingInput) { readNewEvent(); SDL_SemPost( pollSem ); return; } Vector2D<float> Pos; #if SDL_VERSION_ATLEAST(2, 0, 0) #else GsRect<Uint16> Res(SDL_GetVideoSurface()->w, SDL_GetVideoSurface()->h); #endif // copy all the input of the last poll to a space for checking pressing or holding a button memcpy(last_immediate_keytable, immediate_keytable, KEYTABLE_SIZE*sizeof(char)); for(int i=0 ; i<MAX_COMMANDS ; i++) for(int j=0 ; j<NUM_INPUTS ; j++) InputCommand[j][i].lastactive = InputCommand[j][i].active; GsRect<Uint16> activeArea = gVideoDriver.mpVideoEngine->getAspectCorrRect(); auto &dispRect = gVideoDriver.getVidConfig().m_DisplayRect; #if SDL_VERSION_ATLEAST(2, 0, 0) #else //if( !gVideoDriver.isOpenGL() ) { activeArea.x = 0; activeArea.y = 0; } #endif // While there's an event to handle while( SDL_PollEvent( &Event ) ) { bool passSDLEventVec = true; switch( Event.type ) { case SDL_QUIT: gLogging.textOut("SDL: Got quit event!"); m_exit = true; gDreamsForceClose = 1; break; case SDL_KEYDOWN: passSDLEventVec = processKeys(1); break; case SDL_KEYUP: passSDLEventVec = processKeys(0); break; case SDL_JOYAXISMOTION: passSDLEventVec = true; processJoystickAxis(); break; case SDL_JOYBUTTONDOWN: passSDLEventVec = true; processJoystickButton(1); break; case SDL_JOYBUTTONUP: passSDLEventVec = true; processJoystickButton(0); break; case SDL_JOYHATMOTION: passSDLEventVec = true; processJoystickHat(); break; #if SDL_VERSION_ATLEAST(2, 0, 0) case SDL_FINGERDOWN: case SDL_FINGERUP: case SDL_FINGERMOTION: processMouse(Event); break; case SDL_WINDOWEVENT: if(Event.window.event == SDL_WINDOWEVENT_RESIZED) { gVideoDriver.mpVideoEngine->resizeDisplayScreen( GsRect<Uint16>(Event.window.data1, Event.window.data2) ); dispRect.w = Event.window.data1; dispRect.h = Event.window.data2; } break; #else case SDL_VIDEORESIZE: gVideoDriver.mpVideoEngine->resizeDisplayScreen( GsRect<Uint16>(Event.resize.w, Event.resize.h) ); dispRect.w = Event.resize.w; dispRect.h = Event.resize.h; break; #endif case SDL_MOUSEBUTTONDOWN: // If Virtual gamepad takes control... if(mpVirtPad && mpVirtPad->active()) { if(Event.button.button <= 3) { transMouseRelCoord(Pos, Event.motion, activeArea); mpVirtPad->mouseDown(Pos); } } else { if(Event.button.button <= 3) { transMouseRelCoord(Pos, Event.motion, activeArea); m_EventList.add( new PointingDevEvent( Pos, PDE_BUTTONDOWN ) ); gPointDevice.mPointingState.mActionButton = 1; gPointDevice.mPointingState.mPos = Pos; } else if(Event.button.button == 4) // scroll up { gEventManager.add( new MouseWheelEvent( Vector2D<float>(0.0, -1.0) ) ); } else if(Event.button.button == 5) // scroll down { gEventManager.add( new MouseWheelEvent( Vector2D<float>(0.0, 1.0) ) ); } } break; case SDL_MOUSEBUTTONUP: if(mpVirtPad && mpVirtPad->active()) { transMouseRelCoord(Pos, Event.motion, activeArea); mpVirtPad->mouseUp(Pos); } else { passSDLEventVec = true; transMouseRelCoord(Pos, Event.motion, activeArea); m_EventList.add( new PointingDevEvent( Pos, PDE_BUTTONUP ) ); gPointDevice.mPointingState.mActionButton = 0; gPointDevice.mPointingState.mPos = Pos; } break; case SDL_MOUSEMOTION: transMouseRelCoord(Pos, Event.motion, activeArea); m_EventList.add( new PointingDevEvent( Pos, PDE_MOVED ) ); gPointDevice.mPointingState.mPos = Pos; break; } if(passSDLEventVec) { mSDLEventVec.push_back(Event); } else { mBackEventBuffer.push_back(Event); } } #ifdef MOUSEWRAPPER // Handle mouse emulation layer processMouse(); #endif for(unsigned int i = 0; i < KEYTABLE_SIZE; ++i) firsttime_immediate_keytable[i] = !last_immediate_keytable[i] && immediate_keytable[i]; for(int i=0 ; i<MAX_COMMANDS ; i++) for(int j=0 ; j<NUM_INPUTS ; j++) InputCommand[j][i].firsttimeactive = !InputCommand[j][i].lastactive && InputCommand[j][i].active; #ifndef MOUSEWRAPPER // TODO: I'm not sure, if that should go here... // Check, if LALT+ENTER was pressed if((getHoldedKey(KALT)) && getPressedKey(KENTER)) { bool value; value = gVideoDriver.getFullscreen(); value = !value; gLogging.textOut(GREEN,"Fullscreen mode triggered by user!<br>"); gVideoDriver.isFullscreen(value); // initialize/activate all drivers gLogging.ftextOut("Restarting graphics driver...<br>"); if ( gVideoDriver.applyMode() && gVideoDriver.start() ) { gLogging.ftextOut(PURPLE, "Toggled Fullscreen quick shortcut...<br>"); } else { value = !value; gLogging.ftextOut(PURPLE, "Couldn't change the resolution, Rolling back...<br>"); gVideoDriver.applyMode(); gVideoDriver.start(); } gInput.flushAll(); } // Check, if LALT+Q or LALT+F4 was pressed if(getHoldedKey(KALT) && (getPressedKey(KF4) || getPressedKey(KQ)) ) { gLogging.textOut("User exit request!"); m_exit = true; gDreamsForceClose = 1; } #endif #if defined(WIZ) || defined(GP2X) WIZ_AdjustVolume( volume_direction ); #endif SDL_SemPost( pollSem ); }
void Camera::update(bool keys[1024], glm::vec2 mouse, glm::vec2 scroll, GLfloat deltaTime) { processKeyboard(keys, deltaTime); processMouse(mouse); processScroll(scroll); }