Code_TYMPAN  4.4.0
Industrial site acoustic simulation
OGLTextElement.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 /*
17  *
18  */
19 
20 #include "OGLTextElement.h"
23 
24 #include "OGLFont.h"
25 
27 {
29 }
30 
32 {
34  {
35  delete m_pOGLFontToDisplay;
36  }
37 }
38 
39 void OGLTextElement::setTextToDisplay(const QString& qsText)
40 {
41  m_qsText = qsText;
42 }
43 
44 void OGLTextElement::setFont(const QString& qsFontPath)
45 {
46  m_qsFontPath = qsFontPath;
47 }
48 
49 void OGLTextElement::setColor(const OColor& oColor)
50 {
51  m_oColor = oColor;
52 }
53 
55 {
56  if (m_bVisible)
57  {
58  // Nouvelle projection
59  glMatrixMode(GL_PROJECTION);
60  glPushMatrix();
61  glLoadIdentity();
62  glOrtho(0, OSizeManager::get()->getWidth(), 0.0, OSizeManager::get()->getHeight(), 0.0, 1.0);
63 
64  // Nouvelle vue
65  glMatrixMode(GL_MODELVIEW);
66  glPushMatrix();
67  glLoadIdentity();
68 
69  // draw the text
70  if (m_pOGLFontToDisplay->load(m_qsFontPath.toStdString().c_str()))
71  {
73 
74  // Convert QString which is UTF-16 encoded to std::string according to
75  // https://stackoverflow.com/questions/4214369/how-to-convert-qstring-to-stdstring
76  std::string stdTxtToDraw;
77 #if defined TY_PLATFORM_LINUX
78  stdTxtToDraw = m_qsText.toUtf8().constData();
79 #else
80  stdTxtToDraw = m_qsText.toLocal8Bit().constData();
81 #endif
82 
84  m_DisplayPositionY + 14);
85  }
86 
87  // Ancienne projection
88  glMatrixMode(GL_PROJECTION);
89  glPopMatrix();
90 
91  // Ancienne vue
92  glMatrixMode(GL_MODELVIEW);
93  glPopMatrix();
94  }
95 
96  return 0;
97 }
Definition: color.h:31
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:68
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
static LPOSizeManager get()