Merge branch 'master' of https://git.epicsparrow.com/epicsparrow/SparrowEngine
This commit is contained in:
commit
80b213a062
@ -50,7 +50,7 @@ void Engine::createWindow(std::string title,
|
||||
m_window->setFramerateLimit(60);
|
||||
m_input = new Input(m_window);
|
||||
m_renderer->initGL(w, h);
|
||||
m_sparrowshell = new SparrowShell(m_window, m_input);
|
||||
m_sparrowshell = new SparrowShell(m_window);
|
||||
}
|
||||
|
||||
void Engine::initPhysics()
|
||||
|
@ -12,6 +12,7 @@ void ShellBuffer::toggleBuffer(){
|
||||
|
||||
void ShellBuffer::update()
|
||||
{
|
||||
GraphicalContainerNode::update();
|
||||
TextNode* tnode;
|
||||
glm::vec2 text_pos(0,0);
|
||||
|
||||
@ -21,11 +22,11 @@ void ShellBuffer::update()
|
||||
for(unsigned int i = 0; i< size();i++)
|
||||
{
|
||||
tnode = (TextNode*) (*this)[i];
|
||||
if (i >= m_index && i < m_index+SparrowShell::BUFFER_DISPLAYED_NUMBER)
|
||||
if (i >= m_index && i < m_index+SparrowShell::BUFFER_DISPLAYED_LINES)
|
||||
{
|
||||
tnode->moveTo2D(text_pos);
|
||||
tnode->setVisible(true);
|
||||
text_pos.y += m_font_size;
|
||||
// std::cout << tnode->getString() << ": " << text_pos.x << " " << text_pos.y << std::endl;
|
||||
}
|
||||
else
|
||||
tnode->moveTo2D(glm::vec2(-100,-100));
|
||||
@ -40,6 +41,7 @@ void ShellBuffer::push(TextNode* tnode){
|
||||
tnode->setSceneTree(m_scene);
|
||||
|
||||
if (m_children.size() >= m_max_size){
|
||||
(m_children[m_zero_offset])->setVisible(false);
|
||||
m_children[m_zero_offset++] = tnode;
|
||||
m_zero_offset %= m_max_size;
|
||||
}else
|
||||
|
@ -15,7 +15,7 @@ private:
|
||||
public:
|
||||
ShellBuffer(int buffer_size):m_max_size(buffer_size), m_zero_offset(0),m_font_size(16.f){
|
||||
m_visible = false;
|
||||
moveTo2D(glm::vec2(0,0));
|
||||
moveTo2D(glm::vec2(0));
|
||||
}
|
||||
GraphicalNode* operator[](int i){return m_children[(m_zero_offset+i)%m_max_size];}
|
||||
void push(TextNode*);
|
||||
@ -27,6 +27,11 @@ public:
|
||||
// if this font_size is scaling down, sizes which are power of 2 render better.
|
||||
void setFontSize(float font_size){m_font_size = font_size;}
|
||||
float getFontSize(){return m_font_size;}
|
||||
|
||||
void increaseIndex(){m_index++;}
|
||||
void decreaseIndex(){m_index--;}
|
||||
unsigned int getIndex(){return m_index;}
|
||||
|
||||
};
|
||||
|
||||
#endif // SHELLBUFFER_H
|
||||
|
@ -6,18 +6,32 @@
|
||||
#include "tools/utils.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
ShellScrollBar::ShellScrollBar(Mesh *mesh, SparrowShell *shell, glm::ivec2 dim):
|
||||
MeshNode(mesh,false), m_shell(shell),m_dimension(dim)
|
||||
{
|
||||
m_position = glm::vec2(m_shell->getDimension().x-SparrowShell::SCROLLBAR_PIXEL_WIDTH,0);
|
||||
moveTo2D(m_position);
|
||||
}
|
||||
|
||||
void ShellScrollBar::update(){
|
||||
MeshNode::update();
|
||||
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);
|
||||
|
||||
float cran = ((float)m_shell->getDimension().y/(float)m_shell->getBuffer()->size());
|
||||
int indexCursor = m_shell->getBuffer()->size()-(m_shell->getIndex()+SparrowShell::BUFFER_DISPLAYED_NUMBER);
|
||||
glm::ivec2 new_pos((int)m_position.x, (int) cran * indexCursor);
|
||||
|
||||
/* if (m_shell->isBufferResized()){
|
||||
glm::ivec2 new_dim(m_dimension.x,(int)(cran * SparrowShell::BUFFER_DISPLAYED_NUMBER));
|
||||
utils::resize2D(m_mesh,m_dimension,new_dim);
|
||||
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);
|
||||
}
|
||||
if (m_shell->isBufferResized() || m_shell->indexMoved())
|
||||
utils::setPosition2D(m_mesh,new_pos);*/
|
||||
{
|
||||
// std::cout << m_position.x << " " << cran*indexCursor << std::endl;
|
||||
glm::ivec2 new_pos((int)m_position.x, (int) cran * indexCursor);
|
||||
moveTo2D(new_pos);
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,7 @@ class ShellScrollBar : public MeshNode
|
||||
glm::ivec2 m_position;
|
||||
glm::ivec2 m_dimension;
|
||||
public:
|
||||
ShellScrollBar(Mesh* mesh, SparrowShell* shell, glm::ivec2 pos, glm::ivec2 dim):
|
||||
MeshNode(mesh,false), m_shell(shell),m_position(pos),m_dimension(dim){}
|
||||
ShellScrollBar(Mesh* mesh, SparrowShell* shell, glm::ivec2 dim);
|
||||
void update();
|
||||
};
|
||||
#endif // SHELLSCROLLBAR_H
|
||||
|
@ -13,19 +13,18 @@
|
||||
#include "tools/loader.h"
|
||||
|
||||
const unsigned int SparrowShell::BUFFER_MAX_LENGTH = 50;
|
||||
const unsigned int SparrowShell::BUFFER_DISPLAYED_NUMBER = 10;
|
||||
const unsigned int SparrowShell::BUFFER_DISPLAYED_LINES = 15;
|
||||
const unsigned int SparrowShell::SCROLLBAR_PIXEL_WIDTH = 10;
|
||||
const float SparrowShell::SHELL_DEPTH = 10;
|
||||
const float SparrowShell::DEFAULT_FONT_SIZE = 16.f;
|
||||
|
||||
SparrowShell::SparrowShell(sf::Window* window, Input* input):
|
||||
m_window(window),
|
||||
m_input(input),
|
||||
m_position(glm::ivec2(10,0)),
|
||||
SparrowShell::SparrowShell(sf::Window* window):
|
||||
m_position(glm::ivec2(0)),
|
||||
m_buffer(new ShellBuffer(BUFFER_MAX_LENGTH))
|
||||
{
|
||||
sf::Vector2u size = m_window->getSize();
|
||||
m_dimension = glm::ivec2(size.x,size.y/2);
|
||||
m_buffer->setFontSize(16.f);
|
||||
sf::Vector2u size = window->getSize();
|
||||
m_dimension = glm::ivec2(size.x,DEFAULT_FONT_SIZE*(BUFFER_DISPLAYED_LINES+1));
|
||||
m_buffer->setFontSize(DEFAULT_FONT_SIZE);
|
||||
|
||||
moveTo2D(glm::vec2(m_position));
|
||||
|
||||
@ -34,7 +33,7 @@ SparrowShell::SparrowShell(sf::Window* window, Input* input):
|
||||
|
||||
//Create mesh for background
|
||||
Mesh* mesh = new Mesh();
|
||||
mesh->addRectangle2D(m_position,m_dimension);
|
||||
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;
|
||||
@ -46,8 +45,8 @@ SparrowShell::SparrowShell(sf::Window* window, Input* input):
|
||||
|
||||
//Create mesh for scrollbar
|
||||
mesh = new Mesh();
|
||||
glm::vec2 shell_pos = glm::vec2(m_dimension.x - SCROLLBAR_PIXEL_WIDTH,0);
|
||||
glm::vec2 shell_dim = glm::vec2(SCROLLBAR_PIXEL_WIDTH,m_dimension.y);
|
||||
glm::vec2 shell_pos = glm::vec2(0,0);
|
||||
glm::vec2 shell_dim = glm::vec2(SCROLLBAR_PIXEL_WIDTH,DEFAULT_FONT_SIZE*BUFFER_DISPLAYED_LINES);
|
||||
mesh->addRectangle2D(shell_pos,shell_dim);
|
||||
mat = new PhongMaterial();
|
||||
mat->diffuse = glm::vec3(0,0,0.5);
|
||||
@ -55,7 +54,7 @@ SparrowShell::SparrowShell(sf::Window* window, Input* input):
|
||||
mesh->setMaterial(mat);
|
||||
mesh->setDepth(SHELL_DEPTH+1);
|
||||
mesh->initGL();
|
||||
m_scrollbar = new ShellScrollBar(mesh,this,shell_pos,shell_dim);
|
||||
m_scrollbar = new ShellScrollBar(mesh,this,shell_dim);
|
||||
|
||||
this->addChild(m_background);
|
||||
this->addChild(m_buffer);
|
||||
@ -68,20 +67,20 @@ void SparrowShell::out(std::string s)
|
||||
TextNode* tnode = shellfont->getTextNode(s,glm::vec3(0.7,1,0.3),m_buffer->getFontSize(),false);
|
||||
tnode->setDepth(SHELL_DEPTH+1);
|
||||
m_buffer->push(tnode);
|
||||
if (m_buffer->size() > SparrowShell::BUFFER_DISPLAYED_NUMBER)
|
||||
if (m_buffer->size() > SparrowShell::BUFFER_DISPLAYED_LINES)
|
||||
m_resizeBuffer = true;
|
||||
}
|
||||
|
||||
void SparrowShell::scrollUp(){
|
||||
if (m_index + SparrowShell::BUFFER_DISPLAYED_NUMBER < m_buffer->size()){
|
||||
m_index++;
|
||||
if (m_buffer->getIndex() + SparrowShell::BUFFER_DISPLAYED_LINES < m_buffer->size()){
|
||||
m_buffer->increaseIndex();
|
||||
m_indexMoved = true;
|
||||
}
|
||||
}
|
||||
|
||||
void SparrowShell::scrollDown(){
|
||||
if (m_index > 0){
|
||||
m_index--;
|
||||
if (m_buffer->getIndex() > 0){
|
||||
m_buffer->decreaseIndex();
|
||||
m_indexMoved = true;
|
||||
}
|
||||
}
|
||||
@ -95,10 +94,20 @@ void SparrowShell::toggleShell(){
|
||||
}
|
||||
|
||||
void SparrowShell::update(){
|
||||
GraphicalContainerNode::update();
|
||||
for(auto action : m_input->getActions()){
|
||||
m_resizeBuffer = false;
|
||||
m_indexMoved = false;
|
||||
auto input = getEngine().getInput();
|
||||
for(auto action : input->getActions()){
|
||||
if(action == 15){
|
||||
toggleShell();
|
||||
}else if(action == 6){
|
||||
out("Plop");
|
||||
}
|
||||
}
|
||||
int scroll = input->getDeltaVerticalScroll();
|
||||
if(scroll > 0)
|
||||
scrollDown();
|
||||
else if(scroll < 0)
|
||||
scrollUp();
|
||||
GraphicalContainerNode::update();
|
||||
}
|
||||
|
@ -22,27 +22,24 @@ class Window;
|
||||
class SparrowShell : public GraphicalContainerNode
|
||||
{
|
||||
private:
|
||||
sf::Window* m_window;
|
||||
Input* m_input;
|
||||
|
||||
glm::ivec2 m_position;
|
||||
glm::ivec2 m_dimension;
|
||||
ShellBuffer* m_buffer;
|
||||
unsigned int m_index = 0;
|
||||
bool m_shellEnabled = false;
|
||||
bool m_resizeBuffer = false;
|
||||
bool m_indexMoved = false;
|
||||
bool m_shellEnabled = false;
|
||||
//textMesh
|
||||
|
||||
MeshNode* m_background;
|
||||
ShellBuffer* m_buffer;
|
||||
ShellScrollBar* m_scrollbar;
|
||||
|
||||
public:
|
||||
static const unsigned int BUFFER_MAX_LENGTH;
|
||||
static const unsigned int BUFFER_DISPLAYED_NUMBER;
|
||||
static const unsigned int BUFFER_DISPLAYED_LINES;
|
||||
static const unsigned int SCROLLBAR_PIXEL_WIDTH;
|
||||
static const float SHELL_DEPTH;
|
||||
static const float DEFAULT_FONT_SIZE;
|
||||
|
||||
SparrowShell(sf::Window*, Input*);
|
||||
SparrowShell(sf::Window*);
|
||||
|
||||
void update();
|
||||
|
||||
@ -52,15 +49,10 @@ public:
|
||||
void toggleShell();
|
||||
void out(std::string);
|
||||
|
||||
// void setSceneTree(SceneTree* tree)
|
||||
// {
|
||||
// GraphicalContainerNode::setSceneTree(tree);
|
||||
// }
|
||||
|
||||
glm::ivec2 getPosition(){return m_position;}
|
||||
glm::ivec2 getDimension(){return m_dimension;}
|
||||
|
||||
unsigned int getIndex(){return m_index;}
|
||||
unsigned int getIndex(){return m_buffer->getIndex();}
|
||||
ShellBuffer* getBuffer(){return m_buffer;}
|
||||
|
||||
bool isEnabled(){return m_shellEnabled;}
|
||||
|
@ -175,9 +175,9 @@ int main(){
|
||||
engine.outputShell("Hello World!");
|
||||
engine.outputShell("Starting test :");
|
||||
|
||||
// for(int i = 0; i < 17; i++){
|
||||
// engine.outputShell(std::to_string(i));
|
||||
// }
|
||||
// for(int i = 0; i < 17; i++){
|
||||
// engine.outputShell(std::to_string(i));
|
||||
// }
|
||||
|
||||
// preparing shaders and launching the engine
|
||||
scene->updateShaders();
|
||||
|
Loading…
x
Reference in New Issue
Block a user