|
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: Base class for PolyLine and PolySpline classes. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "AknsAlPolyBase.h" |
|
20 |
|
21 #include <e32debug.h> |
|
22 |
|
23 // ----------------------------------------------------------------------------- |
|
24 // Constructor. |
|
25 // ----------------------------------------------------------------------------- |
|
26 // |
|
27 CAknsAlPolyBase::CAknsAlPolyBase() |
|
28 { |
|
29 iPoints = NULL; // not needed, but just in case |
|
30 } |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // Destructor. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CAknsAlPolyBase::~CAknsAlPolyBase() |
|
37 { |
|
38 delete iPoints; |
|
39 iPoints = NULL; |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // Sets scaled area. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 void CAknsAlPolyBase::SetScaledArea( const TSize aAreaSize ) |
|
47 { |
|
48 iAreaSize = aAreaSize; |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // Sets poly points. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 void CAknsAlPolyBase::SetPolyPointsL( const TDesC16& aPointString ) |
|
56 { |
|
57 TInt coordCount = aPointString.Length(); |
|
58 |
|
59 if ((coordCount & 0x1) || coordCount < 4) // odd number or too few point coordinates |
|
60 { |
|
61 RDebug::Printf("%s, line %d, ERROR: Illegal coordinate count", __FILE__, __LINE__); |
|
62 User::Leave(KErrArgument); |
|
63 } |
|
64 |
|
65 iPointCount = coordCount >> 1; |
|
66 iPoints = new (ELeave) TPolyPoint[iPointCount]; |
|
67 |
|
68 iPoints[0].iX = aPointString[0]; |
|
69 iPoints[0].iY = aPointString[1]; |
|
70 |
|
71 TUint16 oldX = iPoints[0].iX; |
|
72 TUint16 oldY = iPoints[0].iY; |
|
73 |
|
74 // parse numbers from the descriptor |
|
75 for (TInt i = 1; i < iPointCount; i++) // first point already set |
|
76 { |
|
77 iPoints[i].iX = aPointString[i*2]; |
|
78 iPoints[i].iY = aPointString[i*2+1]; |
|
79 |
|
80 if (oldX == iPoints[i].iX && oldY == iPoints[i].iY) |
|
81 { |
|
82 RDebug::Printf("%s, line %d, ERROR: subsequent coordinates cannot be equal", __FILE__, __LINE__); |
|
83 User::Leave(KErrArgument); |
|
84 } |
|
85 |
|
86 oldX = iPoints[i].iX; |
|
87 oldY = iPoints[i].iY; |
|
88 } |
|
89 } |
|
90 |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // Sets poly1D points. |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 void CAknsAlPolyBase::SetPolyPoints1DL( const TDesC16& aPointString ) |
|
97 { |
|
98 TInt coordCount = aPointString.Length(); |
|
99 |
|
100 if ((coordCount & 0x1) || coordCount < 4) // odd number or too few point coordinates |
|
101 User::Leave(KErrArgument); |
|
102 |
|
103 iPointCount = coordCount >> 1; |
|
104 iPoints = new (ELeave) TPolyPoint[iPointCount]; |
|
105 |
|
106 iPoints[0].iX = aPointString[0]; |
|
107 iPoints[0].iY = aPointString[1]; |
|
108 |
|
109 TUint16 oldX = iPoints[0].iX; |
|
110 |
|
111 // parse numbers from the descriptor |
|
112 for (TInt i = 1; i < iPointCount; i++) // first point already set |
|
113 { |
|
114 iPoints[i].iX = aPointString[i*2]; |
|
115 iPoints[i].iY = aPointString[i*2+1]; |
|
116 |
|
117 if (iPoints[i].iX < oldX) // points must be in ascending order |
|
118 User::Leave(KErrArgument); |
|
119 |
|
120 oldX = iPoints[i].iX; |
|
121 } |
|
122 } |
|
123 |
|
124 // Some helper methods for child classes |
|
125 // ----------------------------------------------------------------------------- |
|
126 // Squareroot. |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 TUint CAknsAlPolyBase::Sqrt( TUint aParam ) |
|
130 { |
|
131 TUint t,b,c=0; |
|
132 |
|
133 for (b=0x40000000;b!=0;b>>=2) |
|
134 { |
|
135 t = c + b; |
|
136 c >>= 1; |
|
137 if (t <= aParam) |
|
138 { |
|
139 aParam -= t; |
|
140 c += b; |
|
141 } |
|
142 } |
|
143 return(c); |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // Calculates scaled point. |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 TPoint CAknsAlPolyBase::CalculateScaledPoint( const TPoint aPoint ) |
|
151 { |
|
152 TPoint ret(0,0); |
|
153 if (iAreaSize.iWidth == 0) |
|
154 { |
|
155 ret.iX = aPoint.iX; |
|
156 } |
|
157 else |
|
158 { |
|
159 ret.iX = (aPoint.iX * iAreaSize.iWidth) >> 16; |
|
160 } |
|
161 |
|
162 if (iAreaSize.iHeight == 0) |
|
163 { |
|
164 ret.iY = aPoint.iY; |
|
165 } |
|
166 else |
|
167 { |
|
168 ret.iY = (aPoint.iY * iAreaSize.iHeight) >> 16; |
|
169 } |
|
170 |
|
171 return ret; |
|
172 } |
|
173 |
|
174 // End of file |
|
175 |