Finally re-added rendering stats, refactored some functions

to better fit new input structure, removed unneeded shortcut
declarations in headers, and changed the cell marker
interaction to use primary/secondary select instead of
shift + primary/secondary edit.
pull/29/head
Aesylwinn 9 years ago
parent faa84e0a35
commit 1b5273f2b7

@ -259,6 +259,7 @@ void CSMPrefs::State::declare()
QKeySequence(Qt::ControlModifier | (int)Qt::MiddleButton)); QKeySequence(Qt::ControlModifier | (int)Qt::MiddleButton));
declareShortcut ("scene-edit-abort", "Scene editor abort key", QKeySequence(Qt::Key_Escape)); declareShortcut ("scene-edit-abort", "Scene editor abort key", QKeySequence(Qt::Key_Escape));
declareShortcut ("scene-focus-toolbar", "Change focus in scene editor", QKeySequence(Qt::Key_T)); declareShortcut ("scene-focus-toolbar", "Change focus in scene editor", QKeySequence(Qt::Key_T));
declareShortcut ("scene-render-stats", "Displays debug rendering stats", QKeySequence(Qt::Key_F3));
} }
void CSMPrefs::State::declareCategory (const std::string& key) void CSMPrefs::State::declareCategory (const std::string& key)

@ -268,10 +268,10 @@ namespace CSVRender
mLockUpright = false; mLockUpright = false;
} }
bool FreeCameraController::handleMouseMoveEvent(std::string mode, int x, int y) void FreeCameraController::handleMouseMoveEvent(int x, int y)
{ {
if (!isActive()) if (!isActive())
return false; return;
if (mNaviPrimary) if (mNaviPrimary)
{ {
@ -287,16 +287,14 @@ namespace CSVRender
translate(movement); translate(movement);
} }
else if (mode == "t-navi") }
{
translate(LocalForward * x * (mFast ? getWheelMovementMultiplier() : 1));
}
else
{
return false;
}
return true; void FreeCameraController::handleMouseScrollEvent(int x)
{
if (!isActive())
return;
translate(LocalForward * x * (mFast ? getWheelMovementMultiplier() : 1));
} }
void FreeCameraController::update(double dt) void FreeCameraController::update(double dt)
@ -336,17 +334,6 @@ namespace CSVRender
getCamera()->getViewMatrix().orthoNormal(getCamera()->getViewMatrix()); getCamera()->getViewMatrix().orthoNormal(getCamera()->getViewMatrix());
} }
void FreeCameraController::resetInput()
{
mFast = false;
mLeft = false;
mRight = false;
mForward = false;
mBackward = false;
mRollLeft = false;
mRollRight = false;
}
void FreeCameraController::yaw(double value) void FreeCameraController::yaw(double value)
{ {
getCamera()->getViewMatrix() *= osg::Matrixd::rotate(value, LocalUp); getCamera()->getViewMatrix() *= osg::Matrixd::rotate(value, LocalUp);
@ -555,10 +542,10 @@ namespace CSVRender
mPickingMask = value; mPickingMask = value;
} }
bool OrbitCameraController::handleMouseMoveEvent(std::string mode, int x, int y) void OrbitCameraController::handleMouseMoveEvent(int x, int y)
{ {
if (!isActive()) if (!isActive())
return false; return;
if (!mInitialized) if (!mInitialized)
initialize(); initialize();
@ -577,16 +564,14 @@ namespace CSVRender
translate(movement); translate(movement);
} }
else if (mode == "t-navi") }
{
zoom(-x * (mFast ? getWheelMovementMultiplier() : 1));
}
else
{
return false;
}
return true; void OrbitCameraController::handleMouseScrollEvent(int x)
{
if (!isActive())
return;
zoom(-x * (mFast ? getWheelMovementMultiplier() : 1));
} }
void OrbitCameraController::update(double dt) void OrbitCameraController::update(double dt)
@ -620,17 +605,6 @@ namespace CSVRender
getCamera()->getViewMatrix().orthoNormal(getCamera()->getViewMatrix()); getCamera()->getViewMatrix().orthoNormal(getCamera()->getViewMatrix());
} }
void OrbitCameraController::resetInput()
{
mFast = false;
mLeft = false;
mRight =false;
mUp = false;
mDown = false;
mRollLeft = false;
mRollRight = false;
}
void OrbitCameraController::onActivate() void OrbitCameraController::onActivate()
{ {
mInitialized = false; mInitialized = false;

@ -57,12 +57,11 @@ namespace CSVRender
// moves the camera to an intelligent position // moves the camera to an intelligent position
void setup(osg::Group* root, unsigned int mask, const osg::Vec3d& up); void setup(osg::Group* root, unsigned int mask, const osg::Vec3d& up);
virtual bool handleMouseMoveEvent(std::string mode, int x, int y) = 0; virtual void handleMouseMoveEvent(int x, int y) = 0;
virtual void handleMouseScrollEvent(int x) = 0;
virtual void update(double dt) = 0; virtual void update(double dt) = 0;
virtual void resetInput() = 0;
protected: protected:
virtual void onActivate(){} virtual void onActivate(){}
@ -96,12 +95,11 @@ namespace CSVRender
void fixUpAxis(const osg::Vec3d& up); void fixUpAxis(const osg::Vec3d& up);
void unfixUpAxis(); void unfixUpAxis();
bool handleMouseMoveEvent(std::string mode, int x, int y); void handleMouseMoveEvent(int x, int y);
void handleMouseScrollEvent(int x);
void update(double dt); void update(double dt);
void resetInput();
private: private:
void yaw(double value); void yaw(double value);
@ -151,12 +149,11 @@ namespace CSVRender
void setOrbitSpeedMultiplier(double value); void setOrbitSpeedMultiplier(double value);
void setPickingMask(unsigned int value); void setPickingMask(unsigned int value);
bool handleMouseMoveEvent(std::string mode, int x, int y); void handleMouseMoveEvent(int x, int y);
void handleMouseScrollEvent(int x);
void update(double dt); void update(double dt);
void resetInput();
private: private:
void onActivate(); void onActivate();

@ -142,74 +142,71 @@ void CSVRender::PagedWorldspaceWidget::addEditModeSelectorButtons (
"terrain-move"); "terrain-move");
} }
void CSVRender::PagedWorldspaceWidget::handleMouseClick (const WorldspaceHitResult& hit, InteractionType type, void CSVRender::PagedWorldspaceWidget::handleInteractionPress (const WorldspaceHitResult& hit, InteractionType type)
bool shift)
{ {
if (hit.tag && hit.tag->getMask()==Mask_CellArrow) if (hit.tag && hit.tag->getMask()==Mask_CellArrow)
{ {
if (type == InteractionType_PrimaryEdit || type == InteractionType_SecondaryEdit) if (CellArrowTag *cellArrowTag = dynamic_cast<CSVRender::CellArrowTag *> (hit.tag.get()))
{ {
if (CellArrowTag *cellArrowTag = dynamic_cast<CSVRender::CellArrowTag *> (hit.tag.get())) CellArrow *arrow = cellArrowTag->getCellArrow();
{
CellArrow *arrow = cellArrowTag->getCellArrow();
CSMWorld::CellCoordinates coordinates = arrow->getCoordinates(); CSMWorld::CellCoordinates coordinates = arrow->getCoordinates();
CellArrow::Direction direction = arrow->getDirection(); CellArrow::Direction direction = arrow->getDirection();
int x = 0; int x = 0;
int y = 0; int y = 0;
switch (direction) switch (direction)
{ {
case CellArrow::Direction_North: y = 1; break; case CellArrow::Direction_North: y = 1; break;
case CellArrow::Direction_West: x = -1; break; case CellArrow::Direction_West: x = -1; break;
case CellArrow::Direction_South: y = -1; break; case CellArrow::Direction_South: y = -1; break;
case CellArrow::Direction_East: x = 1; break; case CellArrow::Direction_East: x = 1; break;
} }
bool modified = false; bool modified = false;
if (shift) if (type == InteractionType_PrimarySelect)
{ {
if (type == InteractionType_PrimaryEdit) addCellSelection (x, y);
addCellSelection (x, y); modified = true;
else }
moveCellSelection (x, y); else if (type == InteractionType_SecondarySelect)
{
moveCellSelection (x, y);
modified = true;
}
else // Primary/SecondaryEdit
{
CSMWorld::CellCoordinates newCoordinates = coordinates.move (x, y);
if (mCells.find (newCoordinates)==mCells.end())
{
addCellToScene (newCoordinates);
mSelection.add (newCoordinates);
modified = true; modified = true;
} }
else
{
CSMWorld::CellCoordinates newCoordinates = coordinates.move (x, y);
if (mCells.find (newCoordinates)==mCells.end()) if (type == InteractionType_SecondaryEdit)
{
if (mCells.find (coordinates)!=mCells.end())
{ {
addCellToScene (newCoordinates); removeCellFromScene (coordinates);
mSelection.add (newCoordinates); mSelection.remove (coordinates);
modified = true; modified = true;
} }
if (type == InteractionType_SecondaryEdit)
{
if (mCells.find (coordinates)!=mCells.end())
{
removeCellFromScene (coordinates);
mSelection.remove (coordinates);
modified = true;
}
}
} }
}
if (modified) if (modified)
adjustCells(); adjustCells();
return; return;
}
} }
} }
WorldspaceWidget::handleMouseClick (hit, type, shift); WorldspaceWidget::handleInteractionPress (hit, type);
} }
void CSVRender::PagedWorldspaceWidget::referenceableDataChanged (const QModelIndex& topLeft, void CSVRender::PagedWorldspaceWidget::referenceableDataChanged (const QModelIndex& topLeft,

@ -138,7 +138,7 @@ namespace CSVRender
virtual void addEditModeSelectorButtons (CSVWidget::SceneToolMode *tool); virtual void addEditModeSelectorButtons (CSVWidget::SceneToolMode *tool);
virtual void handleMouseClick (const WorldspaceHitResult& hit, InteractionType type, bool shift); virtual void handleInteractionPress (const WorldspaceHitResult& hit, InteractionType type);
signals: signals:

@ -107,6 +107,15 @@ osg::Camera *RenderWidget::getCamera()
return mView->getCamera(); return mView->getCamera();
} }
void RenderWidget::toggleRenderStats()
{
osgViewer::GraphicsWindow* window =
static_cast<osgViewer::GraphicsWindow*>(mView->getCamera()->getGraphicsContext());
window->getEventQueue()->keyPress(osgGA::GUIEventAdapter::KEY_S);
window->getEventQueue()->keyRelease(osgGA::GUIEventAdapter::KEY_S);
}
// -------------------------------------------------- // --------------------------------------------------
@ -182,10 +191,6 @@ SceneWidget::SceneWidget(boost::shared_ptr<Resource::ResourceSystem> resourceSys
setMouseTracking(true); setMouseTracking(true);
setFocusPolicy(Qt::ClickFocus); setFocusPolicy(Qt::ClickFocus);
mFocusToolbarShortcut = new CSMPrefs::Shortcut("scene-focus-toolbar", this);
mShortcutHandler->addShortcut(mFocusToolbarShortcut);
connect(mFocusToolbarShortcut, SIGNAL(activated()), this, SIGNAL(focusToolbarRequest()));
connect (&CSMPrefs::State::get(), SIGNAL (settingChanged (const CSMPrefs::Setting *)), connect (&CSMPrefs::State::get(), SIGNAL (settingChanged (const CSMPrefs::Setting *)),
this, SLOT (settingChanged (const CSMPrefs::Setting *))); this, SLOT (settingChanged (const CSMPrefs::Setting *)));
@ -197,6 +202,15 @@ SceneWidget::SceneWidget(boost::shared_ptr<Resource::ResourceSystem> resourceSys
} }
connect (&CompositeViewer::get(), SIGNAL (simulationUpdated(double)), this, SLOT (update(double))); connect (&CompositeViewer::get(), SIGNAL (simulationUpdated(double)), this, SLOT (update(double)));
// Shortcuts
CSMPrefs::Shortcut* focusToolbarShortcut = new CSMPrefs::Shortcut("scene-focus-toolbar", this);
mShortcutHandler->addShortcut(focusToolbarShortcut);
connect(focusToolbarShortcut, SIGNAL(activated()), this, SIGNAL(focusToolbarRequest()));
CSMPrefs::Shortcut* renderStatsShortcut = new CSMPrefs::Shortcut("scene-render-stats", this);
mShortcutHandler->addShortcut(renderStatsShortcut);
connect(renderStatsShortcut, SIGNAL(activated()), this, SLOT(toggleRenderStats()));
} }
SceneWidget::~SceneWidget() SceneWidget::~SceneWidget()
@ -280,7 +294,7 @@ void SceneWidget::setDefaultAmbient (const osg::Vec4f& colour)
void SceneWidget::mouseMoveEvent (QMouseEvent *event) void SceneWidget::mouseMoveEvent (QMouseEvent *event)
{ {
mCurrentCamControl->handleMouseMoveEvent("TODO", event->x() - mPrevMouseX, event->y() - mPrevMouseY); mCurrentCamControl->handleMouseMoveEvent(event->x() - mPrevMouseX, event->y() - mPrevMouseY);
mPrevMouseX = event->x(); mPrevMouseX = event->x();
mPrevMouseY = event->y(); mPrevMouseY = event->y();
@ -288,7 +302,7 @@ void SceneWidget::mouseMoveEvent (QMouseEvent *event)
void SceneWidget::wheelEvent(QWheelEvent *event) void SceneWidget::wheelEvent(QWheelEvent *event)
{ {
mCurrentCamControl->handleMouseMoveEvent("t-navi", event->delta(), 0); mCurrentCamControl->handleMouseScrollEvent(event->delta());
} }
void SceneWidget::update(double dt) void SceneWidget::update(double dt)

@ -69,18 +69,19 @@ namespace CSVRender
osg::ref_ptr<osg::Group> mRootNode; osg::ref_ptr<osg::Group> mRootNode;
QTimer mTimer; QTimer mTimer;
protected slots:
void toggleRenderStats();
}; };
/// Extension of RenderWidget to support lighting mode selection & toolbar /// Extension of RenderWidget to support lighting mode selection & toolbar
class SceneWidget : public RenderWidget class SceneWidget : public RenderWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
SceneWidget(boost::shared_ptr<Resource::ResourceSystem> resourceSystem, QWidget* parent = 0, SceneWidget(boost::shared_ptr<Resource::ResourceSystem> resourceSystem, QWidget* parent = 0,
Qt::WindowFlags f = 0, bool retrieveInput = true); Qt::WindowFlags f = 0, bool retrieveInput = true);
virtual ~SceneWidget(); virtual ~SceneWidget();
CSVWidget::SceneToolMode *makeLightingSelector (CSVWidget::SceneToolbar *parent); CSVWidget::SceneToolMode *makeLightingSelector (CSVWidget::SceneToolbar *parent);
@ -91,7 +92,6 @@ namespace CSVRender
///< \note The actual ambient colour may differ based on lighting settings. ///< \note The actual ambient colour may differ based on lighting settings.
protected: protected:
void setLighting (Lighting *lighting); void setLighting (Lighting *lighting);
///< \attention The ownership of \a lighting is not transferred to *this. ///< \attention The ownership of \a lighting is not transferred to *this.
@ -117,7 +117,6 @@ namespace CSVRender
CameraController* mCurrentCamControl; CameraController* mCurrentCamControl;
CSMPrefs::ShortcutEventHandler *mShortcutHandler; CSMPrefs::ShortcutEventHandler *mShortcutHandler;
CSMPrefs::Shortcut* mFocusToolbarShortcut;
private: private:
bool mCamPositionSet; bool mCamPositionSet;
@ -145,9 +144,7 @@ namespace CSVRender
class CompositeViewer : public QObject, public osgViewer::CompositeViewer class CompositeViewer : public QObject, public osgViewer::CompositeViewer
{ {
Q_OBJECT Q_OBJECT
public: public:
CompositeViewer(); CompositeViewer();
static CompositeViewer& get(); static CompositeViewer& get();

@ -97,25 +97,25 @@ CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidg
CSMPrefs::get()["Tooltips"].update(); CSMPrefs::get()["Tooltips"].update();
// Shortcuts // Shortcuts
mPrimaryEditShortcut = new CSMPrefs::Shortcut("scene-edit-primary", this); CSMPrefs::Shortcut* primaryEditShortcut = new CSMPrefs::Shortcut("scene-edit-primary", this);
mShortcutHandler->addShortcut(mPrimaryEditShortcut); mShortcutHandler->addShortcut(primaryEditShortcut);
connect(mPrimaryEditShortcut, SIGNAL(activated(bool)), this, SLOT(primaryEdit(bool))); connect(primaryEditShortcut, SIGNAL(activated(bool)), this, SLOT(primaryEdit(bool)));
mSecondaryEditShortcut = new CSMPrefs::Shortcut("scene-edit-secondary", this); CSMPrefs::Shortcut* secondaryEditShortcut = new CSMPrefs::Shortcut("scene-edit-secondary", this);
mShortcutHandler->addShortcut(mSecondaryEditShortcut); mShortcutHandler->addShortcut(secondaryEditShortcut);
connect(mSecondaryEditShortcut, SIGNAL(activated(bool)), this, SLOT(secondaryEdit(bool))); connect(secondaryEditShortcut, SIGNAL(activated(bool)), this, SLOT(secondaryEdit(bool)));
mPrimarySelectShortcut = new CSMPrefs::Shortcut("scene-select-primary", this); CSMPrefs::Shortcut* primarySelectShortcut = new CSMPrefs::Shortcut("scene-select-primary", this);
mShortcutHandler->addShortcut(mPrimarySelectShortcut); mShortcutHandler->addShortcut(primarySelectShortcut);
connect(mPrimarySelectShortcut, SIGNAL(activated(bool)), this, SLOT(primarySelect(bool))); connect(primarySelectShortcut, SIGNAL(activated(bool)), this, SLOT(primarySelect(bool)));
mSecondarySelectShortcut = new CSMPrefs::Shortcut("scene-select-secondary", this); CSMPrefs::Shortcut* secondarySelectShortcut = new CSMPrefs::Shortcut("scene-select-secondary", this);
mShortcutHandler->addShortcut(mSecondarySelectShortcut); mShortcutHandler->addShortcut(secondarySelectShortcut);
connect(mSecondarySelectShortcut, SIGNAL(activated(bool)), this, SLOT(secondarySelect(bool))); connect(secondarySelectShortcut, SIGNAL(activated(bool)), this, SLOT(secondarySelect(bool)));
mAbortShortcut = new CSMPrefs::Shortcut("scene-edit-abort", this); CSMPrefs::Shortcut* abortShortcut = new CSMPrefs::Shortcut("scene-edit-abort", this);
mShortcutHandler->addShortcut(mAbortShortcut); mShortcutHandler->addShortcut(abortShortcut);
connect(mSecondaryEditShortcut, SIGNAL(activated()), this, SLOT(abortDrag())); connect(abortShortcut, SIGNAL(activated()), this, SLOT(abortDrag()));
} }
CSVRender::WorldspaceWidget::~WorldspaceWidget () CSVRender::WorldspaceWidget::~WorldspaceWidget ()
@ -670,7 +670,7 @@ void CSVRender::WorldspaceWidget::wheelEvent (QWheelEvent *event)
SceneWidget::wheelEvent(event); SceneWidget::wheelEvent(event);
} }
void CSVRender::WorldspaceWidget::handleMouseClick (const WorldspaceHitResult& hit, InteractionType type, bool shift) void CSVRender::WorldspaceWidget::handleInteractionPress (const WorldspaceHitResult& hit, InteractionType type)
{ {
EditMode& editMode = dynamic_cast<CSVRender::EditMode&> (*mEditMode->getCurrent()); EditMode& editMode = dynamic_cast<CSVRender::EditMode&> (*mEditMode->getCurrent());
@ -729,7 +729,7 @@ void CSVRender::WorldspaceWidget::handleInteraction(InteractionType type, bool a
else else
{ {
WorldspaceHitResult hit = mousePick(mapFromGlobal(QCursor::pos()), getInteractionMask()); WorldspaceHitResult hit = mousePick(mapFromGlobal(QCursor::pos()), getInteractionMask());
handleMouseClick(hit, type, false); handleInteractionPress(hit, type);
} }
} }
} }

@ -68,12 +68,6 @@ namespace CSVRender
bool mShowToolTips; bool mShowToolTips;
int mToolTipDelay; int mToolTipDelay;
CSMPrefs::Shortcut* mPrimaryEditShortcut;
CSMPrefs::Shortcut* mSecondaryEditShortcut;
CSMPrefs::Shortcut* mPrimarySelectShortcut;
CSMPrefs::Shortcut* mSecondarySelectShortcut;
CSMPrefs::Shortcut* mAbortShortcut;
public: public:
enum DropType enum DropType
@ -209,7 +203,7 @@ namespace CSVRender
virtual void mouseMoveEvent (QMouseEvent *event); virtual void mouseMoveEvent (QMouseEvent *event);
virtual void wheelEvent (QWheelEvent *event); virtual void wheelEvent (QWheelEvent *event);
virtual void handleMouseClick (const WorldspaceHitResult& hit, InteractionType type, bool shift); virtual void handleInteractionPress (const WorldspaceHitResult& hit, InteractionType type);
virtual void settingChanged (const CSMPrefs::Setting *setting); virtual void settingChanged (const CSMPrefs::Setting *setting);

Loading…
Cancel
Save