Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYPanelGraphic.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
22 #include "gui/gl/TYRenderContext.h"
23 #include <QtOpenGL>
24 
28 
29 #include "TYPanelGraphic.h"
30 
31 #define IMG(id) OLocalizator::getPicture("TYPanelGraphic", (id))
32 
34 {
35  _font = new OGLFont();
36 
37  // Position
38  _posX = 0.0;
39  _posY = 0.0;
40 
41  // Taille du panel
42  _width = 100.0;
43  _height = 100.0;
44 
47 }
48 
50 
51 void TYPanelGraphic::update(bool force /*=false*/)
52 {
54 }
55 
57 {
58  LPTYPanel pPanel = getElement();
59 
60  if (pPanel == NULL)
61  {
62  return;
63  }
64 
65  if (_visible)
66  {
67  GLint viewport[4];
68  glGetIntegerv(GL_VIEWPORT, viewport);
69  unsigned int width = viewport[2];
70  unsigned int height = viewport[3];
71  // On sauvegarde le mode d'affichage des polygones
72  GLdouble polygonMode[2];
73  glGetDoublev(GL_POLYGON_MODE, polygonMode);
74 
75  // Mode GL_FILL
76  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
77 
78  // Nouvelle projection
79  glMatrixMode(GL_PROJECTION);
80  glPushMatrix();
81  glLoadIdentity();
82  glOrtho(0, width, 0.0, height, 0.0, 1.0);
83 
84  // Nouvelle vue
85  glMatrixMode(GL_MODELVIEW);
86  glPushMatrix();
87  glLoadIdentity();
88 
89  // Eloignement du curseur
90  int offset = 5;
91 
92  int x = _posX + offset;
93  int y = _posY - offset;
94  int dx = _width;
95  int dy = _height;
96 
97  // Dessin du panel
98  glColor3fv(_backColor);
99  glBegin(GL_QUADS);
100  glVertex2i(x, y);
101  glVertex2i(x, y - dy);
102  glVertex2i(x + dx, y - dy);
103  glVertex2i(x + dx, y);
104  glEnd();
105 
106  // On charge la texture des polices pour la valeur min
107  _font->load(IMG("id_font").toLatin1().data());
108  _font->bind();
109 
110  // On affiche la position
111  // Delta en x : 3
112  // Delta en y : -3
113  dx = 3 + offset;
114  dy = -3 - offset;
115  x = _posX + dx;
116  y = _posY + dy;
117  _font->drawText(getElement()->getFirstPos() + " " + getElement()->getSecondPos(), OColor::BLACK, x,
118  y);
119 
120  // On affiche la valeur
121  // Delta en x : 3
122  // Delta en y : -23
123  dx = 3 + offset;
124  dy = -23 - offset;
125  x = _posX + dx;
126  y = _posY + dy;
127  _font->drawText(getElement()->getValue(), OColor::BLACK, x, y);
128 
129  // Ancienne projection
130  glMatrixMode(GL_PROJECTION);
131  glPopMatrix();
132 
133  // Ancienne vue
134  glMatrixMode(GL_MODELVIEW);
135  glPopMatrix();
136 
137  // On restaure le mode d'affichage des polygones
138  glPolygonMode(GL_FRONT_AND_BACK, polygonMode[0]);
139  }
140 }
#define IMG(id)
Representation graphique d'un panel d'informations (fichier header)
Contexte de rendu utilisé par les fonctions d'affichage.
static const OColor BLACK
Definition: color.h:86
static const OColor YELLOW
Definition: color.h:92
bool load(const char *filename)
Definition: OGLFont.cpp:30
void drawText(const std::string &msg, const OColor &color, double x, double y) const
Definition: OGLFont.cpp:64
virtual void bind()
Definition: OGLTexture.cpp:32
classe graphique pour un element de base
bool _visible
Inique si l'element est visible.
virtual void update(bool force=false)
TYPanelGraphic(TYPanel *pElement)
virtual void update(bool force=false)
virtual ~TYPanelGraphic()
virtual void display(TYRenderContext &renderContext)
Classe de definition d'un panel d'information.
Definition: TYPanel.h:34