From bd6e54dde337a1bdbac1865b547627519c053539 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Mon, 3 Nov 2014 21:24:47 +1100 Subject: [PATCH] Add function to cancel drag by pressing ESC. Remove debug code. --- apps/opencs/model/settings/usersettings.cpp | 24 ----- apps/opencs/view/render/mousestate.cpp | 95 ++++++++++---------- apps/opencs/view/render/mousestate.hpp | 3 +- apps/opencs/view/render/scenewidget.hpp | 4 +- apps/opencs/view/render/worldspacewidget.cpp | 10 +++ apps/opencs/view/render/worldspacewidget.hpp | 1 + 6 files changed, 63 insertions(+), 74 deletions(-) diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index 26c6aa5d6..7dac660c3 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -161,30 +161,6 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() ritd->setDeclaredValues (values); } - declareSection ("debug", "Debug Options"); - { - Setting *mousePicking = createSetting (Type_CheckBox, "mouse-picking", "Debug Render Mouse-Picking"); - mousePicking->setDefaultValue ("false"); - mousePicking->setToolTip ("Enable redering debug information for mouse picking. " - "This option may be removed in future once the mouse picking feature is completed."); - - QString defaultValue = "Closer/Further"; - QStringList values = QStringList() << defaultValue << "Up/Down" << "Left/Right"; - - Setting *mouseWheel = createSetting (Type_RadioButton, "mouse-wheel", - "For testing mouse movement directions."); - mouseWheel->setDefaultValue (defaultValue); - mouseWheel->setDeclaredValues (values); - - defaultValue = "screen"; - values = QStringList() << defaultValue << "world"; - - Setting *mouseCoord = createSetting (Type_RadioButton, "mouse-reference", - "For testing mouse movement frame of reference."); - mouseCoord->setDefaultValue (defaultValue); - mouseCoord->setDeclaredValues (values); - } - declareSection ("table-input", "Table Input"); { QString inPlaceEdit ("Edit in Place"); diff --git a/apps/opencs/view/render/mousestate.cpp b/apps/opencs/view/render/mousestate.cpp index 21f3aca78..af835d0a5 100644 --- a/apps/opencs/view/render/mousestate.cpp +++ b/apps/opencs/view/render/mousestate.cpp @@ -61,7 +61,6 @@ namespace CSVRender , mGrabbedSceneNode(""), mOrigObjPos(Ogre::Vector3()), mOrigMousePos(Ogre::Vector3()) , mCurrentMousePos(Ogre::Vector3()), mOffset(0.0f) , mColIndexPosX(0), mColIndexPosY(0), mColIndexPosZ(0), mIdTableModel(0) - //, mModel(0) { const CSMWorld::RefCollection& references = mParent->mDocument.getData().getReferences(); @@ -207,15 +206,6 @@ namespace CSVRender mCurrentObj = result.first; } - // print some debug info - if(isDebug()) - { - std::string referenceId = mPhysics->sceneNodeToRefId(result.first); - std::cout << "ReferenceId: " << referenceId << std::endl; - std::cout << " hit pos "+ QString::number(result.second.x).toStdString() - + ", " + QString::number(result.second.y).toStdString() - + ", " + QString::number(result.second.z).toStdString() << std::endl; - } } break; } @@ -265,13 +255,7 @@ namespace CSVRender std::pair result = terrainUnderCursor(event->x(), event->y()); if(result.first != "") { - if(isDebug()) - { - std::cout << "terrain: " << result.first << std::endl; - std::cout << " hit pos "+ QString::number(result.second.x).toStdString() - + ", " + QString::number(result.second.y).toStdString() - + ", " + QString::number(result.second.z).toStdString() << std::endl; - } + // FIXME: terrain editing } break; } @@ -282,16 +266,7 @@ namespace CSVRender void MouseState::mouseDoubleClickEvent (QMouseEvent *event) { - if(0 && isDebug()) // disable - { - // FIXME: OEngine::PhysicEngine creates only one child scene node for the - // debug drawer. Hence only the first subview that creates the debug drawer - // can view the debug lines. Will need to keep a map in OEngine if multiple - // subviews are to be supported. - mPhysics->addSceneManager(mSceneManager, mParent); - mPhysics->toggleDebugRendering(mSceneManager); - mParent->flagAsModified(); - } + event->ignore(); } bool MouseState::wheelEvent (QWheelEvent *event) @@ -329,37 +304,70 @@ namespace CSVRender return true; } + void MouseState::cancelDrag() + { + switch(mMouseState) + { + case Mouse_Grab: + case Mouse_Drag: + { + // cancel operation & return the object to the original position + mSceneManager->getSceneNode(mGrabbedSceneNode)->setPosition(mOrigObjPos); + // update all SceneWidgets and their SceneManagers + mPhysics->moveSceneNodes(mGrabbedSceneNode, mOrigObjPos); + updateSceneWidgets(); + + // reset states + mMouseState = Mouse_Default; + mCurrentMousePos = Ogre::Vector3(); + mOrigMousePos = Ogre::Vector3(); + mOrigObjPos = Ogre::Vector3(); + mGrabbedSceneNode = ""; + mCurrentObj = ""; + mOldPos = QPoint(0, 0); + mMouseEventTimer->invalidate(); + mOffset = 0.0f; + + break; + } + case Mouse_Edit: + case Mouse_Default: + { + break; + } + /* NO_DEFAULT_CASE */ + } + } + //plane Z, upvector Y, mOffset z : x-y plane, wheel up/down //plane Y, upvector X, mOffset y : y-z plane, wheel left/right //plane X, upvector Y, mOffset x : x-z plane, wheel closer/further std::pair MouseState::planeAxis() { - // FIXME: explore using signals instread of retrieving each time - CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); - QString coord = userSettings.setting("debug/mouse-reference", QString("screen")); + bool screenCoord = true; Ogre::Vector3 dir = getCamera()->getDerivedDirection(); - QString wheelDir = userSettings.setting("debug/mouse-wheel", QString("Closer/Further")); + QString wheelDir = "Closer/Further"; if(wheelDir == "Left/Right") { - if(coord == "world") - return std::make_pair(Ogre::Vector3::UNIT_Y, Ogre::Vector3::UNIT_Z); - else + if(screenCoord) return std::make_pair(getCamera()->getDerivedRight(), getCamera()->getDerivedUp()); + else + return std::make_pair(Ogre::Vector3::UNIT_Y, Ogre::Vector3::UNIT_Z); } else if(wheelDir == "Up/Down") { - if(coord == "world") - return std::make_pair(Ogre::Vector3::UNIT_Z, Ogre::Vector3::UNIT_X); - else + if(screenCoord) return std::make_pair(getCamera()->getDerivedUp(), Ogre::Vector3(-dir.x, -dir.y, -dir.z)); + else + return std::make_pair(Ogre::Vector3::UNIT_Z, Ogre::Vector3::UNIT_X); } else { - if(coord == "world") - return std::make_pair(Ogre::Vector3::UNIT_X, Ogre::Vector3::UNIT_Y); - else + if(screenCoord) return std::make_pair(Ogre::Vector3(-dir.x, -dir.y, -dir.z), getCamera()->getDerivedRight()); + else + return std::make_pair(Ogre::Vector3::UNIT_X, Ogre::Vector3::UNIT_Y); } } @@ -450,11 +458,4 @@ namespace CSVRender { return mParent->getCamera()->getViewport(); } - - bool MouseState::isDebug() - { - CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); - - return userSettings.setting("debug/mouse-picking", QString("false")) == "true" ? true : false; - } } diff --git a/apps/opencs/view/render/mousestate.hpp b/apps/opencs/view/render/mousestate.hpp index 2493416ae..27907bb33 100644 --- a/apps/opencs/view/render/mousestate.hpp +++ b/apps/opencs/view/render/mousestate.hpp @@ -72,6 +72,8 @@ namespace CSVRender void mouseDoubleClickEvent (QMouseEvent *event); bool wheelEvent (QWheelEvent *event); + void cancelDrag(); + private: std::pair mousePositionOnPlane(const QPoint &pos, const Ogre::Plane &plane); @@ -79,7 +81,6 @@ namespace CSVRender std::pair objectUnderCursor(const int mouseX, const int mouseY); std::pair planeAxis(); void updateSceneWidgets(); - bool isDebug(); Ogre::Camera *getCamera(); // friend access Ogre::Viewport *getViewport(); // friend access diff --git a/apps/opencs/view/render/scenewidget.hpp b/apps/opencs/view/render/scenewidget.hpp index a3b8cd4b0..699d6a7a5 100644 --- a/apps/opencs/view/render/scenewidget.hpp +++ b/apps/opencs/view/render/scenewidget.hpp @@ -77,13 +77,13 @@ namespace CSVRender void wheelEvent (QWheelEvent *event); + void keyPressEvent (QKeyEvent *event); + private: void paintEvent(QPaintEvent* e); void resizeEvent(QResizeEvent* e); bool event(QEvent* e); - void keyPressEvent (QKeyEvent *event); - void keyReleaseEvent (QKeyEvent *event); void focusOutEvent (QFocusEvent *event); diff --git a/apps/opencs/view/render/worldspacewidget.cpp b/apps/opencs/view/render/worldspacewidget.cpp index f8bec949c..9c8676064 100644 --- a/apps/opencs/view/render/worldspacewidget.cpp +++ b/apps/opencs/view/render/worldspacewidget.cpp @@ -388,3 +388,13 @@ void CSVRender::WorldspaceWidget::wheelEvent (QWheelEvent *event) if(!mMouse->wheelEvent(event)) SceneWidget::wheelEvent(event); } + +void CSVRender::WorldspaceWidget::keyPressEvent (QKeyEvent *event) +{ + if(event->key() == Qt::Key_Escape) + { + mMouse->cancelDrag(); + } + else + SceneWidget::keyPressEvent(event); +} diff --git a/apps/opencs/view/render/worldspacewidget.hpp b/apps/opencs/view/render/worldspacewidget.hpp index 14f091620..5bad3933d 100644 --- a/apps/opencs/view/render/worldspacewidget.hpp +++ b/apps/opencs/view/render/worldspacewidget.hpp @@ -107,6 +107,7 @@ namespace CSVRender virtual void mouseReleaseEvent (QMouseEvent *event); virtual void mouseDoubleClickEvent (QMouseEvent *event); virtual void wheelEvent (QWheelEvent *event); + virtual void keyPressEvent (QKeyEvent *event); private: