|
1 /* |
|
2 * Copyright (c) 2007-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: Canvas visual |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef C_ALFCANVASVISUAL_H |
|
21 #define C_ALFCANVASVISUAL_H |
|
22 |
|
23 #include <alf/alfvisual.h> |
|
24 #include <alf/alftimedvalue.h> |
|
25 #include <alf/alfrealline.h> |
|
26 #include <alf/alfgc.h> |
|
27 #include <gdi.h> |
|
28 |
|
29 class CAlfControl; |
|
30 class CAlfLayout; |
|
31 class CAlfGc; |
|
32 class CAlfCanvasVisual; |
|
33 class CAlfTexture; |
|
34 class CAlfTextStyle; |
|
35 |
|
36 |
|
37 /** |
|
38 * Provides callback method for getting notifications when there is a need |
|
39 * to update the canvas content. |
|
40 * |
|
41 * Implementation of this method should do the drawing using given canvas |
|
42 * and its drawing methods. |
|
43 * |
|
44 * @param aCanvas Canvas visual which is about to be refreshed. |
|
45 */ |
|
46 class MAlfCanvasObserver |
|
47 { |
|
48 public: |
|
49 virtual void UpdateCanvas(CAlfCanvasVisual& aCanvas) = 0; |
|
50 }; |
|
51 |
|
52 /** |
|
53 * Canvas visual can be used to draw custom graphics such as images, texts, |
|
54 * lines, polygons,...into the display using simple drawing primitives. |
|
55 * |
|
56 * Usage: |
|
57 * @code |
|
58 * void CMyCanvasControl::ConstructL() |
|
59 * { |
|
60 * ... |
|
61 * iCanvasVisual = CAlfCanvasVisual::AddNewL(*this, iLayout); |
|
62 * iCanvasVisual->SetCanvasObserver(this); |
|
63 * UpdateCanvas(*iCanvasVisual); |
|
64 * ... |
|
65 * } |
|
66 * |
|
67 * void CMyCanvasControl::UpdateCanvas(CAlfCanvasVisual& aCanvas) |
|
68 * { |
|
69 * aCanvas.BeginDraw(); |
|
70 * aCanvas.SetPenColor(KRgbBlue); |
|
71 * aCanvas.DrawText(_L("Hello world !"), iTextRect); |
|
72 * aCanvas.EndDraw(); |
|
73 * } |
|
74 * |
|
75 * @endcode |
|
76 * |
|
77 * @lib alfclient.lib |
|
78 * @since S60 v5.0 |
|
79 */ |
|
80 NONSHARABLE_CLASS( CAlfCanvasVisual ) : public CAlfVisual |
|
81 { |
|
82 public: |
|
83 |
|
84 /** |
|
85 * Constructor, which gives ownership to the control. |
|
86 * |
|
87 * @param aOwnerControl The control |
|
88 * @param aParentLayout If given, the parent layout. |
|
89 * @return New instance. Ownership NOT transreffed (owned by control) |
|
90 */ |
|
91 IMPORT_C static CAlfCanvasVisual* AddNewL(CAlfControl& aOwnerControl, |
|
92 CAlfLayout* aParentLayout = 0); |
|
93 |
|
94 /** |
|
95 * Constructor. |
|
96 */ |
|
97 IMPORT_C CAlfCanvasVisual(); |
|
98 |
|
99 /** |
|
100 * Second-phase constructor. |
|
101 */ |
|
102 IMPORT_C void ConstructL(CAlfControl& aOwner); |
|
103 |
|
104 /** |
|
105 * Destructor. |
|
106 */ |
|
107 IMPORT_C virtual ~CAlfCanvasVisual(); |
|
108 |
|
109 /** |
|
110 * Sets canvas observer which is responsible for doing the actual drawing |
|
111 * commands into canvas. |
|
112 * |
|
113 * @param aObserver Canvas observer. |
|
114 */ |
|
115 IMPORT_C void SetCanvasObserver( MAlfCanvasObserver* aObserver ); |
|
116 |
|
117 /** |
|
118 * Prepares the canvas for drawing. |
|
119 * This method should be called before calling any drawing commands |
|
120 */ |
|
121 IMPORT_C void BeginDraw(); |
|
122 |
|
123 /** |
|
124 * Ends the actual drawing on the canvas. |
|
125 * This method should be called after calling last drawing method. |
|
126 * |
|
127 */ |
|
128 IMPORT_C void EndDraw(); |
|
129 |
|
130 /** |
|
131 * Draws an image on the canvas visual. For more flexible image drawing |
|
132 * consider using CAlfImageVisual. |
|
133 * |
|
134 * @param aTexture Image Texture |
|
135 * @param aDestinationRect Bounding rectangle for the image |
|
136 */ |
|
137 IMPORT_C void DrawImage(const CAlfTexture& aTexture, const TAlfRealRect& aDestinationRect); |
|
138 |
|
139 /** |
|
140 * Draws a text on the canvas visual. For more flexible text drawing |
|
141 * consider using CAlfTextVisual. |
|
142 * |
|
143 * @param aText Text to be displayed |
|
144 * @param aDestinationRect Bounding rectangle for the text |
|
145 */ |
|
146 IMPORT_C void DrawText(const TDesC& aText, const TAlfRealRect& aDestinationRect); |
|
147 |
|
148 /** |
|
149 * Draws lines on the canvas visual |
|
150 * @param aLines Array of Lines which is split into the number of lines specified in aLineCount |
|
151 * @param aLineCount Number of linesl |
|
152 */ |
|
153 IMPORT_C void DrawLines(const TAlfRealLine* aLines, TInt aLineCount); |
|
154 |
|
155 /** |
|
156 * Draws ellipse on the canvas visual |
|
157 * @param aDestinationRect Bounding rectangle for the ellipse |
|
158 */ |
|
159 IMPORT_C void DrawEllipse(const TAlfRealRect& aDestinationRect); |
|
160 |
|
161 /** |
|
162 * Draws points on the canvas visual |
|
163 * @param aPoints Array of Points to be drawn |
|
164 * @param aPointcount Number of Points |
|
165 */ |
|
166 IMPORT_C void DrawPoints(const TAlfRealPoint* aPoints, TInt aPointCount); |
|
167 |
|
168 /** |
|
169 * Draws a polygon on the canvas visual |
|
170 * @param aPoints Array of points defining the polygon |
|
171 * @param aPointcount Number of Points |
|
172 */ |
|
173 IMPORT_C void DrawPolygon(const TAlfRealPoint* aPoints, TInt aPointCount); |
|
174 |
|
175 /** |
|
176 * Draws rectangles on the canvas visual |
|
177 * @param aRects Array of rectangles to be drawn |
|
178 * @param aRectCount Number of rectangles |
|
179 */ |
|
180 IMPORT_C void DrawRects(const TAlfRealRect* aRects, TInt aRectCount); |
|
181 |
|
182 /** |
|
183 * Sets the Text style. |
|
184 * Subsequent calls to DrawText will use this Text style |
|
185 * @param aTextStyle Text style |
|
186 */ |
|
187 IMPORT_C void SetTextStyle(const CAlfTextStyle& aTextStyle); |
|
188 |
|
189 /** |
|
190 * Sets the pen color for an object to be drawn |
|
191 * Subsequent calls to Draw methods will use this pen color |
|
192 * @param |
|
193 */ |
|
194 IMPORT_C void SetPenColor(const TRgb& aColor); |
|
195 |
|
196 /** |
|
197 * Sets the pen width for an object to be drawn |
|
198 * Subsequent calls to Draw methods will use this pen width |
|
199 * @param |
|
200 */ |
|
201 IMPORT_C void SetPenWidth(const TReal32& aWidth); |
|
202 |
|
203 /** |
|
204 * Sets the opacity for an object to be drawn |
|
205 * Subsequent calls to Draw methods will use this opacity |
|
206 * @param |
|
207 */ |
|
208 IMPORT_C void SetPenOpacity(const TReal32& aOpacity); |
|
209 |
|
210 /** |
|
211 * Sets the mode for filling a polygon |
|
212 * @param aPolygonDrawMode Even-Odd fill or Non-Zero fill |
|
213 */ |
|
214 IMPORT_C void SetPolygonDrawMode(TAlfPolygonDrawMode aPolygonDrawMode); |
|
215 |
|
216 /** |
|
217 * Sets the allignment of Text to be drawn |
|
218 * Subsequent DrawText will draw text with this allignment |
|
219 * @param aAlignHorizontal horizontal allignment |
|
220 * @param aAlignVertical Vertical allignment |
|
221 */ |
|
222 IMPORT_C void SetTextAlign(TAlfAlignHorizontal aAlignHorizontal, TAlfAlignVertical aAlignVertical); |
|
223 |
|
224 /** |
|
225 * Loads identity matrix for canvas draw methods. Note that this does not |
|
226 * affect on the visuals transformation that can be accessed using |
|
227 * CAlfVisual::Transfromation(). |
|
228 */ |
|
229 IMPORT_C void LoadIdentity(); |
|
230 |
|
231 /** |
|
232 * Translates the canvas |
|
233 * @param aX X-axis offset |
|
234 * @param aY Y-axis offset |
|
235 * @param aZ Z-axis offset |
|
236 */ |
|
237 IMPORT_C void Translate(const TReal32& aX, const TReal32& aY, const TReal32& aZ); |
|
238 |
|
239 /** |
|
240 * Scales the canvas |
|
241 * @param aX X-axis offset |
|
242 * @param aY Y-axis offset |
|
243 * @param aZ Z-axis offset |
|
244 */ |
|
245 IMPORT_C void Scale(const TReal32& aX, const TReal32& aY, const TReal32& aZ); |
|
246 |
|
247 /** |
|
248 * Rotates the canvas |
|
249 * @param aX X-axis offset |
|
250 * @param aY Y-axis offset |
|
251 * @param aZ Z-axis offset |
|
252 */ |
|
253 IMPORT_C void Rotate(const TReal32& aAngle, const TReal32& aX, const TReal32& aY, const TReal32& aZ); |
|
254 |
|
255 /** |
|
256 * From CAlfVisual |
|
257 * @see CAlfVisual |
|
258 */ |
|
259 IMPORT_C void RemoveAndDestroyAllD(); |
|
260 IMPORT_C void UpdateChildrenLayout(TInt aTransitionTime = 0); |
|
261 IMPORT_C CAlfVisual* FindTag(const TDesC8& aTag); |
|
262 |
|
263 |
|
264 protected: |
|
265 |
|
266 void SendBuffer( const TPtrC8& aBuffer ); |
|
267 |
|
268 /** |
|
269 * From CAlfVisual |
|
270 * @see CAlfVisual |
|
271 */ |
|
272 IMPORT_C void DoRemoveAndDestroyAllD(); |
|
273 IMPORT_C void PropertyOwnerExtension(const TUid& aExtensionUid, TAny** aExtensionParams); |
|
274 |
|
275 |
|
276 private: |
|
277 |
|
278 struct TCanvasVisualPrivateData; |
|
279 TCanvasVisualPrivateData* iCanvasVisualData; |
|
280 }; |
|
281 |
|
282 |
|
283 #endif // C_ALFCANVASVISUAL_H |