]>
Commit | Line | Data |
---|---|---|
0343cac7 | 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 | // render frame of grid stepper | |
62 | if (MS.fRnrFrame) | |
63 | { | |
64 | UChar_t color[4]; | |
65 | ColorFromIdx(MS.fFrameColor, color); | |
66 | glColor4ubv(color); | |
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 | // glEnable(GL_POLYGON_OFFSET_FILL); | |
80 | ||
81 | UChar_t color[4]; | |
82 | ColorFromIdx(MS.fWColor, color); | |
83 | glColor4ubv(color); | |
84 | ||
85 | Float_t sx =0 ,sy = 0; | |
86 | switch(MS.fWCorner) { | |
87 | case ITSModuleStepper::PT_BottomLeft: | |
88 | sy = -dy; | |
89 | break; | |
90 | case ITSModuleStepper::PT_BottomRight: | |
91 | sy = -dy; | |
92 | break; | |
93 | case ITSModuleStepper::PT_TopLeft: | |
94 | sy = H; | |
95 | break; | |
96 | case ITSModuleStepper::PT_TopRight: | |
97 | sy = H; | |
98 | break; | |
99 | default: | |
100 | sy = dy; | |
101 | break; | |
102 | } | |
103 | ||
104 | if (flags.SecSelection()) glPushName(0); | |
105 | ||
106 | glPushMatrix(); | |
107 | // traslate according to orentation | |
108 | glTranslatef(sx, sy, 0.); | |
109 | ||
110 | if (flags.SecSelection()) glLoadName(2); | |
111 | RenderTriangle(dx, dy, 2); | |
112 | ||
113 | glTranslatef(dx, 0, 0); | |
114 | if (flags.SecSelection()) glLoadName(1); | |
115 | RenderTriangle(dx, dy, 1); | |
116 | glTranslatef(dx, 0, 0); | |
117 | ||
118 | Float_t movex = 0; | |
119 | { | |
120 | GLUtilNS::GL_Capability_Switch texure_on(GL_TEXTURE_2D, true); | |
121 | GLTextNS::txfBindFontTexture(GLTextNS::fgDefaultFont); | |
122 | glPushMatrix(); | |
123 | glTranslatef(0, dy*0.25, 0); | |
124 | Float_t s = (dy)/ (GLTextNS::fgDefaultFont->max_height()); | |
125 | glScalef(s, s, 1); | |
126 | TString info = Form(" %d / %d ", MS.GetCurrentPage(),MS.GetPages()); | |
127 | txfRenderString(GLTextNS::fgDefaultFont, info.Data(), info.Length()); | |
128 | Int_t w, ma, md; | |
129 | txfGetStringMetrics(GLTextNS::fgDefaultFont,info.Data(), info.Length() , w, ma, md); | |
130 | movex = w*s; | |
131 | glPopMatrix(); | |
132 | } | |
133 | glTranslatef(movex, 0, 0); | |
134 | ||
135 | if (flags.SecSelection()) glLoadName(3); | |
136 | RenderTriangle(dx, dy, 3); | |
137 | ||
138 | glTranslatef(dx, 0, 0); | |
139 | if (flags.SecSelection()) glLoadName(4); | |
140 | RenderTriangle(dx, dy, 4); | |
141 | ||
142 | glPopMatrix(); | |
143 | ||
144 | if (flags.SecSelection()) glPopName(); | |
145 | ||
146 | glPopAttrib(); | |
147 | ||
148 | if (lightp) glEnable(GL_LIGHTING); | |
149 | ||
150 | } | |
151 | /**************************************************************************/ | |
152 | void ITSModuleStepperGL::RenderTriangle(Float_t dx, Float_t dy, Int_t id) const | |
153 | { | |
154 | Float_t xs = dx/4, ys = dy/4; | |
155 | ||
156 | glBegin(GL_TRIANGLES); | |
157 | switch (id) { | |
158 | case 1: | |
159 | { | |
160 | glVertex2f(xs*2.5, ys*3); glVertex2f(xs*1.5, ys*2); glVertex2f(xs*2.5, ys); | |
161 | break; | |
162 | } | |
163 | case 2: | |
164 | { | |
165 | glVertex2f(xs*2, ys*3); glVertex2f(xs, ys*2); glVertex2f(xs*2, ys); | |
166 | glVertex2f(xs*3, ys*3); glVertex2f(xs*2, ys*2); glVertex2f(xs*3, ys); | |
167 | break; | |
168 | } | |
169 | case 3: | |
170 | { | |
171 | glVertex2f(xs*1.5, ys); glVertex2f(xs*2.5, ys*2); glVertex2f(xs*1.5, ys*3); | |
172 | break; | |
173 | } | |
174 | case 4: | |
175 | { | |
176 | glVertex2f(xs, ys); glVertex2f(xs*2, ys*2); glVertex2f(xs, ys*3); | |
177 | glVertex2f(xs*2, ys); glVertex2f(xs*3, ys*2); glVertex2f(xs*2, ys*3); | |
178 | break; | |
179 | } | |
180 | default: | |
181 | break; | |
182 | } | |
183 | glEnd(); | |
184 | ||
185 | /* | |
186 | glBegin(GL_LINE_LOOP); | |
187 | glVertex2f(0,0); | |
188 | glVertex2f(0,dy); | |
189 | glVertex2f(dx,dy); | |
190 | glVertex2f(dx,0); | |
191 | glEnd(); | |
192 | */ | |
193 | } | |
194 | ||
195 | /**************************************************************************/ | |
196 | ||
197 | void ITSModuleStepperGL::ProcessSelection(UInt_t* ptr, TGLViewer*, TGLScene*) | |
198 | { | |
199 | // Processes secondary selection from TGLViewer. | |
200 | // Calls TPointSet3D::PointSelected(Int_t) with index of selected | |
201 | // point as an argument. | |
202 | ||
203 | if (ptr[0] < 2) return; | |
204 | UInt_t id = ptr[4]; | |
205 | ||
206 | if(id == 1) | |
207 | fM->Previous(); | |
208 | if(id == 2) | |
209 | fM->Start(); | |
210 | if(id == 3) | |
211 | fM->Next(); | |
212 | if(id == 4) | |
213 | fM->End(); | |
214 | } |