preparation for merge

This commit is contained in:
Lendemor 2016-12-14 12:24:09 +01:00
parent f09b8438a9
commit cf6da07bbe
4 changed files with 57 additions and 18 deletions

View File

@ -16,17 +16,18 @@ ShellScrollBar::ShellScrollBar(Mesh *mesh, SparrowShell *shell, glm::ivec2 dim):
void ShellScrollBar::update(){ void ShellScrollBar::update(){
MeshNode::update(); MeshNode::update();
m_position.y = m_shell->getPosition().y; // m_position.y = m_shell->getPosition().y;
m_dimension.y = m_shell->getDimension().y; // m_dimension.y = m_shell->getDimension().y;
int size = m_shell->getBuffer()->size(); int size = m_shell->getBuffer()->size();
float cran = ((float)m_shell->getDimension().y/(float)size); float cran = ((float)m_shell->getDimension().y/(float)size);
int indexCursor = size - (m_shell->getIndex()+SparrowShell::BUFFER_DISPLAYED_LINES); int indexCursor = size - (m_shell->getIndex()+SparrowShell::BUFFER_DISPLAYED_LINES);
if (m_shell->isBufferResized()){ if (m_shell->isBufferResized()){
std::cout << size << std::endl; // std::cout << size << std::endl;
std::cout << cran * SparrowShell::BUFFER_DISPLAYED_LINES << 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;
} }
if (m_shell->isBufferResized() || m_shell->indexMoved()) if (m_shell->isBufferResized() || m_shell->indexMoved())
{ {

View File

@ -11,6 +11,7 @@
#include "tools/font.h" #include "tools/font.h"
#include "resourcemanager.h" #include "resourcemanager.h"
#include "tools/loader.h" #include "tools/loader.h"
#include <string>
const unsigned int SparrowShell::BUFFER_MAX_LENGTH = 50; const unsigned int SparrowShell::BUFFER_MAX_LENGTH = 50;
const unsigned int SparrowShell::BUFFER_DISPLAYED_LINES = 15; const unsigned int SparrowShell::BUFFER_DISPLAYED_LINES = 15;
@ -20,7 +21,8 @@ const float SparrowShell::DEFAULT_FONT_SIZE = 16.f;
SparrowShell::SparrowShell(sf::Window* window): SparrowShell::SparrowShell(sf::Window* window):
m_position(glm::ivec2(0)), m_position(glm::ivec2(0)),
m_buffer(new ShellBuffer(BUFFER_MAX_LENGTH)) m_buffer(new ShellBuffer(BUFFER_MAX_LENGTH)),
m_input_cursor_pos(0)
{ {
sf::Vector2u size = window->getSize(); sf::Vector2u size = window->getSize();
m_dimension = glm::ivec2(size.x,DEFAULT_FONT_SIZE*(BUFFER_DISPLAYED_LINES+1)); m_dimension = glm::ivec2(size.x,DEFAULT_FONT_SIZE*(BUFFER_DISPLAYED_LINES+1));
@ -31,6 +33,8 @@ SparrowShell::SparrowShell(sf::Window* window):
Font* fonte_des_neiges = Loader::loadFont("../data/consolas.fnt","../data/consolas.png"); Font* fonte_des_neiges = Loader::loadFont("../data/consolas.fnt","../data/consolas.png");
RESOURCE_ADD(fonte_des_neiges,Font,"shellfont"); RESOURCE_ADD(fonte_des_neiges,Font,"shellfont");
m_text_color = glm::vec3(0.7,1,0.3);
//Create mesh for background //Create mesh for background
Mesh* mesh = new Mesh(); Mesh* mesh = new Mesh();
mesh->addRectangle2D(glm::vec2(0),m_dimension); mesh->addRectangle2D(glm::vec2(0),m_dimension);
@ -42,7 +46,6 @@ SparrowShell::SparrowShell(sf::Window* window):
mesh->initGL(); mesh->initGL();
m_background = new MeshNode(mesh,false); m_background = new MeshNode(mesh,false);
//Create mesh for scrollbar //Create mesh for scrollbar
mesh = new Mesh(); mesh = new Mesh();
glm::vec2 shell_pos = glm::vec2(0,0); glm::vec2 shell_pos = glm::vec2(0,0);
@ -64,28 +67,31 @@ SparrowShell::SparrowShell(sf::Window* window):
void SparrowShell::out(std::string s) void SparrowShell::out(std::string s)
{ {
Font *shellfont = RESOURCE_GET(Font,"shellfont"); Font *shellfont = RESOURCE_GET(Font,"shellfont");
TextNode* tnode = shellfont->getTextNode(s,glm::vec3(0.7,1,0.3),m_buffer->getFontSize(),false); TextNode* tnode = shellfont->getTextNode(s,m_text_color,m_buffer->getFontSize(),false);
tnode->setDepth(SHELL_DEPTH+1); tnode->setDepth(SHELL_DEPTH+1);
m_buffer->push(tnode); m_buffer->push(tnode);
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() + SparrowShell::BUFFER_DISPLAYED_LINES < m_buffer->size()){
m_buffer->increaseIndex(); m_buffer->increaseIndex();
m_indexMoved = true; m_indexMoved = true;
} }
} }
void SparrowShell::scrollDown(){ void SparrowShell::scrollDown()
{
if (m_buffer->getIndex() > 0){ if (m_buffer->getIndex() > 0){
m_buffer->decreaseIndex(); m_buffer->decreaseIndex();
m_indexMoved = true; m_indexMoved = true;
} }
} }
void SparrowShell::toggleShell(){ void SparrowShell::toggleShell()
{
m_shellEnabled = !m_shellEnabled; m_shellEnabled = !m_shellEnabled;
for(auto child : m_children) for(auto child : m_children)
child->toggleVisibility(); child->toggleVisibility();
@ -93,7 +99,8 @@ void SparrowShell::toggleShell(){
m_scene->updateShaders(); m_scene->updateShaders();
} }
void SparrowShell::update(){ void SparrowShell::update()
{
m_resizeBuffer = false; m_resizeBuffer = false;
m_indexMoved = false; m_indexMoved = false;
auto input = getEngine().getInput(); auto input = getEngine().getInput();
@ -104,10 +111,36 @@ void SparrowShell::update(){
out("Plop"); out("Plop");
} }
} }
if(m_shellEnabled){
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();
} }
void SparrowShell::updateTextInput()
{
std::string text = getEngine().getInput()->getText();
for(unsigned int i = 0 ; i < text.length() ; i++){
char c = text[i];
if (c == 8){
if(m_input_cursor_pos > 0)
m_input_string.erase(--m_input_cursor_pos,1);
}else
m_input_string.insert(m_input_cursor_pos++,std::string(1,c));
std::cout << text[i] << (int) text[i] << std::endl;
}
Font *shellfont = RESOURCE_GET(Font,"shellfont");
if(m_input_mesh)
this->removeChild(m_input_mesh);
m_input_mesh = shellfont->getTextNode(m_input_string,m_text_color,m_buffer->getFontSize(),false);
this->addChild(m_input_mesh);
// m_input_string.insert(m_input_cursor_pos,c);
// m_input_string.append();
// std::cout << m_input_string << std::endl;
}

View File

@ -32,6 +32,11 @@ private:
ShellBuffer* m_buffer; ShellBuffer* m_buffer;
ShellScrollBar* m_scrollbar; ShellScrollBar* m_scrollbar;
glm::vec3 m_text_color;
std::string m_input_string;
int m_input_cursor_pos;
TextNode* m_input_mesh;
public: public:
static const unsigned int BUFFER_MAX_LENGTH; static const unsigned int BUFFER_MAX_LENGTH;
static const unsigned int BUFFER_DISPLAYED_LINES; static const unsigned int BUFFER_DISPLAYED_LINES;
@ -42,7 +47,7 @@ public:
SparrowShell(sf::Window*); SparrowShell(sf::Window*);
void update(); void update();
void updateTextInput();
void scrollUp(); void scrollUp();
void scrollDown(); void scrollDown();

View File

@ -169,7 +169,7 @@ int main(){
scene->getRootObject()->addChild(sunLight); scene->getRootObject()->addChild(sunLight);
// terrain // terrain
// generateTerrain(scene, engine.getPhysics()); // generateTerrain(scene, engine.getPhysics());
// shell output tests // shell output tests
engine.outputShell("Hello World!"); engine.outputShell("Hello World!");