added folder for gui node

This commit is contained in:
Lendemor 2016-12-16 19:26:11 +01:00
parent fa03256a48
commit d2f5465f93
6 changed files with 56 additions and 28 deletions

View File

@ -7,8 +7,8 @@ SET(VERSION_MINOR 1)
set(EXTRA_INCLUDES ${PROJECT_SOURCE_DIR}/src) set(EXTRA_INCLUDES ${PROJECT_SOURCE_DIR}/src)
# choose source file # choose source file
file(GLOB LIB_SRC_LIST src/*.cpp src/tools/*.cpp src/scene/*.cpp src/sparrowshell/*.cpp) file(GLOB LIB_SRC_LIST src/*.cpp src/tools/*.cpp src/scene/*.cpp src/scene/gui/*.cpp src/sparrowshell/*.cpp)
file(GLOB LIB_HEAD_LIST src/*.h src/tools/*.h src/scene/*.h src/sparrowshell/*.h) file(GLOB LIB_HEAD_LIST src/*.h src/tools/*.h src/scene/*.h src/scene/gui/*.h src/sparrowshell/*.h)
file(GLOB EXEC_SRC_LIST src/test/*.cpp) file(GLOB EXEC_SRC_LIST src/test/*.cpp)
#set compilation option #set compilation option

View File

@ -0,0 +1,21 @@
#include "backgroundnode.h"
#include "glm/vec2.hpp"
#include "glm/vec3.hpp"
#include "mesh.h"
#include "phongmaterial.h"
BackGroundNode::BackGroundNode(glm::vec2 position,glm::vec2 dimension, glm::vec3 color, float opacity,float depth):
MeshNode(nullptr,false)
{
Mesh* mesh = new Mesh();
mesh->addRectangle2D(position,dimension);
PhongMaterial *mat = new PhongMaterial();
mat->diffuse = color;
mat->m_opacity = opacity;
mesh->setMaterial(mat);
mesh->setDepth(depth);
mesh->initGL();
m_geometry.mesh = mesh;
}

View File

@ -0,0 +1,12 @@
#ifndef BACKGROUNDNODE_H
#define BACKGROUNDNODE_H
#include "scene/meshnode.h"
class BackGroundNode : public MeshNode
{
public:
BackGroundNode(glm::vec2 position,glm::vec2 dimension, glm::vec3 color, float opacity,float depth);
};
#endif // BACKGROUNDNODE_H

View File

@ -31,19 +31,17 @@ void ShellScrollBar::update(){
MeshNode::update(); MeshNode::update();
int size = m_shell->getBuffer()->size(); int size = m_shell->getBuffer()->size();
float cran = (m_max_height/(float)size); float cran = (m_max_height/(float)size);
int indexCursor = size - (m_shell->getIndex()+SparrowShell::BUFFER_DISPLAYED_LINES); int indexCursor = m_shell->getIndex();
if (m_shell->isBufferResized()){ if (m_shell->isBufferResized()){
// std::cout << size << std::endl;
// std::cout << cran * SparrowShell::BUFFER_DISPLAYED_LINES << std::endl;
glm::ivec2 new_dim(m_dimension.x,(int)(cran * SparrowShell::BUFFER_DISPLAYED_LINES)); glm::ivec2 new_dim(m_dimension.x,(int)(cran * SparrowShell::BUFFER_DISPLAYED_LINES));
resize2D(m_dimension,new_dim); resize2D(m_dimension,new_dim);
m_dimension = new_dim; m_dimension = new_dim;
} }
if (m_shell->isBufferResized() || m_shell->indexMoved()) if (m_shell->indexMoved())
{ {
// std::cout << m_position.x << " " << cran*indexCursor << std::endl; m_position.y = cran * indexCursor;
glm::ivec2 new_pos((int)m_position.x, (int) cran * indexCursor); std::cout << m_position.x << " " << m_position.y << std::endl;
moveTo2D(new_pos); moveTo2D(m_position);
} }
} }

View File

@ -4,9 +4,13 @@
#include "scene/scenetree.h" #include "scene/scenetree.h"
#include "scene/meshnode.h" #include "scene/meshnode.h"
#include "scene/textnode.h" #include "scene/textnode.h"
#include "scene/gui/backgroundnode.h"
#include "mesh.h" #include "mesh.h"
#include "phongmaterial.h" #include "phongmaterial.h"
#include "tools/utils.h"
//#include "tools/utils.h"
#include "tools/font.h" #include "tools/font.h"
#include "resourcemanager.h" #include "resourcemanager.h"
#include "tools/loader.h" #include "tools/loader.h"
@ -35,16 +39,7 @@ SparrowShell::SparrowShell(sf::Window* window):
RESOURCE_ADD(fonte_des_neiges,Font,"shellfont"); RESOURCE_ADD(fonte_des_neiges,Font,"shellfont");
//Create mesh for background //Create mesh for background
Mesh* mesh = new Mesh(); m_background = new BackGroundNode(glm::vec2(0),m_dimension,glm::vec3(0.1,0.1,0.1),0.5,SHELL_DEPTH);
mesh->addRectangle2D(glm::vec2(0),m_dimension);
PhongMaterial *mat = new PhongMaterial();
mat->diffuse = glm::vec3(0.1,0.1,0.1);
mat->m_opacity = 0.5;
mesh->setMaterial(mat);
mesh->setDepth(SHELL_DEPTH);
mesh->initGL();
m_background = new MeshNode(mesh,false);
//Create mesh for scrollbar //Create mesh for scrollbar
m_scrollbar = new ShellScrollBar(this); m_scrollbar = new ShellScrollBar(this);
@ -65,22 +60,23 @@ void SparrowShell::out(std::string str,glm::vec3 color)
TextNode* tnode = shellfont->getTextNode(str,color,m_buffer->getFontSize(),false); TextNode* tnode = shellfont->getTextNode(str,color,m_buffer->getFontSize(),false);
tnode->setDepth(SHELL_DEPTH+1); tnode->setDepth(SHELL_DEPTH+1);
m_buffer->push(tnode); m_buffer->push(tnode);
scrollDown();
if (m_buffer->size() > SparrowShell::BUFFER_DISPLAYED_LINES) if (m_buffer->size() > SparrowShell::BUFFER_DISPLAYED_LINES)
m_resizeBuffer = true; m_resizeBuffer = true;
} }
void SparrowShell::scrollUp() void SparrowShell::scrollUp()
{ {
if (m_buffer->getIndex() + SparrowShell::BUFFER_DISPLAYED_LINES < m_buffer->size()){ if (m_buffer->getIndex() > 0){
m_buffer->increaseIndex(); m_buffer->decreaseIndex();
m_indexMoved = true; m_indexMoved = true;
} }
} }
void SparrowShell::scrollDown() void SparrowShell::scrollDown()
{ {
if (m_buffer->getIndex() > 0){ if (m_buffer->getIndex() + SparrowShell::BUFFER_DISPLAYED_LINES < m_buffer->size()){
m_buffer->decreaseIndex(); m_buffer->increaseIndex();
m_indexMoved = true; m_indexMoved = true;
} }
} }
@ -122,9 +118,9 @@ void SparrowShell::update()
} }
updateTextInput(); updateTextInput();
int scroll = input->getDeltaVerticalScroll(); int scroll = input->getDeltaVerticalScroll();
if(scroll > 0) if(scroll < 0)
scrollDown(); scrollDown();
else if(scroll < 0) else if(scroll > 0)
scrollUp(); scrollUp();
} }
GraphicalContainerNode::update(); GraphicalContainerNode::update();
@ -144,7 +140,7 @@ void SparrowShell::updateTextInput()
if (m_input_string != ""){ if (m_input_string != ""){
out(m_input_string); out(m_input_string);
//DIMITRI : Take m_input_string here and send it to LUA :D //DIMITRI : Take m_input_string here and send it to LUA :D
} }
m_input_string.clear(); m_input_string.clear();
m_input_cursor_pos = 0; m_input_cursor_pos = 0;
break; break;

View File

@ -14,6 +14,7 @@ class Input;
class MeshNode; class MeshNode;
class TextNode; class TextNode;
class ShellBuffer; class ShellBuffer;
class BackGroundNode;
namespace sf { namespace sf {
class Window; class Window;
@ -28,7 +29,7 @@ private:
bool m_resizeBuffer = false; bool m_resizeBuffer = false;
bool m_indexMoved = false; bool m_indexMoved = false;
MeshNode* m_background; BackGroundNode* m_background;
ShellBuffer* m_buffer; ShellBuffer* m_buffer;
ShellScrollBar* m_scrollbar; ShellScrollBar* m_scrollbar;