]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Alieve/ITSModuleStepperGL.cxx
Following Ivan's latest changes on the DCS aliases
[u/mrichter/AliRoot.git] / EVE / Alieve / ITSModuleStepperGL.cxx
1 // $Header$
2
3 #include "ITSModuleStepperGL.h"
4
5 #include <Reve/GLTextNS.h>
6 #include <Reve/GLUtilNS.h>
7 #include <Alieve/ITSModuleStepper.h>
8
9 #include <TGLDrawFlags.h>
10
11 using namespace Reve;
12 using namespace Alieve;
13
14 //______________________________________________________________________
15 // ITSModuleStepperGL
16 //
17
18 ClassImp(ITSModuleStepperGL)
19
20 ITSModuleStepperGL::ITSModuleStepperGL() : TGLObject(), fM(0)
21 {
22   fCached = false; // Disable display list.
23 }
24
25 ITSModuleStepperGL::~ITSModuleStepperGL()
26 {}
27
28 /**************************************************************************/
29
30 Bool_t ITSModuleStepperGL::SetModel(TObject* obj)
31 {
32   if(SetModelCheckClass(obj, ITSModuleStepper::Class())) {
33     fM = dynamic_cast<ITSModuleStepper*>(obj);
34     return kTRUE;
35   }
36   return kFALSE;
37 }
38
39 void ITSModuleStepperGL::SetBBox()
40 {
41   // !! This ok if master sub-classed from TAttBBox
42   SetAxisAlignedBBox(fM->AssertBBox());
43 }
44
45 /**************************************************************************/
46
47 void ITSModuleStepperGL::DirectDraw(const TGLDrawFlags & flags) const
48 {
49   // printf("ITSModuleStepperGL::DirectDraw Style %d, LOD %d\n", flags.Style(), flags.LOD()); 
50
51   ITSModuleStepper& MS = *fM;
52   Int_t W = Int_t(MS.fStepper->Dx*MS.fStepper->Nx);
53   Int_t H = Int_t(MS.fStepper->Dy*MS.fStepper->Ny);
54   Float_t dx = W*MS.fWWidth;
55   Float_t dy = H*MS.fWHeight;
56
57   GLboolean lightp;
58   glGetBooleanv(GL_LIGHTING, &lightp);
59   if (lightp) glDisable(GL_LIGHTING);
60    
61   UChar_t color[4];
62   ColorFromIdx(MS.fWColor, color);
63   glColor4ubv(color);
64
65   // render frame of grid stepper
66   if (MS.fRnrFrame)
67   {
68     glBegin(GL_LINE_LOOP);
69     glVertex2f(0., 0.);       
70     glVertex2f(W , 0.);
71     glVertex2f(W , H );
72     glVertex2f(0 , H );
73     glEnd();
74   }
75
76   // triangles
77   glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
78   glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
79   glDisable(GL_CULL_FACE);
80     
81   Float_t sx =0 ,sy = 0;
82   switch(MS.fWCorner) {
83     case ITSModuleStepper::PT_BottomLeft:
84       sy = -dy;
85       break;
86     case ITSModuleStepper::PT_BottomRight:
87       sy = -dy;
88       break;
89     case ITSModuleStepper::PT_TopLeft:
90       sy = H;
91       break;
92     case ITSModuleStepper::PT_TopRight:
93       sy = H;
94       break;
95     default:
96       sy = dy;
97       break;
98   }
99   
100   if (flags.SecSelection()) glPushName(0);
101
102   glPushMatrix();
103   // traslate according to orentation 
104   glTranslatef(sx, sy, 0.);
105
106   if (flags.SecSelection()) glLoadName(2);
107   RenderTriangle(dx, dy, 2);
108
109   glTranslatef(dx, 0, 0);
110   if (flags.SecSelection()) glLoadName(1);
111   RenderTriangle(dx, dy, 1);
112   glTranslatef(dx, 0, 0);
113
114   Float_t movex = 0; 
115   {
116     GLUtilNS::GL_Capability_Switch texure_on(GL_TEXTURE_2D, true);
117     GLTextNS::txfBindFontTexture(GLTextNS::fgDefaultFont);
118     glPushMatrix();
119     glTranslatef(0, dy*0.25, 0);
120     Float_t s = (dy)/ (GLTextNS::fgDefaultFont->max_height());
121     glScalef(s, s, 1);
122     TString info = Form(" %d / %d ", MS.GetCurrentPage(),MS.GetPages());
123     txfRenderString(GLTextNS::fgDefaultFont, info.Data(), info.Length());
124     Int_t w, ma, md;
125     txfGetStringMetrics(GLTextNS::fgDefaultFont,info.Data(), info.Length() , w, ma, md);
126     movex = w*s;
127     glPopMatrix();
128   }
129   glTranslatef(movex, 0, 0); 
130
131   if (flags.SecSelection()) glLoadName(3);
132   RenderTriangle(dx, dy, 3);
133
134   glTranslatef(dx, 0, 0);
135   if (flags.SecSelection()) glLoadName(4);
136   RenderTriangle(dx, dy, 4);
137
138   glPopMatrix();
139
140   if (flags.SecSelection()) glPopName();
141
142   glPopAttrib();
143
144   if (lightp) glEnable(GL_LIGHTING);
145       
146 }
147 /**************************************************************************/
148 void ITSModuleStepperGL::RenderTriangle(Float_t dx, Float_t dy, Int_t id) const
149 {
150   Float_t xs = dx/4, ys = dy/4;
151
152   glBegin(GL_TRIANGLES);
153   switch (id) {
154     case 1:
155     {
156       glVertex2f(xs*2.5, ys*3); glVertex2f(xs*1.5, ys*2); glVertex2f(xs*2.5, ys);
157       break;
158     }
159     case 2:
160     {
161       glVertex2f(xs*2, ys*3); glVertex2f(xs, ys*2); glVertex2f(xs*2, ys);
162       glVertex2f(xs*3, ys*3); glVertex2f(xs*2, ys*2); glVertex2f(xs*3, ys);
163       break;
164     }
165     case 3:
166     {
167       glVertex2f(xs*1.5, ys);  glVertex2f(xs*2.5, ys*2); glVertex2f(xs*1.5, ys*3);
168       break;
169     }
170     case 4:
171     {
172       glVertex2f(xs, ys);  glVertex2f(xs*2, ys*2); glVertex2f(xs, ys*3);
173       glVertex2f(xs*2, ys); glVertex2f(xs*3, ys*2); glVertex2f(xs*2, ys*3);
174       break;
175     }
176     default:
177       break;
178   }
179   glEnd();
180
181   /*
182     glBegin(GL_LINE_LOOP);
183     glVertex2f(0,0);
184     glVertex2f(0,dy);
185     glVertex2f(dx,dy);
186     glVertex2f(dx,0);
187     glEnd();
188   */
189 }
190
191 /**************************************************************************/
192
193 void ITSModuleStepperGL::ProcessSelection(UInt_t* ptr, TGLViewer*, TGLScene*)
194 {
195   // Processes secondary selection from TGLViewer.
196   // Calls TPointSet3D::PointSelected(Int_t) with index of selected
197   // point as an argument.
198
199   if (ptr[0] < 2) return;
200   UInt_t id = ptr[4]; 
201
202   if(id == 1)
203     fM->Previous();
204   if(id == 2)
205     fM->Start();
206   if(id == 3)
207     fM->Next();
208   if(id == 4)
209     fM->End();
210 }