From d8c4505ed854a0c07a81d8ebdf8401a773571ae0 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Thu, 16 Feb 2017 19:57:51 +0100 Subject: [PATCH] phantom button --- doc/sceneClasses.graphml | 481 ++++++++++++++++++++++++------ src/engine.cpp | 3 - src/scene/gui/backgroundnode.cpp | 36 ++- src/scene/gui/backgroundnode.h | 19 +- src/scene/gui/buttonnode.cpp | 5 +- src/scene/gui/buttonnode.h | 3 +- src/scene/gui/buttonshape.cpp | 4 +- src/scene/gui/buttonshape.h | 7 +- src/sparrowshell/sparrowshell.cpp | 2 +- src/test/main.cpp | 3 +- 10 files changed, 452 insertions(+), 111 deletions(-) diff --git a/doc/sceneClasses.graphml b/doc/sceneClasses.graphml index d0394aa..734066d 100644 --- a/doc/sceneClasses.graphml +++ b/doc/sceneClasses.graphml @@ -15,10 +15,9 @@ - - + SceneNode @@ -33,10 +32,9 @@ - - + GraphicNode @@ -51,13 +49,12 @@ - - + - GraphicContainerNode + GraphicContainerNode @@ -69,10 +66,9 @@ - - + ContainerNode @@ -87,10 +83,9 @@ - - + MeshNode @@ -105,10 +100,9 @@ - - + LightNode @@ -123,10 +117,9 @@ - - + CameraNode @@ -140,23 +133,145 @@ - + + + + + + + TextNode + + + + + + + + + + + + + + + + + + LabelNode + + + + + + + + + + + + + + + + + + GUINode + + + + + + + + + + + + + + + + + + ButtonNode + + + + + + + + + + + + + + + + + BackGroundNode + + + + + + + + + + + + + + + + + ScrollBarNode + + + + + + + + + + + + + + + + + ButtonShape + + + + + + + + + + + - + - Legend + Legend - + - + Folder 1 @@ -168,12 +283,11 @@ - - - + + - + A @@ -187,11 +301,10 @@ - - + - + B @@ -205,11 +318,10 @@ - - + - + B inherits A @@ -223,11 +335,10 @@ - - + - + A @@ -241,11 +352,10 @@ - - + - + B @@ -259,11 +369,10 @@ - - + - + A can contain instances of B @@ -277,31 +386,66 @@ + + + + + + + A + + + + + + + + + + + + + + + + + B + + + + + + + + + + + + + + + + + A contain one instance of B + + + + + + + + + + - - - - - - - - TextNode - - - - - - - - - - - - + + + + @@ -309,10 +453,9 @@ - - + @@ -320,10 +463,12 @@ - - + + + + @@ -331,10 +476,12 @@ - - + + + + @@ -342,22 +489,92 @@ - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -365,12 +582,58 @@ - - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -378,41 +641,53 @@ - - + - + + + + - - + - - - - - - - - - - - - + - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -422,6 +697,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/engine.cpp b/src/engine.cpp index 2d57bfd..22f7318 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -138,14 +138,11 @@ void Engine::setScene(std::string scene) { previous_scene->removeFromIndex(m_physicsDebugNode); new_scene->addToIndex(m_physicsDebugNode); -// m_scene->removeFromIndex(m_physicsDebugNode); -// scene->addToIndex(m_physicsDebugNode); } previous_scene->getRootObject()->removeChild(m_sparrowshell); m_renderer->setScene(new_scene); m_renderer->resizeGL(m_window->getSize().x, m_window->getSize().y); - // m_sparrowshell->setSceneTree(new_scene); new_scene->getRootObject()->addChild(m_sparrowshell); new_scene->updateShaders(); } diff --git a/src/scene/gui/backgroundnode.cpp b/src/scene/gui/backgroundnode.cpp index e31a1b8..f594b02 100644 --- a/src/scene/gui/backgroundnode.cpp +++ b/src/scene/gui/backgroundnode.cpp @@ -6,8 +6,10 @@ #include "SparrowRenderer/mesh.h" #include "SparrowRenderer/phongmaterial.h" -BackGroundNode::BackGroundNode(glm::vec2 dimension, glm::vec3 color, float opacity,float depth,bool visible): - MeshNode(nullptr,visible) +BackGroundNode::BackGroundNode(glm::vec2 dimension, glm::vec3 color, float opacity,float depth): + m_dimension(dimension), + m_color(color), + m_opacity(opacity) { Mesh* mesh = new Mesh(); mesh->addRectangle2D(glm::vec2(0),dimension); @@ -17,5 +19,33 @@ BackGroundNode::BackGroundNode(glm::vec2 dimension, glm::vec3 color, float opaci mesh->setMaterial(mat); mesh->setDepth(depth); mesh->initGL(); - m_geometry.mesh = mesh; + m_mesh = new MeshNode(mesh,false); +} + +void BackGroundNode::update(){ + if(m_color_updated){ + PhongMaterial* mat = (PhongMaterial*) m_mesh->getGeometryNode()->mesh->getMaterial(); + mat->diffuse = m_color; + m_color_updated = false; + } + if(m_opacity_updated){ + PhongMaterial* mat = (PhongMaterial*) m_mesh->getGeometryNode()->mesh->getMaterial(); + mat->m_opacity = m_opacity; + m_opacity_updated = false; + } + GUINode::update(); +} + +void BackGroundNode::setColor(glm::vec3 color){ + m_color = color; + m_color_updated = true; +} + +void BackGroundNode::setOpacity(float opacity){ + m_opacity = opacity; + m_opacity_updated = true; +} + +glm::vec2 BackGroundNode::getDimension(){ + return m_dimension; } diff --git a/src/scene/gui/backgroundnode.h b/src/scene/gui/backgroundnode.h index 358c49b..04d5ecf 100644 --- a/src/scene/gui/backgroundnode.h +++ b/src/scene/gui/backgroundnode.h @@ -1,12 +1,27 @@ #ifndef BACKGROUNDNODE_H #define BACKGROUNDNODE_H +#include "scene/gui/guinode.h" + #include "scene/meshnode.h" -class BackGroundNode : public MeshNode +class BackGroundNode : public GUINode { +protected: + MeshNode* m_mesh; + glm::vec2 m_dimension; + glm::vec3 m_color; + bool m_color_updated; + float m_opacity; + bool m_opacity_updated; public: - BackGroundNode(glm::vec2 dimension, glm::vec3 color, float opacity,float depth,bool visible=true); + BackGroundNode(glm::vec2 dimension, glm::vec3 color, float opacity,float depth); + void update(); + void setColor(glm::vec3 color); + void setOpacity(float opacity); + glm::vec2 getDimension(); }; + + #endif // BACKGROUNDNODE_H diff --git a/src/scene/gui/buttonnode.cpp b/src/scene/gui/buttonnode.cpp index a7641d1..68a083a 100644 --- a/src/scene/gui/buttonnode.cpp +++ b/src/scene/gui/buttonnode.cpp @@ -24,7 +24,7 @@ ButtonNode::ButtonNode(ButtonShape* shape): addChild(m_label); } -MeshNode* ButtonNode::getBackGround() +BackGroundNode* ButtonNode::getBackGround() { return m_shape->getBackGround(); } @@ -39,7 +39,6 @@ LabelNode* ButtonNode::getLabel(){ void ButtonNode::update() { - GUINode::update(); Input* input = getEngine().getInput(); if(m_label->wasUpdated()){ @@ -54,4 +53,6 @@ void ButtonNode::update() m_callback->exec(); } } + getEngine().getScene()->updateShaders(); + GUINode::update(); } diff --git a/src/scene/gui/buttonnode.h b/src/scene/gui/buttonnode.h index 2ab8049..21e8309 100644 --- a/src/scene/gui/buttonnode.h +++ b/src/scene/gui/buttonnode.h @@ -8,6 +8,7 @@ #include "scene/gui/labelnode.h" class ButtonShape; +class BackGroundNode; class ButtonNode : public GUINode { @@ -19,7 +20,7 @@ class ButtonNode : public GUINode glm::vec2 m_label_position; public: ButtonNode(ButtonShape* shape); - MeshNode* getBackGround(); + BackGroundNode* getBackGround(); glm::vec2 getDimension(); void setCallBack(CallBack* callback){m_callback=callback;} void setAction(int action){m_action=action;} diff --git a/src/scene/gui/buttonshape.cpp b/src/scene/gui/buttonshape.cpp index 8ed1bf0..2902b1b 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(0.2,0.6,0.2),1,0); + m_background = new BackGroundNode(dimension,glm::vec3(1.,1.,1.),1,0); } bool RectangleButtonShape::hover(glm::vec2 button_position, glm::vec2 mouse_position){ @@ -12,7 +12,7 @@ bool RectangleButtonShape::hover(glm::vec2 button_position, glm::vec2 mouse_posi && (mouse_position.y >= button_position.y && mouse_position.y < button_position.y + m_dimension.y); } -MeshNode* RectangleButtonShape::getBackGround(){ +BackGroundNode* RectangleButtonShape::getBackGround(){ return m_background; } diff --git a/src/scene/gui/buttonshape.h b/src/scene/gui/buttonshape.h index 04314bb..e66cf2e 100644 --- a/src/scene/gui/buttonshape.h +++ b/src/scene/gui/buttonshape.h @@ -4,18 +4,19 @@ #include "glm/vec2.hpp" class MeshNode; +class BackGroundNode; class ButtonShape { protected: - MeshNode* m_background; + BackGroundNode* m_background; public: ButtonShape(){} virtual bool hover(glm::vec2 button_position, glm::vec2 mouse_position) = 0; // glm::vec2 getPosition(){return m_position;} - virtual MeshNode* getBackGround() = 0; + virtual BackGroundNode* getBackGround() = 0; virtual glm::vec2 getDimension() = 0; }; @@ -25,7 +26,7 @@ class RectangleButtonShape:public ButtonShape public: RectangleButtonShape(glm::vec2); bool hover(glm::vec2 button_position, glm::vec2 mouse_position); - MeshNode* getBackGround(); + BackGroundNode* getBackGround(); glm::vec2 getDimension(); }; diff --git a/src/sparrowshell/sparrowshell.cpp b/src/sparrowshell/sparrowshell.cpp index 5cde2ee..f761cc3 100644 --- a/src/sparrowshell/sparrowshell.cpp +++ b/src/sparrowshell/sparrowshell.cpp @@ -36,7 +36,7 @@ SparrowShell::SparrowShell(sf::Window* window): RESOURCE_ADD(fonte_des_neiges,Font,"shellfont"); //Create mesh for background - m_background = new BackGroundNode(m_dimension,glm::vec3(0.1,0.1,0.1),0.75,SHELL_DEPTH,false); + m_background = new BackGroundNode(m_dimension,glm::vec3(0.1,0.1,0.1),0.75,SHELL_DEPTH); //Create mesh for scrollbar m_scrollbar = new ShellScrollBar(this); diff --git a/src/test/main.cpp b/src/test/main.cpp index 42a01a3..8beb462 100644 --- a/src/test/main.cpp +++ b/src/test/main.cpp @@ -263,7 +263,8 @@ public: SceneTree* scene = RESOURCE_GET(SceneTree,m_menu_scene); m_button_demo = new ButtonNode(new RectangleButtonShape(glm::vec2(300,100))); m_button_demo->getLabel()->setText("Start DEMO"); - m_button_demo->getLabel()->setColor(glm::vec3(0.9,0.4,0.3)); + m_button_demo->getLabel()->setColor(glm::vec3(1.,1.,1.)); + m_button_demo->getBackGround()->setColor(glm::vec3(0.88,0.05,0.05)); scene->getRootObject()->addChild(m_button_demo); sf::Vector2u size = engine->getWindow()->getSize(); glm::vec2 pos = glm::vec2(size.x,size.y)/glm::vec2(2,2) - m_button_demo->getDimension()/glm::vec2(2,2);