Commit e8af4795 authored by Thibault Soucarre's avatar Thibault Soucarre

clean code for rendering ruler

parent f35201ca
......@@ -207,9 +207,9 @@ public:
inline void draw_container_text(const Element_pos x, const Element_pos y, const std::string value){
/*Container_text_ buf;
buf.x = x;
buf.y = y;
buf.value = value;
buf.x = x;
buf.y = y;
buf.value = value;
_container_texts.push_back(buf);*/
}
......@@ -230,7 +230,7 @@ public:
trace_to_render_y(_containers[i].y),// * _y_state_scale*(_render_height-_ruler_height)/Info::Container::y_max) - _y_state_translate + _ruler_y + _ruler_height,
_z_container,
_containers[i].w * (Info::Render::width/Info::Container::x_max)*_x_scale_container_state,
_containers[i].h * _y_state_scale*(Info::Render::height-_ruler_height)/Info::Container::y_max);
_containers[i].h * _y_state_scale*(Info::Render::height-_ruler_height)/Info::Container::y_max);
}
// std::cout << __FILE__ << " ~ " << __LINE__ << " " << Info::Container::y_max << " " << Info::Container::y_min << std::endl;
......@@ -479,41 +479,7 @@ public:
drawing_instance->start_ruler();
{
/* Since SVG has no depth, first draw the quads then the graduation */
/* Draw quads */
drawing_instance->set_color(0.0, 0.0, 1.0);
drawing_instance->draw_quad(trace_to_render_x(0),
3,
_z_ruler_under,
trace_to_render_x(Info::Render::_x_max_visible) - trace_to_render_x(Info::Render::_x_min_visible),
5.5);
drawing_instance->set_color(0.0, 0.0, 0.0);
drawing_instance->draw_quad(trace_to_render_x(0),
0,
_z_ruler_over,
trace_to_render_x(Info::Render::_x_max_visible) - trace_to_render_x(Info::Render::_x_min_visible),
3);
/* Draw graduations */
drawing_instance->set_color(1, 1, 1);
for (Element_pos i = Info::Render::_x_min_visible ; i < Info::Render::_x_max_visible ; i+=graduation_diff){
const Element_pos grad_div_by_5 = graduation_diff/5;
for (Element_pos j = (i+grad_div_by_5) ;
j<(i+graduation_diff) ;
j+= grad_div_by_5){
drawing_instance->draw_line( trace_to_render_x(j - Info::Render::_x_min_visible) + offset_x, offset_y+3,
trace_to_render_x(j - Info::Render::_x_min_visible) + offset_x, 5+offset_y, _z_ruler);
}
drawing_instance->draw_line( trace_to_render_x(i - Info::Render::_x_min_visible) + offset_x, offset_y+3,
trace_to_render_x(i - Info::Render::_x_min_visible) + offset_x, 7+offset_y, _z_ruler);
}
drawing_instance->call_ruler();
}
drawing_instance->end_ruler();
......@@ -526,63 +492,24 @@ public:
}
/* void browse_container_tree(Trace* trace, std::list<const Container *> l){
const Container::Vector * root_containers = trace->get_root_containers();
if (root_containers->empty()) {
*Message::get_instance() << QObject::tr("There is no container. The trace can not be drawn.").toStdString() << Message::endw;
return;
}
ListContainer root_containers();
ContainerNode *tmp;
for (Container::VectorIt i = root_containers->begin();
i != root_containers->end();
i++)
{
// Use the fact that if a container is selected, then it implies that all his ancestors are
tmp = new ContainerNode(*i, NULL);
root_containers.add(tmp);
}
// position += browse_container(draw_object, *i, position, 0,container);
}
const Container::Vector * root_containers = trace->get_root_containers();
if (root_containers->empty()) {
*Message::get_instance() << QObject::tr("There is no container. The trace can not be drawn.").toStdString() << Message::endw;
return;
}
ListContainer root_containers();
ContainerNode *tmp;
for (Container::VectorIt i = root_containers->begin();
i != root_containers->end();
i++)
{
// Use the fact that if a container is selected, then it implies that all his ancestors are
tmp = new ContainerNode(*i, NULL);
root_containers.add(tmp);
}
// position += browse_container(draw_object, *i, position, 0,container);
}
*/
};
};
#endif
......@@ -244,6 +244,12 @@ virtual void start_draw_events() = 0;
virtual void update_vertical_line() = 0;
//virtual void updateGL() = 0;
/*!
* \brief Draw the ruler display list.
*/
virtual void call_ruler() = 0;
};
......
......@@ -81,6 +81,7 @@ using namespace std;
#define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): "
static bool _draw_container;
static bool _draw_state;
static bool _draw_ruler;
static bool _draw_arrow;
static bool _draw_event;
......@@ -105,7 +106,7 @@ Render_alternate::Render_alternate(Core* core, QWidget *parent, const QGLFormat&
Render_alternate::~Render_alternate(){
cleanupText2D();
//cleanupText2D();
}
/***********************************
......@@ -137,7 +138,7 @@ void Render_alternate::initializeGL() {
std::cout << "init ok" << std::endl;
_modelview = glm::scale(_modelview, glm::vec3(1,-1,1));
_modelview = glm::translate(_modelview, glm::vec3(0,-Info::Render::height, 0));
initText2D("Holstein.DDS");
//initText2D("Holstein.DDS");
}
void Render_alternate::resizeGL(int width, int height) {
......
......@@ -300,7 +300,8 @@ void Render_opengl::paintGL(){
/* Untranslate ruler */
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
call_ruler();
//call_ruler();
glCallList(_list_ruler);
glDisable(GL_BLEND);
if (Info::Render::_vertical_line){
......@@ -723,7 +724,7 @@ void Render_opengl::call_ruler(){
glVertex3d(trace_to_render_x(Info::Render::_x_max_visible) , 3, _z_ruler_over );
glVertex3d(trace_to_render_x(Info::Render::_x_max_visible) , 0, _z_ruler_over );
}
glEnd();
glEnd();
return;
}
......@@ -771,8 +772,6 @@ void Render_opengl::draw_quad(Element_pos x, Element_pos y, Element_pos /*z*/, E
Element_pos offset_x;
const Element_pos offset_y = -_ruler_y - _ruler_height;
if (_draw_ruler) return;/* do not draw quad for ruler */
offset_x = 0;
if (!_draw_container)
......@@ -814,8 +813,6 @@ void Render_opengl::draw_line(Element_pos x1, Element_pos y1, Element_pos x2, El
const Element_pos offset_x = -_default_entity_x_translate;
const Element_pos offset_y = -_ruler_y - _ruler_height;
if (_draw_ruler || _draw_arrow || _draw_event) return;/* do not draw line for ruler or for arrow or for event */
if (_draw_state) message << "Fatal error! Cannot put line in state lists!" << Message::ende;
......@@ -953,10 +950,17 @@ void Render_opengl::end_draw_counter(){
}
void Render_opengl::start_ruler(){
_list_ruler = glGenLists(1);/* create the list */
if (_list_ruler == 0) {
*Message::get_instance() << tr("Error when creating ruler list.").toStdString() << Message::endw;
}
_draw_ruler = true;
glNewList(_list_ruler, GL_COMPILE);/* open the list */
}
void Render_opengl::end_ruler(){
glEndList(); /*close the list*/
_draw_ruler = false;
}
......
......@@ -172,6 +172,11 @@ protected:
*/
GLuint _list_arrows;
/*!
* \brief The ruler GLu list.
*/
GLuint _list_ruler;
/*!
* \brief The wait GLu list.
......
......@@ -326,3 +326,6 @@ void Render_svg::update_vertical_line(){
void Render_svg::set_vertical_line(Element_pos l){
}
void Render_svg::call_ruler(){
}
......@@ -306,6 +306,11 @@ public:
* \param l the line offset.
*/
void set_vertical_line(Element_pos l);
/*!
* \brief Draw the ruler display list.
*/
void call_ruler();
};
......
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