Commit 2c1c78d4 authored by chili's avatar chili
Browse files

extended node tree w/ selection

parent 143981dc
...@@ -65,14 +65,22 @@ void Node::AddChild( std::unique_ptr<Node> pChild ) noxnd ...@@ -65,14 +65,22 @@ void Node::AddChild( std::unique_ptr<Node> pChild ) noxnd
childPtrs.push_back( std::move( pChild ) ); childPtrs.push_back( std::move( pChild ) );
} }
void Node::ShowTree() const noexcept void Node::ShowTree( int& nodeIndexTracked,std::optional<int>& selectedIndex ) const noexcept
{ {
// nodeIndex serves as the uid for gui tree nodes, incremented throughout recursion
const int currentNodeIndex = nodeIndexTracked;
nodeIndexTracked++;
// build up flags for current node
const auto node_flags = ImGuiTreeNodeFlags_OpenOnArrow
| ((currentNodeIndex == selectedIndex.value_or( -1 )) ? ImGuiTreeNodeFlags_Selected : 0)
| ((childPtrs.size() == 0) ? ImGuiTreeNodeFlags_Leaf : 0);
// if tree node expanded, recursively render all children // if tree node expanded, recursively render all children
if( ImGui::TreeNode( name.c_str() ) ) if( ImGui::TreeNodeEx( (void*)(intptr_t)currentNodeIndex,node_flags,name.c_str() ) )
{ {
selectedIndex = ImGui::IsItemClicked() ? currentNodeIndex : selectedIndex;
for( const auto& pChild : childPtrs ) for( const auto& pChild : childPtrs )
{ {
pChild->ShowTree(); pChild->ShowTree( nodeIndexTracked,selectedIndex );
} }
ImGui::TreePop(); ImGui::TreePop();
} }
...@@ -87,10 +95,12 @@ public: ...@@ -87,10 +95,12 @@ public:
{ {
// window name defaults to "Model" // window name defaults to "Model"
windowName = windowName ? windowName : "Model"; windowName = windowName ? windowName : "Model";
// need an ints to track node indices and selected node
int nodeIndexTracker = 0;
if( ImGui::Begin( windowName ) ) if( ImGui::Begin( windowName ) )
{ {
ImGui::Columns( 2,nullptr,true ); ImGui::Columns( 2,nullptr,true );
root.ShowTree(); root.ShowTree( nodeIndexTracker,selectedIndex );
ImGui::NextColumn(); ImGui::NextColumn();
ImGui::Text( "Orientation" ); ImGui::Text( "Orientation" );
...@@ -110,6 +120,7 @@ public: ...@@ -110,6 +120,7 @@ public:
dx::XMMatrixTranslation( pos.x,pos.y,pos.z ); dx::XMMatrixTranslation( pos.x,pos.y,pos.z );
} }
private: private:
std::optional<int> selectedIndex;
struct struct
{ {
float roll = 0.0f; float roll = 0.0f;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "DrawableBase.h" #include "DrawableBase.h"
#include "BindableCommon.h" #include "BindableCommon.h"
#include "Vertex.h" #include "Vertex.h"
#include <optional>
#include <assimp/Importer.hpp> #include <assimp/Importer.hpp>
#include <assimp/scene.h> #include <assimp/scene.h>
#include <assimp/postprocess.h> #include <assimp/postprocess.h>
...@@ -23,7 +24,7 @@ class Node ...@@ -23,7 +24,7 @@ class Node
public: public:
Node( const std::string& name,std::vector<Mesh*> meshPtrs,const DirectX::XMMATRIX& transform ) noxnd; Node( const std::string& name,std::vector<Mesh*> meshPtrs,const DirectX::XMMATRIX& transform ) noxnd;
void Draw( Graphics& gfx,DirectX::FXMMATRIX accumulatedTransform ) const noxnd; void Draw( Graphics& gfx,DirectX::FXMMATRIX accumulatedTransform ) const noxnd;
void ShowTree() const noexcept; void ShowTree( int& nodeIndex,std::optional<int>& selectedIndex ) const noexcept;
private: private:
void AddChild( std::unique_ptr<Node> pChild ) noxnd; void AddChild( std::unique_ptr<Node> pChild ) noxnd;
private: private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment