|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
13 * |
|
14 * Description: Graphics Extension Library source file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "GfxAffineTransform.h" |
|
20 |
|
21 #include "GfxGeneralPath.h" |
|
22 #include "Gfxtrignometric.h" |
|
23 |
|
24 #include "e32debug.h" |
|
25 |
|
26 // ========================================================================== |
|
27 // Notes: |
|
28 // |
|
29 // [ x'] [ m00 m01 m02 ] [ x ] [ m00x + m01y + m02 ] |
|
30 // [ y'] = [ m10 m11 m12 ] [ y ] = [ m10x + m11y + m12 ] |
|
31 // [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ] |
|
32 // |
|
33 // ========================================================================== |
|
34 |
|
35 // ========================================================================== |
|
36 // Constructor |
|
37 // ========================================================================== |
|
38 // -------------------------------------------------------------------------- |
|
39 // TGfxAffineTransform::TGfxAffineTransform() |
|
40 // --------------------------------------------------------------------------- |
|
41 TGfxAffineTransform::TGfxAffineTransform() |
|
42 :iM00(KFloatFixOne), |
|
43 iM10(KFloatFixZero), |
|
44 iM01(KFloatFixZero), |
|
45 iM11(KFloatFixOne), |
|
46 iM02(KFloatFixZero), |
|
47 iM12(KFloatFixZero) |
|
48 { |
|
49 iTransType = KTransformIdentity; |
|
50 } |
|
51 |
|
52 |
|
53 // ========================================================================== |
|
54 // Constructor with elements |
|
55 // ========================================================================== |
|
56 // -------------------------------------------------------------------------- |
|
57 // TGfxAffineTransform::TGfxAffineTransform( TReal32 aM00, |
|
58 // --------------------------------------------------------------------------- |
|
59 TGfxAffineTransform::TGfxAffineTransform( TReal32 aM00, |
|
60 TReal32 aM10, |
|
61 TReal32 aM01, |
|
62 TReal32 aM11, |
|
63 TReal32 aM02, |
|
64 TReal32 aM12 ) |
|
65 { |
|
66 SetTransform( aM00, aM10, aM01, aM11, aM02, aM12 ); |
|
67 } |
|
68 |
|
69 // -------------------------------------------------------------------------- |
|
70 // TGfxAffineTransform::TGfxAffineTransform( TReal32 aM00, |
|
71 // --------------------------------------------------------------------------- |
|
72 TGfxAffineTransform::TGfxAffineTransform( TReal32 aM00, |
|
73 TReal32 aM10, |
|
74 TReal32 aM01, |
|
75 TReal32 aM11, |
|
76 TReal32 aM02, |
|
77 TReal32 aM12, |
|
78 TGfxTransformType aType ) |
|
79 :iM00(aM00), |
|
80 iM10(aM10), |
|
81 iM01(aM01), |
|
82 iM11(aM11), |
|
83 iM02(aM02), |
|
84 iM12(aM12) |
|
85 { |
|
86 iTransType = aType; |
|
87 } |
|
88 |
|
89 // ========================================================================== |
|
90 // Generally used instance creation: Rotation matrix |
|
91 // ========================================================================== |
|
92 // -------------------------------------------------------------------------- |
|
93 // TGfxAffineTransform TGfxAffineTransform::GetRotateInstance( TReal32 aTheta ) |
|
94 // --------------------------------------------------------------------------- |
|
95 TGfxAffineTransform TGfxAffineTransform::GetRotateInstance( TReal32 aTheta ) |
|
96 { |
|
97 TGfxAffineTransform tmp; |
|
98 tmp.SetToRotate( aTheta ); |
|
99 return tmp; |
|
100 } |
|
101 |
|
102 // ========================================================================== |
|
103 // Generally used instance creation: another Rotation matrix |
|
104 // ========================================================================== |
|
105 // -------------------------------------------------------------------------- |
|
106 // TGfxAffineTransform TGfxAffineTransform::GetRotateInstance( TReal32 aTheta, |
|
107 // --------------------------------------------------------------------------- |
|
108 TGfxAffineTransform TGfxAffineTransform::GetRotateInstance( TReal32 aTheta, |
|
109 const TFloatFixPt& aX, |
|
110 const TFloatFixPt& aY ) |
|
111 { |
|
112 TGfxAffineTransform tmp; |
|
113 tmp.SetToRotate( aTheta ); |
|
114 |
|
115 TFloatFixPt x = aX; |
|
116 TFloatFixPt y = aY; |
|
117 TFloatFixPt KOne( KFloatFixOne ); |
|
118 tmp.iM02 = x * ( KOne - tmp.iM00 ) + y * tmp.iM10; |
|
119 tmp.iM12 = y * ( KOne - tmp.iM00 ) - x * tmp.iM10; |
|
120 tmp.iTransType |= KTransformTranslate; |
|
121 return tmp; |
|
122 } |
|
123 |
|
124 // ========================================================================== |
|
125 // Added Zoom Instance for better calculation |
|
126 // ========================================================================== |
|
127 // -------------------------------------------------------------------------- |
|
128 // TGfxAffineTransform TGfxAffineTransform::GetZoomInstance( sf,ax,ay); |
|
129 // --------------------------------------------------------------------------- |
|
130 TGfxAffineTransform TGfxAffineTransform::GetZoomInstance( TReal32 aScaleFactor, |
|
131 const TFloatFixPt& aX, |
|
132 const TFloatFixPt& aY ) |
|
133 { |
|
134 TFloatFixPt KOne( KFloatFixOne ); |
|
135 TGfxAffineTransform tmp; |
|
136 tmp.iM00 = aScaleFactor; |
|
137 tmp.iM11 = aScaleFactor; |
|
138 |
|
139 TMatrixElType x = ( TMatrixElType ) aX; |
|
140 TMatrixElType y = ( TMatrixElType ) aY; |
|
141 tmp.iM02 = x * ( KOne - tmp.iM00 ); |
|
142 tmp.iM12 = y * ( KOne - tmp.iM11 ); |
|
143 tmp.iTransType |= KTransformTranslate | KTransformScale; |
|
144 return tmp; |
|
145 } |
|
146 |
|
147 // -------------------------------------------------------------------------- |
|
148 // void TGfxAffineTransform::SetToRotate( TReal32 aTheta ) |
|
149 // --------------------------------------------------------------------------- |
|
150 void TGfxAffineTransform::SetToRotate( TReal32 aTheta ) |
|
151 { |
|
152 TFloatFixPt KZero; |
|
153 #ifdef SVG_FLOAT_BUILD |
|
154 TFloatFixPt cs = TFloatFixPt::CosFloatDouble( aTheta ); //(GfxMath::svgScalarCos((TInt32)(aTheta * TReal(0x10000)))); |
|
155 TFloatFixPt sn = TFloatFixPt::SinFloatDouble( aTheta ); //(GfxMath::svgScalarSin((TInt32)(aTheta * TReal(0x10000)))); |
|
156 #else |
|
157 TFloatFixPt cs (GfxMath::svgScalarCos((TInt32)(aTheta * TReal(0x10000))), ETrue); |
|
158 TFloatFixPt sn (GfxMath::svgScalarSin((TInt32)(aTheta * TReal(0x10000))), ETrue); |
|
159 #endif |
|
160 iM00 = cs; |
|
161 iM10 = sn; |
|
162 iM01 = KZero - sn; |
|
163 iM11 = cs; |
|
164 |
|
165 iM02 = KZero; |
|
166 iM12 = KZero; |
|
167 iTransType = KTransformShear | KTransformScale; |
|
168 } |
|
169 |
|
170 // ========================================================================== |
|
171 // Generally used instance creation: Scale matrix |
|
172 // ========================================================================== |
|
173 // -------------------------------------------------------------------------- |
|
174 // TGfxAffineTransform TGfxAffineTransform::GetScaleInstance( TReal32 aSx, |
|
175 // --------------------------------------------------------------------------- |
|
176 TGfxAffineTransform TGfxAffineTransform::GetScaleInstance( TReal32 aSx, |
|
177 TReal32 aSy ) |
|
178 { |
|
179 return TGfxAffineTransform( ( TReal32 ) aSx, |
|
180 0.0f, |
|
181 0.0f, |
|
182 ( TReal32 ) aSy, |
|
183 0.0f, |
|
184 0.0f, |
|
185 KTransformScale ); |
|
186 } |
|
187 |
|
188 // ========================================================================== |
|
189 // Generally used instance creation: Shear matrix |
|
190 // ========================================================================== |
|
191 // -------------------------------------------------------------------------- |
|
192 // TGfxAffineTransform TGfxAffineTransform::GetShearInstance( TReal32 aShx, |
|
193 // --------------------------------------------------------------------------- |
|
194 TGfxAffineTransform TGfxAffineTransform::GetShearInstance( TReal32 aShx, |
|
195 TReal32 aShy ) |
|
196 { |
|
197 #ifdef SVG_FLOAT_BUILD |
|
198 TFloatFixPt tnshx = TFloatFixPt::TanFloatDouble( aShx ); //(GfxMath::svgScalarTan(TInt(aShx*0x10000))); |
|
199 TFloatFixPt tnshy = TFloatFixPt::TanFloatDouble( aShy ); //(GfxMath::svgScalarTan(TInt(aShy*0x10000))); |
|
200 #else |
|
201 TFloatFixPt tnshx(GfxMath::svgScalarTan(TInt(aShx*0x10000)), ETrue); |
|
202 TFloatFixPt tnshy(GfxMath::svgScalarTan(TInt(aShy*0x10000)), ETrue); |
|
203 #endif |
|
204 |
|
205 return TGfxAffineTransform( 1.0f, |
|
206 TReal32(tnshy), |
|
207 TReal32(tnshx), |
|
208 1.0f, |
|
209 0.0f, |
|
210 0.0f, |
|
211 KTransformShear ); |
|
212 } |
|
213 |
|
214 |
|
215 // ========================================================================== |
|
216 // Generally used instance creation: Translate matrix |
|
217 // ========================================================================== |
|
218 // -------------------------------------------------------------------------- |
|
219 // TGfxAffineTransform TGfxAffineTransform::GetTranslateInstance( const TFixPt& aTx, |
|
220 // --------------------------------------------------------------------------- |
|
221 TGfxAffineTransform TGfxAffineTransform::GetTranslateInstance( const TFloatFixPt& aTx, |
|
222 const TFloatFixPt& aTy ) |
|
223 { |
|
224 return TGfxAffineTransform( 1.0f, |
|
225 0.0f, |
|
226 0.0f, |
|
227 1.0f, |
|
228 ( TReal32 ) aTx, |
|
229 ( TReal32 ) aTy, |
|
230 KTransformTranslate ); |
|
231 } |
|
232 |
|
233 // -------------------------------------------------------------------------- |
|
234 // TReal32 TGfxAffineTransform::Determinant() const |
|
235 // --------------------------------------------------------------------------- |
|
236 TReal32 TGfxAffineTransform::Determinant() const |
|
237 { |
|
238 return iM00 * iM11 - iM10 * iM01; |
|
239 } |
|
240 |
|
241 // -------------------------------------------------------------------------- |
|
242 // TBool TGfxAffineTransform::IsIdentity() const |
|
243 // --------------------------------------------------------------------------- |
|
244 TBool TGfxAffineTransform::IsIdentity() const |
|
245 { |
|
246 return ( (int)iTransType == KTransformIdentity ); |
|
247 } |
|
248 |
|
249 // -------------------------------------------------------------------------- |
|
250 // TReal32 TGfxAffineTransform::ScaleX() const |
|
251 // --------------------------------------------------------------------------- |
|
252 TReal32 TGfxAffineTransform::ScaleX() const |
|
253 { |
|
254 return iM00; |
|
255 } |
|
256 |
|
257 // -------------------------------------------------------------------------- |
|
258 // TReal32 TGfxAffineTransform::ScaleY() const |
|
259 // --------------------------------------------------------------------------- |
|
260 TReal32 TGfxAffineTransform::ScaleY() const |
|
261 { |
|
262 return iM11; |
|
263 } |
|
264 |
|
265 // -------------------------------------------------------------------------- |
|
266 // TReal32 TGfxAffineTransform::ShearX() const |
|
267 // --------------------------------------------------------------------------- |
|
268 TReal32 TGfxAffineTransform::ShearX() const |
|
269 { |
|
270 return iM01; |
|
271 } |
|
272 |
|
273 // -------------------------------------------------------------------------- |
|
274 // TReal32 TGfxAffineTransform::ShearY() const |
|
275 // --------------------------------------------------------------------------- |
|
276 TReal32 TGfxAffineTransform::ShearY() const |
|
277 { |
|
278 return iM10; |
|
279 } |
|
280 |
|
281 // -------------------------------------------------------------------------- |
|
282 // TReal32 TGfxAffineTransform::TranslateX() const |
|
283 // --------------------------------------------------------------------------- |
|
284 TReal32 TGfxAffineTransform::TranslateX() const |
|
285 { |
|
286 return iM02; |
|
287 } |
|
288 |
|
289 // -------------------------------------------------------------------------- |
|
290 // TReal32 TGfxAffineTransform::TranslateY() const |
|
291 // --------------------------------------------------------------------------- |
|
292 TReal32 TGfxAffineTransform::TranslateY() const |
|
293 { |
|
294 return iM12; |
|
295 } |
|
296 |
|
297 |
|
298 // -------------------------------------------------------------------------- |
|
299 // void TGfxAffineTransform::Concatenate( const TGfxAffineTransform& aTransform ) |
|
300 // --------------------------------------------------------------------------- |
|
301 void TGfxAffineTransform::Concatenate( const TGfxAffineTransform& aTransform ) |
|
302 { |
|
303 |
|
304 if ( IsIdentity() ) |
|
305 { |
|
306 iM00 = aTransform.iM00; |
|
307 iM01 = aTransform.iM01; |
|
308 iM02 = aTransform.iM02; |
|
309 iM11 = aTransform.iM11; |
|
310 iM10 = aTransform.iM10; |
|
311 iM12 = aTransform.iM12; |
|
312 iTransType = aTransform.iTransType; |
|
313 } |
|
314 else if ( aTransform.IsIdentity() ) |
|
315 { |
|
316 // Do nothing |
|
317 } |
|
318 else |
|
319 { |
|
320 TFloatFixPt m0, m1; |
|
321 m0 = iM00; |
|
322 m1 = iM01; |
|
323 iM00 = aTransform.iM00 * m0 + aTransform.iM10 * m1; |
|
324 iM01 = aTransform.iM01 * m0 + aTransform.iM11 * m1; |
|
325 iM02 += aTransform.iM02 * m0 + aTransform.iM12 * m1; |
|
326 m0 = iM10; |
|
327 m1 = iM11; |
|
328 iM11 = aTransform.iM01 * m0 + aTransform.iM11 * m1; |
|
329 iM10 = aTransform.iM00 * m0 + aTransform.iM10 * m1; |
|
330 iM12 += aTransform.iM02 * m0 + aTransform.iM12 * m1; |
|
331 iTransType |= aTransform.iTransType; |
|
332 } |
|
333 } |
|
334 |
|
335 // -------------------------------------------------------------------------- |
|
336 // TGfxAffineTransform TGfxAffineTransform::CreateInverse() |
|
337 // --------------------------------------------------------------------------- |
|
338 TGfxAffineTransform TGfxAffineTransform::CreateInverse() |
|
339 { |
|
340 TFloatFixPt KZero; |
|
341 TFloatFixPt det = iM00* iM11 - iM01* iM10; |
|
342 if ( det == KZero ) |
|
343 return TGfxAffineTransform(); |
|
344 else |
|
345 { |
|
346 #ifdef SVG_FLOAT_BUILD |
|
347 TFloatFixPt idet = TFloatFixPt(1.0f) / det; |
|
348 #else |
|
349 TFloatFixPt idet = TFloatFixPt(0x10000,ETrue)/ det; |
|
350 |
|
351 #endif |
|
352 return TGfxAffineTransform( iM11 * idet, |
|
353 KZero - iM10 * idet, |
|
354 KZero - iM01 * idet, |
|
355 iM00 * idet, |
|
356 ( iM01 * iM12 - iM11 * iM02 ) * idet, |
|
357 ( iM10 * iM02 - iM00 * iM12 ) * idet ); |
|
358 } |
|
359 } |
|
360 |
|
361 // -------------------------------------------------------------------------- |
|
362 // void TGfxAffineTransform::Rotate( TReal32 aTheta ) |
|
363 // --------------------------------------------------------------------------- |
|
364 void TGfxAffineTransform::Rotate( TReal32 aTheta ) |
|
365 { |
|
366 Concatenate( GetRotateInstance( aTheta ) ); |
|
367 iTransType |= ( KTransformShear | KTransformScale ); |
|
368 } |
|
369 |
|
370 // -------------------------------------------------------------------------- |
|
371 // void TGfxAffineTransform::Rotate( TReal32 aTheta, |
|
372 // --------------------------------------------------------------------------- |
|
373 void TGfxAffineTransform::Rotate( TReal32 aTheta, |
|
374 const TFloatFixPt& aX, |
|
375 const TFloatFixPt& aY ) |
|
376 { |
|
377 Concatenate( GetRotateInstance( aTheta, aX, aY ) ); |
|
378 iTransType |= ( KTransformShear | KTransformScale | KTransformTranslate ); |
|
379 } |
|
380 |
|
381 // -------------------------------------------------------------------------- |
|
382 // void TGfxAffineTransform::Scale( TReal32 aSx, TReal32 aSy ) |
|
383 // --------------------------------------------------------------------------- |
|
384 void TGfxAffineTransform::Scale( TReal32 aSx, TReal32 aSy ) |
|
385 { |
|
386 Concatenate( GetScaleInstance( aSx, aSy ) ); |
|
387 iTransType |= KTransformScale; |
|
388 } |
|
389 |
|
390 // -------------------------------------------------------------------------- |
|
391 // void TGfxAffineTransform::Translate( const TFixPt& aTx, |
|
392 // --------------------------------------------------------------------------- |
|
393 void TGfxAffineTransform::Translate( const TFloatFixPt& aTx, |
|
394 const TFloatFixPt& aTy ) |
|
395 { |
|
396 Concatenate( GetTranslateInstance( aTx, aTy ) ); |
|
397 iTransType |= KTransformTranslate; |
|
398 } |
|
399 |
|
400 // -------------------------------------------------------------------------- |
|
401 // void TGfxAffineTransform::Shear( TReal32 aShX, TReal32 aShY ) |
|
402 // --------------------------------------------------------------------------- |
|
403 void TGfxAffineTransform::Shear( TReal32 aShX, TReal32 aShY ) |
|
404 { |
|
405 Concatenate( GetShearInstance( aShX, aShY ) ); |
|
406 iTransType |= KTransformShear; |
|
407 } |
|
408 |
|
409 // -------------------------------------------------------------------------- |
|
410 // void TGfxAffineTransform::SetTransform( TReal32 aM00, |
|
411 // --------------------------------------------------------------------------- |
|
412 void TGfxAffineTransform::SetTransform( TReal32 aM00, |
|
413 TReal32 aM10, |
|
414 TReal32 aM01, |
|
415 TReal32 aM11, |
|
416 TReal32 aM02, |
|
417 TReal32 aM12 ) |
|
418 { |
|
419 iM00 = aM00; |
|
420 iM01 = aM01; |
|
421 iM02 = aM02; |
|
422 iM10 = aM10; |
|
423 iM11 = aM11; |
|
424 iM12 = aM12; |
|
425 UpdateState(); |
|
426 } |
|
427 |
|
428 // -------------------------------------------------------------------------- |
|
429 // void TGfxAffineTransform::Transform( TGfxPoint2D* aSrcPts, |
|
430 // --------------------------------------------------------------------------- |
|
431 void TGfxAffineTransform::Transform( TGfxPoint2D* aSrcPts, |
|
432 TGfxPoint2D* aDstPts, |
|
433 TInt32 aNumPts ) const |
|
434 { |
|
435 |
|
436 if ( (int)iTransType == KTransformIdentity ) |
|
437 { |
|
438 if ( aSrcPts != aDstPts ) |
|
439 { |
|
440 for ( TInt32 i = 0; i < aNumPts; i++ ) |
|
441 { |
|
442 aDstPts[i] = aSrcPts[i]; |
|
443 } |
|
444 } |
|
445 return; |
|
446 } |
|
447 |
|
448 if ( (int)iTransType == KTransformScale ) |
|
449 { |
|
450 for ( TInt32 i = 0; i < aNumPts; i++ ) |
|
451 { |
|
452 aDstPts[i].iX = aSrcPts[i].iX * iM00; |
|
453 aDstPts[i].iY = aSrcPts[i].iY * iM11; |
|
454 } |
|
455 } |
|
456 else if ( (int)iTransType == KTransformTranslate ) |
|
457 { |
|
458 for ( TInt32 i = 0; i < aNumPts; i++ ) |
|
459 { |
|
460 aDstPts[i].iX = aSrcPts[i].iX + iM02; |
|
461 aDstPts[i].iY = aSrcPts[i].iY + iM12; |
|
462 } |
|
463 } |
|
464 else if ( (int)iTransType == ( KTransformScale | KTransformTranslate ) ) |
|
465 { |
|
466 for ( TInt32 i = 0; i < aNumPts; i++ ) |
|
467 { |
|
468 aDstPts[i].iX = ( aSrcPts[i].iX * iM00 ) + iM02; |
|
469 aDstPts[i].iY = ( aSrcPts[i].iY * iM11 ) + iM12; |
|
470 } |
|
471 } |
|
472 else |
|
473 { |
|
474 TFloatFixPt x, y; |
|
475 |
|
476 for ( TInt32 i = 0; i < aNumPts; i++ ) |
|
477 { |
|
478 x = aSrcPts[i].iX; |
|
479 y = aSrcPts[i].iY; |
|
480 aDstPts[i].iX = ( iM00 * x ) + ( iM01 * y ) + iM02; |
|
481 aDstPts[i].iY = ( iM10 * x ) + ( iM11 * y ) + iM12; |
|
482 } |
|
483 } |
|
484 } |
|
485 |
|
486 // -------------------------------------------------------------------------- |
|
487 // void TGfxAffineTransform::Transform( TFixPt* aSrcPts, |
|
488 // --------------------------------------------------------------------------- |
|
489 void TGfxAffineTransform::Transform( TFloatFixPt* aSrcPts, |
|
490 TFloatFixPt* aDstPts, |
|
491 TInt32 aNumPts ) const |
|
492 { |
|
493 aNumPts <<= 1; |
|
494 |
|
495 if ( (int)iTransType == KTransformIdentity ) |
|
496 { |
|
497 if ( aSrcPts != aDstPts ) |
|
498 { |
|
499 for ( TInt32 i = 0; i < aNumPts; i++ ) |
|
500 { |
|
501 *aDstPts++ = *aSrcPts++; |
|
502 *aDstPts++ = *aSrcPts++; |
|
503 } |
|
504 } |
|
505 return; |
|
506 } |
|
507 |
|
508 if ( (int)iTransType == KTransformScale ) |
|
509 { |
|
510 for ( TInt32 i = 0; i < aNumPts; i += 2 ) |
|
511 { |
|
512 *aDstPts++ = *aSrcPts++ * iM00; |
|
513 *aDstPts++ = *aSrcPts++ * iM11; |
|
514 } |
|
515 } |
|
516 else if ( (int)iTransType == KTransformTranslate ) |
|
517 { |
|
518 for ( TInt32 i = 0; i < aNumPts; i += 2 ) |
|
519 { |
|
520 *aDstPts++ = *aSrcPts++ + iM02; |
|
521 *aDstPts++ = *aSrcPts++ + iM12; |
|
522 } |
|
523 } |
|
524 else if ( (int)iTransType == ( KTransformScale | KTransformTranslate ) ) |
|
525 { |
|
526 for ( TInt32 i = 0; i < aNumPts; i += 2 ) |
|
527 { |
|
528 *aDstPts++ = ( *aSrcPts++ * iM00 ) + iM02; |
|
529 *aDstPts++ = ( *aSrcPts++ * iM11 ) + iM12; |
|
530 } |
|
531 } |
|
532 else |
|
533 { |
|
534 TFloatFixPt x, y; |
|
535 |
|
536 for ( TInt32 i = 0; i < aNumPts; i += 2 ) |
|
537 { |
|
538 x = *aSrcPts++; |
|
539 y = *aSrcPts++; |
|
540 *aDstPts++ = ( iM00 * x ) + ( iM01 * y ) + iM02; |
|
541 *aDstPts++ = ( iM10 * x ) + ( iM11 * y ) + iM12; |
|
542 } |
|
543 } |
|
544 } |
|
545 |
|
546 // -------------------------------------------------------------------------- |
|
547 // void TGfxAffineTransform::Transform( TFixPt* aSrcDstPts, |
|
548 // --------------------------------------------------------------------------- |
|
549 void TGfxAffineTransform::Transform( TFloatFixPt* aSrcDstPts, |
|
550 TInt32 aNumPts ) const |
|
551 { |
|
552 if ( (int)iTransType == KTransformIdentity ) |
|
553 return; |
|
554 |
|
555 aNumPts <<= 1; |
|
556 |
|
557 if ( (int)iTransType == KTransformScale ) |
|
558 { |
|
559 for ( TInt32 i = 0; i < aNumPts; i += 2 ) |
|
560 { |
|
561 *aSrcDstPts++ *= iM00; |
|
562 *aSrcDstPts++ *= iM11; |
|
563 } |
|
564 } |
|
565 else if ( (int)iTransType == KTransformTranslate ) |
|
566 { |
|
567 for ( TInt32 i = 0; i < aNumPts; i += 2 ) |
|
568 { |
|
569 *aSrcDstPts++ += iM02; |
|
570 *aSrcDstPts++ += iM12; |
|
571 } |
|
572 } |
|
573 else if ( (int)iTransType == ( KTransformScale | KTransformTranslate ) ) |
|
574 { |
|
575 for ( TInt32 i = 0; i < aNumPts; i += 2 ) |
|
576 { |
|
577 *aSrcDstPts *= iM00; |
|
578 *aSrcDstPts++ += iM02; |
|
579 *aSrcDstPts *= iM11; |
|
580 *aSrcDstPts++ += iM12; |
|
581 } |
|
582 } |
|
583 else |
|
584 { |
|
585 TFloatFixPt x, y; |
|
586 |
|
587 for ( TInt32 i = 0; i < aNumPts; i += 2 ) |
|
588 { |
|
589 x = *aSrcDstPts; |
|
590 y = *( aSrcDstPts + 1 ); |
|
591 *aSrcDstPts++ = ( iM00 * x ) + ( iM01 * y ) + iM02; |
|
592 *aSrcDstPts++ = ( iM10 * x ) + ( iM11 * y ) + iM12; |
|
593 } |
|
594 } |
|
595 } |
|
596 |
|
597 // -------------------------------------------------------------------------- |
|
598 // void TGfxAffineTransform::UpdateState() |
|
599 // --------------------------------------------------------------------------- |
|
600 void TGfxAffineTransform::UpdateState() |
|
601 { |
|
602 TFloatFixPt KZero; |
|
603 TFloatFixPt KOne( KFloatFixOne ); |
|
604 iTransType = KTransformIdentity; |
|
605 |
|
606 if ( iM02 != KZero || iM12 != KZero ) |
|
607 iTransType |= KTransformTranslate; |
|
608 |
|
609 if ( iM00 != KZero || iM11 != KZero ) |
|
610 iTransType |= KTransformScale; |
|
611 |
|
612 if ( iM01 != KZero || iM10 != KZero ) |
|
613 iTransType |= KTransformShear; |
|
614 |
|
615 if ( (int)iTransType == KTransformScale && iM00 == KOne && iM11 == KOne ) |
|
616 iTransType = KTransformIdentity; |
|
617 } |
|
618 |
|
619 // -------------------------------------------------------------------------- |
|
620 // TUint32 TGfxAffineTransform::TransformType() |
|
621 // --------------------------------------------------------------------------- |
|
622 TUint32 TGfxAffineTransform::TransformType() |
|
623 { |
|
624 return iTransType; |
|
625 } |
|
626 |
|
627 // -------------------------------------------------------------------------- |
|
628 // void TGfxAffineTransform::Print() |
|
629 // prints out the matrix |
|
630 // --------------------------------------------------------------------------- |
|
631 void TGfxAffineTransform::Print() |
|
632 { |
|
633 RDebug::Printf("a=%f b=%f c=%f d=%f e=%f f=%f", (TReal32)iM00, (TReal32)iM10, (TReal32)iM01, (TReal32)iM11, (TReal32)iM02, (TReal32)iM12); |
|
634 } |
|
635 |
|
636 // -------------------------------------------------------------------------- |
|
637 // Get the scaling factor set in this transform. This function returns correctly |
|
638 // for a uniform scaling in both directions only. |
|
639 // --------------------------------------------------------------------------- |
|
640 TFloatFixPt TGfxAffineTransform::ScalingFactor() const |
|
641 { |
|
642 TGfxPoint2D ep( 1, 0 ), org( 2, 0 ); |
|
643 Transform( &ep, & ep, 1 ); |
|
644 Transform( &org, & org, 1 ); |
|
645 ep.iX -= org.iX; |
|
646 ep.iY -= org.iY; |
|
647 return TFloatFixPt::Sqrt( ep.iX * ep.iX + ep.iY * ep.iY ); |
|
648 } |
|
649 |
|
650 |
|
651 |
|
652 // -------------------------------------------------------------------------- |
|
653 // |
|
654 // Appends this transform with the existing transform |
|
655 // Multiply in reverse order |
|
656 // For Ex: In cases of zoom, rotate and pan of already transformed content. |
|
657 // If T is the existing transform and zoom operation has to be applied to it |
|
658 // the resultant transform would be Z*T. |
|
659 // |
|
660 // void TGfxAffineTransform::AppendTransform( const TGfxAffineTransform& aTransform ) |
|
661 // --------------------------------------------------------------------------- |
|
662 void TGfxAffineTransform::AppendTransform( const TGfxAffineTransform& aTransform ) |
|
663 { |
|
664 |
|
665 if ( IsIdentity() ) |
|
666 { |
|
667 iM00 = aTransform.iM00; |
|
668 iM01 = aTransform.iM01; |
|
669 iM02 = aTransform.iM02; |
|
670 iM11 = aTransform.iM11; |
|
671 iM10 = aTransform.iM10; |
|
672 iM12 = aTransform.iM12; |
|
673 iTransType = aTransform.iTransType; |
|
674 } |
|
675 else if ( aTransform.IsIdentity() ) |
|
676 { |
|
677 // Do nothing |
|
678 } |
|
679 else |
|
680 { |
|
681 TMatrixElType m00, m01,m02,m10,m11,m12; |
|
682 m00 = iM00; |
|
683 m01 = iM01; |
|
684 m02 = iM02; |
|
685 m10 = iM10; |
|
686 m11 = iM11; |
|
687 m12 = iM12; |
|
688 iM00 = aTransform.iM00 * m00 + aTransform.iM01 * m10; |
|
689 iM01 = aTransform.iM00 * m01 + aTransform.iM01 * m11; |
|
690 iM02 = aTransform.iM00 * m02 + aTransform.iM01 * m12 + aTransform.iM02; |
|
691 |
|
692 iM10 = aTransform.iM10 * m00 + aTransform.iM11 * m10; |
|
693 iM11 = aTransform.iM10 * m01 + aTransform.iM11 * m11; |
|
694 iM12 = aTransform.iM10 * m02 + aTransform.iM11 * m12 + aTransform.iM12; |
|
695 |
|
696 iTransType |= aTransform.iTransType; |
|
697 } |
|
698 } |
|
699 |
|
700 // -------------------------------------------------------------------------- |
|
701 // void TGfxAffineTransform::UserRoatate( TReal32 aTheta, |
|
702 // --------------------------------------------------------------------------- |
|
703 void TGfxAffineTransform::UserRotate( TReal32 aTheta, |
|
704 const TFloatFixPt& aX, |
|
705 const TFloatFixPt& aY ) |
|
706 { |
|
707 AppendTransform( GetRotateInstance( aTheta, aX, aY ) ); |
|
708 iTransType |= ( KTransformShear | KTransformScale | KTransformTranslate ); |
|
709 } |
|
710 |
|
711 // -------------------------------------------------------------------------- |
|
712 // void TGfxAffineTransform::UserZoom( TReal32 aScaleFactor, |
|
713 // --------------------------------------------------------------------------- |
|
714 void TGfxAffineTransform::UserZoom( TReal32 aScaleFactor, |
|
715 const TFloatFixPt& aX, |
|
716 const TFloatFixPt& aY ) |
|
717 { |
|
718 AppendTransform( GetZoomInstance( aScaleFactor, aX, aY ) ); |
|
719 iTransType |= ( KTransformScale | KTransformTranslate ); |
|
720 } |
|
721 |
|
722 // -------------------------------------------------------------------------- |
|
723 // void TGfxAffineTransform::UserPan( const TFloatFixPt& aTx, |
|
724 // --------------------------------------------------------------------------- |
|
725 void TGfxAffineTransform::UserPan( const TFloatFixPt& aTx, |
|
726 const TFloatFixPt& aTy ) |
|
727 { |
|
728 AppendTransform( GetTranslateInstance( aTx, aTy ) ); |
|
729 iTransType |= KTransformTranslate; |
|
730 } |
|
731 |
|
732 |
|
733 // |