Commit f35201ca authored by Thibault Soucarre's avatar Thibault Soucarre

change text rendering

parent afa63bc6
......@@ -97,7 +97,7 @@ static bool _draw_event;
**********************************/
Render_alternate::Render_alternate(Core* core, QWidget *parent, const QGLFormat& format)
: Hook_event(this, core, parent, format), _containers(GL_QUADS), _states(GL_QUADS), _events(GL_POLYGON), _arrows(GL_LINE), _counters(GL_LINE), _shader("vertexshader.vertexshader", "fragmentshader.fragmentshader"), _modelview(glm::mat4(1.0)), _projection(glm::mat4(1.0)){
: Hook_event(this, core, parent, format), _containers(GL_QUADS), _states(GL_QUADS), _events(GL_POLYGON), _arrows(GL_LINE), _counters(GL_LINE), _ruler(GL_QUADS), _shader("vertexshader.vertexshader", "fragmentshader.fragmentshader"), _modelview(glm::mat4(1.0)), _projection(glm::mat4(1.0)){
setAutoFillBackground(false);
......@@ -183,10 +183,15 @@ void Render_alternate::paintGL(){
glm::mat4 tmp = _modelview;
//_modelview = glm::translate(_modelview, glm::vec3(0.0, Info::Render::height, 100.0));
//_modelview = glm::rotate(_modelview, (float)180.0, glm::vec3(1.0, 0.0, 0.0));
tmp = _modelview;
_ruler.lock();
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
glDrawArrays(GL_QUADS, 0, _ruler.getNbVertex());
_ruler.unlock();
/* drawing containers*/
_containers.lock();
//_modelview = glm::translate(_modelview, glm::vec3(0.0f, _ruler_y + _ruler_height -_y_state_translate, _z_container));
_modelview = glm::translate(_modelview, glm::vec3(0.0, _ruler_y + _ruler_height - _y_state_translate, 0.0));
_modelview = glm::scale(_modelview, glm::vec3(_x_scale_container_state/0.20, _y_state_scale, 1.0));
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
......@@ -196,7 +201,7 @@ void Render_alternate::paintGL(){
/*drawing states*/
_states.lock();
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, 0.0/*_ruler_y + _ruler_height - _y_state_translate*/, 0.0/*_z_state*/));
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate, 0.0/*_z_state*/));
_modelview = glm::scale(_modelview, glm::vec3(_x_state_scale, _y_state_scale, 1));
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
......@@ -218,7 +223,7 @@ void Render_alternate::paintGL(){
//save current modelview
tmp = _modelview;
//change matrix
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, 0 , 0));
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate , 0));
_modelview = glm::scale(_modelview, glm::vec3(_x_state_scale, _y_state_scale, 1.0));
_modelview = glm::translate(_modelview, glm::vec3(_links[4*i+2], _links[4*i+3], 0));
_modelview = glm::rotate(_modelview, (float) _links[4*i], glm::vec3(0,0,1));
......@@ -239,7 +244,7 @@ void Render_alternate::paintGL(){
glUseProgram(0);
//_modelview = glm::translate(_modelview, glm::vec3(0.0, -100*Info::Render::height, 0.0));
//_modelview = glm::scale(_modelview, glm::vec3(1000,100,1));
for(int i=0; i<_texts.size(); i++){
/*for(int i=0; i<_texts.size(); i++){
glm::vec4 current(_texts[i].x, _texts[i].y, 0.0, 1.0);
//we get coordinates beetween (-1 ; 1)
current = _projection * _modelview * current;
......@@ -248,7 +253,44 @@ void Render_alternate::paintGL(){
current[1] = current[1] * 300 + 300;
printText2D(_texts[i].value.c_str(), current[0], current[1], _texts[i].size, _projection, _modelview);
}
_modelview = tmp;
_modelview = tmp;*/
QFont arial_font = QFont("Arial", 10);
qglColor(Qt::white);
const QFontMetrics metric(arial_font);
//we calculate the height of the interline we want : max height of the font + 1 pixel to avoid overlapping (metric.height() returns a bigger value, a bit too much)
int height = metric.tightBoundingRect("fg").height()+1;
/* Draw container text */
const unsigned int texts_size = _texts.size();
std::map<Element_pos,Element_pos> previous_by_column;
//int skipped,displayed=0;
for (unsigned int i=0 ; i<texts_size ; i++){
if (trace_to_render_y(_texts[i].y) + 0.5 < 9) continue;/* Do not display text if it is on the ruler area */
//check if ye are not too close to another container to properly display the text
std::map<Element_pos,Element_pos>::const_iterator it = previous_by_column.find(_texts[i].x);
const std::map<Element_pos,Element_pos>::const_iterator it_end = previous_by_column.end();
if (it==it_end || render_to_screen_y(trace_to_render_y(_texts[i].y)) - render_to_screen_y(trace_to_render_y((*it).second))> height ){
const QString text_elided = metric.elidedText(_texts[i].value.c_str(), Qt::ElideRight, _x_scale_container_state*Info::Screen::width/(Info::Trace::depth+1.));
renderText ( render_to_screen_x(_texts[i].x * _x_scale_container_state/0.20),
render_to_screen_y( trace_to_render_y(_texts[i].y) + 0.5),
text_elided,
arial_font);
//push only displayed values in the map
previous_by_column[_texts[i].x]=_texts[i].y;
//displayed++;
}//else{skipped++;}
}
// Render_alternate::QGLWidget::setFocus(Qt::ActiveWindowFocusReason);/* give the focus to the render area for mouse and keyboard events */
......@@ -682,16 +724,14 @@ void Render_alternate::set_color(float r, float g, float b){
void Render_alternate::draw_text(const Element_pos x, const Element_pos y, const Element_pos size, const std::string s){
if (_draw_ruler) return;/* do not draw text for ruler */
const Element_pos offset_y = -_ruler_y - _ruler_height;
Container_text_ buf;
buf.x = x;
buf.y = y + offset_y; //render_to_trace_y(y);/* Cancel previous transformation. */
buf.y = render_to_trace_y(y);// + offset_y; //render_to_trace_y(y);/* Cancel previous transformation. */
buf.value = s;
buf.size = size;
_texts.push_back(buf);
}
void Render_alternate::draw_quad(Element_pos x, Element_pos y, Element_pos z, Element_pos w, Element_pos h){
Element_pos offset_x;
const Element_pos offset_y = -_ruler_y - _ruler_height;
......@@ -710,6 +750,14 @@ void Render_alternate::draw_quad(Element_pos x, Element_pos y, Element_pos z, El
_states.add(x+offset_x+w, y+offset_y , _r/2, _g/2, _b/2);
_states.add(x+offset_x+w, y+offset_y+h, _r/2, _g/2, _b/2);
_states.add(x+offset_x , y+offset_y+h, _r, _g, _b);
}
else if(_draw_ruler){
std::cout << "coucou" << std::endl;
_ruler.add(x , y , _r, _g, _b);
_ruler.add(x , y+h, _r, _g, _b);
_ruler.add(x+w, y+h, _r, _g, _b);
_ruler.add(x+w, y , _r, _g, _b);
}
/*state = Vbo::VBO_OK;
......@@ -728,7 +776,7 @@ void Render_alternate::draw_quad(Element_pos x, Element_pos y, Element_pos z, El
/* if (NULL == _current_vbo)
message << tr("Cannot create a Vbo for states.").toStdString() << Message::ende;*/
}
/*
glBegin(GL_QUADS);
......@@ -906,6 +954,8 @@ void Render_alternate::start_ruler(){
void Render_alternate::end_ruler(){
_draw_ruler = false;
std::cout << "end_ruler" << std::endl;
_ruler.config();
}
void Render_alternate::end_draw(){
......
......@@ -128,11 +128,12 @@ protected:
std::vector<Container_text_> _texts;
//std::vector<Arrow_> _arrows;
//std::vector<Event_> _circles;
Vbo _containers;
Vbo _states;
Vbo _events;
Vbo _arrows;
Vbo _counters;
Vbo _containers;
Vbo _states;
Vbo _events;
Vbo _arrows;
Vbo _counters;
Vbo _ruler;
public:
......
......@@ -47,8 +47,8 @@ void printText2D(const char * text, int x, int y, int size, glm::mat4 projection
for ( unsigned int i=0 ; i<length ; i++ ){
glm::vec2 vertex_up_left = glm::vec2( x+i*size , y+size );
glm::vec2 vertex_up_right = glm::vec2( x+i*size+size, y+size );
glm::vec2 vertex_down_right = glm::vec2( x+i*size+size, y );
glm::vec2 vertex_down_left = glm::vec2( x+i*size , y );
glm::vec2 vertex_down_right = glm::vec2( x+i*size+size, y-size );
glm::vec2 vertex_down_left = glm::vec2( x+i*size , y-size );
vertices.push_back(vertex_up_left );
vertices.push_back(vertex_down_left );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment