|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Definition for CHuiCurvePath. Curve paths are composed of path |
|
15 * segments and can be used as mapping functions, and in line visuals. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef __HUICURVEPATH_H__ |
|
22 #define __HUICURVEPATH_H__ |
|
23 |
|
24 |
|
25 #include <e32base.h> |
|
26 |
|
27 #include <uiacceltk/HuiTimedValue.h> |
|
28 #include <uiacceltk/HuiTimedPoint.h> |
|
29 #include <uiacceltk/HuiRealPoint.h> |
|
30 #include <uiacceltk/HuiImage.h> |
|
31 |
|
32 |
|
33 class CHuiGc; |
|
34 class CHuiVisual; |
|
35 struct THuiCurvePathExtension; |
|
36 |
|
37 |
|
38 /** |
|
39 * CHuiCurvePath is a 2D path composed out of line segments and ellipse arcs. |
|
40 * Each segment can have a length factor that causes it to be shorter or |
|
41 * longer than its real length. |
|
42 */ |
|
43 class CHuiCurvePath : public CBase, public MHuiMappingFunction |
|
44 { |
|
45 |
|
46 friend class CHuiLineVisual; |
|
47 |
|
48 public: |
|
49 |
|
50 /* Constructors and destructor. */ |
|
51 |
|
52 /** |
|
53 * Constructor. |
|
54 */ |
|
55 IMPORT_C static CHuiCurvePath* NewL(); |
|
56 |
|
57 /** |
|
58 * Constructor. The new brush is left on the cleanup stack. |
|
59 */ |
|
60 IMPORT_C static CHuiCurvePath* NewLC(); |
|
61 |
|
62 /** |
|
63 * Constructor. Not exported. |
|
64 */ |
|
65 IMPORT_C CHuiCurvePath(); |
|
66 |
|
67 /** |
|
68 * Destructor. |
|
69 */ |
|
70 IMPORT_C ~CHuiCurvePath(); |
|
71 |
|
72 |
|
73 /* Methods. */ |
|
74 |
|
75 /** |
|
76 * Resets the path by removing all segments. |
|
77 */ |
|
78 IMPORT_C virtual void Reset(); |
|
79 |
|
80 /** |
|
81 * Enables or disables looping of the path. Looping means that all |
|
82 * positions are wrapped to the path, so that, e.g., positions past |
|
83 * the end are wrapped to the beginning of the path. Looping is enabled by |
|
84 * default. |
|
85 */ |
|
86 IMPORT_C void EnableLoop(TBool aEnable = ETrue); |
|
87 |
|
88 /** |
|
89 * Determines if the path is wrapped. |
|
90 */ |
|
91 IMPORT_C TBool Loop() const; |
|
92 |
|
93 /** |
|
94 * Determines if the path needs updating. |
|
95 */ |
|
96 IMPORT_C TBool NeedUpdate() const; |
|
97 |
|
98 /** |
|
99 * Called when the path needs updating. |
|
100 */ |
|
101 IMPORT_C void SetNeedsUpdate(); |
|
102 |
|
103 /** |
|
104 * Sets the position that is at path location zero. |
|
105 * |
|
106 * @param aPosOrigin Added to positions when evaluating. |
|
107 */ |
|
108 IMPORT_C void SetOrigin(TReal32 aPosOrigin) __SOFTFP; |
|
109 |
|
110 /** |
|
111 * Appends a line segment to the path. |
|
112 * @deprecated |
|
113 * |
|
114 * @param aLength Negative length means that the length will be the |
|
115 * actual length of the line segment. |
|
116 */ |
|
117 IMPORT_C void AppendLineL(const TPoint& aStart, const TPoint& aEnd, |
|
118 TReal32 aLength = -1) __SOFTFP; |
|
119 |
|
120 /** |
|
121 * Appends a line segment to the path. Note that the coordinate values should |
|
122 * match to the metrics unit type of the visual that uses this class. |
|
123 * |
|
124 * @param aStart Start point of the line segment. |
|
125 * @param aEnd End point of the line segment. |
|
126 * @param aLength Negative length means that the length will be the |
|
127 * actual length of the line segment. |
|
128 */ |
|
129 IMPORT_C void AppendLineL(const THuiRealPoint& aStart, const THuiRealPoint& aEnd, |
|
130 TReal32 aLength = -1) __SOFTFP; |
|
131 |
|
132 /** |
|
133 * Appends a curve segment to the path. |
|
134 * @deprecated |
|
135 * |
|
136 * @param aOrigin Origin of the arc ellipse. |
|
137 * @param aSize Horiz and vert radii of the arc ellipse. |
|
138 * @param aStartAngle Start angle of the arc (degrees). |
|
139 * @param aEndAngle End angle of the arc (degrees). |
|
140 * @param aLength Negative length means that the length will be the |
|
141 * actual length of the arc. |
|
142 */ |
|
143 IMPORT_C void AppendArcL(const TPoint& aOrigin, const TSize& aSize, |
|
144 TReal32 aStartAngle, TReal32 aEndAngle, |
|
145 TReal32 aLength = -1) __SOFTFP; |
|
146 |
|
147 /** |
|
148 * Appends a curve segment to the path. Note that the coordinate values should |
|
149 * match to the metrics unit type of the visual that uses this class. |
|
150 * |
|
151 * @param aOrigin Origin of the arc ellipse. |
|
152 * @param aSize Horiz and vert radii of the arc ellipse. |
|
153 * @param aStartAngle Start angle of the arc (degrees). |
|
154 * @param aEndAngle End angle of the arc (degrees). |
|
155 * @param aLength Negative length means that the length will be the |
|
156 * actual length of the arc. |
|
157 */ |
|
158 IMPORT_C void AppendArcL(const THuiRealPoint& aOrigin, const THuiRealSize& aSize, |
|
159 TReal32 aStartAngle, TReal32 aEndAngle, |
|
160 TReal32 aLength = -1) __SOFTFP; |
|
161 |
|
162 /** |
|
163 * Determines the total length of the path. |
|
164 */ |
|
165 IMPORT_C TReal32 Length() const __SOFTFP; |
|
166 |
|
167 /** |
|
168 * Evaluates a point along the curve path. |
|
169 * |
|
170 * @param aPos Position along the path. |
|
171 * @param aPoint X and Y coordinates of the point on the path. |
|
172 */ |
|
173 IMPORT_C void Evaluate(TReal32 aPos, THuiRealPoint& aPoint) const __SOFTFP; |
|
174 |
|
175 /** |
|
176 * Recalculate the path's vertices and colors. |
|
177 */ |
|
178 IMPORT_C virtual void Update(TReal32 aStartPos, TReal32 aEndPos, |
|
179 TReal32 aAlphaFactor, |
|
180 MHuiMappingFunction* aAlphaFunction, |
|
181 MHuiMappingFunction* aWidthFunction) __SOFTFP; |
|
182 |
|
183 /** |
|
184 * Draws the path's triangles. |
|
185 */ |
|
186 IMPORT_C virtual void Draw(const TPoint& aOrigin, CHuiGc* aGc) const; |
|
187 |
|
188 |
|
189 /* Implements the MHuiMappingFunction interface. */ |
|
190 |
|
191 IMPORT_C TReal32 MapValue(TReal32 aValue, TInt aComponent) const __SOFTFP; |
|
192 |
|
193 IMPORT_C TBool MappingFunctionChanged() const; |
|
194 |
|
195 IMPORT_C void MappingFunctionClearChanged(); |
|
196 IMPORT_C void SetVisual(const CHuiVisual* aVisual) const; |
|
197 IMPORT_C const CHuiVisual* GetVisual() const; |
|
198 IMPORT_C TBool IsLegacyApiUsed() const; |
|
199 |
|
200 protected: |
|
201 |
|
202 /* Methods. */ |
|
203 |
|
204 /** |
|
205 * Determines the total length of the path by summing the lengths of |
|
206 * all the segments. |
|
207 */ |
|
208 IMPORT_C TReal32 CalculateLength() const; |
|
209 |
|
210 |
|
211 protected: |
|
212 |
|
213 /* Types. */ |
|
214 |
|
215 /** Segment type. */ |
|
216 enum TSegmentType |
|
217 { |
|
218 ESegmentTypeLine, |
|
219 ESegmentTypeArc |
|
220 }; |
|
221 |
|
222 /** |
|
223 * A single segment of a path, of shape TSegmentType. These are joined |
|
224 * together to make a complex path. |
|
225 * |
|
226 */ |
|
227 struct TSegment |
|
228 { |
|
229 /** Straight or curved. */ |
|
230 TSegmentType iType; |
|
231 /** Length of the path segment. */ |
|
232 TReal32 iLength; |
|
233 /** Point where it starts. */ |
|
234 THuiRealPoint iOrigin; |
|
235 /** Point where it ends. */ |
|
236 THuiRealPoint iDelta; |
|
237 /** Starting angle (if curved). */ |
|
238 TReal32 iStartAngle; |
|
239 /** Arc size (if curved). */ |
|
240 TReal32 iAngleDelta; |
|
241 |
|
242 /** Start position of the segment measured from the start. */ |
|
243 TReal32 iTotalPos; |
|
244 }; |
|
245 |
|
246 |
|
247 protected: |
|
248 |
|
249 /* Methods. */ |
|
250 |
|
251 /** |
|
252 * Returns the number of segments. |
|
253 */ |
|
254 IMPORT_C TInt SegmentCount() const; |
|
255 |
|
256 /** |
|
257 * Returns a segment. |
|
258 * |
|
259 * @return Segment data. |
|
260 */ |
|
261 IMPORT_C TSegment Segment(TInt aIndex) const; |
|
262 |
|
263 /** |
|
264 * Evaluates a point on a segment. |
|
265 * |
|
266 * @param aPos Position. |
|
267 * @param aSegment Segment (arc or line). |
|
268 * @param aPoint Result point. |
|
269 * @param aNormal If specified, returns the normal of the path point. |
|
270 */ |
|
271 IMPORT_C void EvaluateSegment(TReal32 aPos, const TSegment& aSegment, |
|
272 THuiRealPoint& aPoint, |
|
273 THuiRealPoint* aNormal = 0) const; |
|
274 |
|
275 |
|
276 /** |
|
277 * Provides expandability, helps keeping the binary compatibility. Since virtual |
|
278 * table is now exported and this class is dll derivable and the implementation |
|
279 * is more difficult to change, hence this method, which can provide additional |
|
280 * extension APIs. |
|
281 * |
|
282 * @param aExtensionUid UID, which is being used for recognizing the extension |
|
283 * @param aExtensionParams Return pointer to the extension API, once recognized from the extension uid |
|
284 */ |
|
285 IMPORT_C virtual void CurvePathExtension(const TUid& aExtensionUid, TAny** aExtensionParams); |
|
286 |
|
287 |
|
288 private: |
|
289 |
|
290 /** Array of line and arc segments. */ |
|
291 RArray<TSegment> iSegments; |
|
292 |
|
293 /** Path location origin. */ |
|
294 TReal32 iPosOrigin; |
|
295 |
|
296 TReal32 iTotalLength; |
|
297 |
|
298 THuiCurvePathExtension* iExtension; |
|
299 |
|
300 /** Flag to determine if the path has changed. */ |
|
301 TBool iChanged; |
|
302 |
|
303 TBool iNeedUpdate; |
|
304 |
|
305 /** Spare member to help keeping binary compatibility, since HuiCurvePath |
|
306 is now dll derivable **/ |
|
307 TInt iSpare; |
|
308 |
|
309 public: |
|
310 |
|
311 /* Public properties. */ |
|
312 |
|
313 /** Offset to the entire path. */ |
|
314 THuiTimedPoint iOffset; |
|
315 |
|
316 }; |
|
317 |
|
318 |
|
319 #endif |