InputAPI::InputAPI(Framework *framework_) : Object(framework_->GetContext()), lastMouseX(0), lastMouseY(0), mouseCursorVisible(false), gesturesEnabled(false), releaseInputWhenApplicationInactive(true), mouseFPSModeEnterX(0), mouseFPSModeEnterY(0), topLevelInputContext(this, "TopLevel", 100000), // The priority value for the top level context does not really matter, just put an arbitrary big value for display. heldMouseButtons(0), pressedMouseButtons(0), releasedMouseButtons(0), newMouseButtonsPressedQueue(0), newMouseButtonsReleasedQueue(0), currentModifiers(0), numTouchPoints(0), framework(framework_) { if (framework_->IsHeadless()) return; SubscribeToEvent(Urho3D::E_KEYDOWN, URHO3D_HANDLER(InputAPI, EventFilter)); SubscribeToEvent(Urho3D::E_KEYUP, URHO3D_HANDLER(InputAPI, EventFilter)); SubscribeToEvent(Urho3D::E_MOUSEBUTTONDOWN, URHO3D_HANDLER(InputAPI, EventFilter)); SubscribeToEvent(Urho3D::E_MOUSEBUTTONUP, URHO3D_HANDLER(InputAPI, EventFilter)); SubscribeToEvent(Urho3D::E_MOUSEMOVE, URHO3D_HANDLER(InputAPI, EventFilter)); SubscribeToEvent(Urho3D::E_MOUSEWHEEL, URHO3D_HANDLER(InputAPI, EventFilter)); SubscribeToEvent(Urho3D::E_TOUCHBEGIN, URHO3D_HANDLER(InputAPI, EventFilter)); SubscribeToEvent(Urho3D::E_TOUCHMOVE, URHO3D_HANDLER(InputAPI, EventFilter)); SubscribeToEvent(Urho3D::E_TOUCHEND, URHO3D_HANDLER(InputAPI, EventFilter)); LoadKeyBindingsFromFile(); }
InputAPI::InputAPI(Framework *framework_) :lastMouseX(0), lastMouseY(0), mouseCursorVisible(true), gesturesEnabled(false), //sceneMouseCapture(NoMouseCapture), mouseFPSModeEnterX(0), mouseFPSModeEnterY(0), topLevelInputContext(this, "TopLevel", 100000), // The priority value for the top level context does not really matter, just put an arbitrary big value for display. heldMouseButtons(0), pressedMouseButtons(0), releasedMouseButtons(0), newMouseButtonsPressedQueue(0), newMouseButtonsReleasedQueue(0), currentModifiers(0), mainView(0), mainWindow(0), numTouchPoints(0), framework(framework_) { assert(framework_); // Set up the global widget event filters that we will use to read our scene input from. // Note: Since we set up this object as an event filter to multiple widgets, we will receive // the same events several times, so care has to be taken to ignore those duplicate events. // Qt oddities: // 1. If we set setMouseTracking(true) to either the main QGraphicsView or its viewport, // we do not still receive mouse move events if we install an event filter to those widgets. // So, we set mouse tracking enabled to the application main window. // 2. Mouse wheel events are taken from the application main window. // 3. Key presses are taken from the main QGraphicsView and release events are taken from the main window. // 4. Mouse press and release events do not work if taken from the main window. Presses come through fine, // but the releases are never received. Therefore, we take all our mouse presses and releases from // the QGraphicsView viewport. // 5. Mouse moves are passed to the main window, but if a mouse button is down, the viewport will start receiving // the mouse moves instead of the main window. (This is due to Qt's mouse grabbing feature). // In the event filter, we take care that we only take each event from the widget we intended to take it from, // avoiding duplicates. if (framework_->IsHeadless()) return; mainView = framework_->Ui()->GraphicsView(); assert(mainView); assert(mainView->viewport()); // For key press events. mainView->installEventFilter(this); // For mouse presses and releases, as well as mouse moves when a button is being held down. mainView->viewport()->installEventFilter(this); mainView->viewport()->setAttribute(Qt::WA_AcceptTouchEvents, true); // Find the top-level widget that the QGraphicsView is contained in. We need // to track mouse move events from that window. mainWindow = mainView; while(mainWindow->parentWidget()) mainWindow = mainWindow->parentWidget(); mainWindow->setMouseTracking(true); // For Mouse wheel events, key releases, and mouse moves (no button down). mainWindow->installEventFilter(this); mainWindow->setAttribute(Qt::WA_AcceptTouchEvents, true); LoadKeyBindingsFromFile(); // Accept gestures // [Mac OS X] bug: Pan gesture is triggered if the (left) mouse button is long-pressed and not moved at all. Disabling gestures for now on Mac #ifndef Q_WS_MAC QList<Qt::GestureType> gestures; gestures << Qt::PanGesture << Qt::PinchGesture << Qt::TapAndHoldGesture; foreach(Qt::GestureType type, gestures) mainWindow->grabGesture(type); #endif }
QtInputService::QtInputService(Foundation::Framework *framework_) :lastMouseX(0), lastMouseY(0), mouseCursorVisible(true), //sceneMouseCapture(NoMouseCapture), mouseFPSModeEnterX(0), mouseFPSModeEnterY(0), topLevelInputContext("TopLevel", 100000), // The priority value for the top level context does not really matter, just put an arbitrary big value for display. inputCategory(0), heldMouseButtons(0), pressedMouseButtons(0), releasedMouseButtons(0), newMouseButtonsPressedQueue(0), newMouseButtonsReleasedQueue(0), current_modifiers_(0), mainView(0), mainWindow(0), framework(framework_) { assert(framework_); eventManager = framework_->GetEventManager(); assert(eventManager); // We still need to register this for legacy reasons, but shouldn't have to. // The 'Input' category should be removed and replaced with 'RexInput' or something // similar that is world logic -centric. inputCategory = eventManager->RegisterEventCategory("Input"); inputCategory = eventManager->RegisterEventCategory("SceneInput"); eventManager->RegisterEvent(inputCategory, QtInputEvents::KeyPressed, "KeyPressed"); eventManager->RegisterEvent(inputCategory, QtInputEvents::KeyReleased, "KeyReleased"); eventManager->RegisterEvent(inputCategory, QtInputEvents::MousePressed, "MousePressed"); eventManager->RegisterEvent(inputCategory, QtInputEvents::MouseReleased, "MouseReleased"); eventManager->RegisterEvent(inputCategory, QtInputEvents::MouseClicked, "MouseClicked"); eventManager->RegisterEvent(inputCategory, QtInputEvents::MouseDoubleClicked, "MouseDoubleClicked"); eventManager->RegisterEvent(inputCategory, QtInputEvents::MouseMove, "MouseMove"); // Next, set up the global widget event filters that we will use to read our scene input from. // Note: Since we set up this object as an event filter to multiple widgets, we will receive // the same events several times, so care has to be taken to ignore those duplicate events. // Qt oddities: // 1. If we set setMouseTracking(true) to either the main QGraphicsView or its viewport, // we do not still receive mouse move events if we install an event filter to those widgets. // So, we set mouse tracking enabled to the application main window. // 2. Mouse wheel events are taken from the application main window. // 3. Key presses are taken from the main QGraphicsView and release events are taken from the main window. // 4. Mouse press and release events do not work if taken from the main window. Presses come through fine, // but the releases are never received. Therefore, we take all our mouse presses and releases from // the QGraphicsView viewport. // 5. Mouse moves are passed to the main window, but if a mouse button is down, the viewport will start receiving // the mouse moves instead of the main window. (This is due to Qt's mouse grabbing feature). // In the event filter, we take care that we only take each event from the widget we intended to take it from, // avoiding duplicates. mainView = framework_->GetUIView(); assert(mainView); assert(mainView->viewport()); // For key press events. mainView->installEventFilter(this); // For mouse presses and releases, as well as mouse moves when a button is being held down. mainView->viewport()->installEventFilter(this); // Find the top-level widget that the QGraphicsView is contained in. We need // to track mouse move events from that window. mainWindow = mainView; while(mainWindow->parentWidget()) mainWindow = mainWindow->parentWidget(); mainWindow->setMouseTracking(true); // For Mouse wheel events, key releases, and mouse moves (no button down). mainWindow->installEventFilter(this); LoadKeyBindingsFromFile(); lastMouseButtonReleaseTime = QTime::currentTime(); doubleClickDetected = false; }