]>
Commit | Line | Data |
---|---|---|
0343cac7 | 1 | // $Header$ |
2 | ||
3 | #include "ITSModuleStepperGL.h" | |
4 | ||
5 | #include <Reve/GLTextNS.h> | |
6 | #include <Reve/GLUtilNS.h> | |
64736a7f | 7 | #include <Reve/RGTopFrame.h> |
8 | #include <Reve/RGEditor.h> | |
9 | #include <Reve/RGBAPalette.h> | |
10 | ||
0343cac7 | 11 | #include <Alieve/ITSModuleStepper.h> |
64736a7f | 12 | #include <Alieve/ITSScaledModule.h> |
0343cac7 | 13 | |
14 | #include <TGLDrawFlags.h> | |
15 | ||
16 | using namespace Reve; | |
17 | using namespace Alieve; | |
18 | ||
19 | //______________________________________________________________________ | |
20 | // ITSModuleStepperGL | |
21 | // | |
22 | ||
23 | ClassImp(ITSModuleStepperGL) | |
24 | ||
25 | ITSModuleStepperGL::ITSModuleStepperGL() : TGLObject(), fM(0) | |
26 | { | |
98b5e1dd | 27 | fCached = false; // Disable display list. |
0343cac7 | 28 | } |
29 | ||
30 | ITSModuleStepperGL::~ITSModuleStepperGL() | |
31 | {} | |
32 | ||
33 | /**************************************************************************/ | |
34 | ||
35 | Bool_t ITSModuleStepperGL::SetModel(TObject* obj) | |
36 | { | |
37 | if(SetModelCheckClass(obj, ITSModuleStepper::Class())) { | |
38 | fM = dynamic_cast<ITSModuleStepper*>(obj); | |
39 | return kTRUE; | |
40 | } | |
41 | return kFALSE; | |
42 | } | |
43 | ||
44 | void ITSModuleStepperGL::SetBBox() | |
45 | { | |
46 | // !! This ok if master sub-classed from TAttBBox | |
47 | SetAxisAlignedBBox(fM->AssertBBox()); | |
48 | } | |
49 | ||
50 | /**************************************************************************/ | |
51 | ||
52 | void ITSModuleStepperGL::DirectDraw(const TGLDrawFlags & flags) const | |
53 | { | |
54 | // printf("ITSModuleStepperGL::DirectDraw Style %d, LOD %d\n", flags.Style(), flags.LOD()); | |
55 | ||
56 | ITSModuleStepper& MS = *fM; | |
57 | Int_t W = Int_t(MS.fStepper->Dx*MS.fStepper->Nx); | |
58 | Int_t H = Int_t(MS.fStepper->Dy*MS.fStepper->Ny); | |
59 | Float_t dx = W*MS.fWWidth; | |
64736a7f | 60 | Float_t dy = 6; // H*MS.fWHeight; |
0343cac7 | 61 | |
62 | GLboolean lightp; | |
63 | glGetBooleanv(GL_LIGHTING, &lightp); | |
64 | if (lightp) glDisable(GL_LIGHTING); | |
65 | ||
98b5e1dd | 66 | UChar_t color[4]; |
67 | ColorFromIdx(MS.fWColor, color); | |
68 | glColor4ubv(color); | |
69 | ||
0343cac7 | 70 | // render frame of grid stepper |
71 | if (MS.fRnrFrame) | |
72 | { | |
0343cac7 | 73 | glBegin(GL_LINE_LOOP); |
64736a7f | 74 | glVertex2f(-1, -1); |
75 | glVertex2f(W+1, -1); | |
76 | glVertex2f(W+1, H+1); | |
77 | glVertex2f(-1 , H+1); | |
0343cac7 | 78 | glEnd(); |
79 | } | |
80 | ||
81 | // triangles | |
82 | glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT); | |
83 | glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | |
98b5e1dd | 84 | glDisable(GL_CULL_FACE); |
64736a7f | 85 | glEnable(GL_BLEND); |
86 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | |
0343cac7 | 87 | |
88 | Float_t sx =0 ,sy = 0; | |
89 | switch(MS.fWCorner) { | |
90 | case ITSModuleStepper::PT_BottomLeft: | |
91 | sy = -dy; | |
92 | break; | |
93 | case ITSModuleStepper::PT_BottomRight: | |
94 | sy = -dy; | |
95 | break; | |
96 | case ITSModuleStepper::PT_TopLeft: | |
97 | sy = H; | |
98 | break; | |
99 | case ITSModuleStepper::PT_TopRight: | |
100 | sy = H; | |
101 | break; | |
102 | default: | |
103 | sy = dy; | |
104 | break; | |
105 | } | |
106 | ||
107 | if (flags.SecSelection()) glPushName(0); | |
0343cac7 | 108 | glPushMatrix(); |
0343cac7 | 109 | glTranslatef(sx, sy, 0.); |
110 | ||
64736a7f | 111 | // pager |
0343cac7 | 112 | if (flags.SecSelection()) glLoadName(2); |
64736a7f | 113 | RenderSymbol(dx, dy, 2); |
0343cac7 | 114 | glTranslatef(dx, 0, 0); |
115 | if (flags.SecSelection()) glLoadName(1); | |
64736a7f | 116 | RenderSymbol(dx, dy, 1); |
0343cac7 | 117 | glTranslatef(dx, 0, 0); |
64736a7f | 118 | RenderString(Form(" %d/%d ", MS.GetCurrentPage(), MS.GetPages()), dy); |
0343cac7 | 119 | if (flags.SecSelection()) glLoadName(3); |
64736a7f | 120 | RenderSymbol(dx, dy, 3); |
0343cac7 | 121 | glTranslatef(dx, 0, 0); |
122 | if (flags.SecSelection()) glLoadName(4); | |
64736a7f | 123 | RenderSymbol(dx, dy, 4); |
124 | glTranslatef(2*dx, 0, 0); | |
125 | ||
126 | // scale info | |
127 | Int_t cnx = 0, cnz = 0; | |
128 | ITSDigitsInfo* di = MS.fDigitsInfo; | |
129 | Int_t scale = fM->fScaleInfo->GetScale(); | |
130 | ITSScaledModule* sm = dynamic_cast<ITSScaledModule*>(*fM->BeginChildren()); | |
131 | switch(sm->GetSubDetID()) | |
132 | { | |
133 | case 0: | |
134 | cnx = di->fSPDScaleX[scale], cnz = di->fSPDScaleZ[scale]; | |
135 | break; | |
136 | case 1: | |
137 | cnx = di->fSDDScaleX[scale], cnz = di->fSDDScaleZ[scale]; | |
138 | break; | |
139 | case 2: | |
140 | cnx = di->fSSDScale[scale], cnz = 1; | |
141 | break; | |
142 | } | |
143 | RenderString(Form("Scale: %dx%d ", cnx, cnz), dy); | |
144 | ||
145 | // up down arrows | |
146 | if (flags.SecSelection()) glLoadName(6); | |
147 | RenderSymbol(dx, dy, 5); | |
148 | if (flags.SecSelection()) glLoadName(7); | |
149 | RenderSymbol(dx, dy, 6); | |
150 | glTranslatef(2*dx, 0, 0); | |
151 | glTranslatef(0, dy*0.25,0); | |
152 | ||
0343cac7 | 153 | |
64736a7f | 154 | glPopMatrix(); |
155 | if (flags.SecSelection()) glLoadName(5); | |
156 | glPushMatrix(); | |
157 | glTranslatef(W+2, 0, 0); | |
158 | RenderPalette(H, 4); | |
0343cac7 | 159 | glPopMatrix(); |
160 | ||
161 | if (flags.SecSelection()) glPopName(); | |
162 | ||
163 | glPopAttrib(); | |
164 | ||
165 | if (lightp) glEnable(GL_LIGHTING); | |
0343cac7 | 166 | } |
64736a7f | 167 | |
0343cac7 | 168 | /**************************************************************************/ |
64736a7f | 169 | |
170 | void ITSModuleStepperGL::RenderPalette(Float_t dx, Float_t dy) const | |
171 | { | |
172 | ITSModule* qs = dynamic_cast<ITSModule*>(*fM->BeginChildren()); | |
173 | RGBAPalette* p = qs->GetPalette(); | |
174 | Float_t xs = dx/(p->GetMaxVal()- p->GetMinVal()); | |
175 | Float_t ys = dy; | |
176 | ||
177 | Float_t x = 0; | |
178 | glBegin(GL_QUAD_STRIP); | |
179 | for(Int_t i=p->GetMinVal(); i<=p->GetMaxVal(); i++) | |
180 | { | |
181 | glColor4ubv(p->ColorFromValue(i + p->GetMinVal())); | |
182 | glVertex2f(0, x); | |
183 | glVertex2f(ys, x); | |
184 | x+=xs; | |
185 | } | |
186 | glEnd(); | |
187 | } | |
188 | ||
189 | /**************************************************************************/ | |
190 | ||
191 | void ITSModuleStepperGL::RenderSymbol(Float_t dx, Float_t dy, Int_t id) const | |
0343cac7 | 192 | { |
193 | Float_t xs = dx/4, ys = dy/4; | |
194 | ||
64736a7f | 195 | if(id == 0) { |
196 | glBegin(GL_QUADS); | |
197 | glVertex2f(0,ys); glVertex2f(0, ys*3); | |
198 | glVertex2f(dx, ys*3); glVertex2f(dx, ys); | |
199 | glEnd(); | |
200 | return; | |
201 | } | |
202 | ||
203 | ||
0343cac7 | 204 | glBegin(GL_TRIANGLES); |
205 | switch (id) { | |
206 | case 1: | |
207 | { | |
208 | glVertex2f(xs*2.5, ys*3); glVertex2f(xs*1.5, ys*2); glVertex2f(xs*2.5, ys); | |
209 | break; | |
210 | } | |
211 | case 2: | |
212 | { | |
213 | glVertex2f(xs*2, ys*3); glVertex2f(xs, ys*2); glVertex2f(xs*2, ys); | |
214 | glVertex2f(xs*3, ys*3); glVertex2f(xs*2, ys*2); glVertex2f(xs*3, ys); | |
215 | break; | |
216 | } | |
217 | case 3: | |
218 | { | |
219 | glVertex2f(xs*1.5, ys); glVertex2f(xs*2.5, ys*2); glVertex2f(xs*1.5, ys*3); | |
220 | break; | |
221 | } | |
222 | case 4: | |
223 | { | |
224 | glVertex2f(xs, ys); glVertex2f(xs*2, ys*2); glVertex2f(xs, ys*3); | |
225 | glVertex2f(xs*2, ys); glVertex2f(xs*3, ys*2); glVertex2f(xs*2, ys*3); | |
226 | break; | |
227 | } | |
64736a7f | 228 | case 5: |
229 | { | |
230 | glVertex2f(xs, ys*2.5); glVertex2f(xs*2, ys*3.5); glVertex2f(xs*3, ys*2.5); | |
231 | break; | |
232 | } | |
233 | case 6: | |
234 | { | |
235 | glVertex2f(xs, ys*1.5); glVertex2f(xs*2, ys*0.5); glVertex2f(xs*3, ys*1.5); | |
236 | break; | |
237 | } | |
238 | ||
0343cac7 | 239 | default: |
240 | break; | |
241 | } | |
242 | glEnd(); | |
64736a7f | 243 | } |
0343cac7 | 244 | |
64736a7f | 245 | /**************************************************************************/ |
246 | void ITSModuleStepperGL::RenderString(TString info, Float_t dy, Bool_t trans) const | |
247 | { | |
248 | Float_t movex = 0; | |
249 | ||
250 | GLUtilNS::GL_Capability_Switch texure_on(GL_TEXTURE_2D, true); | |
251 | GLTextNS::txfBindFontTexture(GLTextNS::fgDefaultFont); | |
252 | ||
253 | glPushMatrix(); | |
254 | glTranslatef(0, dy*0.25, 0); | |
255 | Float_t s = (dy)/ (GLTextNS::fgDefaultFont->max_height()); | |
256 | Float_t sx = s*0.75; Float_t sy = s*0.8; | |
257 | glScalef(sx, sy, 1); | |
258 | txfRenderString(GLTextNS::fgDefaultFont, info.Data(), info.Length()); | |
259 | Int_t w, ma, md; | |
260 | txfGetStringMetrics(GLTextNS::fgDefaultFont,info.Data(), info.Length() , w, ma, md); | |
261 | movex = w*sx; | |
262 | glPopMatrix(); | |
263 | ||
264 | if(trans) | |
265 | glTranslatef(movex, 0, 0); | |
0343cac7 | 266 | } |
267 | ||
268 | /**************************************************************************/ | |
269 | ||
270 | void ITSModuleStepperGL::ProcessSelection(UInt_t* ptr, TGLViewer*, TGLScene*) | |
271 | { | |
272 | // Processes secondary selection from TGLViewer. | |
273 | // Calls TPointSet3D::PointSelected(Int_t) with index of selected | |
274 | // point as an argument. | |
275 | ||
276 | if (ptr[0] < 2) return; | |
64736a7f | 277 | |
278 | switch (ptr[4]){ | |
279 | case 1 : | |
280 | fM->Previous(); | |
281 | break; | |
282 | case 2: | |
283 | fM->Start(); | |
284 | break; | |
285 | case 3: | |
286 | fM->Next(); | |
287 | break; | |
288 | case 4: | |
289 | fM->End(); | |
290 | break; | |
291 | case 5: | |
292 | gReve->GetEditor()->DisplayRenderElement(*fM->BeginChildren()); | |
293 | break; | |
294 | case 6: | |
295 | { | |
296 | DigitScaleInfo* si = fM->fScaleInfo; | |
297 | if(si->fScale < 4) | |
298 | si->ScaleChanged(si->fScale + 1); | |
299 | gReve->Redraw3D(); | |
300 | break; | |
301 | } | |
302 | case 7: | |
303 | { | |
304 | DigitScaleInfo* si = fM->fScaleInfo; | |
305 | if(si->fScale > 0) | |
306 | si->ScaleChanged(si->GetScale() - 1); | |
307 | gReve->Redraw3D(); | |
308 | break; | |
309 | } | |
310 | default: | |
311 | break; | |
312 | } | |
0343cac7 | 313 | } |