Code_TYMPAN
4.4.0
Industrial site acoustic simulation
Tympan
gui
tools
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
"
21
#include "
Tympan/models/business/OLocalizator.h
"
22
#include "
Tympan/gui/OSizeManager.h
"
23
24
#include "
OGLFont.h
"
25
26
OGLTextElement::OGLTextElement
()
27
{
28
m_pOGLFontToDisplay
=
new
OGLFont
();
29
}
30
31
OGLTextElement::~OGLTextElement
()
32
{
33
if
(
m_pOGLFontToDisplay
)
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
54
int
OGLTextElement::render
()
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
{
72
m_pOGLFontToDisplay
->
bind
();
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
83
m_pOGLFontToDisplay
->
drawText
(stdTxtToDraw,
m_oColor
,
m_DisplayPositionX
,
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
}
OGLFont.h
OGLTextElement.h
OLocalizator.h
OSizeManager.h
OColor
Definition:
color.h:31
OGLElement::m_DisplayPositionX
double m_DisplayPositionX
Definition:
OGLElement.h:71
OGLElement::m_DisplayPositionY
double m_DisplayPositionY
Definition:
OGLElement.h:75
OGLElement::m_bVisible
bool m_bVisible
Definition:
OGLElement.h:76
OGLFont
Definition:
OGLFont.h:34
OGLFont::load
bool load(const char *filename)
Definition:
OGLFont.cpp:30
OGLFont::drawText
void drawText(const std::string &msg, const OColor &color, double x, double y) const
Definition:
OGLFont.cpp:68
OGLTextElement::render
virtual int render()
Definition:
OGLTextElement.cpp:54
OGLTextElement::setColor
void setColor(const OColor &oColor)
Definition:
OGLTextElement.cpp:49
OGLTextElement::m_pOGLFontToDisplay
OGLFont * m_pOGLFontToDisplay
Definition:
OGLTextElement.h:64
OGLTextElement::~OGLTextElement
virtual ~OGLTextElement()
Definition:
OGLTextElement.cpp:31
OGLTextElement::m_oColor
OColor m_oColor
Definition:
OGLTextElement.h:65
OGLTextElement::setTextToDisplay
void setTextToDisplay(const QString &qsText)
Definition:
OGLTextElement.cpp:39
OGLTextElement::m_qsText
QString m_qsText
Definition:
OGLTextElement.h:59
OGLTextElement::setFont
void setFont(const QString &qsFontPath)
Definition:
OGLTextElement.cpp:44
OGLTextElement::OGLTextElement
OGLTextElement()
Definition:
OGLTextElement.cpp:26
OGLTextElement::m_qsFontPath
QString m_qsFontPath
Definition:
OGLTextElement.h:63
OGLTexture::bind
virtual void bind()
Definition:
OGLTexture.cpp:32
OSizeManager::get
static LPOSizeManager get()
Definition:
OSizeManager.cpp:29
Generated on Mon Nov 27 2023 07:56:32 for Code_TYMPAN by
1.9.1