From a91efd73541993bd6e2359d5d6988a306fa20f73 Mon Sep 17 00:00:00 2001 From: Anselme Date: Thu, 19 Oct 2017 22:23:24 +0200 Subject: [PATCH] added more control over Gui widget's depth --- src/editor.cpp | 36 ++++++++++++++++++++------------ src/scene/gui/backgroundnode.cpp | 7 ++++++- src/scene/gui/backgroundnode.h | 2 ++ src/scene/gui/buttonnode.cpp | 3 +++ src/scene/gui/buttonshape.cpp | 2 +- src/scene/gui/buttonshape.h | 2 +- src/scene/gui/labelnode.h | 1 + src/scene/meshnode.cpp | 8 ++++++- src/scene/meshnode.h | 1 + 9 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/editor.cpp b/src/editor.cpp index 03117db..77b4eca 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -50,24 +50,34 @@ void Editor::update() void Editor::gui() { - ImGui::Begin("SparrowEditor", &m_editorEnabled); + if(ImGui::BeginMainMenuBar()) { - ImGui::Checkbox("Material editor", &m_materialEditorEnabled); + if(ImGui::BeginMenu("File")) + { + ImGui::MenuItem("Load scene"); + ImGui::EndMenu(); + } + if(ImGui::BeginMenu("Tools")) + { + ImGui::MenuItem("Material editor", NULL, &m_materialEditorEnabled); - DeferredPipeline* pipeline = dynamic_cast(m_scene->getPipeline()); - bool pipeline_gui_status = pipeline->isDebugGuiVisible(); - if(ImGui::Checkbox("Rendering pipeline debug gui", &pipeline_gui_status)) - pipeline->toggleDebugGui(); + DeferredPipeline* pipeline = dynamic_cast(m_scene->getPipeline()); + bool pipeline_gui_status = pipeline->isDebugGuiVisible(); + if(ImGui::MenuItem("Rendering pipeline debug gui", NULL, &pipeline_gui_status)) + pipeline->toggleDebugGui(); - bool resroucePackEditorStatus = m_editedResourcePack; - if(ImGui::Checkbox("Resource pack editor editor", &resroucePackEditorStatus)) - toggleResourcePackGui(); + bool resroucePackEditorStatus = m_editedResourcePack; + if(ImGui::MenuItem("Resource pack editor editor", NULL, &resroucePackEditorStatus)) + toggleResourcePackGui(); - bool pickerStatus = m_pickerEnabled; - if(ImGui::Checkbox("Picker", &pickerStatus)) - togglePicker(); + bool pickerStatus = m_pickerEnabled; + if(ImGui::MenuItem("Picker", NULL, &pickerStatus)) + togglePicker(); + + ImGui::EndMenu(); + } + ImGui::EndMainMenuBar(); } - ImGui::End(); } void Editor::materialGui() diff --git a/src/scene/gui/backgroundnode.cpp b/src/scene/gui/backgroundnode.cpp index 7358055..e646ff2 100644 --- a/src/scene/gui/backgroundnode.cpp +++ b/src/scene/gui/backgroundnode.cpp @@ -9,7 +9,7 @@ #include "SparrowRenderer/mesh.h" #include "SparrowRenderer/pbrmaterial.h" -BackGroundNode::BackGroundNode(glm::vec2 dimension, glm::vec3 color, float opacity,float depth): +BackGroundNode::BackGroundNode(glm::vec2 dimension, glm::vec3 color, float opacity, float depth): m_dimension(dimension), m_color(color), m_color_updated(false), @@ -52,6 +52,11 @@ void BackGroundNode::setOpacity(float opacity){ m_opacity_updated = true; } +void BackGroundNode::setDepth(float depth) +{ + m_mesh->setDepth(depth); +} + glm::vec2 BackGroundNode::getDimension(){ return m_dimension; } diff --git a/src/scene/gui/backgroundnode.h b/src/scene/gui/backgroundnode.h index 04d5ecf..062d56b 100644 --- a/src/scene/gui/backgroundnode.h +++ b/src/scene/gui/backgroundnode.h @@ -19,7 +19,9 @@ public: void update(); void setColor(glm::vec3 color); void setOpacity(float opacity); + void setDepth(float depth); glm::vec2 getDimension(); + MeshNode* getMeshNode() { return m_mesh; } }; diff --git a/src/scene/gui/buttonnode.cpp b/src/scene/gui/buttonnode.cpp index 90e3931..16fbef6 100644 --- a/src/scene/gui/buttonnode.cpp +++ b/src/scene/gui/buttonnode.cpp @@ -43,6 +43,9 @@ void ButtonNode::update() if(m_label->wasUpdated()){ m_label->setPosition(m_shape->getDimension()/glm::vec2(2,2) - m_label->getDimension()/glm::vec2(2,2)); + // make sure the label is in front of the button background + if(m_label->getTextNode() != nullptr) + m_label->getTextNode()->setDepth(m_shape->getBackGround()->getMeshNode()->getDepth() + 0.1f); } for (auto action : input->getActions()) diff --git a/src/scene/gui/buttonshape.cpp b/src/scene/gui/buttonshape.cpp index 2902b1b..af241c5 100644 --- a/src/scene/gui/buttonshape.cpp +++ b/src/scene/gui/buttonshape.cpp @@ -4,7 +4,7 @@ RectangleButtonShape::RectangleButtonShape(glm::vec2 dimension):ButtonShape(),m_dimension(dimension) { - m_background = new BackGroundNode(dimension,glm::vec3(1.,1.,1.),1,0); + m_background = new BackGroundNode(dimension, glm::vec3(1.,1.,1.), 1, 5); } bool RectangleButtonShape::hover(glm::vec2 button_position, glm::vec2 mouse_position){ diff --git a/src/scene/gui/buttonshape.h b/src/scene/gui/buttonshape.h index e66cf2e..563204c 100644 --- a/src/scene/gui/buttonshape.h +++ b/src/scene/gui/buttonshape.h @@ -20,7 +20,7 @@ public: virtual glm::vec2 getDimension() = 0; }; -class RectangleButtonShape:public ButtonShape +class RectangleButtonShape : public ButtonShape { glm::vec2 m_dimension; public: diff --git a/src/scene/gui/labelnode.h b/src/scene/gui/labelnode.h index 24be51d..40fe519 100644 --- a/src/scene/gui/labelnode.h +++ b/src/scene/gui/labelnode.h @@ -20,6 +20,7 @@ public: void setColor(glm::vec3 color); glm::vec2 getDimension(); bool wasUpdated(); + TextNode* getTextNode() { return m_text; } }; #endif // LABELNODE_H diff --git a/src/scene/meshnode.cpp b/src/scene/meshnode.cpp index cd40531..2444888 100644 --- a/src/scene/meshnode.cpp +++ b/src/scene/meshnode.cpp @@ -13,7 +13,13 @@ void MeshNode::setSceneTree(SceneTree *tree) m_scene->registerMeshType(m_geometry.mesh->getFlags()); } -void MeshNode::setDepth(float depth){ +float MeshNode::getDepth() +{ + return m_geometry.mesh->getDepth(); +} + +void MeshNode::setDepth(float depth) +{ m_geometry.mesh->setDepth(depth); } diff --git a/src/scene/meshnode.h b/src/scene/meshnode.h index e1aeae6..2cf01fa 100644 --- a/src/scene/meshnode.h +++ b/src/scene/meshnode.h @@ -30,6 +30,7 @@ public: virtual void update(); + float getDepth(); void setDepth(float depth); virtual GeometryNode* getGeometryNode() { return &m_geometry; }