render_area.hpp 20.2 KB
Newer Older
1 2 3 4 5 6 7
/*!
 *\file render_area.hpp
 */

#ifndef RENDER_AREA_HPP
#define RENDER_AREA_HPP

8

9 10
class Render_area;

11

12 13
#include <QtGui>
#include <QGLWidget>/* for the OpenGL Widget */
14

15

16
#include "render.hpp"
17

18
#include "resource.hpp"
19

20 21 22
/*!
 * \brief Structure used to store event information.
 */
23
struct Event_{
24 25 26
    /*!
     * \brief time of an event
     */
27
    Element_pos time;
28 29 30
    /*!
     * \brief height of an event
     */
31
    Element_pos height;
32 33 34
    /*!
     * \brief height of the container
     */
35 36
    Element_pos container_height;
};
37

38 39 40
/*!
 * \brief Structure used to store arrow information.
 */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
41
struct Arrow_{
42 43 44
    /*!
     * \brief time when the arrow starts
     */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
45
    Element_pos start_time;
46 47 48
    /*!
     * \brief time when the arrow ends
     */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
49
    Element_pos end_time;
50 51 52
    /*!
     * \brief ?
     */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
53
    Element_pos start_height;
54 55 56
    /*!
     * \brief ?
     */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
57 58 59 60
    Element_pos end_height;
};


61
/*!
62
 * \brief This class redefined the OpenGL widget - QGLWidget - to display the trace.
63
 */
64
class Render_area : public QGLWidget, public Render
65 66
 {
     Q_OBJECT
67 68


69

70
 protected:
71 72


73 74 75
     /*!
      * \brief Contains container text coordinates.
      */
76 77
     std::list<Element_pos> _text_pos;

78
     /*!
79
      * \brief Contains container strings.
80
      */
81
     std::list<std::string> _text_value;
82

83 84 85 86
     /*!
      * \brief Contains arrow informations.
      */
     std::vector<Arrow_> _arrows;
87

88 89 90 91
     /*!
      * \brief Contains event informations.
      */
     std::vector<Event_> _events;
92 93


94 95 96 97 98 99

     /***********************************
      *
      * Render area state attributes.
      *
      **********************************/
100

101
     /*!
102 103 104 105 106 107 108 109
      * \brief State when there is no file opened.
      */
     static const int DRAWING_STATE_WAINTING = 1;
     
     /*!
      * \brief State when the application is drawing traces.
      */
     static const int DRAWING_STATE_DRAWING = 2;
110

111
     /*!
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
      * \brief Contains the kind of state for the render area (drawing, waiting, etc.).
      */
     int _state;
 


     /***********************************
      *
      * Default QGLWidget functions.
      *
      **********************************/
     
     /*!
      * \brief Call by the system to initialize the OpenGL render area.
      */
     void initializeGL();
     
     /*!
      * \brief Call by the system when the render area was resized (occurs during a window resizement).
      * \arg width : the new width of the render area.
      *      height : the new height of the render area. 
      */
     void resizeGL(int width, int height);
     
     /*!
      * \brief Call by the system each time the render area need to be updated.
138 139
      */
     void paintGL();
140 141 142 143 144 145 146 147 148 149 150 151

     /***********************************
      *
      * The wait screen drawing.
      *
      **********************************/

     
     /***********************************
      * The wait list Attributes.
      **********************************/
     
152 153 154 155 156
     /*!
      * \brief Used for draw counter.
      */
     bool _line_already_begun;

157
     /*!
158 159
      * \brief The wait GLu list.
      */
160
     GLuint _wait_list;
161 162 163 164

     /*!
      * \brief The container GLu list.
      */
165
     GLuint _list_containers;
166 167 168 169

     /*!
      * \brief The state GLu list.
      */
170
     GLuint _list_states;
171 172 173 174

     /*!
      * \brief The counter GLu list.
      */
175
     GLuint _list_counters;
176

177
     /*!
178
      * \brief Rotation angle for the wait.
179 180 181 182
     */
     float _wait_angle;

     /*!
183 184 185 186
      * \brief Time in ms between two frames for the waiting screen.
      */
     static const int DRAWING_TIMER_DEFAULT = 10;
     
187
     /*!
188 189
      * \brief Wait animation seconds per frame.
      */
190
     int _wait_spf;
191 192 193 194 195
     
     /*!
      * \brief Timer to animate the wait. 
      */
     QTimer* _wait_timer;
196

197

198 199 200 201
     /***********************************
      * Drawing function for the wait screen.
      **********************************/
     
202
     /*!
203 204
     * \brief Display a wait on the screen if there is no file opened.
     * \return Asset value of the wait.
205
     */
206 207 208 209
     GLuint draw_wait();



210

211 212 213 214 215 216 217 218 219 220 221
     /***********************************
      *
      * The trace drawing.
      *
      **********************************/


     /***********************************
      * The drawing list Attributes.
      **********************************/
     
222
     /*!
223
      * \brief The trace Glu list.
224
     */
225
     GLuint _drawing_list;
226

227 228 229
     /*!
      * \brief The last x position of the point (for counter).
      */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
230 231
     Element_pos _counter_last_x;

232 233 234 235
     /*!
      * \brief The last y position of the point (for counter).
     */
     Element_pos _counter_last_y;
Olivier Lagrasse's avatar
Olivier Lagrasse committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256

     /*!
      * \brief The opengl render area width in pixels.
      */
     Element_pos _screen_width;

     /*!
      * \brief The opengl render area height in pixels.
      */
     Element_pos _screen_height;

     /*!
      * \brief The opengl visibled scene width in the OpenGL units.
      */
     Element_pos _render_width;

     /*!
      * \brief The opengl visibled scene height in the OpenGL units.
      */
     Element_pos _render_height;

257 258 259
     /*!
      * \brief The width of container area draw.
      */
260
     Element_pos _container_x_max;
Olivier Lagrasse's avatar
Olivier Lagrasse committed
261

262 263 264 265
     /*!
      * \brief The height of container area draw.
      */
     Element_pos _container_y_max;
266

267 268 269
     /*!
      * \brief The width of state area draw.
      */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
270
     Element_pos _state_x_max;
271 272 273 274

     /*!
      * \brief The height of state area draw.
      */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
275
     Element_pos _state_y_max;
276 277 278 279 280 281 282 283 284 285
     
     /*!
      * \brief z position for containers. 
      */
     Element_pos _z_container;

     /*!
      * z position for states.
      */
     Element_pos _z_state;
Olivier Lagrasse's avatar
Olivier Lagrasse committed
286

287 288 289 290
     /*!
      * z position for events.
      */
     Element_pos _z_event;
Olivier Lagrasse's avatar
Olivier Lagrasse committed
291

292 293 294 295
     /*!
      * z position for arrows.
      */
     Element_pos _z_arrow;
Olivier Lagrasse's avatar
Olivier Lagrasse committed
296

297 298 299 300 301
     /*!
      * z position for counters.
      */
     Element_pos _z_counter;

302 303 304 305

     /***********************************
      * Trace Drawing functions and attributes.
      **********************************/
306

307 308 309 310
     /*!
      * \brief The percentage taken by container display in the render area.
      */
     Element_pos _x_scale_container_state;/* temporary */
311

312 313 314
     /*!
      * \brief the scale of state drawing.
      */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
315
     int _state_scale;/* temporary */
316 317 318 319

     /*!
      * \brief The x position of camera view for state drawing area.
     */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
320
     int _state_translate;/* temporary */
321

322

323
 public:
324

325 326 327 328 329 330 331 332


     /***********************************
      *
      * Constructor and destructor.
      *
      **********************************/

333 334 335
     /*!
     * \brief The default constructor
     */
336
     Render_area(QWidget *parent);
337 338 339 340 341

     /*!
     * \brief The destructor
     */
     virtual ~Render_area();
342

343 344 345 346 347 348 349 350


     /***********************************
      *
      * Building functions.
      *
      **********************************/

351
     /*!
352
      * \brief This function draws the trace.
353
      * \arg trace the trace which be displayed. 
354
      */
355
     bool build();
356 357

     /*!
358 359
      * \brief This function releases the trace.
      */
360 361
     bool unbuild();

362 363 364 365
     /*!
     * \brief Change the scale of state drawing.
     * \param scale The new scale value.
     */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
366
     void change_scale(int scale);/* temporary -> to change the scale to view states */
367 368 369 370 371

     /*!
     * \brief Change the x position of camera view for state drawing area.
     * \param translate The new position.
     */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
372
     void change_translate(int translate);/* temporary -> to change the translate to view states */
373 374 375 376 377

     /*!
     * \brief Change the percentage taken by container display in the render area.
     * \param view_size The new percentage (between 0 to 100).
     */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
378 379
     void change_scale_container_state(int view_size);/* temporary -> to change the size of container view */

380
     
381 382 383
     /*!
      * \brief Proceeds with the initialization of the OpenGL draw functions.
      */
384
     void start_draw();
385

386 387 388
     /*!
      * \brief Creates and opens the display list for container draws.
      */
389
     void start_draw_containers();
390 391 392 393 394 395 396 397

     /*!
     * \brief Draw a container according to the parameters
     * \param x the x position of the container
     * \param y the y position of the container
     * \param w the width of the container
     * \param h the height of the container
     */
398
     void draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h);
399 400 401 402 403 404

     /*!
      * \brief Draw the text of a container.
      * \param x the x position of the text.
      * \param y the y position of the text.
      * \param value the string value of the text.
405 406
      *
      * This function stores text in a list. This list will be display each time the render area need to be updated.
407
      */
408
     void draw_container_text(const Element_pos x, const Element_pos y, const std::string value);
409

410 411 412
     /*!
      * \brief Closes the container display list.
      */
413
     void end_draw_containers();
Olivier Lagrasse's avatar
Olivier Lagrasse committed
414
     
415 416 417
     /*!
      * \brief Creates and opens the display list for stater draws.
      */
418
     void start_draw_states();
419 420 421 422 423 424 425 426 427 428 429

     /*!
      * \brief Draw a state of the trace.
      * \param start the beginning time of the state.
      * \param end the ending time of the state.
      * \param base vertical position of the state.
      * \param height the state height.
      * \param r the red color rate of the state.
      * \param g the green color rate of the state.
      * \param b the blue color rate of the state.
      */
430 431
     void draw_state(const Element_pos start , const Element_pos end, const Element_pos base, const Element_pos height, const Element_col r, const Element_col g, const Element_col b);

432 433 434
     /*!
      * \brief Closes the state display list.
      */
435
     void end_draw_states();
436

437 438 439 440 441 442 443 444 445
     /*!
      * \brief Draw an arrow.
      * \param start_time the beginning time of the arrow.
      * \param end_time the ending time of the arrow.
      * \param start_height vertical position of the begining time of the arrow.
      * \param end_height vertical position of the ending time of the arrow.
      *
      * This function stores all the information of the arrow to display it each time the render area need to be updated.
      */
446
     void draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height);
447

448 449 450 451
     /*!
      * \brief Draw arrows contained in the Arrow_ vector
      * \param arrows An arrow vector.
      */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
452 453
     void draw_stored_arrows(std::vector<Arrow_> &arrows);

454 455 456 457 458 459 460 461
     /*!
      * \brief Draw an event.
      * \param time time when the event occurs.
      * \param height vertical position of the event.
      * \param container_height information to draw event. It corresponds to the container height when they are drawn horizontally.
      *
      * This function stores all the information of the event to display it each time the render area need to be updated.
      */
462 463
     void draw_event(const Element_pos time, const Element_pos height,  const Element_pos container_height);

464 465 466 467
     /*!
      * \brief Draw events contained in the Event_ vector
      * \param events An event vector.
      */
468 469
     void draw_stored_events(std::vector<Event_> &events);

470 471 472
     /*!
      * \brief Creates and opens the display list for counter draws.
      */
473 474
     void start_draw_counter();
     
475 476 477 478 479 480 481
     /*!
      * \brief Draw a point of the counter.
      * \param x x position of the point.
      * \param y y position of the point.
      *
      * Each time counter is increased, this function is called with the coordinates of the new point.
      */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
482 483
     void draw_counter(const Element_pos x, const Element_pos y);
     
484 485 486
     /*!
      * \brief Closes the counter display list.
      */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
487
     void end_draw_counter();
488

489 490 491
     /*!
      * \brief Do nothing (it is present for compatibility of the Render class).
      */
492
     void end_draw();
493
    
494 495
  };

496

497 498


499 500 501
/* inline function area */


502 503 504 505 506 507 508 509 510 511
/***********************************
 *
 *
 *
 * Drawing function for the trace.
 *
 *
 *
 **********************************/

512 513 514 515 516

inline void Render_area::start_draw(){
    /* clear lists to store container texts */
    _text_pos.clear();
    _text_value.clear();
Olivier Lagrasse's avatar
Olivier Lagrasse committed
517 518 519 520 521 522

    /* clear the event vector */
    _events.clear();

    /* clear the arrow vector */
    _arrows.clear();
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
}


inline void Render_area::start_draw_containers(){

    _list_containers = glGenLists(1);/* create the list */
    if (_list_containers==0){
        
        //        _parent->warning("Error when creating list");
    }

    glNewList(_list_containers, GL_COMPILE);/* open the list */

}


inline void Render_area::draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h) {

    float j=0.6;

    glBegin(GL_QUADS);/* create a quads */
    {
        glColor3d(0, 0, j);glVertex2d(x, y);
        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();

552 553
    if ((x+w)>_container_x_max)
        _container_x_max = x+w;
554
    
555 556
    if ((y+h)>_container_y_max)
        _container_y_max = y+h;
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594

}

inline void Render_area::draw_container_text(const Element_pos x, const Element_pos y, const std::string value){

    _text_pos.push_back(x); 
    _text_pos.push_back(y);
    _text_value.push_back(value);

}



inline void Render_area::end_draw_containers(){
    glEndList();/* close the list */
}




inline void Render_area::start_draw_states(){

    _list_states = glGenLists(1);/* create the list */
    if (_list_states==0){
        
        //      _parent->warning("Error when creating list");
    }
    
    glNewList(_list_states, GL_COMPILE);/* open the list */
}


inline void Render_area::draw_state(const Element_pos start, const Element_pos end, const Element_pos base, const Element_pos height, const Element_col r, const Element_col g, const Element_col b){

    

#ifdef DEBUG_MODE_RENDER_AREA
    
595 596
    std::cerr << __FILE__ << " l." << __LINE__ << ":" << std::endl;  
    std::cerr << "States position (for drawing): (x = " <<  start << ", y = " << base << ", w = " << end-start << ", h = " << height << ")" << std::endl << std::endl;  
597 598 599

#endif

600 601 602 603
    /** DEBUG **/
    //  if (start==end)
    /* std::cout << std::setprecision(15) << std::endl;
       std::cerr << "Start "<< start << " end " << end << std::endl;*/
604 605 606 607 608
  
    glBegin(GL_QUADS);/* create a quads */
    {
        glColor3d(r, g, b);glVertex2d(start, base);
        glColor3d(r, g, b);glVertex2d(start, base + height);
609 610
        glColor3d(r/1.5, g/1.5, b/1.5);glVertex2d(end, base + height);
        glColor3d(r/1.5, g/1.5, b/1.5);glVertex2d(end, base);
611 612
    }
    glEnd();
Olivier Lagrasse's avatar
Olivier Lagrasse committed
613 614 615 616 617 618

    if (end>_state_x_max)
        _state_x_max = end;
    
    if ((base+height)>_state_y_max)
        _state_y_max = base+height;
619 620 621 622 623 624 625 626 627 628
}


inline void Render_area::end_draw_states(){
    glEndList();/* close the list */
}


inline void Render_area::draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height){

Olivier Lagrasse's avatar
Olivier Lagrasse committed
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
    Arrow_ buf;

    buf.start_time = start_time;
    buf.end_time = end_time;
    buf.start_height = start_height;
    buf.end_height = end_height;

    _arrows.push_back(buf);
}



inline void Render_area::draw_stored_arrows(std::vector<Arrow_> &arrows){

    Element_pos start_time, end_time, start_height, end_height;

    /* Manage the event drawing size from state size and render area dimensions */
    Element_pos arrow_scale_x = _state_scale*(_render_width/_state_x_max);
647
    Element_pos arrow_scale_y = _render_height/_container_y_max;
Olivier Lagrasse's avatar
Olivier Lagrasse committed
648

649 650
    Element_pos angle;

651

Olivier Lagrasse's avatar
Olivier Lagrasse committed
652 653 654 655 656 657 658
    for (long i=0 ; i<(long)arrows.size() ; i++){
        
        
        start_time = arrows[i].start_time*arrow_scale_x + _render_width*_x_scale_container_state-_state_translate; 
        end_time = arrows[i].end_time*arrow_scale_x + _render_width*_x_scale_container_state-_state_translate; 
        start_height = arrows[i].start_height*arrow_scale_y;
        end_height = arrows[i].end_height*arrow_scale_y;
659

Olivier Lagrasse's avatar
Olivier Lagrasse committed
660 661 662 663 664
        /* DEBUG */
        // std::cerr << "Arrow draw: (" << start_time << ", " << start_height << ") to (" << end_time << ", " << end_height << ")" << std::endl;


        glPushMatrix();
665
    
Olivier Lagrasse's avatar
Olivier Lagrasse committed
666 667
        glTranslated(end_time, end_height, _z_arrow);
        glScalef(2, 2, 0);/* should be set */
668
    
669

Olivier Lagrasse's avatar
Olivier Lagrasse committed
670
        if (start_time != end_time){
671

Olivier Lagrasse's avatar
Olivier Lagrasse committed
672
            angle = atan2((end_height - start_height), (end_time - start_time))*180.0f/PI;/* arc tangent */
673

Olivier Lagrasse's avatar
Olivier Lagrasse committed
674
            glRotatef(angle, 0, 0, 1);
675
 
Olivier Lagrasse's avatar
Olivier Lagrasse committed
676 677
        }/* end if (start_time != end_time) */
        else
Olivier Lagrasse's avatar
Olivier Lagrasse committed
678
            glRotatef(90, 0, 0, 1);/* vertical alignment */
679
   
680
    
681

Olivier Lagrasse's avatar
Olivier Lagrasse committed
682 683
        glBegin(GL_TRIANGLES);/* create an arrow */
        {
Olivier Lagrasse's avatar
Olivier Lagrasse committed
684 685 686
            glColor3d(1.0, 1.0, 1.0);glVertex2d(0.0, 0.0);
            glColor3d(0.9, 0.9, 0.9);glVertex2d(-0.6, -0.2);
            glColor3d(0.9, 0.9, 0.9);glVertex2d(-0.6, 0.2);
Olivier Lagrasse's avatar
Olivier Lagrasse committed
687 688
        }
        glEnd();
689
    
Olivier Lagrasse's avatar
Olivier Lagrasse committed
690
        glPopMatrix();
691

Olivier Lagrasse's avatar
Olivier Lagrasse committed
692
        glPushMatrix();
693

Olivier Lagrasse's avatar
Olivier Lagrasse committed
694
        glTranslated(0, 0, _z_arrow);
Olivier Lagrasse's avatar
Olivier Lagrasse committed
695
        // glLineWidth(1.5f);
Olivier Lagrasse's avatar
Olivier Lagrasse committed
696 697
        glBegin(GL_LINES);
        {
Olivier Lagrasse's avatar
Olivier Lagrasse committed
698 699
            glColor3d(0.8, 0.8, 0.8);glVertex2d(start_time, start_height);
            glColor3d(1.0, 1.0, 1.0);glVertex2d(end_time, end_height);
700
        }
Olivier Lagrasse's avatar
Olivier Lagrasse committed
701
        glEnd();
Olivier Lagrasse's avatar
Olivier Lagrasse committed
702
        // glLineWidth(1.0f);/* 1 is the default value */
703

Olivier Lagrasse's avatar
Olivier Lagrasse committed
704 705
        glPopMatrix();
    }
706 707 708
}


709 710
inline void Render_area::draw_event(const Element_pos time, const Element_pos height,  const Element_pos container_height){

711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
    Event_ buf;

    buf.time = time;
    buf.height = height;
    buf.container_height = container_height;

    _events.push_back(buf);
}


inline void Render_area::draw_stored_events(std::vector<Event_> &events){

    Element_pos time, height, container_height;

    /* Manage the event drawing size from state size and render area dimensions */
    Element_pos event_scale_x = _state_scale*(_render_width/_state_x_max);
727
    Element_pos event_scale_y = _render_height/_container_y_max;
728

729 730 731 732 733 734
    Element_pos radius;/* the circle radius */
    Element_pos angle;
    Element_pos delta_angle;
    int step;


735
    for (long i=0 ; i<(long)events.size() ; i++){
736

737 738 739
        time = events[i].time*event_scale_x + _render_width*_x_scale_container_state-_state_translate; 
        height = events[i].height*event_scale_y;
        container_height = events[i].container_height*event_scale_y;
740 741


742 743 744
        /* DEBUG */
        //  std::cerr << "Event draw: (" << time << ", " << height << ") with height of:" << container_height << " - " << _render_width << " : " << _render_height << std::endl;
    
745

746 747 748 749 750
        /* IMPROVEMENT: put the circle into a display list */
        


        /* draw a circle */
751
        radius = 1.0f;
752 753 754 755 756 757 758 759 760 761 762
        angle = PI/2.0f;
        step = 20;/* 20 polygons for the circle */
        
        if (step!=0)
            delta_angle = 2*PI/step;
        
        
        glColor3d(0.5, 0.8, 0.5);
        glBegin(GL_POLYGON);
        {
            for(int i =0 ; i<step ; i++){
Olivier Lagrasse's avatar
Olivier Lagrasse committed
763
                glVertex3d(time + cos(angle+delta_angle*i)*radius , height + sin(angle+delta_angle*i)*radius , _z_event);
764
            }
765
        }
766 767 768
        glEnd();
        
        /* draw line */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
769
        // glLineWidth(1.5f);
770

771 772
        glBegin(GL_LINES);
        {
Olivier Lagrasse's avatar
Olivier Lagrasse committed
773 774
            glColor3d(0.5, 0.8, 0.5);glVertex3d(time, height, _z_event);
            glColor3d(0.4, 0.7, 0.4);glVertex3d(time, height+container_height, _z_event);
775 776
        }
        glEnd();
Olivier Lagrasse's avatar
Olivier Lagrasse committed
777
        // glLineWidth(1.0f);
778

779
    }/* and loop */
780 781 782
}


783 784 785 786 787 788 789 790
/********************
 * Counter
 *******************/

inline void Render_area::start_draw_counter(){

    _list_counters = glGenLists(1);/* create the list */
    if (_list_counters==0){
791
        std::cerr << "Error when creating list" << std::endl;
792 793 794 795
    }
    
    glNewList(_list_counters, GL_COMPILE);/* open the list */

Olivier Lagrasse's avatar
Olivier Lagrasse committed
796
   
797 798 799 800
}


inline void Render_area::draw_counter(const Element_pos x, const Element_pos y){
Olivier Lagrasse's avatar
Olivier Lagrasse committed
801
    
802
    if (x <= 0.0 ){
803 804
        if (_line_already_begun==true){/* it is not the first call */
              glEnd();
Olivier Lagrasse's avatar
Olivier Lagrasse committed
805
        }else
806 807
            _line_already_begun = true;
        
Olivier Lagrasse's avatar
Olivier Lagrasse committed
808
        glBegin(GL_LINE_STRIP);/* set of connected verteces */
809
        glColor3d(1.0, 1.0, 1.0);glVertex2d(0.0, y);/* draw the init point */
810
        
811
        _counter_last_x = 0.0;
812
        
Olivier Lagrasse's avatar
Olivier Lagrasse committed
813
    }else{
814
        
Olivier Lagrasse's avatar
Olivier Lagrasse committed
815
        glColor3d(1.0, 1.0, 1.0);glVertex2d(x, y);
816
        
Olivier Lagrasse's avatar
Olivier Lagrasse committed
817
        _counter_last_x = x;
Olivier Lagrasse's avatar
Olivier Lagrasse committed
818
    }
819
    
Olivier Lagrasse's avatar
Olivier Lagrasse committed
820
    _counter_last_y = y;
821 822 823 824
}


inline void Render_area::end_draw_counter(){
Olivier Lagrasse's avatar
Olivier Lagrasse committed
825
   
826 827 828
    if ( _line_already_begun == true){/* if a line was previously opened */
        glEnd();/* suppose that line is not ended */
    }
Olivier Lagrasse's avatar
Olivier Lagrasse committed
829

830 831 832 833
    glEndList();/* close the list */
}


834

835 836 837 838 839
inline void Render_area::end_draw(){

}


840
 #endif