Mise à jour terminée. Pour connaître les apports de la version 13.8.4 par rapport à notre ancienne version vous pouvez lire les "Release Notes" suivantes :
https://about.gitlab.com/releases/2021/02/11/security-release-gitlab-13-8-4-released/
https://about.gitlab.com/releases/2021/02/05/gitlab-13-8-3-released/

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

#include <QtGui>

8 9 10
#include "render_area.hpp"


11 12 13 14


Render_area::Render_area(QWidget *parent)
 : QGLWidget(parent)
15
{
16 17 18 19 20 21 22
    _parent = (Interface_graphic*)parent;

    if (_parent==NULL){
        cerr << "The render area parent must be passed by arguments.";
        exit(EXIT_FAILURE);
    }

23
    _drawing_state = DRAWING_STATE_WAINTING;/* At the beginning, no trace is drawing */
24

25 26 27 28 29 30 31 32
    /* init the wait animation */
    _wait_list = 0;/* init list */
    _wait_angle=0.0f;/* begin with 0 rad angle */
    _wait_timer = NULL;
    _wait_spf=10;/* 10 milliseconds per frame */
    
    _drawing_list=0;
 
33
}
34 35

 Render_area::~Render_area()
36
 {
37 38
     if (glIsList(_wait_list)==GL_TRUE)
         glDeleteLists(_wait_list, 1);
39 40 41

     if (glIsList(_drawing_list)==GL_TRUE)
         glDeleteLists(_drawing_list, 1);
42 43 44 45 46
 }


void  Render_area::initializeGL()
{
47
    glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
48 49 50
  
    glEnable(GL_DEPTH_TEST);

51
    _wait_list = draw_wait();
52 53 54 55 56 57 58 59 60
}

void  Render_area::resizeGL(int width, int height)
{
     int side = qMin(width, height);
    glViewport((width - side) / 2, (height - side) / 2, side, side);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
61 62 63
    //    gluPerspective(45,(double)640/480,0.1,1000);

    glOrtho(0, 200, 0, 200, 0, 1000);
64 65
    glMatrixMode(GL_MODELVIEW);
}
66

67 68 69 70 71 72

void  Render_area::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
    glLoadIdentity();
73
    gluLookAt(0,0,60,0,0,0,0,1,0);
74 75
  

76 77
    switch(_drawing_state){

78 79 80 81 82 83 84 85
    case DRAWING_STATE_WAINTING:/* A wait is drawn */
       
        /* turn around y axis */
        glTranslatef(100, 100, 0);
        glScalef(3, 3, 0);
        glRotatef(_wait_angle*(-360.0f/(2*PI)), 0.0f, 1.0f, 0.0f);
        _wait_angle+=PI/720.0f;
        if (_wait_angle>=2.0f*PI) _wait_angle=0.0f;
86

87
        glCallList(_wait_list);
88
        break;
89
    
90
    case DRAWING_STATE_DRAWING:/* A trace is drawn */
91

92 93 94 95 96
        glCallList(_drawing_list);
        break;
    default:
        _parent->error("Undefined value for the drawing state attribute - Render area");
    }
97 98

 
99 100 101 102
    
    glFlush();
 
}
103 104 105 106




107
GLuint Render_area::draw_wait()
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
{
    GLuint object;
    GLuint texture;

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

    glGenTextures(1, &texture);/* create the texture and link it with the list previously created */   
    
    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(-15, -8);
            glTexCoord2d(1,0); glVertex2f(15, -8);
            glTexCoord2d(1,1); glVertex2f(15, 8);
            glTexCoord2d(0,1); glVertex2f(-15, 8);
        }
        glEnd();
        
134
     
135 136 137 138 139 140 141 142 143 144 145 146
    }    
    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);

147 148 149 150 151 152 153 154
  
    /* Now, timer is set */
    _wait_angle = 0.0f;
  
    _wait_timer = new QTimer(this);
    connect(_wait_timer, SIGNAL(timeout()), this, SLOT(updateGL()));
    _wait_timer->start(_wait_spf);

155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
    return object;
}



GLuint Render_area::draw_trace()
{
    GLuint object;

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

    glNewList(object, GL_COMPILE);/* open the list */
    {
        glBegin(GL_QUADS);/* create a quads */
        {
            glVertex2f(-15, -8);
            glVertex2f(15, -8);
            glVertex2f(15, 8);
            glVertex2f(-15, 8);
        }
        glEnd();
        
    }    
    glEndList();/* close the list */
    

    return object;
}



bool Render_area::build(){

191 192 193 194 195
    if (glIsList(_wait_list)==GL_TRUE)/* if the list exists */
        glDeleteLists(_wait_list, 1);

    if (_wait_timer->isActive()==true)/* if timer for the wait animation is running */
        _wait_timer->stop();
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223

    if (glIsList(_drawing_list)==GL_FALSE)
        _drawing_list = draw_trace();/* create the trace draw */
    else
        {
            _parent->warning("The trace was not released.");
            return false;
        }

    /* if there is an error, do not display the trace an return immediatly */
    if (_drawing_list!=0)
        {
            _parent->warning("Cannot create the trace.");
            return false;
        }

    _drawing_state = DRAWING_STATE_DRAWING;/* change the drawing state */

    /* disable some OpenGL features to enhance the rendering */
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);

    return true;
}


bool Render_area::unbuild(){

224 225 226 227 228 229 230 231
    if (glIsList(_drawing_list)==GL_TRUE)/* if the list exists */
        glDeleteLists(_drawing_list, 1);
    
    if (_wait_timer->isActive()==true)/* if timer for the wait animation is running */
        _wait_timer->stop();
    
    if (glIsList(_wait_list)==GL_FALSE)
        _wait_list = draw_wait();/* create the wait draw */
232 233
    else
        {
234
            _parent->warning("The wait draw was not released.");
235 236
            return false;
        }
237 238 239
    
    /* if there is an error, do not display the wait an return immediatly */
    if (_wait_list!=0)
240
        {
241
            _parent->warning("Cannot create the wait draw.");
242 243 244
            return false;
        }

245 246 247
    if (_wait_timer->isActive()==false)/* if timer for the wait animation is running */
        _wait_timer->start(_wait_spf);

248 249 250 251 252 253 254 255 256 257 258
    _drawing_state = DRAWING_STATE_WAINTING;/* change the drawing state */

    /* 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);

259
  
260 261
    return true;
}
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293


 
void draw_container(const Level level, const string &name){
    
    /* QPainter painter(this);
    qreal a = 100;
    painter.drawText(QRectF::QRectF(a, a, a, a), Qt::AlignCenter, tr("coucou"));
    */
    glBegin(GL_QUADS);/* create a quads */
    {
        glVertex2f(0, level);
        glVertex2f(0, level+10);
        glVertex2f(name.size(), level+10);
        glVertex2f(name.size(), level);
    }
    glEnd();
    
}

/*void draw_state(const Date start, const Date end, const Level level) const{

   glBegin(GL_QUADS);
    {
        glVertex2f(start, level);
        glVertex2f(end, level+10);
        glVertex2f(end, level+10);
        glVertex2f(start, level);
    }
    glEnd();

    }*/