Text dissapeared
This commit is contained in:
parent
ea06b027f8
commit
2e4af8852d
@ -6,10 +6,12 @@
|
|||||||
class TextNode : public MeshNode
|
class TextNode : public MeshNode
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
std::string m_string;
|
||||||
float m_fontSize;
|
float m_fontSize;
|
||||||
public:
|
public:
|
||||||
TextNode(Mesh* mesh,float fontSize) : MeshNode(mesh),m_fontSize(fontSize) {}
|
TextNode(Mesh* mesh,std::string s,float fontSize) : MeshNode(mesh),m_string(s),m_fontSize(fontSize) {}
|
||||||
float getFontSize(){return m_fontSize;}
|
float getFontSize(){return m_fontSize;}
|
||||||
|
std::string getString(){return m_string;}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TEXTNODE_H
|
#endif // TEXTNODE_H
|
||||||
|
@ -24,6 +24,7 @@ SparrowShell::SparrowShell(sf::Window* window, Input* input):
|
|||||||
sf::Vector2u size = m_window->getSize();
|
sf::Vector2u size = m_window->getSize();
|
||||||
m_dimension = glm::ivec2(size.x,size.y/2);
|
m_dimension = glm::ivec2(size.x,size.y/2);
|
||||||
Mesh* mesh = new Mesh();
|
Mesh* mesh = new Mesh();
|
||||||
|
m_buffer.setFontSize(12.f);
|
||||||
mesh->addRectangle2D(m_position,m_dimension);
|
mesh->addRectangle2D(m_position,m_dimension);
|
||||||
PhongMaterial *mat = new PhongMaterial();
|
PhongMaterial *mat = new PhongMaterial();
|
||||||
mat->diffuse = glm::vec3(0.1,0.1,0.1);
|
mat->diffuse = glm::vec3(0.1,0.1,0.1);
|
||||||
@ -38,7 +39,11 @@ SparrowShell::SparrowShell(sf::Window* window, Input* input):
|
|||||||
|
|
||||||
void SparrowShell::out(std::string s)
|
void SparrowShell::out(std::string s)
|
||||||
{
|
{
|
||||||
m_buffer.push(s);
|
Font *shellfont = RESOURCE_GET(Font,"shellfont");
|
||||||
|
TextNode* tnode = shellfont->getTextNode(s,glm::vec3(0.7,1,0.3),m_buffer.getFontSize());
|
||||||
|
tnode->setDepth(SHELL_DEPTH+1);
|
||||||
|
// m_currentScene->addToIndex(tnode);
|
||||||
|
m_buffer.push(tnode);
|
||||||
if (m_buffer.size() > BUFFER_DISPLAYED_NUMBER)
|
if (m_buffer.size() > BUFFER_DISPLAYED_NUMBER)
|
||||||
m_resizeScrollBar = true;
|
m_resizeScrollBar = true;
|
||||||
}
|
}
|
||||||
@ -59,34 +64,35 @@ void SparrowShell::scrollDown(){
|
|||||||
|
|
||||||
void SparrowShell::update()
|
void SparrowShell::update()
|
||||||
{
|
{
|
||||||
Font *shellfont = RESOURCE_GET(Font,"shellfont");
|
//Font *shellfont = RESOURCE_GET(Font,"shellfont");
|
||||||
TextNode* mnode;
|
TextNode* tnode;
|
||||||
glm::vec2 text_pos(0);
|
glm::vec2 text_pos(0);
|
||||||
//std::vector<MeshNode*> textMeshes;
|
|
||||||
if(m_indexMoved){
|
// if(m_indexMoved){
|
||||||
for(auto textMesh: m_textMeshes)
|
// unsigned int count_stop = m_buffer.size() > BUFFER_DISPLAYED_NUMBER ? m_index + BUFFER_DISPLAYED_NUMBER: m_buffer.size();
|
||||||
m_currentScene->removeObject(this,textMesh);
|
//move position of shellBuffer
|
||||||
m_textMeshes.clear();
|
// position textnode inside shellBuffer
|
||||||
for(unsigned int i = m_index;i<m_index+BUFFER_DISPLAYED_NUMBER;i++){
|
for(unsigned int i = 0; i<m_buffer.size(); i++){
|
||||||
mnode = shellfont->getTextNode(m_buffer[i],glm::vec3(0.7,1,0.3),12.f);
|
tnode = (TextNode*)m_buffer[i];
|
||||||
utils::setPosition2D((TextNode*)mnode,text_pos);
|
if (i >= m_index && i < m_index + BUFFER_DISPLAYED_NUMBER){
|
||||||
text_pos.y += shellfont->getLineHeight();
|
utils::setPosition2D(tnode,text_pos);
|
||||||
mnode->setDepth(SHELL_DEPTH+1);
|
text_pos.y += m_buffer.getFontSize();
|
||||||
m_textMeshes.push_back(mnode);
|
m_currentScene->addToIndex(tnode);
|
||||||
m_currentScene->addObject(this,mnode);
|
// m_currentScene->addObject(this,mnode);
|
||||||
}
|
}
|
||||||
m_indexMoved = false;
|
|
||||||
}
|
}
|
||||||
|
// m_indexMoved = false;
|
||||||
|
// }
|
||||||
m_scrollbar.update();
|
m_scrollbar.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SparrowShell::ShellBuffer::push(std::string s){
|
void SparrowShell::ShellBuffer::push(TextNode* s){
|
||||||
if (m_buffer.size() >= m_size){
|
if (m_children.size() >= m_max_size){
|
||||||
m_buffer[m_zero_offset++] = s;
|
m_children[m_zero_offset++] = s;
|
||||||
m_zero_offset %= m_size;
|
m_zero_offset %= m_max_size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_buffer.push_back(s);
|
m_children.push_back(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
SparrowShell::ScrollBar::ScrollBar(SparrowShell* shell):m_shell(shell){
|
SparrowShell::ScrollBar::ScrollBar(SparrowShell* shell):m_shell(shell){
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
class Input;
|
class Input;
|
||||||
class MeshNode;
|
class MeshNode;
|
||||||
|
class TextNode;
|
||||||
|
|
||||||
namespace sf {
|
namespace sf {
|
||||||
class Window;
|
class Window;
|
||||||
@ -17,33 +18,30 @@ class Window;
|
|||||||
class SparrowShell : public ContainerNode
|
class SparrowShell : public ContainerNode
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
//class BackGround : public MeshNode {
|
|
||||||
|
|
||||||
// };
|
|
||||||
|
|
||||||
class ScrollBar{
|
class ScrollBar{
|
||||||
SparrowShell* m_shell;
|
SparrowShell* m_shell;
|
||||||
glm::ivec2 m_position;
|
glm::ivec2 m_position;
|
||||||
glm::ivec2 m_dimension;
|
glm::ivec2 m_dimension;
|
||||||
MeshNode *m_mesh;
|
MeshNode *m_mesh;
|
||||||
//TODO : Add rectangle mesh
|
//TODO : Add rectangle mesh
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ScrollBar(){}
|
ScrollBar(){}
|
||||||
ScrollBar(SparrowShell* shell);
|
ScrollBar(SparrowShell* shell);
|
||||||
void update();
|
void update();
|
||||||
};
|
};
|
||||||
|
|
||||||
class ShellBuffer{
|
class ShellBuffer : public ContainerNode {
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> m_buffer;
|
|
||||||
int m_zero_offset = 0;
|
int m_zero_offset = 0;
|
||||||
unsigned int m_size;
|
unsigned int m_max_size;
|
||||||
|
float m_font_size;
|
||||||
public:
|
public:
|
||||||
ShellBuffer(int size):m_size(size){}
|
ShellBuffer(int buffer_size):m_max_size(buffer_size){}
|
||||||
std::string& operator[](int i){return m_buffer[(m_zero_offset+i)%m_size];}
|
SceneNode* operator[](int i){return m_children[(m_zero_offset+i)%m_max_size];}
|
||||||
void push(std::string);
|
void push(TextNode*);
|
||||||
unsigned int size(){return m_size;}
|
unsigned int size(){return m_children.size();}
|
||||||
|
void setFontSize(float font_size){m_font_size = font_size;}
|
||||||
|
float getFontSize(){return m_font_size;}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const unsigned int BUFFER_MAX_LENGTH;
|
static const unsigned int BUFFER_MAX_LENGTH;
|
||||||
@ -57,11 +55,11 @@ private:
|
|||||||
|
|
||||||
glm::ivec2 m_position;
|
glm::ivec2 m_position;
|
||||||
glm::ivec2 m_dimension;
|
glm::ivec2 m_dimension;
|
||||||
std::vector<MeshNode*> m_textMeshes;
|
|
||||||
ShellBuffer m_buffer;
|
ShellBuffer m_buffer;
|
||||||
int m_index = 0;
|
unsigned int m_index = 0;
|
||||||
bool m_resizeScrollBar = false;
|
bool m_resizeScrollBar = false;
|
||||||
bool m_indexMoved = false;
|
bool m_indexMoved = false;
|
||||||
|
|
||||||
//textMesh
|
//textMesh
|
||||||
MeshNode* m_background;
|
MeshNode* m_background;
|
||||||
ScrollBar m_scrollbar;
|
ScrollBar m_scrollbar;
|
||||||
|
@ -62,7 +62,7 @@ int main(){
|
|||||||
// utils::rotate2D(mnode, glm::vec2(10,10),0.5);
|
// utils::rotate2D(mnode, glm::vec2(10,10),0.5);
|
||||||
// scene.addObject(scene.getRootObject(),mnode);
|
// scene.addObject(scene.getRootObject(),mnode);
|
||||||
|
|
||||||
tnode = fonte_des_neiges->getTextNode("Such Text", glm::vec3(0.7, 0.4, 0.2));
|
tnode = fonte_des_neiges->getTextNode("Such Text", glm::vec3(0.7, 0.4, 0.2),12.f);
|
||||||
|
|
||||||
utils::setPosition2D((MeshNode*)tnode,glm::vec2(200, 170));
|
utils::setPosition2D((MeshNode*)tnode,glm::vec2(200, 170));
|
||||||
utils::rotate2D((MeshNode*)tnode, glm::vec2(0),-0.5);
|
utils::rotate2D((MeshNode*)tnode, glm::vec2(0),-0.5);
|
||||||
@ -84,14 +84,16 @@ int main(){
|
|||||||
// mnode->m_movement = glm::translate(glm::rotate(glm::translate(glm::mat4(), glm::vec3(580, 280, 0)), 0.03f, glm::vec3(0, 0, 1)), glm::vec3(-580, -280, 0));
|
// mnode->m_movement = glm::translate(glm::rotate(glm::translate(glm::mat4(), glm::vec3(580, 280, 0)), 0.03f, glm::vec3(0, 0, 1)), glm::vec3(-580, -280, 0));
|
||||||
// scene.addObject(scene.getRootObject(),mnode);
|
// scene.addObject(scene.getRootObject(),mnode);
|
||||||
|
|
||||||
|
|
||||||
|
engine.setScene(&scene);
|
||||||
|
|
||||||
engine.outputShell("Hello World!");
|
engine.outputShell("Hello World!");
|
||||||
engine.outputShell("Starting test :");
|
engine.outputShell("Starting test :");
|
||||||
|
|
||||||
for(int i = 0; i < 23; i++){
|
for(int i = 0; i < 17; i++){
|
||||||
engine.outputShell(std::to_string(i));
|
engine.outputShell(std::to_string(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.setScene(&scene);
|
|
||||||
engine.start();
|
engine.start();
|
||||||
|
|
||||||
/* GraphNode n1 = GraphNode();
|
/* GraphNode n1 = GraphNode();
|
||||||
|
@ -10,22 +10,29 @@ Font::Font()
|
|||||||
|
|
||||||
TextNode* Font::getTextNode(std::string s, glm::vec3 color, float font_size)
|
TextNode* Font::getTextNode(std::string s, glm::vec3 color, float font_size)
|
||||||
{
|
{
|
||||||
|
|
||||||
Mesh* textmesh = new Mesh();
|
Mesh* textmesh = new Mesh();
|
||||||
glm::ivec2 current_pos;
|
glm::vec2 current_pos;
|
||||||
|
float sizeRatio = font_size / m_defaultLineHeight;
|
||||||
for(char c : s){
|
for(char c : s){
|
||||||
if(c == '\n')
|
if(c == '\n')
|
||||||
{
|
{
|
||||||
current_pos.x = 0; // left alignment -> TODO : be able to center or align right
|
current_pos.x = 0; // left alignment -> TODO : be able to center or align right
|
||||||
current_pos.y += m_lineHeight;
|
current_pos.y += m_defaultLineHeight;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CharInfo charInfo = m_charTable[c];
|
CharInfo charInfo = m_charTable[c];
|
||||||
textmesh->addRectangle2D(current_pos + charInfo.offset,
|
|
||||||
charInfo.dim,
|
glm::vec2 font_offset = glm::vec2(charInfo.offset) * sizeRatio;
|
||||||
glm::vec2(charInfo.pos)/m_scale,
|
|
||||||
glm::vec2(charInfo.dim)/m_scale);
|
textmesh->addRectangle2D((current_pos + font_offset)* sizeRatio,
|
||||||
current_pos.x += charInfo.xadvance;
|
charInfo.dim * sizeRatio,
|
||||||
|
charInfo.pos/m_scale,
|
||||||
|
charInfo.dim/m_scale
|
||||||
|
);
|
||||||
|
|
||||||
|
current_pos.x += (charInfo.xadvance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PhongMaterial *mat = new PhongMaterial();
|
PhongMaterial *mat = new PhongMaterial();
|
||||||
@ -34,6 +41,6 @@ TextNode* Font::getTextNode(std::string s, glm::vec3 color, float font_size)
|
|||||||
mat->diffuse = color;
|
mat->diffuse = color;
|
||||||
textmesh->setMaterial((Material*)mat);
|
textmesh->setMaterial((Material*)mat);
|
||||||
textmesh->initGL();
|
textmesh->initGL();
|
||||||
TextNode *text = new TextNode(textmesh,font_size);
|
TextNode *text = new TextNode(textmesh,s,font_size);
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,10 @@ class Font
|
|||||||
public:
|
public:
|
||||||
struct CharInfo
|
struct CharInfo
|
||||||
{
|
{
|
||||||
glm::ivec2 pos;
|
glm::vec2 pos;
|
||||||
glm::ivec2 dim;
|
glm::vec2 dim;
|
||||||
glm::ivec2 offset;
|
glm::vec2 offset;
|
||||||
int xadvance;
|
float xadvance;
|
||||||
};
|
};
|
||||||
Font();
|
Font();
|
||||||
|
|
||||||
@ -24,8 +24,8 @@ public:
|
|||||||
void setName(std::string name){m_name = name;}
|
void setName(std::string name){m_name = name;}
|
||||||
void addCharInfo(wchar_t character, CharInfo character_info){ m_charTable[character] = character_info; }
|
void addCharInfo(wchar_t character, CharInfo character_info){ m_charTable[character] = character_info; }
|
||||||
void setNbChar(int nbchar){m_nbChar =nbchar;}
|
void setNbChar(int nbchar){m_nbChar =nbchar;}
|
||||||
void setLineHeight(int line_h){m_lineHeight = line_h;}
|
void setLineHeight(int line_h){m_defaultLineHeight = line_h;}
|
||||||
int getLineHeight(){return m_lineHeight;}
|
int getLineHeight(){return m_defaultLineHeight;}
|
||||||
void setBase(int base){m_base = base;}
|
void setBase(int base){m_base = base;}
|
||||||
void setAntiAnliasing(bool antialiasing){m_antiAliasing = antialiasing;}
|
void setAntiAnliasing(bool antialiasing){m_antiAliasing = antialiasing;}
|
||||||
void setScale(glm::vec2 scale){m_scale = scale;}
|
void setScale(glm::vec2 scale){m_scale = scale;}
|
||||||
@ -39,7 +39,7 @@ private:
|
|||||||
glm::vec2 m_scale;
|
glm::vec2 m_scale;
|
||||||
bool m_antiAliasing;
|
bool m_antiAliasing;
|
||||||
int m_nbChar;
|
int m_nbChar;
|
||||||
int m_lineHeight;
|
int m_defaultLineHeight;
|
||||||
int m_base;
|
int m_base;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ Font* Loader::loadFont(const std::string &description_file, const std::string &t
|
|||||||
std::getline(file, line);
|
std::getline(file, line);
|
||||||
Font::CharInfo char_info;
|
Font::CharInfo char_info;
|
||||||
int id;
|
int id;
|
||||||
sscanf(line.c_str(),"char id=%d x=%d y=%d width=%d height=%d xoffset=%d yoffset=%d xadvance=%d",
|
sscanf(line.c_str(),"char id=%f x=%f y=%f width=%f height=%f xoffset=%f yoffset=%f xadvance=%f",
|
||||||
&id, &(char_info.pos.x),&(char_info.pos.y),&(char_info.dim.x), &(char_info.dim.y),
|
&id, &(char_info.pos.x),&(char_info.pos.y),&(char_info.dim.x), &(char_info.dim.y),
|
||||||
&(char_info.offset.x), &(char_info.offset.y), &(char_info.xadvance));
|
&(char_info.offset.x), &(char_info.offset.y), &(char_info.xadvance));
|
||||||
font->addCharInfo(id,char_info);
|
font->addCharInfo(id,char_info);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "glm/ext.hpp"
|
#include "glm/ext.hpp"
|
||||||
//#include "scene/scenetree.h"
|
//#include "scene/scenetree.h"
|
||||||
#include "scene/meshnode.h"
|
#include "scene/meshnode.h"
|
||||||
|
#include "iostream"
|
||||||
|
|
||||||
std::vector<std::string> utils::split(const std::string &line, char sep){
|
std::vector<std::string> utils::split(const std::string &line, char sep){
|
||||||
std::vector<std::string> tokens;
|
std::vector<std::string> tokens;
|
||||||
@ -16,7 +17,10 @@ std::vector<std::string> utils::split(const std::string &line, char sep){
|
|||||||
|
|
||||||
void utils::setPosition2D(MeshNode *mnode, glm::vec2 pos){
|
void utils::setPosition2D(MeshNode *mnode, glm::vec2 pos){
|
||||||
const glm::mat4 &tr = mnode->getTransform();
|
const glm::mat4 &tr = mnode->getTransform();
|
||||||
|
// glm::vec3 v1(pos.x,pos.y,0);
|
||||||
|
// glm::vec3 v2(tr[3]);
|
||||||
mnode->setTransform(glm::translate(tr,glm::vec3(pos.x,pos.y,0) - glm::vec3(tr[3])));
|
mnode->setTransform(glm::translate(tr,glm::vec3(pos.x,pos.y,0) - glm::vec3(tr[3])));
|
||||||
|
// mnode->setTransform(glm::translate(tr,v1 - v2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void utils::resize2D(MeshNode *mnode, glm::vec2 dim, glm::vec2 new_dim){
|
void utils::resize2D(MeshNode *mnode, glm::vec2 dim, glm::vec2 new_dim){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user