This commit is contained in:
Anselme 2016-12-10 16:04:11 +01:00
commit e42e1f3543
9 changed files with 48 additions and 32 deletions

View File

@ -4,7 +4,7 @@
void GraphicalNode::setSceneTree(SceneTree *tree){
SceneNode::setSceneTree(tree);
if(tree)
if(tree && m_visible)
tree->addToIndex(this);
}

View File

@ -20,8 +20,13 @@ protected:
bool m_transformChanged;
public:
GraphicalNode() : m_visible(true), m_transformChanged(true) {}
// GraphicalNode();
// GraphicalNode(bool);
GraphicalNode(bool visible = true) : m_visible(visible), m_transformChanged(true) {}
bool isVisible(){return m_visible;}
void toggleVisibility();
virtual void setSceneTree(SceneTree* tree);

View File

@ -25,7 +25,7 @@ public:
glm::mat4 m_movement;
glm::mat4 m_acceleration;
MeshNode(Mesh* mesh) : m_geometry(mesh, glm::mat4()), m_rigidBody(nullptr) {}
MeshNode(Mesh* mesh, bool visible = true) : GraphicalNode(visible), m_geometry(mesh, glm::mat4()), m_rigidBody(nullptr) {}
virtual void update();

View File

@ -1,6 +1,8 @@
#include "shellbuffer.h"
#include "scene/meshnode.h"
#include "scene/textnode.h"
#include "sparrowshell/sparrowshell.h"
#include "tools/utils.h"
void ShellBuffer::toggleBuffer(){
for(auto child : m_children){
@ -12,7 +14,28 @@ void ShellBuffer::toggleBuffer(){
void ShellBuffer::update()
{
TextNode* tnode;
glm::vec2 text_pos(0);
SparrowShell* shell = dynamic_cast<SparrowShell*>(m_parent);
// if(shell && shell->isEnabled())
// {
// for(unsigned int i = 0; i< size();i++)
// {
// tnode = (TextNode*) this+i;
// if (i >= m_index && i < m_index+SparrowShell::BUFFER_DISPLAYED_NUMBER)
// {
// utils::setPosition2D(tnode,text_pos);
// text_pos.y += m_font_size;
// //m_scene
// }
// else{
// utils::setPosition2D(tnode,glm::vec2(-100,-100));
// }
// }
// }
}
void ShellBuffer::push(TextNode* s){

View File

@ -10,6 +10,7 @@ private:
unsigned int m_max_size;
int m_zero_offset;
float m_font_size;
unsigned int m_index = 0;
public:
ShellBuffer(int buffer_size):m_max_size(buffer_size), m_zero_offset(0),m_font_size(16.f){}
GraphicalNode* operator[](int i){return m_children[(m_zero_offset+i)%m_max_size];}

View File

@ -24,7 +24,7 @@ ShellScrollBar::ShellScrollBar(SparrowShell* shell):m_shell(shell){
mesh->setMaterial(mat);
mesh->initGL();
m_mesh = new MeshNode(mesh);
m_mesh = new MeshNode(mesh,false);
utils::setPosition2D(m_mesh,m_position);
m_shell->addChild(m_mesh);
}

View File

@ -2,11 +2,11 @@
#define SHELLSCROLLBAR_H
#include "glm/vec2.hpp"
#include "scene/meshnode.h"
class MeshNode;
class SparrowShell;
class ShellScrollBar
class ShellScrollBar// : public MeshNode
{
SparrowShell* m_shell;
glm::ivec2 m_position;

View File

@ -32,7 +32,7 @@ SparrowShell::SparrowShell(sf::Window* window, Input* input):
mesh->setMaterial(mat);
mesh->setDepth(SHELL_DEPTH);
mesh->initGL();
m_background = new MeshNode(mesh);
m_background = new MeshNode(mesh,false);
this->addChild(m_background);
this->addChild(m_buffer);
m_scrollbar = ShellScrollBar(this);
@ -44,7 +44,8 @@ void SparrowShell::out(std::string s)
TextNode* tnode = shellfont->getTextNode(s,glm::vec3(0.7,1,0.3),m_buffer->getFontSize());
tnode->setDepth(SHELL_DEPTH+1);
m_buffer->push(tnode);
m_scene->addToIndex(tnode);
if(m_shellEnabled)
m_scene->addToIndex(tnode);
if (m_buffer->size() > SparrowShell::BUFFER_DISPLAYED_NUMBER)
m_resizeBuffer = true;
}
@ -65,37 +66,21 @@ void SparrowShell::scrollDown(){
void SparrowShell::toggleShell(){
m_shellEnabled = !m_shellEnabled;
for(auto child : m_children){
MeshNode* meshchild = dynamic_cast<MeshNode*>(child);
// if(meshchild)
// meshchild->toggleVisibility();
}
// m_buffer->toggleBuffer();
m_background->toggleVisibility();
// for(auto child : m_children){
// MeshNode* meshchild = dynamic_cast<MeshNode*>(child);
// // if(meshchild)
// // meshchild->toggleVisibility();
// }
//// m_buffer->toggleBuffer();
//// m_background->toggleVisibility();
}
void SparrowShell::update(){
TextNode* tnode;
glm::vec2 text_pos(0);
for(auto action : m_input->getActions()){
if(action == 15){
toggleShell();
}
}
//move position of shellBuffer
// position textnode inside shellBuffer
m_buffer->update();
/* if(m_shellEnabled){
for(unsigned int i = 0; i<m_buffer->size(); i++){
tnode = (TextNode*)(m_buffer+i);
if (i >= m_index && i < m_index + BUFFER_DISPLAYED_NUMBER){
utils::setPosition2D(tnode,text_pos);
text_pos.y += m_buffer->getFontSize();
m_scene->addToIndex(tnode);
}
}
}*/
m_scrollbar.update();
}

View File

@ -51,10 +51,11 @@ public:
void toggleShell();
void out(std::string);
void setSceneTree(SceneTree* tree)
{
GraphicalContainerNode::setSceneTree(tree);
m_buffer->setSceneTree(tree);
// m_buffer->setSceneTree(tree);
}
glm::ivec2 getPosition(){return m_position;}
@ -63,6 +64,7 @@ public:
unsigned int getIndex(){return m_index;}
ShellBuffer* getBuffer(){return m_buffer;}
bool isEnabled(){return m_shellEnabled;}
bool isBufferResized(){return m_resizeBuffer;}
bool indexMoved(){return m_indexMoved;}
};