Merge branch 'visibility'

deque
Marc Zinnschlag 11 years ago
commit 1e6d557089

@ -69,7 +69,7 @@ opencs_units_noqt (view/world
)
opencs_units (view/widget
scenetoolbar scenetool scenetoolmode pushbutton
scenetoolbar scenetool scenetoolmode pushbutton scenetooltoggle
)
opencs_units (view/render
@ -82,6 +82,10 @@ opencs_units_noqt (view/render
lightingbright object cell
)
opencs_hdrs_noqt (view/render
elements
)
opencs_units (view/tools
reportsubview

@ -0,0 +1,23 @@
#ifndef CSV_RENDER_ELEMENTS_H
#define CSV_RENDER_ELEMENTS_H
namespace CSVRender
{
/// Visual elements in a scene
enum Elements
{
// elements that are part of the actual scene
Element_Reference = 0x1,
Element_Terrain = 0x2,
Element_Water = 0x4,
Element_Pathgrid = 0x8,
Element_Fog = 0x10,
// control elements
Element_CellMarker = 0x10000,
Element_CellArrow = 0x20000,
Element_CellBorder = 0x40000
};
}
#endif

@ -9,6 +9,8 @@
#include "../../model/world/ref.hpp"
#include "../../model/world/refidcollection.hpp"
#include "elements.hpp"
void CSVRender::Object::clearSceneNode (Ogre::SceneNode *node)
{
for (Ogre::SceneNode::ObjectIterator iter = node->getAttachedObjectIterator();
@ -63,12 +65,14 @@ void CSVRender::Object::update()
{
Ogre::Entity* entity = mBase->getCreator()->createEntity (Ogre::SceneManager::PT_CUBE);
entity->setMaterialName("BaseWhite"); /// \todo adjust material according to error
entity->setVisibilityFlags (Element_Reference);
mBase->attachObject (entity);
}
else
{
mObject = NifOgre::Loader::createObjects (mBase, "Meshes\\" + model);
mObject->setVisibilityFlags (Element_Reference);
}
}

@ -10,6 +10,10 @@
#include "../../model/world/tablemimedata.hpp"
#include "../../model/world/idtable.hpp"
#include "../widget/scenetooltoggle.hpp"
#include "elements.hpp"
bool CSVRender::PagedWorldspaceWidget::adjustCells()
{
bool modified = false;
@ -237,6 +241,31 @@ CSVRender::WorldspaceWidget::dropRequirments CSVRender::PagedWorldspaceWidget::g
}
}
unsigned int CSVRender::PagedWorldspaceWidget::getElementMask() const
{
return WorldspaceWidget::getElementMask() | mControlElements->getSelection();
}
CSVWidget::SceneToolToggle *CSVRender::PagedWorldspaceWidget::makeControlVisibilitySelector (
CSVWidget::SceneToolbar *parent)
{
mControlElements = new CSVWidget::SceneToolToggle (parent,
"Controls & Guides Visibility", ":door.png");
mControlElements->addButton (":activator.png", Element_CellMarker, ":activator.png",
"Cell marker");
mControlElements->addButton (":armor.png", Element_CellArrow, ":armor.png", "Cell arrows");
mControlElements->addButton (":armor.png", Element_CellBorder, ":armor.png", "Cell border");
mControlElements->setSelection (0xffffffff);
connect (mControlElements, SIGNAL (selectionChanged()),
this, SLOT (elementSelectionChanged()));
return mControlElements;
}
void CSVRender::PagedWorldspaceWidget::cellDataChanged (const QModelIndex& topLeft,
const QModelIndex& bottomRight)
{

@ -18,6 +18,7 @@ namespace CSVRender
CSMWorld::CellSelection mSelection;
std::map<CSMWorld::CellCoordinates, Cell *> mCells;
std::string mWorldspace;
CSVWidget::SceneToolToggle *mControlElements;
private:
@ -58,6 +59,13 @@ namespace CSVRender
virtual dropRequirments getDropRequirements(dropType type) const;
/// \attention The created tool is not added to the toolbar (via addTool). Doing
/// that is the responsibility of the calling function.
virtual CSVWidget::SceneToolToggle *makeControlVisibilitySelector (
CSVWidget::SceneToolbar *parent);
virtual unsigned int getElementMask() const;
signals:
void cellSelectionChanged (const CSMWorld::CellSelection& selection);

@ -126,7 +126,9 @@ namespace CSVRender
#endif
mWindow = Ogre::Root::getSingleton().createRenderWindow(windowTitle.str(), this->width(), this->height(), false, &params);
mWindow->addViewport(mCamera)->setBackgroundColour(Ogre::ColourValue(0.3,0.3,0.3,1));
mViewport = mWindow->addViewport (mCamera);
mViewport->setBackgroundColour (Ogre::ColourValue (0.3,0.3,0.3,1));
Ogre::Real aspectRatio = Ogre::Real(width()) / Ogre::Real(height());
mCamera->setAspectRatio(aspectRatio);
@ -141,6 +143,11 @@ namespace CSVRender
Ogre::Root::getSingleton().destroySceneManager (mSceneMgr);
}
void SceneWidget::setVisibilityMask (unsigned int mask)
{
mViewport->setVisibilityMask (mask);
}
void SceneWidget::setNavigation (Navigation *navigation)
{
if ((mNavigation = navigation))

@ -14,6 +14,7 @@ namespace Ogre
class Camera;
class SceneManager;
class RenderWindow;
class Viewport;
}
namespace CSVWidget
@ -42,6 +43,8 @@ namespace CSVRender
///< \attention The created tool is not added to the toolbar (via addTool). Doing that
/// is the responsibility of the calling function.
virtual void setVisibilityMask (unsigned int mask);
protected:
void setNavigation (Navigation *navigation);
@ -85,6 +88,7 @@ namespace CSVRender
Ogre::Camera* mCamera;
Ogre::SceneManager* mSceneMgr;
Ogre::RenderWindow* mWindow;
Ogre::Viewport *mViewport;
Navigation *mNavigation;
Lighting *mLighting;

@ -11,6 +11,10 @@
#include "../../model/world/idtable.hpp"
#include "../../model/world/tablemimedata.hpp"
#include "../widget/scenetooltoggle.hpp"
#include "elements.hpp"
void CSVRender::UnpagedWorldspaceWidget::update()
{
const CSMWorld::Record<CSMWorld::Cell>& record =
@ -25,6 +29,14 @@ void CSVRender::UnpagedWorldspaceWidget::update()
flagAsModified();
}
void CSVRender::UnpagedWorldspaceWidget::addVisibilitySelectorButtons (
CSVWidget::SceneToolToggle *tool)
{
WorldspaceWidget::addVisibilitySelectorButtons (tool);
tool->addButton (":armor.png", Element_Fog, ":armor.png", "Fog");
}
CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget (const std::string& cellId, CSMDoc::Document& document, QWidget* parent)
: WorldspaceWidget (document, parent), mCellId (cellId)
{

@ -32,6 +32,10 @@ namespace CSVRender
void update();
protected:
virtual void addVisibilitySelectorButtons (CSVWidget::SceneToolToggle *tool);
public:
UnpagedWorldspaceWidget (const std::string& cellId, CSMDoc::Document& document,

@ -10,6 +10,9 @@
#include "../../model/world/universalid.hpp"
#include "../widget/scenetoolmode.hpp"
#include "../widget/scenetooltoggle.hpp"
#include "elements.hpp"
CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidget* parent)
: SceneWidget (parent), mDocument(document)
@ -94,6 +97,21 @@ CSVWidget::SceneToolMode *CSVRender::WorldspaceWidget::makeNavigationSelector (
return tool;
}
CSVWidget::SceneToolToggle *CSVRender::WorldspaceWidget::makeSceneVisibilitySelector (CSVWidget::SceneToolbar *parent)
{
mSceneElements= new CSVWidget::SceneToolToggle (parent,
"Scene Element Visibility", ":door.png");
addVisibilitySelectorButtons (mSceneElements);
mSceneElements->setSelection (0xffffffff);
connect (mSceneElements, SIGNAL (selectionChanged()),
this, SLOT (elementSelectionChanged()));
return mSceneElements;
}
CSVRender::WorldspaceWidget::dropType CSVRender::WorldspaceWidget::getDropType (
const std::vector< CSMWorld::UniversalId >& data)
{
@ -147,6 +165,20 @@ CSVRender::WorldspaceWidget::dropType CSVRender::WorldspaceWidget::getDropType (
return output;
}
unsigned int CSVRender::WorldspaceWidget::getElementMask() const
{
return mSceneElements->getSelection();
}
void CSVRender::WorldspaceWidget::addVisibilitySelectorButtons (
CSVWidget::SceneToolToggle *tool)
{
tool->addButton (":activator.png", Element_Reference, ":activator.png", "References");
tool->addButton (":armor.png", Element_Terrain, ":armor.png", "Terrain");
tool->addButton (":armor.png", Element_Water, ":armor.png", "Water");
tool->addButton (":armor.png", Element_Pathgrid, ":armor.png", "Pathgrid");
}
void CSVRender::WorldspaceWidget::dragEnterEvent (QDragEnterEvent* event)
{
event->accept();
@ -157,7 +189,6 @@ void CSVRender::WorldspaceWidget::dragMoveEvent(QDragMoveEvent *event)
event->accept();
}
void CSVRender::WorldspaceWidget::dropEvent (QDropEvent* event)
{
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
@ -169,3 +200,9 @@ void CSVRender::WorldspaceWidget::dropEvent (QDropEvent* event)
emit dataDropped(mime->getData());
} //not handling drops from different documents at the moment
}
void CSVRender::WorldspaceWidget::elementSelectionChanged()
{
setVisibilityMask (getElementMask());
flagAsModified();
}

@ -16,6 +16,7 @@ namespace CSMWorld
namespace CSVWidget
{
class SceneToolMode;
class SceneToolToggle;
class SceneToolbar;
}
@ -28,6 +29,7 @@ namespace CSVRender
CSVRender::Navigation1st m1st;
CSVRender::NavigationFree mFree;
CSVRender::NavigationOrbit mOrbit;
CSVWidget::SceneToolToggle *mSceneElements;
public:
@ -53,6 +55,11 @@ namespace CSVRender
///< \attention The created tool is not added to the toolbar (via addTool). Doing that
/// is the responsibility of the calling function.
/// \attention The created tool is not added to the toolbar (via addTool). Doing
/// that is the responsibility of the calling function.
CSVWidget::SceneToolToggle *makeSceneVisibilitySelector (
CSVWidget::SceneToolbar *parent);
void selectDefaultNavigationMode();
static dropType getDropType(const std::vector<CSMWorld::UniversalId>& data);
@ -64,8 +71,13 @@ namespace CSVRender
virtual void handleDrop(const std::vector<CSMWorld::UniversalId>& data) = 0;
virtual unsigned int getElementMask() const;
protected:
const CSMDoc::Document& mDocument; //for checking if drop comes from same document
virtual void addVisibilitySelectorButtons (CSVWidget::SceneToolToggle *tool);
const CSMDoc::Document& mDocument;
private:
@ -92,6 +104,10 @@ namespace CSVRender
virtual void referenceAdded (const QModelIndex& index, int start, int end) = 0;
protected slots:
void elementSelectionChanged();
signals:
void closeRequest();

@ -26,6 +26,14 @@ void CSVWidget::PushButton::setExtendedToolTip (const QString& text)
"<p>(left click to activate,"
"<br>shift-left click to activate and keep panel open)";
case Type_Toggle:
tooltip += "<p>(left click to ";
tooltip += isChecked() ? "disable" : "enable";
tooltip += "<p>shift-left click to ";
tooltip += isChecked() ? "disable" : "enable";
tooltip += " and keep panel open)";
break;
}
@ -45,6 +53,9 @@ void CSVWidget::PushButton::keyReleaseEvent (QKeyEvent *event)
if (event->key()==Qt::Key_Return || event->key()==Qt::Key_Enter)
{
mKeepOpen = event->modifiers() & Qt::ShiftModifier;
setChecked (!isChecked());
emit clicked();
}
@ -61,14 +72,14 @@ CSVWidget::PushButton::PushButton (const QIcon& icon, Type type, const QString&
QWidget *parent)
: QPushButton (icon, "", parent), mKeepOpen (false), mType (type), mToolTip (tooltip)
{
setCheckable (type==Type_Mode);
setCheckable (type==Type_Mode || type==Type_Toggle);
setExtendedToolTip (tooltip);
}
CSVWidget::PushButton::PushButton (Type type, const QString& tooltip, QWidget *parent)
: QPushButton (parent), mKeepOpen (false), mType (type), mToolTip (tooltip)
{
setCheckable (type==Type_Mode);
setCheckable (type==Type_Mode || type==Type_Toggle);
setExtendedToolTip (tooltip);
}

@ -14,7 +14,8 @@ namespace CSVWidget
enum Type
{
Type_TopMode, // top level button for mode selector panel
Type_Mode // mode button
Type_Mode, // mode button
Type_Toggle
};
private:

@ -0,0 +1,205 @@
#include "scenetooltoggle.hpp"
#include <stdexcept>
#include <QHBoxLayout>
#include <QFrame>
#include <QIcon>
#include <QPainter>
#include "scenetoolbar.hpp"
#include "pushbutton.hpp"
void CSVWidget::SceneToolToggle::adjustToolTip()
{
QString toolTip = mToolTip;
toolTip += "<p>Currently enabled: ";
bool first = true;
for (std::map<PushButton *, ButtonDesc>::const_iterator iter (mButtons.begin());
iter!=mButtons.end(); ++iter)
if (iter->first->isChecked())
{
if (!first)
toolTip += ", ";
else
first = false;
toolTip += iter->second.mName;
}
if (first)
toolTip += "none";
toolTip += "<p>(left click to alter selection)";
setToolTip (toolTip);
}
void CSVWidget::SceneToolToggle::adjustIcon()
{
unsigned int selection = getSelection();
if (!selection)
setIcon (QIcon (QString::fromUtf8 (mEmptyIcon.c_str())));
else
{
QPixmap pixmap (48, 48);
pixmap.fill (QColor (0, 0, 0, 0));
{
QPainter painter (&pixmap);
for (std::map<PushButton *, ButtonDesc>::const_iterator iter (mButtons.begin());
iter!=mButtons.end(); ++iter)
if (iter->first->isChecked())
{
painter.drawImage (getIconBox (iter->second.mIndex),
QImage (QString::fromUtf8 (iter->second.mSmallIcon.c_str())));
}
}
setIcon (pixmap);
}
}
QRect CSVWidget::SceneToolToggle::getIconBox (int index) const
{
// layout for a 3x3 grid
int xMax = 3;
int yMax = 3;
// icon size
int xBorder = 1;
int yBorder = 1;
int iconXSize = (mIconSize-xBorder*(xMax+1))/xMax;
int iconYSize = (mIconSize-yBorder*(yMax+1))/yMax;
int y = index / xMax;
int x = index % xMax;
int total = mButtons.size();
int actualYIcons = total/xMax;
if (total % xMax)
++actualYIcons;
if (actualYIcons!=yMax)
{
// space out icons vertically, if there aren't enough to populate all rows
int diff = yMax - actualYIcons;
yBorder += (diff*(yBorder+iconXSize)) / (actualYIcons+1);
}
if (y==actualYIcons-1)
{
// generating the last row of icons
int actualXIcons = total % xMax;
if (actualXIcons)
{
// space out icons horizontally, if there aren't enough to fill the last row
int diff = xMax - actualXIcons;
xBorder += (diff*(xBorder+iconXSize)) / (actualXIcons+1);
}
}
return QRect ((iconXSize+xBorder)*x+xBorder, (iconYSize+yBorder)*y+yBorder,
iconXSize, iconYSize);
}
CSVWidget::SceneToolToggle::SceneToolToggle (SceneToolbar *parent, const QString& toolTip,
const std::string& emptyIcon)
: SceneTool (parent), mEmptyIcon (emptyIcon), mButtonSize (parent->getButtonSize()),
mIconSize (parent->getIconSize()), mToolTip (toolTip), mFirst (0)
{
mPanel = new QFrame (this, Qt::Popup);
mLayout = new QHBoxLayout (mPanel);
mLayout->setContentsMargins (QMargins (0, 0, 0, 0));
mPanel->setLayout (mLayout);
}
void CSVWidget::SceneToolToggle::showPanel (const QPoint& position)
{
mPanel->move (position);
mPanel->show();
if (mFirst)
mFirst->setFocus (Qt::OtherFocusReason);
}
void CSVWidget::SceneToolToggle::addButton (const std::string& icon, unsigned int id,
const std::string& smallIcon, const QString& name, const QString& tooltip)
{
if (mButtons.size()>=9)
throw std::runtime_error ("Exceeded number of buttons in toggle type tool");
PushButton *button = new PushButton (QIcon (QPixmap (icon.c_str())),
PushButton::Type_Toggle, tooltip.isEmpty() ? name: tooltip, mPanel);
button->setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed));
button->setIconSize (QSize (mIconSize, mIconSize));
button->setFixedSize (mButtonSize, mButtonSize);
mLayout->addWidget (button);
ButtonDesc desc;
desc.mId = id;
desc.mSmallIcon = smallIcon;
desc.mName = name;
desc.mIndex = mButtons.size();
mButtons.insert (std::make_pair (button, desc));
connect (button, SIGNAL (clicked()), this, SLOT (selected()));
if (mButtons.size()==1)
mFirst = button;
}
unsigned int CSVWidget::SceneToolToggle::getSelection() const
{
unsigned int selection = 0;
for (std::map<PushButton *, ButtonDesc>::const_iterator iter (mButtons.begin());
iter!=mButtons.end(); ++iter)
if (iter->first->isChecked())
selection |= iter->second.mId;
return selection;
}
void CSVWidget::SceneToolToggle::setSelection (unsigned int selection)
{
for (std::map<PushButton *, ButtonDesc>::iterator iter (mButtons.begin());
iter!=mButtons.end(); ++iter)
iter->first->setChecked (selection & iter->second.mId);
adjustToolTip();
adjustIcon();
}
void CSVWidget::SceneToolToggle::selected()
{
std::map<PushButton *, ButtonDesc>::const_iterator iter =
mButtons.find (dynamic_cast<PushButton *> (sender()));
if (iter!=mButtons.end())
{
if (!iter->first->hasKeepOpen())
mPanel->hide();
adjustToolTip();
adjustIcon();
emit selectionChanged();
}
}

@ -0,0 +1,75 @@
#ifndef CSV_WIDGET_SCENETOOL_TOGGLE_H
#define CSV_WIDGET_SCENETOOL_TOGGLE_H
#include "scenetool.hpp"
#include <map>
class QHBoxLayout;
class QRect;
namespace CSVWidget
{
class SceneToolbar;
class PushButton;
///< \brief Multi-Toggle tool
class SceneToolToggle : public SceneTool
{
Q_OBJECT
struct ButtonDesc
{
unsigned int mId;
std::string mSmallIcon;
QString mName;
int mIndex;
};
std::string mEmptyIcon;
QWidget *mPanel;
QHBoxLayout *mLayout;
std::map<PushButton *, ButtonDesc> mButtons; // widget, id
int mButtonSize;
int mIconSize;
QString mToolTip;
PushButton *mFirst;
void adjustToolTip();
void adjustIcon();
QRect getIconBox (int index) const;
public:
SceneToolToggle (SceneToolbar *parent, const QString& toolTip,
const std::string& emptyIcon);
virtual void showPanel (const QPoint& position);
/// \attention After the last button has been added, setSelection must be called at
/// least once to finalise the layout.
///
/// \note The layout algorithm can not handle more than 9 buttons. To prevent this An
/// attempt to add more will result in an exception being thrown.
/// The small icons will be sized at (x-4)/3 (where x is the main icon size).
void addButton (const std::string& icon, unsigned int id,
const std::string& smallIcon, const QString& name, const QString& tooltip = "");
unsigned int getSelection() const;
/// \param or'ed button IDs. IDs that do not exist will be ignored.
void setSelection (unsigned int selection);
signals:
void selectionChanged();
private slots:
void selected();
};
}
#endif

@ -19,6 +19,7 @@
#include "../widget/scenetoolbar.hpp"
#include "../widget/scenetoolmode.hpp"
#include "../widget/scenetooltoggle.hpp"
#include "tablebottombox.hpp"
#include "creator.hpp"
@ -107,18 +108,19 @@ CSVWidget::SceneToolbar* CSVWorld::SceneSubView::makeToolbar (CSVRender::Worldsp
CSVWidget::SceneToolMode *lightingTool = widget->makeLightingSelector (toolbar);
toolbar->addTool (lightingTool);
/* Add buttons specific to the type. For now no need for it.
*
switch (type)
{
case widget_Paged:
break;
CSVWidget::SceneToolToggle *sceneVisibilityTool =
widget->makeSceneVisibilitySelector (toolbar);
toolbar->addTool (sceneVisibilityTool);
case widget_Unpaged:
break;
if (type==widget_Paged)
{
CSVWidget::SceneToolToggle *controlVisibilityTool =
dynamic_cast<CSVRender::PagedWorldspaceWidget&> (*widget).
makeControlVisibilitySelector (toolbar);
toolbar->addTool (controlVisibilityTool);
}
*/
return toolbar;
}

@ -115,6 +115,24 @@ ObjectScene::~ObjectScene()
mSkelBase = NULL;
}
void ObjectScene::setVisibilityFlags (unsigned int flags)
{
if (mSkelBase)
mSkelBase->setVisibilityFlags (flags);
for (std::vector<Ogre::Entity*>::iterator iter (mEntities.begin()); iter!=mEntities.end();
++iter)
(*iter)->setVisibilityFlags (flags);
for (std::vector<Ogre::ParticleSystem*>::iterator iter (mParticles.begin());
iter!=mParticles.end(); ++iter)
(*iter)->setVisibilityFlags (flags);
for (std::vector<Ogre::Light*>::iterator iter (mLights.begin()); iter!=mLights.end();
++iter)
(*iter)->setVisibilityFlags (flags);
}
void ObjectScene::rotateBillboardNodes(Ogre::Camera *camera)
{
for (std::vector<Ogre::Node*>::iterator it = mBillboardNodes.begin(); it != mBillboardNodes.end(); ++it)

@ -82,6 +82,8 @@ struct ObjectScene {
// Rotate nodes in mBillboardNodes so they face the given camera
void rotateBillboardNodes(Ogre::Camera* camera);
void setVisibilityFlags (unsigned int flags);
};
typedef Ogre::SharedPtr<ObjectScene> ObjectScenePtr;

Loading…
Cancel
Save