mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:53:53 +00:00
Add function to cancel drag by pressing ESC. Remove debug code.
This commit is contained in:
parent
092080c69c
commit
bd6e54dde3
6 changed files with 63 additions and 74 deletions
|
@ -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");
|
||||
|
|
|
@ -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<std::string, Ogre::Vector3> 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<Ogre::Vector3, Ogre::Vector3> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,8 @@ namespace CSVRender
|
|||
void mouseDoubleClickEvent (QMouseEvent *event);
|
||||
bool wheelEvent (QWheelEvent *event);
|
||||
|
||||
void cancelDrag();
|
||||
|
||||
private:
|
||||
|
||||
std::pair<bool, Ogre::Vector3> mousePositionOnPlane(const QPoint &pos, const Ogre::Plane &plane);
|
||||
|
@ -79,7 +81,6 @@ namespace CSVRender
|
|||
std::pair<std::string, Ogre::Vector3> objectUnderCursor(const int mouseX, const int mouseY);
|
||||
std::pair<Ogre::Vector3, Ogre::Vector3> planeAxis();
|
||||
void updateSceneWidgets();
|
||||
bool isDebug();
|
||||
|
||||
Ogre::Camera *getCamera(); // friend access
|
||||
Ogre::Viewport *getViewport(); // friend access
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
Loading…
Reference in a new issue