Skip to content

Commit

Permalink
Templatize GtkInspector on the scenegraph object type
Browse files Browse the repository at this point in the history
  • Loading branch information
wivlaro committed Jan 18, 2015
1 parent 3046dee commit 8f3021b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 34 deletions.
30 changes: 20 additions & 10 deletions GtkInspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
#include "Inspector.h"
#include "Inspectable.h"
#include "GtkAbstractInspector.h"
#include <Magnum/SceneGraph/AbstractObject.h>

namespace MagnumInspector {

typedef Magnum::SceneGraph::Object<Magnum::SceneGraph::MatrixTransformation3D> Object3D;
typedef Magnum::SceneGraph::Object<Magnum::SceneGraph::MatrixTransformation2D> Object2D;

class GtkInspectorNode;

template<class SceneGraphObject>
class GtkInspector : public GtkAbstractInspector
{
public:
Expand All @@ -29,14 +28,25 @@ class GtkInspector : public GtkAbstractInspector

void init();

bool update(Object3D* node);
bool update(SceneGraphObject* node);

bool refreshNextFrame;

protected:
Glib::ustring getNodeName(Object3D& node);
Glib::ustring getNodeName(SceneGraphObject& node);

private:

class MyModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
Gtk::TreeModelColumn<Glib::ustring> name;
Gtk::TreeModelColumn<SceneGraphObject*> pointer;
MyModelColumns() { add(name); add(pointer); }
};

MyModelColumns columns;

Gtk::Main* gtkMain;
Gtk::Window* window;

Expand All @@ -47,14 +57,14 @@ class GtkInspector : public GtkAbstractInspector
Gtk::TreeView* treeView;
Glib::RefPtr<Gtk::TreeStore> treeStore;
Gtk::Box* detailsPane;
Object3D* detailNode;
SceneGraphObject* detailNode;
Gtk::Label* detailNodeLabel;

void updateChildren(Object3D& node, const Gtk::TreeNodeChildren& children);
void updateNode(Object3D& node, const Gtk::TreeRow& row);
void updateChildren(SceneGraphObject& node, const Gtk::TreeNodeChildren& children);
void updateNode(SceneGraphObject& node, const Gtk::TreeRow& row);

void setRoot(Object3D* node);
void setupDetails(Object3D* node);
void setRoot(SceneGraphObject* node);
void setupDetails(SceneGraphObject* node);
void updateDetailNode();
void addInspectableFields(Gtk::Box* box, MagnumInspector::Inspectable* arg2);

Expand Down
43 changes: 21 additions & 22 deletions GtkInspector.cpp → GtkInspector.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

#pragma once

#include "GtkInspector.h"

#include <gtkmm/box.h>
Expand All @@ -20,19 +23,9 @@


namespace MagnumInspector {

class MyModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
Gtk::TreeModelColumn<Glib::ustring> name;
Gtk::TreeModelColumn<Object3D*> pointer;
MyModelColumns() { add(name); add(pointer); }
};

MyModelColumns columns;


GtkInspector::GtkInspector()
template <class SceneGraphObject>
GtkInspector<SceneGraphObject>::GtkInspector()
: refreshNextFrame(true)
, gtkMain(nullptr)
, window(nullptr)
Expand All @@ -45,17 +38,17 @@ GtkInspector::GtkInspector()

}

GtkInspector::~GtkInspector()
template <class SceneGraphObject>
GtkInspector<SceneGraphObject>::~GtkInspector()
{
std::cout << "GtkInspector::~GtkInspector\n";

delete window;
delete gtkMain;
}



void GtkInspector::init()
template <class SceneGraphObject>
void GtkInspector<SceneGraphObject>::init()
{
std::cout << "GtkInspector::init\n";
gtkMain = new Gtk::Main();
Expand Down Expand Up @@ -101,7 +94,8 @@ void GtkInspector::init()
window->show_all();
}

void GtkInspector::setupDetails(Object3D* node)
template <class SceneGraphObject>
void GtkInspector<SceneGraphObject>::setupDetails(SceneGraphObject* node)
{
detailNode = node;

Expand All @@ -119,7 +113,8 @@ void GtkInspector::setupDetails(Object3D* node)
// detailsPane->show_all();
}

void GtkInspector::setRoot(Object3D* node)
template <class SceneGraphObject>
void GtkInspector<SceneGraphObject>::setRoot(SceneGraphObject* node)
{
if (node) {
updateChildren(*node, treeStore->children());
Expand All @@ -129,7 +124,8 @@ void GtkInspector::setRoot(Object3D* node)
}
}

void GtkInspector::updateChildren(Object3D& node, const Gtk::TreeNodeChildren& dstChildren)
template <class SceneGraphObject>
void GtkInspector<SceneGraphObject>::updateChildren(SceneGraphObject& node, const Gtk::TreeNodeChildren& dstChildren)
{
auto dstIt = dstChildren.begin();
for (auto srcChild = node.children().first(); srcChild; srcChild = srcChild->nextSibling()) {
Expand All @@ -144,7 +140,8 @@ void GtkInspector::updateChildren(Object3D& node, const Gtk::TreeNodeChildren& d
}
}

Glib::ustring GtkInspector::getNodeName(Object3D& node)
template <class SceneGraphObject>
Glib::ustring GtkInspector<SceneGraphObject>::getNodeName(SceneGraphObject& node)
{
std::string name;
auto entity = dynamic_cast<Inspectable*>(&node);
Expand All @@ -158,7 +155,8 @@ Glib::ustring GtkInspector::getNodeName(Object3D& node)
}


void GtkInspector::updateNode(Object3D& node, const Gtk::TreeRow& row)
template <class SceneGraphObject>
void GtkInspector<SceneGraphObject>::updateNode(SceneGraphObject& node, const Gtk::TreeRow& row)
{
if (row.get_value(columns.pointer) != &node || updateNamesToggle->get_active()) {
row.set_value(columns.name, getNodeName(node));
Expand All @@ -174,7 +172,8 @@ void GtkInspector::updateNode(Object3D& node, const Gtk::TreeRow& row)



bool GtkInspector::update(Object3D* node)
template <class SceneGraphObject>
bool GtkInspector<SceneGraphObject>::update(SceneGraphObject* node)
{
// std::cout << "GtkInspector::update\n";
if (autoRefreshToggle->get_active() || refreshNextFrame) {
Expand Down
2 changes: 1 addition & 1 deletion forwarddeclarations.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

namespace MagnumInspector {
class GtkInspector;
template<class SceneGraphObject> class GtkInspector;
}
1 change: 0 additions & 1 deletion inspector.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ link_directories(${GTK3_LIBRARY_DIRS})

set(MAGNUMINSPECTOR_SOURCE_PREFIX ${CMAKE_CURRENT_LIST_DIR})
set(MAGNUMINSPECTOR_SOURCES
${MAGNUMINSPECTOR_SOURCE_PREFIX}/GtkInspector.cpp
${MAGNUMINSPECTOR_SOURCE_PREFIX}/GtkAbstractInspector.cpp
${MAGNUMINSPECTOR_SOURCE_PREFIX}/GtkChildPopulator.cpp
${MAGNUMINSPECTOR_SOURCE_PREFIX}/GtkInspectionField.cpp
Expand Down

0 comments on commit 8f3021b

Please sign in to comment.