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)
# choose source file
file(GLOB LIB_SRC_LIST src/*.cpp src/tools/*.cpp src/scene/*.cpp src/sparrowshell/*.cpp)
file(GLOB LIB_HEAD_LIST src/*.h src/tools/*.h src/scene/*.h src/sparrowshell/*.h)
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/scene/gui/*.h src/sparrowshell/*.h)
file(GLOB EXEC_SRC_LIST src/test/*.cpp)
#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();
int size = m_shell->getBuffer()->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()){
// 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));
resize2D(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;
glm::ivec2 new_pos((int)m_position.x, (int) cran * indexCursor);
moveTo2D(new_pos);
m_position.y = cran * indexCursor;
std::cout << m_position.x << " " << m_position.y << std::endl;
moveTo2D(m_position);
}
}

View File

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

View File

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