|
1 /* |
|
2 * Copyright (c) 2004-2008 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: PolySpline. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "AknsAlPolyLine1D.h" |
|
20 |
|
21 |
|
22 // ----------------------------------------------------------------------------- |
|
23 // C++ constructor. |
|
24 // ----------------------------------------------------------------------------- |
|
25 // |
|
26 CAknsAlPolyLine1D::CAknsAlPolyLine1D() |
|
27 { |
|
28 } |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // Destructor. |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CAknsAlPolyLine1D::~CAknsAlPolyLine1D() |
|
35 { |
|
36 } |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // Symbian 1st phase constructor. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CAknsAlPolyLine1D* CAknsAlPolyLine1D::NewL() |
|
43 { // static |
|
44 CAknsAlPolyLine1D* self=new(ELeave) CAknsAlPolyLine1D(); |
|
45 return self; |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // Gets poly point. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 TPoint CAknsAlPolyLine1D::GetPolyPoint( const TUint32 aPosition ) |
|
53 { |
|
54 // linepoints have x-coordinates between 0...16bit, |
|
55 // so we only need to use upper 16 bits from aPosition |
|
56 TInt pos = aPosition >> 16; |
|
57 |
|
58 // find the line, where pos is pointing |
|
59 TInt i = 0; // first index |
|
60 TInt j = iPointCount-1; // last index |
|
61 TInt k; |
|
62 while ( i < j ) |
|
63 { |
|
64 k = (i + j)/2; |
|
65 if ( pos < iPoints[k].iX ) |
|
66 { |
|
67 j = k; |
|
68 } |
|
69 else |
|
70 { |
|
71 i = k + 1; |
|
72 } |
|
73 } |
|
74 // i = j = wanted line's end point index |
|
75 |
|
76 TUint32 deltaX = iPoints[i].iX - iPoints[i-1].iX; // always positive, 16 bits |
|
77 TUint32 deltaY; // might be negative, so use flag to get correct results |
|
78 TBool negativeY = EFalse; |
|
79 if ((iPoints[i].iY - iPoints[i-1].iY) < 0) |
|
80 { |
|
81 deltaY = iPoints[i-1].iY - iPoints[i].iY; |
|
82 negativeY = ETrue; |
|
83 } |
|
84 else |
|
85 { |
|
86 deltaY = iPoints[i].iY - iPoints[i-1].iY; |
|
87 } |
|
88 pos -= iPoints[i-1].iX; |
|
89 |
|
90 if (pos == 0) // we are in line's first pixel |
|
91 { |
|
92 return TPoint((iPoints[i-1].iX * iAreaSize.iWidth) >> 16, |
|
93 (iPoints[i-1].iY * iAreaSize.iHeight) >> 16); |
|
94 } |
|
95 |
|
96 TUint32 calculatedY = (deltaY * pos) / deltaX; // first get delta from start point |
|
97 if (negativeY) |
|
98 { |
|
99 calculatedY = iPoints[i-1].iY - calculatedY; // line going downwards |
|
100 } |
|
101 else |
|
102 { |
|
103 calculatedY = iPoints[i-1].iY + calculatedY; // line going upwards |
|
104 } |
|
105 |
|
106 return CalculateScaledPoint(TPoint(aPosition >> 16,calculatedY)); |
|
107 } |
|
108 |
|
109 // End of file |
|
110 |