Commit 12c725a6 authored by Olivier Lagrasse's avatar Olivier Lagrasse
Browse files

- Correct bug with double clic.

- Rename Render_area to Hook_event.
- Add the '75%' entry for the zoom combo box.
parent fddeffaa
This diff is collapsed.
......@@ -41,17 +41,17 @@
**
*/
/*!
*\file Render_area.hpp
*\file Hook_event.hpp
*/
#ifndef RENDER_AREA_HPP
#define RENDER_AREA_HPP
#ifndef HOOK_EVENT_HPP
#define HOOK_EVENT_HPP
class Render_area;
class Hook_event;
class Core;
class Render_opengl;
......@@ -140,7 +140,7 @@ struct Selection_{
/*!
* \brief This class redefined the OpenGL widget - QGLWidget - to display the trace.
*/
class Render_area : public QGLWidget/*, public Render*/
class Hook_event : public QGLWidget/*, public Render*/
{
Q_OBJECT
......@@ -554,29 +554,6 @@ protected:
/***********************************
*
* Render OpenGL drawing functions.
*
**********************************/
/*!
* \brief Display a wait on the screen if there is no file opened.
* \return Asset value of the wait.
*/
GLuint draw_wait();
/*!
* \brief Create the ruler display list.
* \return Asset value of the ruler.
*/
GLuint draw_ruler();
/*!
* \brief Draw the ruler display list.
*/
void call_ruler();
/***********************************
*
......@@ -587,9 +564,9 @@ protected:
/*!
* \brief The default constructor.
*
* Default constructor has a private scope to avoid any direct instantiation of Render_area.
* Default constructor has a private scope to avoid any direct instantiation of Hook_event.
*/
Render_area();
Hook_event();
public:
......@@ -599,12 +576,12 @@ public:
* \brief The constructor.
* \param render_instance The instance of a drawing class.
*/
Render_area(Render_opengl* render_instance, Core* core, QWidget *parent);
Hook_event(Render_opengl* render_instance, Core* core, QWidget *parent);
/*!
* \brief The destructor
*/
virtual ~Render_area();
virtual ~Hook_event();
......@@ -753,22 +730,6 @@ public:
*/
Element_pos trace_to_render_y(Element_pos e);
/***********************************
*
* Building functions.
*
**********************************/
/*!
* \brief This function draws the trace.
*/
bool build();
/*!
* \brief This function releases the trace.
*/
bool unbuild();
};
......
......@@ -48,7 +48,7 @@
#include "Render_opengl.hpp"
#include "Render_area.hpp"
#include "Hook_event.hpp"
......@@ -70,7 +70,7 @@ using namespace std;
**********************************/
Render_opengl::Render_opengl(Render_opengl* render, Core* core, QWidget *parent)
: Render_area(render, core, parent){
: Hook_event(render, core, parent){
setAutoFillBackground(false);
......@@ -257,3 +257,489 @@ void Render_opengl::paintGL(){
if(glerror != GL_NO_ERROR)
message << tr("Render area : the following OpengGL error occured: ").toStdString() << (char *)gluErrorString(glerror) << Message::endw;
}
/***********************************
*
*
*
* Building functions.
*
*
*
**********************************/
bool Render_opengl::build(){
_state = DRAWING_STATE_DRAWING;/* change the drawing state */
/* disable some OpenGL features to enhance the rendering */
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
replace_scale(1);/* for states scaling */
_x_state_translate = 0;/* for states translation */
_y_state_scale = 1;/* for states scaling */
_y_state_translate = 0;/* for states translation */
_x_scroll_pos = 0;/* horizontal bar placed on 0 */
_y_scroll_pos = 0;/* vertical bar placed on 0 */
if (NULL == _render_instance)
return true;
return _render_instance->display_build();
}
bool Render_opengl::unbuild(){
/**********************
*
* Init OpenGL features
*
**********************/
/* enable some OpenGL features*/
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);/* enable blending for the alpha color */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor3d(1.0, 1.0, 1.0);/* init color to white */
/*****************************
*
* Init render area attributes
*
*****************************/
_state = DRAWING_STATE_WAITING;/* change the drawing state */
_wait_angle=0.0f;/* begin with 0 rad angle */
_wait_angle_y=0.0f;/* begin with 0 rad angle */
/* init measurement attributes */
_container_x_max = 0;
_container_y_max = 0;
_container_x_min = 0;
_container_y_min = 0;
_state_x_max = 0;
_state_y_max = 0;
_state_x_min = 0;
_state_y_min = 0;
_line_already_begun = false;
/* empty the selection stack */
while(false == _previous_selection.empty())
_previous_selection.pop();
if (NULL == _render_instance)
return true;
return _render_instance->display_unbuild();
}
/***********************************
*
*
*
* Drawing function for the wait screen.
*
*
*
**********************************/
GLuint Render_opengl::draw_wait() {
GLuint object;
GLuint texture;
object = glGenLists(1);/* create the list */
if (object == 0)
message << tr("Error when creating list").toStdString() << Message::endw;
glGenTextures(1, &texture);/* create the texture and link it with the list previously created */
QFile texture_file(QString(":/img/img/logo") + QDate::currentDate().toString("MMdd") + QString(".png"));
if (true == texture_file.exists())/* The texture exists */
texture = bindTexture(QPixmap(texture_file.fileName()), GL_TEXTURE_2D);
else/* use the default picture */
texture = bindTexture(QPixmap(":/img/img/logo.png"), GL_TEXTURE_2D);
glNewList(object, GL_COMPILE);/* open the list */
{
glBindTexture(GL_TEXTURE_2D, texture);/* load texture for drawing */
glBegin(GL_QUADS);/* draw a square */
{
glTexCoord2d(0,0); glVertex2f(-1, -1);
glTexCoord2d(1,0); glVertex2f(1, -1);
glTexCoord2d(1,1); glVertex2f(1, 1);
glTexCoord2d(0,1); glVertex2f(-1, 1);
}
glEnd();
}
glEndList();/* close the list */
/* apply some parameters on the texture */
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);/* enable blending for the alpha color */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
/* Now, timer is set */
if (_wait_timer == NULL){
_wait_angle = 0.0f;
_wait_timer = new QTimer(this);
connect(_wait_timer, SIGNAL(timeout()), _render_instance, SLOT(updateGL()));
_wait_timer->start(_wait_spf);
}
return object;
}
GLuint Render_opengl::draw_ruler() {
GLuint object;
unsigned int nb_graduation;
Element_pos graduation_distance_per_5;
double ruler_bg_r, ruler_bg_g, ruler_bg_b;/* the ruler background color (in RGB mode)*/
/* light blue color */
{
ruler_bg_r = 0.5;
ruler_bg_g = 0.5;
ruler_bg_b = 1.0;
}
/*
* NOTE:
* _ruler_distance is the desire distance between 2 graduations.
* There are ceil(_render_width/_ruler_distance) graduations.
* Between 2 consecutive graduations, there are 4 small graduations.
*/
/*
* Graduation number.
*/
nb_graduation = (unsigned int)ceil(_render_width/_ruler_distance);
/*
* Distance between 2 small consecutive graduations.
*/
graduation_distance_per_5 = _ruler_distance/5.0;
/*
* create the list
*/
object = glGenLists(1);
if (object == 0)
message << tr("Error when creating list").toStdString() << Message::endw;
/*
* open the list
*/
glNewList(object, GL_COMPILE);
{
for (unsigned int i = 0 ; i<=nb_graduation ; i++){
/*
* draw small graduations
*/
for (char k = 1 ; k < 5 ; k ++){
glBegin(GL_LINES);
{
glColor3d(1.0, 1.0, 1.0);glVertex2d(i*_ruler_distance+k*graduation_distance_per_5, _ruler_y);
glColor3d(0.6, 0.6, 1.0);glVertex2d(i*_ruler_distance+k*graduation_distance_per_5, _ruler_y+_ruler_height/3.0);
}
glEnd();
}/* end for( k ) */
/*
* Draw the graduation
*/
glBegin(GL_LINES);
{
glColor3d(1.0, 1.0, 1.0);glVertex2d(i*_ruler_distance, _ruler_y);
glColor3d(0.6, 0.6, 1.0);glVertex2d(i*_ruler_distance, _ruler_y+_ruler_height);
}
glEnd();
}/* end for ( i ) */
/* Draw the background */
glBegin(GL_QUADS);
{
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex2d(0, _ruler_y+_ruler_height);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.5);glVertex2d(0, _ruler_y);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.5);glVertex2d(0 + nb_graduation*_ruler_distance, _ruler_y);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex2d(0 + nb_graduation*_ruler_distance, _ruler_y+_ruler_height);
}
glEnd();
}
glEndList();/* close the list */
return object;
}
void Render_opengl::call_ruler(){
Element_pos nb_graduation;
Element_pos graduation_distance_per_5;
Element_pos buf_time;
Element_pos _info_degree_x;
Element_pos _info_degree_width;
ostringstream buf_txt;
Element_pos entire_part_d;
Element_pos degree_d;
Element_pos pow_10_degree_d;
Element_pos buf_min;
Element_pos buf_max;
Element_pos buf_d;
double ruler_bg_r, ruler_bg_g, ruler_bg_b;/* the ruler background color (in RGB mode)*/
/* light blue color */
{
ruler_bg_r = 0.5;
ruler_bg_g = 0.5;
ruler_bg_b = 1.0;
}
/* Contains the degree scale to get a number from 0.01 to 100 */
const Element_pos mul_scale_d = 4;
/* Contains the scale to get a number from 0.01 to 100 (equals to 10^mul_scale_d) */
const Element_pos mul_scale = 10000;
/* The ruler accurate */
const Element_pos limit_d = 0.00000000001;
/* Graduation number. */
nb_graduation = ceil(_render_width/_ruler_distance);
/* Distance between 2 small consecutive graduations. */
graduation_distance_per_5 = _ruler_distance/5.0;
/* Use to temporary store the graduation time value. */
buf_time = 0;
/* The info degree x beginning position. */
_info_degree_x = 0;
/* The info degree width: dynamically computed to fit its value. Default size: 1. */
_info_degree_width = 0;
/* Use to temporary store the graduation time value text. */
buf_txt.str("");
/*
* The following variables are used to work out each graduation value
* in a correct format.
* Need to work out the degree of ruler graduation time value.
*
* Try to distinct the common number part of each graduation and the distinct part
* from the left.
* For example, between 3.67834 and 3.67854, the common part is: 3.678 and
* the distinct part is 0.000xx (xx = {34,54})
*/
/* Update Info::Render::_x_min_visible and Info::Render::_x_max_visible values */
update_visible_interval_value();
/* Contains the common left part of each graduate values */
entire_part_d = 0;
/* Contains the degree used to know how many we need to multiply to get
the uncommon right part of each graduate values more than 0.01 */
degree_d = 0;
/* Contains 10^degree_d */
pow_10_degree_d = 1;
/* Just a buffer for intermediate computations */
buf_d = 0;
/*
* Draw ruler
*/
if (glIsList(_list_ruler) == GL_FALSE) {
message << tr("ERROR LIST not exist for the ruler.").toStdString() << Message::ende;
}
else{
glPushMatrix();
/*
* Just translate for ruler follows the entity translate.
*/
glTranslated( - (int)_x_state_translate % (int)_ruler_distance, 0, _z_ruler);
glCallList(_list_ruler);
glPopMatrix();
}
/*
* Work out the graduation time value degree.
*/
buf_max = Info::Render::_x_max_visible;
buf_min = Info::Render::_x_min_visible;
if (buf_max>limit_d){
while (buf_max>1){
buf_max/=10.0;
buf_min/=10.0;
degree_d--;
pow_10_degree_d /= 10.0;
}
}
buf_d = 0;/* to secure */
while ( (floor(buf_max) == floor(buf_min)) && (buf_d<10) ){/* buf<10 means that buf_max if greater than limit_d ! */
buf_max *= 10;
buf_min *= 10;
pow_10_degree_d *= 10;
degree_d++;
buf_d++;
}
/* ignore the last figure */
// if (degree_d >= 0){
pow_10_degree_d /= 10;
degree_d--;
//}
entire_part_d = floor( Info::Render::_x_max_visible * pow_10_degree_d );
/*
* Draw the current ruler degree
*/
/* Draw the text */
glColor3d(1.0, 1.0, 1.0);/* text color */
glRasterPos2f( 0, _ruler_y+_ruler_height);
buf_txt << entire_part_d << "Xe-" << degree_d+mul_scale_d;
for(unsigned int j = 0 ; j < buf_txt.str().length() ; j ++){
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]);
_info_degree_width += glutBitmapWidth(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]);
}
_info_degree_width = screen_to_render_x(_info_degree_width);
buf_txt.str("");/* flush the buffer */
/* Draw the foreground */
glBegin(GL_QUADS);
{
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x, _ruler_y+_ruler_height, _z_ruler_over);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x, _ruler_y, _z_ruler_over);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x + _info_degree_width, _ruler_y, _z_ruler_over);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x + _info_degree_width, _ruler_y+_ruler_height, _z_ruler_over);
}
glEnd();
/*
* Draw coordinates
*/
glColor3d(1.0, 1.0, 1.0);/* text color */
for (unsigned int i = 0 ; i<=nb_graduation ; i++){
/*
* Work out the graduation time value.
*/
buf_time = render_to_trace_x(i*_ruler_distance);
if (buf_time < 0) continue;/* do not display negative time values */
/* Now, convert (XXX,XXXXXXXXX) to (YYY * 10^ZZ and a common part WWWWWW * 10^TT) */
/* trunc the common part of each number */
buf_d = buf_time*pow_10_degree_d;
buf_d = buf_d - floor( buf_d );
/* Mul buf_time to belongs to ]1000;0[ */
buf_d *= mul_scale;
/* Keep the entire part only */
buf_d = floor(buf_d);
/* Finally, fill the text buffer to display the graduate value */
buf_txt << buf_d;
/*
* Display the graduation time value.
*/
glRasterPos2f( - (int)_x_state_translate % (int)_ruler_distance + i*_ruler_distance, _ruler_y+_ruler_height);/* set position */
if ( _info_degree_width < ( i*_ruler_distance - ((int)_x_state_translate % (int)_ruler_distance)) ){
for(unsigned int j = 0 ; j < buf_txt.str().length() ; j ++){
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]);
}
}/* end for ( i ) */
buf_txt.str("");/* flush the buffer */
}/* end for ( i ) */
}
......@@ -51,13 +51,13 @@
class Core;
#include "render.hpp"
#include "Render_area.hpp"
#include "Hook_event.hpp"
/*!