Code_TYMPAN  4.4.0
Industrial site acoustic simulation
OGLTextElement.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 
16 /*
17  *
18  */
19 
20 #include "OGLTextElement.h"
22 
23 #include "OGLFont.h"
24 
26 {
28 }
29 
31 {
33  {
34  delete m_pOGLFontToDisplay;
35  }
36 }
37 
38 void OGLTextElement::setTextToDisplay(const QString& qsText)
39 {
40  m_qsText = qsText;
41 }
42 
43 void OGLTextElement::setFont(const QString& qsFontPath)
44 {
45  m_qsFontPath = qsFontPath;
46 }
47 
48 void OGLTextElement::setColor(const OColor& oColor)
49 {
50  m_oColor = oColor;
51 }
52 
54 {
55  if (m_bVisible)
56  {
57 
58  GLint viewport[4];
59  glGetIntegerv(GL_VIEWPORT, viewport);
60  unsigned int width = viewport[2];
61  unsigned int height = viewport[3];
62 
63  // Nouvelle projection
64  glMatrixMode(GL_PROJECTION);
65  glPushMatrix();
66  glLoadIdentity();
67  glOrtho(0, width, 0.0, height, 0.0, 1.0);
68 
69  // Nouvelle vue
70  glMatrixMode(GL_MODELVIEW);
71  glPushMatrix();
72  glLoadIdentity();
73 
74  // draw the text
75  if (m_pOGLFontToDisplay->load(m_qsFontPath.toStdString().c_str()))
76  {
78 
79  // Convert QString which is UTF-16 encoded to std::string according to
80  // https://stackoverflow.com/questions/4214369/how-to-convert-qstring-to-stdstring
81  std::string stdTxtToDraw;
82 #if defined TY_PLATFORM_LINUX
83  stdTxtToDraw = m_qsText.toUtf8().constData();
84 #else
85  stdTxtToDraw = m_qsText.toLocal8Bit().constData();
86 #endif
87 
89  m_DisplayPositionY + 14);
90  }
91 
92  // Ancienne projection
93  glMatrixMode(GL_PROJECTION);
94  glPopMatrix();
95 
96  // Ancienne vue
97  glMatrixMode(GL_MODELVIEW);
98  glPopMatrix();
99  }
100 
101  return 0;
102 }
Definition: color.h:36
double m_DisplayPositionX
Definition: OGLElement.h:71
double m_DisplayPositionY
Definition: OGLElement.h:75
bool m_bVisible
Definition: OGLElement.h:76
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 int render()
void setColor(const OColor &oColor)
OGLFont * m_pOGLFontToDisplay
virtual ~OGLTextElement()
void setTextToDisplay(const QString &qsText)
void setFont(const QString &qsFontPath)
QString m_qsFontPath
virtual void bind()
Definition: OGLTexture.cpp:32