render_stats_opengl.hpp 9.62 KB
Newer Older
Mathieu Faverge's avatar
Mathieu Faverge committed
1 2 3 4 5 6 7 8
/*
** This file is part of the ViTE project.
**
** This software is governed by the CeCILL-A license under French law
** and abiding by the rules of distribution of free software. You can
** use, modify and/or redistribute the software under the terms of the
** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following
** URL: "http://www.cecill.info".
9
**
Mathieu Faverge's avatar
Mathieu Faverge committed
10 11 12 13 14
** As a counterpart to the access to the source code and rights to copy,
** modify and redistribute granted by the license, users are provided
** only with a limited warranty and the software's author, the holder of
** the economic rights, and the successive licensors have only limited
** liability.
15
**
Mathieu Faverge's avatar
Mathieu Faverge committed
16 17 18 19 20 21 22 23 24 25
** In this respect, the user's attention is drawn to the risks associated
** with loading, using, modifying and/or developing or reproducing the
** software by the user in light of its specific status of free software,
** that may mean that it is complicated to manipulate, and that also
** therefore means that it is reserved for developers and experienced
** professionals having in-depth computer knowledge. Users are therefore
** encouraged to load and test the software's suitability as regards
** their requirements in conditions enabling the security of their
** systems and/or data to be ensured and, more generally, to use and
** operate it in the same conditions as regards security.
26
**
Mathieu Faverge's avatar
Mathieu Faverge committed
27 28 29 30
** The fact that you are presently reading this means that you have had
** knowledge of the CeCILL-A license and that you accept its terms.
**
**
31
** ViTE developers are (for version 0.* to 1.0):
Mathieu Faverge's avatar
Mathieu Faverge committed
32 33 34 35 36 37 38 39
**
**        - COULOMB Kevin
**        - FAVERGE Mathieu
**        - JAZEIX Johnny
**        - LAGRASSE Olivier
**        - MARCOUEILLE Jule
**        - NOISETTE Pascal
**        - REDONDY Arthur
40
**        - VUCHENER Clément
Mathieu Faverge's avatar
Mathieu Faverge committed
41 42
**
*/
43 44 45 46 47 48 49
/*!
 *\file render_stats_opengl.hpp
 */

#ifndef RENDER_STATS_OPENGL_HPP
#define RENDER_STATS_OPENGL_HPP

50 51 52 53 54
/* Needed for moc compilation */
#include <stack>
#include <iostream>
/* -- */
#include <QObject>
55
#include <QGLWidget>
56
/* -- */
57
#include "common/common.hpp"
58 59 60 61
/* -- */
#include "render/Geometry.hpp"
#include "render/Hook_event.hpp"
#include "render/render_stats.hpp"
62 63 64 65 66 67 68

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

69
private:
70

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

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

    GLuint _rect_list;
82 83

    double _translated_y;
84

85
    double _translated_x;
86

87 88
    bool _stats_beginned_drawed;

89 90 91 92 93 94
public:

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

96 97 98 99 100 101 102 103 104
    /*!
     * \brief The destructor
     */
    ~Render_stats_opengl();

    /*!
     * \brief Call by the system to initialize the OpenGL render area.
     */
    void initializeGL();
105

106 107 108
    /*!
     * \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.
109
     * \param height : the new height of the render area.
110 111
     */
    void resizeGL(int width, int height);
112

113 114 115 116
    /*!
     * \brief Call by the system each time the render area need to be updated.
     */
    void paintGL();
117

118 119 120
    /*!
     * \brief Proceeds with the initialization of draw functions.
     */
121

122 123 124
    void start_draw();

    /*!
125
     * \fn draw_text(const Element_pos x, const Element_pos y, const std::string value)
126 127 128 129 130
     * \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.
     */
131
    void draw_text(const Element_pos x, const Element_pos y, const std::string value);
132

133 134 135 136 137 138 139 140 141 142
    /*!
     * \fn draw_line(const Element_pos x, const Element_pos y, const Element_pos x2, const Element_pos y2)
     * \brief Draw a line.
     * \param x the x position of the origin.
     * \param y the y position of the origin.
     * \param x2 the x position of the other point.
     * \param y2 the y position of the other point.
     */
    void draw_line(const Element_pos x, const Element_pos y, const Element_pos x2, const Element_pos y2);

143
    /*!
144
     * \fn draw_horizontal_line(const Element_pos x, const Element_pos y, const Element_pos size_x)
145
     * \brief Draw a line.
146 147 148
     * \param x the x position of the origin.
     * \param y the y position of the origin.
     * \param size_x the length of the line.
149
     */
150 151
    void draw_horizontal_line(const Element_pos x, const Element_pos y, const Element_pos size_x);

152
    /*!
153
     * \fn draw_vertical_line(const Element_pos x, const Element_pos y, const Element_pos size_y)
154
     * \brief Draw a line.
155 156 157
     * \param x the x position of the origin.
     * \param y the y position of the origin.
     * \param size_y the length of the line.
158
     */
159
    void draw_vertical_line(const Element_pos x, const Element_pos y, const Element_pos size_y);
160

161 162 163 164 165 166 167 168
    /*!
     * \fn draw_axis(const Element_pos x, const Element_pos y, const Element_pos size_x, const Element_pos size_y)
     * \brief Draw axis.
     * \param x the x position of the origin.
     * \param y the y position of the origin.
     * \param size_x the length for the horizontal axis.
     * \param size_y the length for the vertical axis.
     */
169 170 171
    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.
172 173 174 175 176 177 178
     * \param x the x position of the rectangle.
     * \param y the y position of the rectangle.
     * \param w the width of the rectangle.
     * \param h the height position of the rectangle.
     * \param r the red component color of the rectangle.
     * \param g the green component color of the rectangle.
     * \param b the blue component color of the rectangle.
179
     */
180 181
    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);
    /*!
182
     * \fn end_draw()
183 184 185
     * \brief Proceeds with the end of draw functions.
     */
    void end_draw();
186

187 188 189 190 191
    /*!
     * \fn translate_y(int value)
     * \brief Translate the window on the vertical axis.
     * \param value the new value of the scroll bar.
     */
192
    void translate_y(int value);
193 194 195 196 197
    /*!
     * \fn translate_x(int value)
     * \brief Translate the window on the horizontal axis.
     * \param value the new value of the scroll bar.
     */
198 199
    void translate_x(int value);

200
    /*!
201
     * \fn set_total_height(Element_pos h)
202
     * \brief Set the height of the render area.
203
     * \param h the new height.
204 205
     */
    void set_total_height(Element_pos h);
206 207

    /*!
208
     * \fn set_total_width(Element_pos w)
209
     * \brief Set the width of the render area.
210
     * \param w the new width.
211 212 213
     */
    void set_total_width(Element_pos w);

214 215 216 217 218
    /*!
     * \brief Set the height for one container.
     */
    void set_height_for_one_container(Element_pos h);

219 220 221 222
    /*!
     * \fn clear()
     * \brief Reinitialize the render.
     */
223
    void clear();
224 225
};

226

227 228 229
inline void Render_stats_opengl::start_draw(){
    _text_pos.clear();
    _text_value.clear();
230
    //  makeCurrent();
231
    _stats_beginned_drawed = true;
232
    _rect_list = glGenLists(1);
233
    if(_rect_list == 0) {
234
        std::cerr << "error while initialising _rect_list for stats\n" << std::endl;
235
    }
236 237
    glNewList(_rect_list, GL_COMPILE);
}
238 239

inline void Render_stats_opengl::draw_text(const Element_pos x, const Element_pos y, const std::string value) {
240

241
    _text_pos.push_back(x);
242 243 244 245
    _text_pos.push_back(y);
    _text_value.push_back(value);
}

246 247 248 249 250 251 252 253 254 255
inline void Render_stats_opengl::draw_line(const Element_pos x, const Element_pos y, const Element_pos x2, const Element_pos y2) {
    glBegin(GL_LINES);
    {
        glColor3ub(0, 0, 0);
        glVertex2d(x, y);
        glVertex2d(x2, y2);
    }
    glEnd();
}

256 257 258 259
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);
260 261
        glVertex2d(x, y);
        glVertex2d(x+size_x, y);
262 263 264 265
    }
    glEnd();
}

266 267 268 269
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);
270 271
        glVertex2d(x, y);
        glVertex2d(x, y+size_y);
272 273 274 275
    }
    glEnd();
}

276 277 278 279
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);
280 281 282 283
        glVertex2d(x, y);
        glVertex2d(x+size_x, y);
        glVertex2d(x, y);
        glVertex2d(x, y+size_y);
284 285
    }
    glEnd();
286 287 288 289

    glBegin(GL_TRIANGLES);/* create an arrow */
    {
        glColor3d(0, 0, 0);
290 291 292
        glVertex2d(x-5, y+size_y-5);
        glVertex2d(x, y+size_y);
        glVertex2d(x+5, y+size_y-5);
293 294 295 296 297 298
    }
    glEnd();

    glBegin(GL_TRIANGLES);/* create an arrow */
    {
        glColor3d(0, 0, 0);
299 300 301
        glVertex2d(x+size_x-5, y+5);
        glVertex2d(x+size_x, y);
        glVertex2d(x+size_x-5, y-5);
302 303
    }
    glEnd();
304 305 306
}

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) {
307 308 309
    glBegin(GL_QUADS);
    {
        glColor3d(r, g, b); glVertex2d(x, y);
310
        glColor3d(r/1.5, g/1.5, b/1.5); glVertex2d(x, y+h);
311
        glColor3d(r, g, b); glVertex2d(x+w, y+h);
312
        glColor3d(r/1.5, g/1.5, b/1.5); glVertex2d(x+w, y);
313 314
    }
    glEnd();
315 316
}

317 318 319
inline void Render_stats_opengl::end_draw(){
    glEndList();
    paintGL();
320
    //  doneCurrent();
321
}
322

323
#endif