render_stats_opengl.hpp 5.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*!
 *\file render_stats_opengl.hpp
 */

#ifndef RENDER_STATS_OPENGL_HPP
#define RENDER_STATS_OPENGL_HPP

class Render_stats_opengl;

/* Global informations */
#include "../info/info.hpp"
#include "../interface/interface_console.hpp"
#include "render_stats.hpp"
#include <QGLWidget>
#include "resource.hpp"


/*!
 * \brief This class redefined the OpenGL widget - QGLWidget - to display the trace.
 */
class Render_stats_opengl : public QGLWidget, public Render_stats {
    Q_OBJECT

24
25
26
27
28
29
30
31
32
33
34
35
36
private:
    
    /*!
     * \brief Contains container text coordinates.
     */
    std::list<Element_pos> _text_pos;
    
    /*!
     * \brief Contains container strings.
     */
    std::list<std::string> _text_value;

    GLuint _rect_list;
37
38

    double _translated_y;
39
40
    
    double _translated_x;
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
public:

    /*!
     * \brief The default constructor
     */
    Render_stats_opengl(QWidget *parent);
    
    /*!
     * \brief The destructor
     */
    ~Render_stats_opengl();

    /*!
     * \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).
     * \param width : the new width of the render area.
     * \param 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.
     */
    void paintGL();
  
    /*!
     * \brief Proceeds with the initialization of draw functions.
     */
    
    void start_draw();

    /*!
     * \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.
     */
83
    void draw_text(const Element_pos x, const Element_pos y, const std::string value);
84
85

    /*!
86
87
88
89
90
     * \brief Draw a line.
     * \param x the x position of the text.
     * \param y the y position of the text.
     * \param value the string value of the text.
     */
91
92
    void draw_horizontal_line(const Element_pos x, const Element_pos y, const Element_pos size_x);

93
94
95
96
97
98
99
100
    /*!
     * \brief Draw a line.
     * \param x the x position of the text.
     * \param y the y position of the text.
     * \param value the string value of the text.
     */
    void draw_vertical_line(const Element_pos x, const Element_pos y, const Element_pos size_x);

101
102
103
    void draw_axis(const Element_pos x, const Element_pos y, const Element_pos size_x, const Element_pos size_y);
    /*!
     * \brief Draw a rectangle.
104
105
106
     * \param x the x position of the text.
     * \param y the y position of the text.
     * \param value the string value of the text.
107
     */
108
109
110
111
112
    void draw_rect(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h, const Element_pos r, const Element_pos g, const Element_pos b);
    /*!
     * \brief Proceeds with the end of draw functions.
     */
    void end_draw();
113
114
    
    void translate_y(int value);
115
116
    void translate_x(int value);

117
118
119
120
    /*!
     * \brief Set the height of the render area.
     */
    void set_total_height(Element_pos h);
121
122
123
124
125
126
127

    /*!
     * \brief Set the width of the render area.
     */
    void set_total_width(Element_pos w);

    void clear();
128
129
};

130

131
132
133
134
135
136
137
inline void Render_stats_opengl::start_draw(){
    _text_pos.clear();
    _text_value.clear();
    makeCurrent();
    _rect_list = glGenLists(10);
    glNewList(_rect_list, GL_COMPILE);
}
138
139

inline void Render_stats_opengl::draw_text(const Element_pos x, const Element_pos y, const std::string value) {
140
141
142
143
144
145
146
147

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

//     std::cout << "text: " << value << " @ position : ("<<x<<","<<y<<")." << std::endl;
}

148
149
150
151
152
153
154
155
156
157
inline void Render_stats_opengl::draw_horizontal_line(const Element_pos x, const Element_pos y, const Element_pos size_x){
    glBegin(GL_LINES);
    {
        glColor3ub(0, 0, 0);
        glVertex2i(x, y);
        glVertex2i(x+size_x, y);
    }
    glEnd();
}

158
159
160
161
162
163
164
165
166
167
inline void Render_stats_opengl::draw_vertical_line(const Element_pos x, const Element_pos y, const Element_pos size_y){
    glBegin(GL_LINES);
    {
        glColor3ub(0, 0, 0);
        glVertex2i(x, y);
        glVertex2i(x, y+size_y);
    }
    glEnd();
}

168
169
170
171
172
173
174
175
176
177
inline void Render_stats_opengl::draw_axis(const Element_pos x, const Element_pos y, const Element_pos size_x, const Element_pos size_y){
    glBegin(GL_LINES);
    {
        glColor3ub(0, 0, 0);
        glVertex2i(x, y);
        glVertex2i(x+size_x, y);
        glVertex2i(x, y);
        glVertex2i(x, y+size_y);
    }
    glEnd();
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195

    glBegin(GL_TRIANGLES);/* create an arrow */
    {
        glColor3d(0, 0, 0);
        glVertex2i(x-5, y+size_y-5);
        glVertex2i(x, y+size_y);
        glVertex2i(x+5, y+size_y-5);
    }
    glEnd();

    glBegin(GL_TRIANGLES);/* create an arrow */
    {
        glColor3d(0, 0, 0);
        glVertex2i(x+size_x-5, y+5);
        glVertex2i(x+size_x, y);
        glVertex2i(x+size_x-5, y-5);
    }
    glEnd();
196
197
198
}

inline void Render_stats_opengl::draw_rect(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h, const Element_pos r, const Element_pos g, const Element_pos b) {
199
200
201
    glBegin(GL_QUADS);
    {
        glColor3d(r, g, b); glVertex2d(x, y);
202
        glColor3d(r/1.5, g/1.5, b/1.5); glVertex2d(x, y+h);
203
        glColor3d(r, g, b); glVertex2d(x+w, y+h);
204
        glColor3d(r/1.5, g/1.5, b/1.5); glVertex2d(x+w, y);
205
206
207
    }
    glEnd();
    //std::cout << "rect: " << "x ="<<x<<", y = "<<y<<", w = "<<w<<", "<<h << " ("<<r<<", "<<g<<", "<<b<<") "<<std::endl;
208
209
}

210
211
212
213
214
inline void Render_stats_opengl::end_draw(){
    glEndList();
    paintGL();
    doneCurrent();
}
215

216
#endif