preparation for merge
This commit is contained in:
parent
f09b8438a9
commit
cf6da07bbe
@ -16,17 +16,18 @@ ShellScrollBar::ShellScrollBar(Mesh *mesh, SparrowShell *shell, glm::ivec2 dim):
|
||||
|
||||
void ShellScrollBar::update(){
|
||||
MeshNode::update();
|
||||
m_position.y = m_shell->getPosition().y;
|
||||
m_dimension.y = m_shell->getDimension().y;
|
||||
// m_position.y = m_shell->getPosition().y;
|
||||
// m_dimension.y = m_shell->getDimension().y;
|
||||
int size = m_shell->getBuffer()->size();
|
||||
float cran = ((float)m_shell->getDimension().y/(float)size);
|
||||
int indexCursor = size - (m_shell->getIndex()+SparrowShell::BUFFER_DISPLAYED_LINES);
|
||||
|
||||
if (m_shell->isBufferResized()){
|
||||
std::cout << size << std::endl;
|
||||
std::cout << cran * SparrowShell::BUFFER_DISPLAYED_LINES << std::endl;
|
||||
// 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())
|
||||
{
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "tools/font.h"
|
||||
#include "resourcemanager.h"
|
||||
#include "tools/loader.h"
|
||||
#include <string>
|
||||
|
||||
const unsigned int SparrowShell::BUFFER_MAX_LENGTH = 50;
|
||||
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):
|
||||
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();
|
||||
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");
|
||||
RESOURCE_ADD(fonte_des_neiges,Font,"shellfont");
|
||||
|
||||
m_text_color = glm::vec3(0.7,1,0.3);
|
||||
|
||||
//Create mesh for background
|
||||
Mesh* mesh = new Mesh();
|
||||
mesh->addRectangle2D(glm::vec2(0),m_dimension);
|
||||
@ -42,7 +46,6 @@ SparrowShell::SparrowShell(sf::Window* window):
|
||||
mesh->initGL();
|
||||
m_background = new MeshNode(mesh,false);
|
||||
|
||||
|
||||
//Create mesh for scrollbar
|
||||
mesh = new Mesh();
|
||||
glm::vec2 shell_pos = glm::vec2(0,0);
|
||||
@ -64,28 +67,31 @@ SparrowShell::SparrowShell(sf::Window* window):
|
||||
void SparrowShell::out(std::string s)
|
||||
{
|
||||
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);
|
||||
m_buffer->push(tnode);
|
||||
if (m_buffer->size() > SparrowShell::BUFFER_DISPLAYED_LINES)
|
||||
m_resizeBuffer = true;
|
||||
}
|
||||
|
||||
void SparrowShell::scrollUp(){
|
||||
void SparrowShell::scrollUp()
|
||||
{
|
||||
if (m_buffer->getIndex() + SparrowShell::BUFFER_DISPLAYED_LINES < m_buffer->size()){
|
||||
m_buffer->increaseIndex();
|
||||
m_indexMoved = true;
|
||||
}
|
||||
}
|
||||
|
||||
void SparrowShell::scrollDown(){
|
||||
void SparrowShell::scrollDown()
|
||||
{
|
||||
if (m_buffer->getIndex() > 0){
|
||||
m_buffer->decreaseIndex();
|
||||
m_indexMoved = true;
|
||||
}
|
||||
}
|
||||
|
||||
void SparrowShell::toggleShell(){
|
||||
void SparrowShell::toggleShell()
|
||||
{
|
||||
m_shellEnabled = !m_shellEnabled;
|
||||
for(auto child : m_children)
|
||||
child->toggleVisibility();
|
||||
@ -93,7 +99,8 @@ void SparrowShell::toggleShell(){
|
||||
m_scene->updateShaders();
|
||||
}
|
||||
|
||||
void SparrowShell::update(){
|
||||
void SparrowShell::update()
|
||||
{
|
||||
m_resizeBuffer = false;
|
||||
m_indexMoved = false;
|
||||
auto input = getEngine().getInput();
|
||||
@ -104,10 +111,36 @@ void SparrowShell::update(){
|
||||
out("Plop");
|
||||
}
|
||||
}
|
||||
int scroll = input->getDeltaVerticalScroll();
|
||||
if(scroll > 0)
|
||||
scrollDown();
|
||||
else if(scroll < 0)
|
||||
scrollUp();
|
||||
if(m_shellEnabled){
|
||||
updateTextInput();
|
||||
int scroll = input->getDeltaVerticalScroll();
|
||||
if(scroll > 0)
|
||||
scrollDown();
|
||||
else if(scroll < 0)
|
||||
scrollUp();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -32,6 +32,11 @@ private:
|
||||
ShellBuffer* m_buffer;
|
||||
ShellScrollBar* m_scrollbar;
|
||||
|
||||
glm::vec3 m_text_color;
|
||||
std::string m_input_string;
|
||||
int m_input_cursor_pos;
|
||||
TextNode* m_input_mesh;
|
||||
|
||||
public:
|
||||
static const unsigned int BUFFER_MAX_LENGTH;
|
||||
static const unsigned int BUFFER_DISPLAYED_LINES;
|
||||
@ -42,7 +47,7 @@ public:
|
||||
SparrowShell(sf::Window*);
|
||||
|
||||
void update();
|
||||
|
||||
void updateTextInput();
|
||||
void scrollUp();
|
||||
void scrollDown();
|
||||
|
||||
|
@ -169,7 +169,7 @@ int main(){
|
||||
scene->getRootObject()->addChild(sunLight);
|
||||
|
||||
// terrain
|
||||
// generateTerrain(scene, engine.getPhysics());
|
||||
// generateTerrain(scene, engine.getPhysics());
|
||||
|
||||
// shell output tests
|
||||
engine.outputShell("Hello World!");
|
||||
|
Loading…
x
Reference in New Issue
Block a user