Commit 3be520db authored by Olivier Lagrasse's avatar Olivier Lagrasse

integration du texte dans le render area

parent 50bcc8d6
......@@ -22,19 +22,14 @@ using namespace std;
Interface_graphic::Interface_graphic(QWidget *parent):QWidget(parent){
/* Init pointer attributes */
// _parser = NULL;
_trace = NULL;
_is_rendering_trace = false;
load_windows();
}
Interface_graphic::Interface_graphic(char* file_path, QWidget *parent):QWidget(parent){
/* Init pointer attributes */
// _parser = NULL;
_trace = NULL;
_is_rendering_trace = false;
load_windows();
......@@ -44,6 +39,8 @@ Interface_graphic::Interface_graphic(char* file_path, QWidget *parent):QWidget(p
Interface_graphic::~Interface_graphic(){
/* Qt desallocates _ui_main_window, _ui_info_window and _render_area automatically */
}
......@@ -187,23 +184,34 @@ void Interface_graphic::on_open_triggered(){
ParserPaje parser;
parser.parse(filename.toStdString(), trace);
if(_is_rendering_trace == true)/* Realease the previous trace */
if (_ui_render_area->unbuild()==false)
error("Close file : an error occured with trace releasing.");
if (build(&trace)==false)
error("Open file : an error occured with wait screen releasing.");
_is_rendering_trace = true;
_ui_render_area->update();
}
}
void Interface_graphic::on_close_triggered(){
/***********************************************************************************************/
/* Not Yet Implemented -> Stop the parser and the data structure if they are still implemented */
/***********************************************************************************************/
if(_is_rendering_trace == false)
return;
if (_ui_render_area->unbuild()==false)
error("Close file : an error occured with trace releasing.");
_is_rendering_trace = false;
information(string("File closed."));
_ui_render_area->update();
}
......
......@@ -84,6 +84,17 @@ class Interface_graphic : public QWidget, public Interface{
/***********************************
*
* Render area attribute.
*
**********************************/
/*!
* \brief The state of render.
*/
bool _is_rendering_trace;
/***********************************
*
* Parser attribute.
......@@ -106,7 +117,7 @@ class Interface_graphic : public QWidget, public Interface{
/*!
* \brief The data structure attribute.
*/
Trace* _trace;
//Trace* _trace;
public:
......
......@@ -49,6 +49,8 @@ Render_area::Render_area(QWidget *parent)
_container_x_max = 0;
_container_y_max = 0;
setAutoFillBackground(false);
}
......@@ -87,37 +89,46 @@ void Render_area::initializeGL(){
}
void Render_area::resizeGL(int width, int height){
int side = qMin(width, height);
glViewport((width - side) / 2, (height - side) / 2, side, side);
// int side = qMin(width, height);
// glViewport((width - side) / 2, (height - side) / 2, side, side);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 200, 0, 200, 0, 1000);
glOrtho(0, 100, 0, 100, 0, 1000);
glMatrixMode(GL_MODELVIEW);
}
void Render_area::paintGL(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
void Render_area::paintEvent(QPaintEvent *event){
resizeGL(width(), height());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0,0,60,0,0,0,0,1,0);
switch(_state){
case DRAWING_STATE_WAINTING:/* A wait is drawn */
/* turn around y axis */
glTranslatef(100, 100, 0);
glScalef(3, 3, 0);
glRotatef(-_wait_angle, 0.0f, 1.0f, 0.0f);
_wait_angle+=0.1f;
if (_wait_angle>=360) _wait_angle=0.0f;
// _wait_angle+=0.1f;
//if (_wait_angle>=360) _wait_angle=0.0f;
// glRotatef(-_wait_angle,0, 1, 0);
glPushMatrix();
glTranslatef(50, 50, 0);
glScalef(20, 20, 0);
glCallList(_wait_list);
glPopMatrix();
break;
case DRAWING_STATE_DRAWING:/* A trace is drawn */
......@@ -125,8 +136,8 @@ void Render_area::paintGL(){
glPushMatrix();
glTranslatef(-100, 0, 0);
glScalef(150.0/_container_x_max, 150.0/_container_y_max, 0);
glTranslatef(0, 25, 0);
glScalef(10/_container_x_max, 50.0/_container_y_max, 0);
glCallList(_drawing_list);
......@@ -136,9 +147,9 @@ void Render_area::paintGL(){
default:
_parent->error("Undefined value for the drawing state attribute - Render area");
}
glFlush();
glFlush();
/* Check the errors */
......@@ -147,9 +158,83 @@ void Render_area::paintGL(){
if( glerror != GL_NO_ERROR)
_parent->warning(std::string("Render area : the following OpengGL error occured: ") + std::string((char *)gluErrorString(glerror)));
if (_state== DRAWING_STATE_DRAWING){
QPainter painter(this);
QFont textFont("Helvetica [Cronyx]", 2, QFont::Bold);;
list<Element_pos>::iterator it_pos;
list<string>::iterator it_txt;
Element_pos buf_rot;
Element_pos buf_x;
Element_pos buf_y;
string buf_txt;
painter.setPen(Qt::SolidLine);
painter.setBrush(Qt::white);
painter.setFont(textFont);
painter.translate(0, 25);
painter.scale(10/_container_x_max, 50.0/_container_y_max);
for (it_txt=_text_value.begin(), it_pos=_text_pos.begin() ; it_txt!=_text_value.end(); it_txt++, it_pos++ ){
buf_rot = *it_pos;
it_pos++;
buf_x = *it_pos;
it_pos++;
buf_y = *it_pos;
buf_txt = *it_txt;
cerr << (25+buf_y*height()/100) << " "<< (height()/100)- (25+buf_y*height()/100) <<endl;
// if (buf_rot==1){
// painter.rotate(90);
// painter.translate( (buf_x*width()/100) -10, 25+(buf_y*height()/100) -10);
// painter.drawText(0, 0, buf_txt.c_str());
//}
//else{
// painter.rotate(0);
// painter.translate(0, -(buf_rot*height()/200) );
painter.drawText( (buf_x*width()/100)-10 , 25+(buf_y*height()/100) , buf_txt.c_str());
//painter.drawText( (buf_x*width()/100) -10, 25+(buf_y*height()/100) -10 , buf_txt.c_str());
// }
// painter.drawText(_text_pos.at(i)*(10/_container_x_max), 25+_text_pos.at(i)*( 50.0/_container_y_max), _text_value.at(j).c_str());
}/* end for(...) */
painter.end();
}/* end if (_state== DRAWING_STATE_DRAWING) */
}
//void Render_area::paintEvent(QPaintEvent *event){
//}
/***********************************
*
*
......@@ -166,8 +251,10 @@ bool Render_area::build(Trace* trace){
_trace = trace;
if (glIsList(_wait_list)==GL_TRUE)/* if the list exists */
if (glIsList(_wait_list)==GL_TRUE){/* if the list exists */
glDeleteLists(_wait_list, 1);
_wait_list = 0;
}
if (_wait_timer->isActive()==true)/* if timer for the wait animation is running */
_wait_timer->stop();
......@@ -203,8 +290,10 @@ bool Render_area::unbuild(){
_trace = NULL;
if (glIsList(_drawing_list)==GL_TRUE)/* if the list exists */
if (glIsList(_drawing_list)==GL_TRUE){/* if the list exists */
glDeleteLists(_drawing_list, 1);
_drawing_list = 0;
}
if (_wait_timer->isActive()==false)/* if timer for the wait animation is not running */
_wait_timer->start(_wait_spf);
......@@ -276,10 +365,10 @@ GLuint Render_area::draw_wait() {
glBegin(GL_QUADS);/* draw a square */
{
glTexCoord2d(0,0); glVertex2f(-11, -8);
glTexCoord2d(1,0); glVertex2f(11, -8);
glTexCoord2d(1,1); glVertex2f(11, 8);
glTexCoord2d(0,1); glVertex2f(-11, 8);
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();
......@@ -330,6 +419,7 @@ GLuint Render_area::draw_trace(){//Trace trace)
GLuint list_states;
stack<EntityList> stack_states;
list_containers = glGenLists(1);/* create the list */
if (list_containers==0){
......@@ -414,6 +504,8 @@ GLuint Render_area::draw_trace(){//Trace trace)
if (1 >= number_of_children(container)){/* Should be drawn horizontally */
height_buf = 0;
if (0 == number_of_children(container)){
/* y contains the current height, y_buf the new adding height */
y_buf = _container_height+_container_v_space;
......@@ -422,10 +514,23 @@ GLuint Render_area::draw_trace(){//Trace trace)
/* Then, we store the list of entity */
stack_states.push(container->get_states());
}
draw_container(x, y, _container_width, _container_height);
height_buf = _container_height;
}else
height_buf = height_stack.top()-_container_v_space;/* take the child's height */
draw_container(x, y, _container_width, height_buf);
_text_pos.push_back(height_buf);
_text_pos.push_back(x);
_text_pos.push_back(y);
_text_value.push_back(container->get_name().to_string());
x -= (_container_width + _container_h_space);
}
......@@ -445,7 +550,12 @@ GLuint Render_area::draw_trace(){//Trace trace)
draw_container(x, y, _container_height, height_buf);/* Vertically, it is drawn as higher as it has children */
_text_pos.push_back(height_buf);
_text_pos.push_back(x);
_text_pos.push_back(y);
_text_value.push_back(container->get_name().to_string());
x -= (_container_height + _container_h_space);
......@@ -573,8 +683,8 @@ void Render_area::draw_container(const Element_pos x, const Element_pos y, const
glBegin(GL_QUADS);/* create a quads */
{
glColor3d(0, 0, j);glVertex2d(x, y);
glColor3d(0, 0, j);glVertex2d(x, y-h);
glColor3d(0, 0, j);glVertex2d(x-w, y-h);
glColor3d(0, 0, j-0.1);glVertex2d(x, y-h);
glColor3d(0, 0, j-0.1);glVertex2d(x-w, y-h);
glColor3d(0, 0, j);glVertex2d(x-w, y);
}
glEnd();
......
......@@ -36,6 +36,10 @@ class Render_area : public QGLWidget
std::list<Element_pos> _text_pos;
std::list<std::string> _text_value;
/***********************************
*
* Environment attributes.
......@@ -106,9 +110,10 @@ class Render_area : public QGLWidget
/*!
* \brief Call by the system each time the render area need to be updated.
*/
void paintGL();
// void paintGL();
void paintEvent(QPaintEvent *event);
/***********************************
......@@ -180,17 +185,17 @@ class Render_area : public QGLWidget
/*!
* \brief The default height for containers.
*/
static const float DRAWING_CONTAINER_HEIGHT_DEFAULT = 1.0f;
static const float DRAWING_CONTAINER_HEIGHT_DEFAULT = 1.2f;
/*!
* \brief The default width for containers.
*/
static const float DRAWING_CONTAINER_WIDTH_DEFAULT = 2.0f;
static const float DRAWING_CONTAINER_WIDTH_DEFAULT = 2.5f;
/*!
* \brief The default horizontal space between containers.
*/
static const float DRAWING_CONTAINER_H_SPACE_DEFAULT = 0.2f;
static const float DRAWING_CONTAINER_H_SPACE_DEFAULT = 0.1f;
/*!
* \brief The default vertical space between containers.
......
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