-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobjectosd.cc
302 lines (290 loc) · 9.59 KB
/
globjectosd.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
191
192
193
194
195
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
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
294
295
296
297
298
299
300
301
302
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2007-2023
// e-mail: [email protected]
// address: Centre de donneeS Astrophysique de Marseille (CeSAM)
// Laboratoire d'Astrophysique de Marseille
// P�le de l'Etoile, site de Ch�teau-Gombert
// 38, rue Fr�d�ric Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS U.M.R 7326
// ============================================================================
// See the complete license in LICENSE and/or "http://www.cecill.info".
// ============================================================================
#include "globjectosd.h"
#include <GL/glu.h>
namespace glnemo {
// init static data
char * GLObjectOsd::OsdText[n_OsdKeys] = {
(char *) "" , // DataType
(char *) "" , // Title
(char *) "nbody" , // Nbody
(char *) "time" , // Time
(char *) "" , // Getdata
(char *) "Zoom" , // Zoom
(char *) "Rot" , // Rotation Angle
(char *) "Center" , // Tanslation
(char *) "" , // Loading
(char *) "" // Projection type
};
#define MAX(x,y) ((x) > (y) ? (x) : (y))
// ============================================================================
// constructor
GLObjectOsd::GLObjectOsd(const int w, const int h,
const fntRenderer &f,const QColor &c,
bool activated):GLObject()
{
mycolor = c;
is_activated = activated;
font = f;
width = w;
height = h;
//Osd_text = new GLTextObject[n_OsdKeys](font,c);
Osd_text = new GLTextObject[n_OsdKeys];
for (int i=0; i<n_OsdKeys; i++) {
Osd_text[i].setFont(font);
Osd_text[i].setColor(c);
Osd_text[i].setActivate(true);
}
setTextColor(GLObjectOsd::Loading,Qt::red);
// initialization
for (int i=0; i<n_OsdKeys; i++) {
setText((const OsdKeys) i,"");
}
setText(Loading,"Loading....");
setText(Trans,0.,0.,0.);
setText(Rot,0.,0.,0.);
setText(Zoom,(const float) 0.);
setText(Projection,"Perspective");
Osd_text[Loading].setActivate(FALSE);
updateDisplay();
}
// ============================================================================
// destructor
GLObjectOsd::~GLObjectOsd()
{
}
// ============================================================================
// GLObjectOsd::setWH()
// set witdh and height window
void GLObjectOsd::setWH(int w, int h)
{
width = w;
height = h;
updateDisplay();
}
// ============================================================================
// GLObjectOsd::setText()
// set Text to the selected HubObject
void GLObjectOsd::setText(const OsdKeys k, const QString text)
{
Osd_text[k].setText(OsdText[k], text);
updateDisplay((const OsdKeys) k);
}
// ============================================================================
// GLObjectOsd::setText()
// set int value to the selected HubObject
void GLObjectOsd::setText(const OsdKeys k, int value)
{
setText(k,QString(": %1").arg(value));
}
// ============================================================================
// GLObjectOsd::setText()
// set float value to the selected HubObject
void GLObjectOsd::setText(const OsdKeys k, float value)
{
setText(k,QString(": %1").arg(value,0,'f',4));
}
// ============================================================================
// GLObjectOsd::setText()
// set triple float value to the selected HubObject
void GLObjectOsd::setText(const OsdKeys k,const float x, const float y,
const float z)
{
QString my_text=QString(": %1 %2 %3").arg(x,0,'f',2)
.arg(y,0,'f',2)
.arg(z,0,'f',2);
setText(k,my_text);
}
// ============================================================================
// GLObjectOsd::setTextColor()
// set text color to the selected HubObject
void GLObjectOsd::setTextColor(const OsdKeys k, const QColor c)
{
Osd_text[k].setColor(c);
}
// ============================================================================
// GLObjectOsd::setColor()
// set text color to the selected HubObject
void GLObjectOsd::setColor(const QColor c)
{
for (int i=0; i<n_OsdKeys; i++) {
Osd_text[i].setColor(c);
}
}
// ============================================================================
// GLObjectOsd::keysToggle()
// Toggle the selected HubObject
void GLObjectOsd::keysToggle(const OsdKeys k)
{
Osd_text[k].toggleActivate();
}
// ============================================================================
// GLObjectOsd::keysActivate()
// Activate the selected HubObject
void GLObjectOsd::keysActivate(const OsdKeys k, const bool status)
{
Osd_text[k].setActivate(status);
}
// ============================================================================
// GLObjectOsd::setFont()
// set global font
void GLObjectOsd::setFont(fntRenderer f)
{
font =f;
// first we update the fonts
for (int i=0; i<n_OsdKeys; i++) {
Osd_text[i].setFont(f);
}
// 2nd we update text positions
// first step must be complete otherwise
// it crashs the application
for (int i=0; i<n_OsdKeys; i++) {
updateDisplay((const OsdKeys) i);
}
}
// ============================================================================
// GLObjectOsd::setFont()
// set font to the selected HubObject
void GLObjectOsd::setFont(const OsdKeys k,fntRenderer f)
{
Osd_text[k].setFont(f);
}
// ============================================================================
// GLObjectOsd::updateDisplay()
// Update display for all OsdObject activated
void GLObjectOsd::updateDisplay()
{
if (is_activated) {
for (int i=0; i<n_OsdKeys; i++) {
if (Osd_text[i].getActivate()) {
updateDisplay((const OsdKeys) i);
}
}
}
}
// ============================================================================
// GLObjectOsd::updateDisplay()
// Update display for OsdObject selected
void GLObjectOsd::updateDisplay(const OsdKeys k)
{
int x=0,y=0,x_text=0, max;
switch (k) {
case DataType:
x=0;
y=Osd_text[k].getHeight();
break;
case Title:
x=0;
x_text=(width/2)-Osd_text[k].getTextWidth()/2;
y=Osd_text[k].getHeight();
break;
case Nbody:
max=MAX(Osd_text[Nbody].getLabelWidth(),
Osd_text[Time].getLabelWidth());
x = 0;
y = Osd_text[Time].getHeight()+2+Osd_text[Nbody].getHeight();
x_text = max;
break;
case Time:
max=MAX(Osd_text[Nbody].getLabelWidth(),
Osd_text[Time].getLabelWidth());
x = 0;
y = Osd_text[Time].getHeight();
x_text = max;
break;
case Getdata:
x = 0;
x_text=width-Osd_text[k].getTextWidth()-3;
y=Osd_text[k].getHeight();
break;
case Zoom:
x=0;
y=height-5-Osd_text[Trans].getHeight()-1-
Osd_text[Rot].getHeight()-1;
x_text = Osd_text[Trans].getLabelWidth();
break;
case Rot:
x=0;
y=height-5-Osd_text[Trans].getHeight()-1;
x_text = Osd_text[Trans].getLabelWidth();
break;
case Trans:
x=0;
y=height-5;
x_text = Osd_text[Trans].getLabelWidth();
break;
case Loading:
x = 0;
x_text=width-Osd_text[k].getTextWidth()-3;
y=Osd_text[Getdata].getHeight()+2+Osd_text[k].getHeight();
break;
case Projection:
x=0;
x_text=(width/2)-Osd_text[k].getTextWidth()/2;
y=height-5;
break;
case n_OsdKeys:
break;
}
if (k < n_OsdKeys ) {
Osd_text[k].setPos(x,y, x_text);
}
}
// ============================================================================
// GLObjectOsd::display()
// render Osd text object
void GLObjectOsd::display()
{
if (is_activated) {
// save OpenGL state
glDisable( GL_DEPTH_TEST );
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
//glOrtho(0.,width,0.,height,-1,1);
gluOrtho2D(0.,width,0.,height);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
//glBlendFunc( GL_SRC_ALPHA, GL_ONE ); // original
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // No Alpha bending accumulation
glEnable(GL_BLEND);
font.begin();
for (int i=0; i<n_OsdKeys; i++) {
if (Osd_text[i].getActivate()) {
Osd_text[(const OsdKeys) i].display(width,height);
}
}
font.end();
glDisable(GL_BLEND);
// Restore OpenGL state
glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );
glPopMatrix();
glEnable( GL_DEPTH_TEST );
}
}
// ============================================================================
// GLObjectOsd::updateColor()
// render Osd text object
void GLObjectOsd::updateColor(const QColor col)
{
if (is_activated) {
for (int i=0; i<n_OsdKeys; i++) {
Osd_text[(const OsdKeys) i].setColor(col);
}
}
}
// ============================================================================
}