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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
#include <sstream>
#include "TGLIncludes.h"
#include "TGLCamera.h"
#include "TGLRnrCtx.h"
#include "TGLSelectRecord.h"
#include "TGLViewerBase.h"
#include "TGLViewer.h"
#include "TImage.h"
#include "TEveManager.h"
#include "Fireworks/Core/interface/CmsAnnotation.h"
#include "Fireworks/Core/src/FWCheckBoxIcon.h"
#include "Fireworks/Core/interface/FWConfiguration.h"
CmsAnnotation::CmsAnnotation(TGLViewerBase* parent, Float_t posx, Float_t posy)
: TGLOverlayElement(TGLOverlayElement::kUser),
fPosX(posx),
fPosY(posy),
fMouseX(0),
fMouseY(0),
fDrag(kNone),
fParent(nullptr),
fSize(0.2),
fSizeDrag(0.0),
fActive(false),
fAllowDestroy(false) {
// Constructor.
// Create annotation as plain text
parent->AddOverlayElement(this);
fParent = (TGLViewer*)parent;
}
CmsAnnotation::~CmsAnnotation() {
// Destructor.
fParent->RemoveOverlayElement(this);
}
void CmsAnnotation::Render(TGLRnrCtx& rnrCtx) {
if (rnrCtx.GetCamera()->RefViewport().Width() == 0 || rnrCtx.GetCamera()->RefViewport().Height() == 0)
return;
static UInt_t ttid_black = 0;
static UInt_t ttid_white = 0;
bool whiteBg = rnrCtx.ColorSet().Background().GetColorIndex() == kWhite;
UInt_t& ttid = whiteBg ? ttid_white : ttid_black;
if ((whiteBg == false && ttid == 0) || (whiteBg && ttid == 0)) {
TImage* imgs[3];
TString base = whiteBg ? "White" : "Black";
imgs[0] = TImage::Open(FWCheckBoxIcon::coreIcondir() + "CMSLogo" + base + "Bg.png");
imgs[1] = TImage::Open(FWCheckBoxIcon::coreIcondir() + "CMSLogo" + base + "BgM.png");
imgs[2] = TImage::Open(FWCheckBoxIcon::coreIcondir() + "CMSLogo" + base + "BgS.png");
glGenTextures(1, &ttid);
glBindTexture(GL_TEXTURE_2D, ttid);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
for (int i = 0; i < 3; i++)
glTexImage2D(GL_TEXTURE_2D,
i,
GL_RGBA,
imgs[i]->GetWidth(),
imgs[i]->GetHeight(),
0,
GL_BGRA,
GL_UNSIGNED_BYTE,
imgs[i]->GetArgbArray());
glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
for (int i = 0; i < 3; i++)
delete imgs[i];
}
glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_POLYGON_BIT);
TGLCapabilitySwitch lights_off(GL_LIGHTING, kFALSE);
// reset matrix
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
if (rnrCtx.Selection()) {
TGLRect rect(*rnrCtx.GetPickRectangle());
rnrCtx.GetCamera()->WindowToViewport(rect);
gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(), (Int_t*)rnrCtx.GetCamera()->RefViewport().CArr());
}
const TGLRect& vp = rnrCtx.RefCamera().RefViewport();
glOrtho(vp.X(), vp.Width(), vp.Y(), vp.Height(), 0, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// move to pos
Float_t posX = vp.Width() * fPosX;
Float_t posY = vp.Height() * fPosY;
glTranslatef(posX, posY, -0.99);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, ttid);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
// logo
glPushName(kMove);
TGLUtil::Color(rnrCtx.ColorSet().Background().GetColorIndex());
glBegin(GL_QUADS);
Float_t z = 0.9;
Float_t a = fSize * vp.Height();
glTexCoord2f(0, 1);
glVertex3f(0, -a, z);
glTexCoord2f(1, 1);
glVertex3f(a, -a, z);
glTexCoord2f(1, 0);
glVertex3f(a, 0, z);
glTexCoord2f(0, 0);
glVertex3f(0, 0, z);
glEnd();
glPopName();
glDisable(GL_TEXTURE_2D);
if (fActive) {
// resize button
glPushMatrix();
glBegin(GL_QUADS);
Float_t a = fSize * vp.Height();
TGLUtil::ColorTransparency(rnrCtx.ColorSet().Markup().GetColorIndex(), 95);
glTexCoord2f(0, 1);
glVertex3f(0, -a, z);
glTexCoord2f(1, 1);
glVertex3f(a, -a, z);
glTexCoord2f(1, 0);
glVertex3f(a, 0, z);
glTexCoord2f(0, 0);
glVertex3f(0, 0, z);
glEnd();
glTranslatef(a, -a, 0);
a *= 0.2;
z = 0.95;
glPushName(kResize);
TGLUtil::ColorTransparency(rnrCtx.ColorSet().Markup().GetColorIndex(), 100);
glBegin(GL_QUADS);
glVertex3f(0, 0, z);
glVertex3f(0, a, z);
glVertex3f(-a, a, z);
glVertex3f(-a, 0, z);
glEnd();
{
glTranslatef(-a / 3, a / 3, 0);
glBegin(GL_LINES);
TGLUtil::ColorTransparency(rnrCtx.ColorSet().Markup().GetColorIndex(), 40);
Float_t s = a / 3;
glVertex3f(0, 0, z);
glVertex3f(0, s, z);
glVertex3f(0, 0, z);
glVertex3f(-s, 0, z);
glEnd();
}
glPopName();
glPopMatrix();
// delete
if (fAllowDestroy) {
glPushName(7);
TGLUtil::ColorTransparency(rnrCtx.ColorSet().Markup().GetColorIndex(), 100);
glTranslatef(0, -a, 0);
glBegin(GL_QUADS);
glVertex3f(0, 0, z);
glVertex3f(a, 0, z);
glVertex3f(a, a, z);
glVertex3f(0, a, z);
glEnd();
{
glBegin(GL_LINES);
TGLUtil::ColorTransparency(rnrCtx.ColorSet().Markup().GetColorIndex(), 40);
Float_t s = a / 3;
glVertex3f(s, s, z);
glVertex3f(a - s, a - s, z);
glVertex3f(s, a - s, z);
glVertex3f(a - s, s, z);
glEnd();
}
glPopName();
}
}
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPopAttrib();
}
Bool_t CmsAnnotation::Handle(TGLRnrCtx& rnrCtx, TGLOvlSelectRecord& selRec, Event_t* event) {
// Handle overlay event.
// Return TRUE if event was handled.
if (selRec.GetN() < 2)
return kFALSE;
int recID = selRec.GetItem(1);
switch (event->fType) {
case kButtonPress: {
fMouseX = event->fX;
fMouseY = event->fY;
fDrag = (recID == kResize) ? kResize : kMove;
fSizeDrag = fSize;
return kTRUE;
}
case kButtonRelease: {
fDrag = kNone;
if (recID == 7) {
fParent->RequestDraw(rnrCtx.ViewerLOD());
delete this;
return kTRUE;
}
break;
}
case kMotionNotify: {
const TGLRect& vp = rnrCtx.RefCamera().RefViewport();
if (vp.Width() == 0 || vp.Height() == 0)
return false;
if (fDrag != kNone) {
if (fDrag == kMove) {
fPosX += (Float_t)(event->fX - fMouseX) / vp.Width();
fPosY -= (Float_t)(event->fY - fMouseY) / vp.Height();
fMouseX = event->fX;
fMouseY = event->fY;
Float_t h = fSize;
Float_t w = fSize / vp.Aspect();
// Make sure we don't go offscreen (use fDraw variables set in draw)
if (fPosX < 0)
fPosX = 0;
else if (fPosX + w > 1.0f)
fPosX = 1.0f - w;
if (fPosY < h)
fPosY = h;
else if (fPosY > 1.0f)
fPosY = 1.0f;
} else {
using namespace TMath;
Float_t oovpw = 1.0f / vp.Width(), oovph = 1.0f / vp.Height();
Float_t xw = oovpw * Min(Max(0, event->fX), vp.Width());
Float_t yw = oovph * Min(Max(0, vp.Height() - event->fY), vp.Height());
Float_t rx = Max((xw - fPosX) / (oovpw * fMouseX - fPosX), 0.0f);
Float_t ry = Max((yw - fPosY) / (oovph * (vp.Height() - fMouseY) - fPosY), 0.0f);
fSize = Max(fSizeDrag * Min(rx, ry), 0.01f);
}
}
return kTRUE;
}
default: {
return kFALSE;
}
}
return false;
}
//______________________________________________________________________________
Bool_t CmsAnnotation::MouseEnter(TGLOvlSelectRecord& /*rec*/) {
// Mouse has entered overlay area.
fActive = kTRUE;
return kTRUE;
}
//______________________________________________________________________
void CmsAnnotation::MouseLeave() {
// Mouse has left overlay area.
fActive = kFALSE;
}
//______________________________________________________________________
bool CmsAnnotation::getVisible() const { return GetState() == TGLOverlayElement::kActive; }
//______________________________________________________________________
void CmsAnnotation::setVisible(Bool_t x) {
SetState(x ? (TGLOverlayElement::kActive) : (TGLOverlayElement::kInvisible));
fParent->Changed();
gEve->Redraw3D();
}
//______________________________________________________________________________
void CmsAnnotation::addTo(FWConfiguration& iTo) const {
std::stringstream s;
s << fSize;
iTo.addKeyValue("LogoSize", FWConfiguration(s.str()));
std::stringstream x;
x << fPosX;
iTo.addKeyValue("LogoPosX", FWConfiguration(x.str()));
std::stringstream y;
y << fPosY;
iTo.addKeyValue("LogoPosY", FWConfiguration(y.str()));
}
void CmsAnnotation::setFrom(const FWConfiguration& iFrom) {
const FWConfiguration* value;
value = iFrom.valueForKey("LogoSize");
if (value)
fSize = atof(value->value().c_str());
value = iFrom.valueForKey("LogoPosX");
if (value)
fPosX = atof(value->value().c_str());
value = iFrom.valueForKey("LogoPosY");
if (value)
fPosY = atof(value->value().c_str());
}
|