|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: Juha Kauppinen, Mika Hokkanen |
|
13 * |
|
14 * Description: Photo Browser |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "DrawUtility.h" |
|
19 #include "debug.h" |
|
20 |
|
21 const KTNSize = 10; |
|
22 |
|
23 /*--------------------------------------------------------------------------*/ |
|
24 // Class constants |
|
25 |
|
26 // Mesh data |
|
27 |
|
28 // Triangle count |
|
29 const int CDrawUtility::iTriCount = 4; |
|
30 |
|
31 // Vertices |
|
32 const GLfixed CDrawUtility::iVertices[4*3]= |
|
33 { |
|
34 // Tetrahedron coordinates |
|
35 10*(1<<16), 10*(1<<16), 10*(1<<16), |
|
36 -10*(1<<16), -10*(1<<16), 10*(1<<16), |
|
37 -10*(1<<16), 10*(1<<16), -10*(1<<16), |
|
38 10*(1<<16), -10*(1<<16), -10*(1<<16), |
|
39 }; |
|
40 |
|
41 // Normals |
|
42 const GLfixed CDrawUtility::iNormals[4*3]= |
|
43 { |
|
44 // Tetrahedron normals |
|
45 /* |
|
46 Normal is a vector with unit lenght (length=1) |
|
47 Unit lenght vector = vector/lenght |
|
48 |
|
49 Calculate normals from corners, makes gouraud shading |
|
50 Vector: (1,1,1) |
|
51 Lenght = SQRT( 1*1 + 1*1 + 1*1 ) = SQRT(3) = 1.732050808 |
|
52 1/Lenght = 0.577350269 |
|
53 In fixed point: 0.577350269*(1<<16) = 37837 |
|
54 */ |
|
55 37837, 37837, 37837, |
|
56 -37837, -37837, 37837, |
|
57 -37837, 37837, -37837, |
|
58 37837, -37837, -37837, |
|
59 }; |
|
60 |
|
61 // Indexes define which vertices make a triangle |
|
62 // These are just indexes to iVertices table |
|
63 const GLushort CDrawUtility::iIndices[4*3]= |
|
64 { |
|
65 0,2,3, |
|
66 0,1,3, |
|
67 0,1,2, |
|
68 2,1,3, |
|
69 }; |
|
70 |
|
71 /*--------------------------------------------------------------------------*/ |
|
72 // NewL |
|
73 // |
|
74 //CDrawableInterface* CDrawUtility::NewL(void) |
|
75 CDrawUtility* CDrawUtility::NewL(CImagicContainerBrowser* aContainer) |
|
76 { |
|
77 // Create object |
|
78 CDrawUtility* self = new(ELeave) CDrawUtility(); |
|
79 |
|
80 // Call 2nd stage constructor |
|
81 CleanupStack::PushL(self); |
|
82 self->ConstructL(aContainer); |
|
83 CleanupStack::Pop(self); |
|
84 |
|
85 return self; |
|
86 } |
|
87 |
|
88 /*--------------------------------------------------------------------------*/ |
|
89 // Constructor |
|
90 // |
|
91 CDrawUtility::CDrawUtility() : |
|
92 //CDrawableInterface(), |
|
93 iAngleX(0), |
|
94 iAngleY(0), |
|
95 iAngleZ(0) |
|
96 { |
|
97 // Nothing here |
|
98 } |
|
99 |
|
100 /*--------------------------------------------------------------------------*/ |
|
101 // Second stage constructor |
|
102 // |
|
103 void CDrawUtility::ConstructL(CImagicContainerBrowser* aContainer) |
|
104 { |
|
105 iContainer = aContainer; |
|
106 iRotation = 0; |
|
107 iRotationTarget = 0; |
|
108 |
|
109 float ambient[4]={0.3,0.3,0.3, 1}; |
|
110 float diffuse[4]={1, 1, 1, 1}; |
|
111 glLightfv(GL_LIGHT0,GL_AMBIENT, ambient); |
|
112 glLightfv(GL_LIGHT0,GL_DIFFUSE, diffuse); |
|
113 } |
|
114 |
|
115 /*--------------------------------------------------------------------------*/ |
|
116 // Destructor |
|
117 // |
|
118 CDrawUtility::~CDrawUtility() |
|
119 { |
|
120 // Nothing here |
|
121 } |
|
122 |
|
123 /*--------------------------------------------------------------------------*/ |
|
124 // Makes sure that angle is on valid range |
|
125 // |
|
126 void CDrawUtility::LimitAngle(TInt &Angle) |
|
127 { |
|
128 while (Angle<0) |
|
129 Angle+=360; |
|
130 while (Angle>360) |
|
131 Angle-=360; |
|
132 } |
|
133 |
|
134 /*--------------------------------------------------------------------------*/ |
|
135 // Update animation |
|
136 // Returns true if screen should be redrawn |
|
137 // |
|
138 TBool CDrawUtility::Update(void) |
|
139 { |
|
140 // Rotate |
|
141 iAngleX+=4; |
|
142 iAngleY+=2; |
|
143 iAngleZ-=2; |
|
144 |
|
145 // Check limist |
|
146 LimitAngle(iAngleX); |
|
147 LimitAngle(iAngleY); |
|
148 LimitAngle(iAngleZ); |
|
149 |
|
150 // Since this is loading animation, this doesn't want screen to be updated |
|
151 return EFalse; |
|
152 } |
|
153 |
|
154 |
|
155 |
|
156 /*--------------------------------------------------------------------------*/ |
|
157 // Draws Zoom image thumbnail |
|
158 // |
|
159 void CDrawUtility::DrawZoomIcon( const CImageData* aImageData, |
|
160 const TSize aScreenSize, |
|
161 float aDrawOneByOneX, |
|
162 float aDrawOneByOneY, |
|
163 TReal aDrawOnebyOneW, |
|
164 TReal aDrawOnebyOneH, |
|
165 TBool aShowLocationRect) |
|
166 { |
|
167 |
|
168 iScrAspectratio = (TReal)aScreenSize.iWidth/(TReal)aScreenSize.iHeight; |
|
169 |
|
170 if(aImageData->iGridData.iGlLQ128TextIndex != 0) |
|
171 { |
|
172 iDrawOneByOneX = aDrawOneByOneX; |
|
173 iDrawOneByOneY = aDrawOneByOneY; |
|
174 iDrawOnebyOneW = aDrawOnebyOneW; |
|
175 iDrawOnebyOneH = aDrawOnebyOneH; |
|
176 |
|
177 iAspectRatio = aImageData->GetAspectRatio(); |
|
178 iScrSize = aScreenSize; |
|
179 |
|
180 //Define thumbnail size dependinf on screen orientation |
|
181 if(iAspectRatio > 1) |
|
182 { |
|
183 iThumbSize.iWidth=(iScrSize.iWidth/KTNSize); |
|
184 iThumbSize.iHeight=iThumbSize.iWidth/iAspectRatio; |
|
185 iZoomRectSize.iWidth = iScrSize.iWidth/KTNSize; |
|
186 iZoomRectSize.iHeight = iZoomRectSize.iWidth/iScrAspectratio; |
|
187 } |
|
188 else |
|
189 { |
|
190 iThumbSize.iWidth=(iScrSize.iHeight/KTNSize); |
|
191 iThumbSize.iHeight=iThumbSize.iWidth/iAspectRatio; |
|
192 iZoomRectSize.iHeight = iScrSize.iHeight/KTNSize; |
|
193 iZoomRectSize.iWidth = iZoomRectSize.iHeight*iScrAspectratio; |
|
194 } |
|
195 |
|
196 GLfixed vertices[8]; |
|
197 SetPictureVertices(vertices, iAspectRatio); |
|
198 |
|
199 glColor4f(1,1,1, 1); |
|
200 |
|
201 // Set OpenGL state |
|
202 glDepthMask(GL_FALSE); |
|
203 glDisable(GL_DEPTH_TEST); |
|
204 glEnable(GL_TEXTURE_2D); |
|
205 glVertexPointer( 2, GL_FIXED, 0, vertices ); |
|
206 |
|
207 glPushMatrix(); |
|
208 |
|
209 // Set ortho to match screen size |
|
210 glLoadIdentity(); |
|
211 glOrthof(0,aScreenSize.iWidth, aScreenSize.iHeight,0, -50,50); |
|
212 |
|
213 //Move to top right corner and leave some space around "frame" |
|
214 if(iContainer->GetScreenOrientation()) |
|
215 { |
|
216 iRotationTarget = 0 - (TReal)aImageData->GetOrientation(); |
|
217 |
|
218 if(iAspectRatio > 1 && iRotationTarget == 0) |
|
219 glTranslatef(iThumbSize.iWidth+4, iScrSize.iHeight-iThumbSize.iHeight-4, 1); |
|
220 else if(iAspectRatio < 1 && iRotationTarget == 0) |
|
221 glTranslatef((iThumbSize.iWidth)*iAspectRatio+4, iScrSize.iHeight-iThumbSize.iWidth-4, 1); |
|
222 else// if(iAspectRatio < 1 && iRotationTarget == 0) |
|
223 glTranslatef((iThumbSize.iHeight)+4, iScrSize.iHeight-iThumbSize.iWidth-4, 1); |
|
224 } |
|
225 else |
|
226 { |
|
227 iRotationTarget = -90 - (TReal)aImageData->GetOrientation(); |
|
228 |
|
229 if(iAspectRatio > 1 && iRotationTarget == -90) |
|
230 glTranslatef(iScrSize.iWidth-iThumbSize.iHeight-4, iScrSize.iHeight-iThumbSize.iWidth-4, 1); |
|
231 else if(iAspectRatio < 1 && iRotationTarget == -90) |
|
232 glTranslatef(iScrSize.iWidth-(iThumbSize.iHeight*iAspectRatio)-4, iScrSize.iHeight-(iThumbSize.iWidth*iAspectRatio)-4, 1); |
|
233 else// if(iAspectRatio < 1 && iRotationTarget == -90) |
|
234 glTranslatef(iScrSize.iWidth-(iThumbSize.iHeight*iAspectRatio)-4, iScrSize.iHeight-(iThumbSize.iHeight)-4, 1); |
|
235 } |
|
236 |
|
237 iContainer->Interpolate(iRotation, iRotationTarget, 0.60); |
|
238 glRotatef(iRotation, 0,0,1); |
|
239 |
|
240 DrawFrame(0); |
|
241 |
|
242 glBindTexture(GL_TEXTURE_2D, aImageData->iGridData.iGlLQ128TextIndex); |
|
243 glDrawArrays(GL_TRIANGLE_STRIP,0,4); |
|
244 |
|
245 // Restore OpenGL state |
|
246 glDepthMask(GL_TRUE); |
|
247 glEnable(GL_DEPTH_TEST); |
|
248 glEnable(GL_TEXTURE_2D); |
|
249 |
|
250 //glDisable(GL_BLEND); |
|
251 if(aShowLocationRect) |
|
252 DrawZoomFrame(iRotationTarget); |
|
253 |
|
254 glDisableClientState(GL_VERTEX_ARRAY); |
|
255 glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
256 glPopMatrix(); |
|
257 } |
|
258 } |
|
259 |
|
260 //Shows rectangle for zoomed are |
|
261 void CDrawUtility::DrawZoomFrame(float aRotationTarget) |
|
262 { |
|
263 DP0_IMAGIC(_L("CImagicContainerBrowser::DrawFaceFrame++")); |
|
264 DP1_IMAGIC(_L("CImagicContainerBrowser::DrawZoomFrame - aRotationTarget: %f"),aRotationTarget); |
|
265 |
|
266 GLfixed vertices[8]; |
|
267 glPushMatrix(); |
|
268 glDisable(GL_TEXTURE_2D); |
|
269 glTranslatef(0, 0, 0.01f); |
|
270 glColor4f(0,0.7,0,1); |
|
271 glLineWidth(2.0f); |
|
272 glVertexPointer(2, GL_FIXED, 0, vertices); |
|
273 |
|
274 TReal xPos = iDrawOneByOneX*(TReal)iThumbSize.iWidth*2; |
|
275 TReal yPos = iDrawOneByOneY*(TReal)iThumbSize.iHeight*2*iAspectRatio; |
|
276 |
|
277 //float x,y; |
|
278 TInt x,y; |
|
279 TInt rotationTarget = aRotationTarget; |
|
280 rotationTarget%=360; |
|
281 |
|
282 if(rotationTarget == 0) |
|
283 { |
|
284 glTranslatef(-xPos, yPos, 0); |
|
285 if(iAspectRatio > 1) |
|
286 { |
|
287 x=iDrawOnebyOneW*iZoomRectSize.iWidth * (1<<16); |
|
288 y=iDrawOnebyOneW*iZoomRectSize.iHeight * (1<<16); |
|
289 } |
|
290 else |
|
291 { |
|
292 x=iDrawOnebyOneH*iZoomRectSize.iWidth * (1<<16); |
|
293 y=iDrawOnebyOneH*iZoomRectSize.iHeight * (1<<16); |
|
294 } |
|
295 |
|
296 } |
|
297 else if(rotationTarget == -90) |
|
298 { |
|
299 glTranslatef(-yPos, -xPos, 0); |
|
300 if(iAspectRatio > 1) |
|
301 { |
|
302 y=iDrawOnebyOneH*iScrAspectratio*iZoomRectSize.iWidth * (1<<16); |
|
303 x=iDrawOnebyOneH*iScrAspectratio*iZoomRectSize.iHeight * (1<<16); |
|
304 } |
|
305 else |
|
306 { |
|
307 y=iDrawOnebyOneH*iZoomRectSize.iWidth * (1<<16); |
|
308 x=iDrawOnebyOneH*iZoomRectSize.iHeight * (1<<16); |
|
309 } |
|
310 } |
|
311 else if(rotationTarget == -180) |
|
312 { |
|
313 glTranslatef(xPos, -yPos, 0); |
|
314 if(iAspectRatio > 1) |
|
315 { |
|
316 x=iDrawOnebyOneW*iZoomRectSize.iWidth * (1<<16); |
|
317 y=iDrawOnebyOneW*iZoomRectSize.iHeight * (1<<16); |
|
318 } |
|
319 else |
|
320 { |
|
321 x=iDrawOnebyOneH*iZoomRectSize.iWidth * (1<<16); |
|
322 y=iDrawOnebyOneH*iZoomRectSize.iHeight * (1<<16); |
|
323 } |
|
324 } |
|
325 else if(rotationTarget == -270) |
|
326 { |
|
327 glTranslatef(yPos, xPos, 0); |
|
328 if(iAspectRatio > 1) |
|
329 { |
|
330 y=iDrawOnebyOneH*iScrAspectratio*iZoomRectSize.iWidth * (1<<16); |
|
331 x=iDrawOnebyOneH*iScrAspectratio*iZoomRectSize.iHeight * (1<<16); |
|
332 } |
|
333 else |
|
334 { |
|
335 y=iDrawOnebyOneH*iZoomRectSize.iWidth * (1<<16); |
|
336 x=iDrawOnebyOneH*iZoomRectSize.iHeight * (1<<16); |
|
337 } |
|
338 } |
|
339 |
|
340 TInt tnSizeFixedH = iThumbSize.iHeight*(1<<16); |
|
341 TInt tnSizeFixedW = iThumbSize.iWidth*(1<<16); |
|
342 |
|
343 if(y > tnSizeFixedH) |
|
344 y=tnSizeFixedH; |
|
345 if(x > tnSizeFixedW) |
|
346 x=tnSizeFixedW; |
|
347 |
|
348 vertices[0*2+0] = -x; vertices[0*2+1] = -y; |
|
349 vertices[1*2+0] = x; vertices[1*2+1] = -y; |
|
350 vertices[2*2+0] = x; vertices[2*2+1] = y; |
|
351 vertices[3*2+0] = -x; vertices[3*2+1] = y; |
|
352 |
|
353 glDrawArrays(GL_LINE_LOOP,0,4); |
|
354 |
|
355 glColor4f(1,1,1,1); |
|
356 glEnable(GL_TEXTURE_2D); |
|
357 glPopMatrix(); |
|
358 |
|
359 DP0_IMAGIC(_L("CImagicContainerBrowser::DrawZoomFrame--")); |
|
360 } |
|
361 |
|
362 /*----------------------------------------------------------------------*/ |
|
363 // Draws background frame |
|
364 // |
|
365 void CDrawUtility::DrawFrame(TInt aIndex) |
|
366 { |
|
367 |
|
368 // Draw frame around selected image |
|
369 glPushMatrix(); |
|
370 glDisable(GL_TEXTURE_2D); |
|
371 |
|
372 //Frame size |
|
373 float scale=1.09; |
|
374 glColor4f(1,1,1, 1); |
|
375 |
|
376 glTranslatef(0,0,-0.03); |
|
377 glScalef(scale,scale,scale); |
|
378 glDrawArrays(GL_TRIANGLE_STRIP,0,4); |
|
379 |
|
380 //glDisable(GL_BLEND); |
|
381 glEnable(GL_TEXTURE_2D); |
|
382 glPopMatrix(); |
|
383 } |
|
384 |
|
385 void CDrawUtility::SetPictureVertices(GLfixed* aVertices, TReal aAspectRatio) |
|
386 { |
|
387 //DP0_IMAGIC(_L("CImagicContainerBrowser::SetPictureVertices")); |
|
388 |
|
389 GLfixed vx = (iThumbSize.iWidth)*(1<<16); |
|
390 GLfixed vy = (iThumbSize.iWidth)*(1<<16); |
|
391 |
|
392 |
|
393 if(aAspectRatio > 1) |
|
394 { |
|
395 vy = ((iThumbSize.iWidth)/aAspectRatio)*(1<<16); |
|
396 } |
|
397 else |
|
398 { |
|
399 vx = ((iThumbSize.iWidth)*aAspectRatio)*(1<<16); |
|
400 } |
|
401 |
|
402 |
|
403 aVertices[0*2+0] = -vx; |
|
404 aVertices[0*2+1] = vy; |
|
405 |
|
406 aVertices[1*2+0] = vx; |
|
407 aVertices[1*2+1] = vy; |
|
408 |
|
409 aVertices[2*2+0] = -vx; |
|
410 aVertices[2*2+1] = -vy; |
|
411 |
|
412 aVertices[3*2+0] = vx; |
|
413 aVertices[3*2+1] = -vy; |
|
414 |
|
415 } |
|
416 |
|
417 #if 1 |
|
418 |
|
419 /*--------------------------------------------------------------------------*/ |
|
420 // Draw moving arrow |
|
421 // |
|
422 void CDrawUtility::DrawMovingArrow(TBool aPrevArrow, TBool aUpDownArrow, const TSize& aScreenSize) |
|
423 { |
|
424 //Define shape of direction array |
|
425 const GLfixed vertices[4*2] = |
|
426 { |
|
427 0*1<<16, 0*1<<16, |
|
428 10*1<<16, 7*1<<16, |
|
429 7*1<<16, 0*1<<16, |
|
430 10*1<<16,-7*1<<16, |
|
431 }; |
|
432 //Define colors of direction array |
|
433 const GLubyte colors[4*4] = |
|
434 { |
|
435 //61,174,227, 128, |
|
436 /*255,255,255, 255, |
|
437 81,194,247, 255, |
|
438 61,174,227, 255, |
|
439 41,154,207, 255,*/ |
|
440 255,255,255, 255, |
|
441 128,128,128, 255, |
|
442 50,50,50, 255, |
|
443 128,128,128, 255, |
|
444 }; |
|
445 //And order of drawing |
|
446 const GLushort indices[2*3]= |
|
447 { |
|
448 0,1,2, |
|
449 2,3,0, |
|
450 }; |
|
451 |
|
452 TReal scale = 1; |
|
453 if(aScreenSize.iHeight > 320 || aScreenSize.iWidth > 320) |
|
454 { |
|
455 scale = 1.5; |
|
456 } |
|
457 |
|
458 // Set OpenGL state |
|
459 // Shade model |
|
460 glShadeModel(GL_SMOOTH); |
|
461 glDepthMask(GL_FALSE); |
|
462 glDisable(GL_DEPTH_TEST); |
|
463 glDisable(GL_TEXTURE_2D); |
|
464 glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
465 glEnableClientState(GL_COLOR_ARRAY); |
|
466 glPushMatrix(); |
|
467 |
|
468 #ifdef ENABLE_ALPHA |
|
469 // Setup alpha |
|
470 glEnable(GL_ALPHA_TEST); |
|
471 glEnable(GL_BLEND); |
|
472 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
473 #endif |
|
474 // Set ortho to match screen size |
|
475 glLoadIdentity(); |
|
476 glOrthof(0,aScreenSize.iWidth, aScreenSize.iHeight,0, -100,100); |
|
477 glPushMatrix(); |
|
478 |
|
479 // Move to arrow position |
|
480 int ArrowDistance=5; |
|
481 if(aPrevArrow) |
|
482 { |
|
483 glTranslatef(ArrowDistance,aScreenSize.iHeight/2,0); |
|
484 glVertexPointer(2,GL_FIXED,0, vertices); |
|
485 glColorPointer(4,GL_UNSIGNED_BYTE,0, colors); |
|
486 glScalef(scale,scale,scale); |
|
487 glDrawElements(GL_TRIANGLES, 2*3, GL_UNSIGNED_SHORT, indices); |
|
488 glScalef(1/scale,1/scale,1/scale); |
|
489 glTranslatef(aScreenSize.iWidth-2*ArrowDistance,0/*aScreenSize.iHeight/2*/,0); |
|
490 // Flip arrow around so it points to right |
|
491 glRotatef(180,0,0,1); |
|
492 // Also flip it on X |
|
493 //glRotatef(180,1,0,0); |
|
494 glVertexPointer(2,GL_FIXED,0, vertices); |
|
495 glColorPointer(4,GL_UNSIGNED_BYTE,0, colors); |
|
496 glScalef(scale,scale,scale); |
|
497 glDrawElements(GL_TRIANGLES, 2*3, GL_UNSIGNED_SHORT, indices); |
|
498 glScalef(1/scale,1/scale,1/scale); |
|
499 |
|
500 glPopMatrix(); |
|
501 glPushMatrix(); |
|
502 } |
|
503 |
|
504 if(aUpDownArrow) |
|
505 { |
|
506 glTranslatef(aScreenSize.iWidth/2, ArrowDistance,0); |
|
507 //glTranslatef(aScreenSize.iWidth/2,(aScreenSize.iHeight)-ArrowDistance,0); |
|
508 // Flip arrow around so it points to right |
|
509 glRotatef(90,0,0,1); |
|
510 // Also flip it on X |
|
511 //glRotatef(180,1,0,0); |
|
512 // Draw arrow |
|
513 glVertexPointer(2,GL_FIXED,0, vertices); |
|
514 glColorPointer(4,GL_UNSIGNED_BYTE,0, colors); |
|
515 glScalef(scale,scale,scale); |
|
516 glDrawElements(GL_TRIANGLES, 2*3, GL_UNSIGNED_SHORT, indices); |
|
517 glScalef(1/scale,1/scale,1/scale); |
|
518 |
|
519 glTranslatef(aScreenSize.iHeight-ArrowDistance*2,0,0); |
|
520 glRotatef(180,0,0,1); |
|
521 |
|
522 // Draw arrow |
|
523 glVertexPointer(2,GL_FIXED,0, vertices); |
|
524 glColorPointer(4,GL_UNSIGNED_BYTE,0, colors); |
|
525 glScalef(scale,scale,scale); |
|
526 glDrawElements(GL_TRIANGLES, 2*3, GL_UNSIGNED_SHORT, indices); |
|
527 glScalef(1,1,1); |
|
528 } |
|
529 |
|
530 glPopMatrix(); |
|
531 #ifdef ENABLE_ALPHA |
|
532 // Remove alpha |
|
533 glDisable(GL_BLEND); |
|
534 glDisable(GL_ALPHA_TEST); |
|
535 #endif |
|
536 // Restore OpenGL state |
|
537 glDepthMask(GL_TRUE); |
|
538 glEnable(GL_DEPTH_TEST); |
|
539 glEnable(GL_TEXTURE_2D); |
|
540 glShadeModel(GL_FLAT); |
|
541 glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
542 glDisableClientState(GL_COLOR_ARRAY); |
|
543 glPopMatrix(); |
|
544 } |
|
545 |
|
546 /*--------------------------------------------------------------------------*/ |
|
547 // Draw animation |
|
548 // |
|
549 void CDrawUtility::Draw(const TSize &aScreenSize) |
|
550 { |
|
551 // Set OpenGL state |
|
552 glEnable(GL_LIGHTING); |
|
553 glEnable(GL_LIGHT0); |
|
554 glDepthMask(GL_FALSE); |
|
555 glDisable(GL_DEPTH_TEST); |
|
556 glDisable(GL_TEXTURE_2D); |
|
557 glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
558 glEnableClientState(GL_NORMAL_ARRAY); |
|
559 glPushMatrix(); |
|
560 |
|
561 // Set ortho to match screen size |
|
562 glLoadIdentity(); |
|
563 glOrthof(0,aScreenSize.iWidth, aScreenSize.iHeight,0, -100,100); |
|
564 |
|
565 // Move to top right corner |
|
566 glTranslatef(aScreenSize.iWidth-40,40,0); |
|
567 |
|
568 /* |
|
569 // Calculate prespective values |
|
570 GLfloat aspectRatio = (GLfloat)(aScreenSize.iWidth) / (GLfloat)(aScreenSize.iHeight); |
|
571 const float near = 0.001; |
|
572 const float far = 100.0; |
|
573 const float top = 0.414*near; |
|
574 const float bottom = -top; |
|
575 const float left = aspectRatio * bottom; |
|
576 const float right = aspectRatio * top; |
|
577 |
|
578 // Set perspective |
|
579 glLoadIdentity(); |
|
580 glFrustumf(left,right, bottom,top, near,far); |
|
581 glTranslatef(0,0,-40); |
|
582 */ |
|
583 // Update light direction |
|
584 float direction[4]={1, 0, -1, 0}; |
|
585 glLightfv(GL_LIGHT0,GL_POSITION, direction); |
|
586 glColor4f(1,1,1, 1); |
|
587 // Apply rotations |
|
588 glRotatef(iAngleX, 1,0,0); |
|
589 glRotatef(iAngleY, 0,1,0); |
|
590 glRotatef(iAngleZ, 0,0,1); |
|
591 |
|
592 // Draw tetrahedron |
|
593 glVertexPointer(3,GL_FIXED,0, iVertices); |
|
594 glNormalPointer(GL_FIXED,0, iNormals); |
|
595 glDrawElements(GL_TRIANGLES, iTriCount*3,GL_UNSIGNED_SHORT,iIndices); |
|
596 |
|
597 // Restore OpenGL state |
|
598 glDepthMask(GL_TRUE); |
|
599 glEnable(GL_DEPTH_TEST); |
|
600 glDisable(GL_LIGHTING); |
|
601 glEnable(GL_TEXTURE_2D); |
|
602 glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
603 glDisableClientState(GL_NORMAL_ARRAY); |
|
604 glPopMatrix(); |
|
605 } |
|
606 #endif |
|
607 |
|
608 /*--------------------------------------------------------------------------*/ |
|
609 // Draw moving arrow |
|
610 // |
|
611 void CDrawUtility::DrawMenuIndicators(const TSize& aScreenSize) |
|
612 { |
|
613 //Define shape of direction array |
|
614 const GLfixed vertices[4*2] = |
|
615 { |
|
616 0*1<<16, 0*1<<16, |
|
617 10*1<<16, 7*1<<16, |
|
618 7*1<<16, 0*1<<16, |
|
619 10*1<<16,-7*1<<16, |
|
620 }; |
|
621 //Define colors of direction array |
|
622 const GLubyte colors[4*4] = |
|
623 { |
|
624 //61,174,227, 128, |
|
625 255,255,255, 255, |
|
626 81,194,247, 255, |
|
627 61,174,227, 255, |
|
628 41,154,207, 255, |
|
629 }; |
|
630 //And order of drawing |
|
631 const GLushort indices[2*3]= |
|
632 { |
|
633 0,1,2, |
|
634 2,3,0, |
|
635 }; |
|
636 |
|
637 TReal scale = 1; |
|
638 if(aScreenSize.iHeight > 320 || aScreenSize.iWidth > 320) |
|
639 { |
|
640 scale = 1.5; |
|
641 } |
|
642 |
|
643 // Set OpenGL state |
|
644 // Shade model |
|
645 glShadeModel(GL_SMOOTH); |
|
646 glDepthMask(GL_FALSE); |
|
647 glDisable(GL_DEPTH_TEST); |
|
648 glDisable(GL_TEXTURE_2D); |
|
649 glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
650 glEnableClientState(GL_COLOR_ARRAY); |
|
651 glPushMatrix(); |
|
652 |
|
653 #ifdef ENABLE_ALPHA |
|
654 // Setup alpha |
|
655 glEnable(GL_ALPHA_TEST); |
|
656 glEnable(GL_BLEND); |
|
657 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
658 #endif |
|
659 // Set ortho to match screen size |
|
660 glLoadIdentity(); |
|
661 glOrthof(0,aScreenSize.iWidth, aScreenSize.iHeight,0, -100,100); |
|
662 glPushMatrix(); |
|
663 |
|
664 // Move to arrow position |
|
665 TInt ArrowDistance=20; |
|
666 |
|
667 glTranslatef(aScreenSize.iWidth - ArrowDistance, aScreenSize.iHeight/2, 0); |
|
668 |
|
669 //glTranslatef(ArrowDistance, aScreenSize.iWidth/2,0); |
|
670 glVertexPointer(2,GL_FIXED,0, vertices); |
|
671 glColorPointer(4,GL_UNSIGNED_BYTE,0, colors); |
|
672 glScalef(scale,scale,scale); |
|
673 glDrawElements(GL_TRIANGLES, 2*3, GL_UNSIGNED_SHORT, indices); |
|
674 glScalef(1/scale,1/scale,1/scale); |
|
675 glTranslatef(aScreenSize.iWidth-2*ArrowDistance, 0, 0); |
|
676 |
|
677 // Flip arrow around so it points to right |
|
678 glRotatef(180,0,0,1); |
|
679 |
|
680 glVertexPointer(2,GL_FIXED,0, vertices); |
|
681 glColorPointer(4,GL_UNSIGNED_BYTE,0, colors); |
|
682 glScalef(scale,scale,scale); |
|
683 glDrawElements(GL_TRIANGLES, 2*3, GL_UNSIGNED_SHORT, indices); |
|
684 glScalef(1/scale,1/scale,1/scale); |
|
685 |
|
686 |
|
687 |
|
688 glPopMatrix(); |
|
689 |
|
690 #ifdef ENABLE_ALPHA |
|
691 // Remove alpha |
|
692 glDisable(GL_BLEND); |
|
693 glDisable(GL_ALPHA_TEST); |
|
694 #endif |
|
695 // Restore OpenGL state |
|
696 glDepthMask(GL_TRUE); |
|
697 glEnable(GL_DEPTH_TEST); |
|
698 glEnable(GL_TEXTURE_2D); |
|
699 glShadeModel(GL_FLAT); |
|
700 glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
701 glDisableClientState(GL_COLOR_ARRAY); |
|
702 glPopMatrix(); |
|
703 } |
|
704 |
|
705 /*--------------------------------------------------------------------------*/ |
|
706 // Draw icon texture |
|
707 // |
|
708 void CDrawUtility::DrawIcon(const TSize &aScreenSize, GLuint aTexIndex) |
|
709 { |
|
710 if(aTexIndex != 0) |
|
711 { |
|
712 GLfixed vertices[8]; |
|
713 SetPictureVertices(vertices, 1); |
|
714 |
|
715 glColor4f(1,1,1, 0.75); |
|
716 |
|
717 // Set OpenGL state |
|
718 glDepthMask(GL_FALSE); |
|
719 glDisable(GL_DEPTH_TEST); |
|
720 glEnable(GL_TEXTURE_2D); |
|
721 |
|
722 //Enable alpha blending |
|
723 glEnable(GL_BLEND); |
|
724 glEnable(GL_ALPHA_TEST); |
|
725 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_COLOR); |
|
726 |
|
727 |
|
728 glVertexPointer( 2, GL_FIXED, 0, vertices ); |
|
729 |
|
730 glPushMatrix(); |
|
731 |
|
732 // Set ortho to match screen size |
|
733 glLoadIdentity(); |
|
734 glOrthof(0,aScreenSize.iWidth, aScreenSize.iHeight,0, -50,50); |
|
735 |
|
736 // Move to top right corner |
|
737 //glTranslatef(29, 29, 1); |
|
738 glTranslatef(0, 0, 0); |
|
739 |
|
740 //#ifdef _S60_5x_ACCELEROMETER_ |
|
741 if(iContainer->GetScreenOrientation()) |
|
742 { |
|
743 iRotationTarget = 0; |
|
744 } |
|
745 else |
|
746 { |
|
747 iRotationTarget = -90; |
|
748 } |
|
749 iContainer->Interpolate(iRotation, iRotationTarget, 0.25); |
|
750 glRotatef(iRotation, 0,0,1); |
|
751 //#endif |
|
752 |
|
753 glBindTexture(GL_TEXTURE_2D, aTexIndex); |
|
754 glDrawArrays(GL_TRIANGLE_STRIP,0,4); |
|
755 |
|
756 // Restore OpenGL state |
|
757 glDepthMask(GL_TRUE); |
|
758 glEnable(GL_DEPTH_TEST); |
|
759 glEnable(GL_TEXTURE_2D); |
|
760 |
|
761 glDisable(GL_BLEND); |
|
762 glDisable(GL_ALPHA_TEST); |
|
763 |
|
764 glDisableClientState(GL_VERTEX_ARRAY); |
|
765 glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
766 |
|
767 glPopMatrix(); |
|
768 } |
|
769 } |
|
770 |
|
771 |
|
772 void CDrawUtility::DrawIcon2(const TSize &aScreenSize, GLuint aTexIndex, TReal aAlpha) |
|
773 { |
|
774 |
|
775 iScrAspectratio = (TReal)aScreenSize.iWidth/(TReal)aScreenSize.iHeight; |
|
776 |
|
777 GLfixed vertices[8]; |
|
778 SetPictureVertices(vertices, 0.3); |
|
779 |
|
780 //glColor4f(1,1,1, 1); |
|
781 glColor4f(1,1,1, aAlpha); |
|
782 // Set OpenGL state |
|
783 glDepthMask(GL_FALSE); |
|
784 glDisable(GL_DEPTH_TEST); |
|
785 glEnable(GL_TEXTURE_2D); |
|
786 |
|
787 //Enable alpha blending |
|
788 glEnable(GL_BLEND); |
|
789 glEnable(GL_ALPHA_TEST); |
|
790 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_COLOR); |
|
791 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
792 |
|
793 glVertexPointer( 2, GL_FIXED, 0, vertices ); |
|
794 |
|
795 glPushMatrix(); |
|
796 |
|
797 // Set ortho to match screen size |
|
798 glLoadIdentity(); |
|
799 glOrthof(0,aScreenSize.iWidth, aScreenSize.iHeight,0, -50,50); |
|
800 |
|
801 |
|
802 glTranslatef(iScrSize.iWidth-7, iScrSize.iHeight-25, 1); |
|
803 iContainer->Interpolate(iRotation, iRotationTarget, 0.60); |
|
804 //glRotatef(90, 0,0,1); |
|
805 glBindTexture(GL_TEXTURE_2D, aTexIndex); |
|
806 glScalef(0.5, 0.5, 0.5); |
|
807 glDrawArrays(GL_TRIANGLE_STRIP,0,4); |
|
808 glScalef(2, 2, 2); |
|
809 glTranslatef(0, -iScrSize.iHeight+50, 1); |
|
810 glScalef(0.5, 0.5, 0.5); |
|
811 glBindTexture(GL_TEXTURE_2D, aTexIndex); |
|
812 glDrawArrays(GL_TRIANGLE_STRIP,0,4); |
|
813 glScalef(2, 2, 2); |
|
814 |
|
815 // Restore OpenGL state |
|
816 glDepthMask(GL_TRUE); |
|
817 glEnable(GL_DEPTH_TEST); |
|
818 glEnable(GL_TEXTURE_2D); |
|
819 |
|
820 glDisable(GL_BLEND); |
|
821 glDisable(GL_ALPHA_TEST); |
|
822 |
|
823 //glDisable(GL_BLEND); |
|
824 /*if(aShowLocationRect) |
|
825 DrawZoomFrame(iRotationTarget);*/ |
|
826 |
|
827 glDisableClientState(GL_VERTEX_ARRAY); |
|
828 glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
829 glPopMatrix(); |
|
830 |
|
831 } |