|
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 of CHuiTextMesh. CHuiTextMesh stores a cached |
|
15 * version of a text string. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef __HUITEXTMESH_H__ |
|
22 #define __HUITEXTMESH_H__ |
|
23 |
|
24 |
|
25 #include <e32base.h> |
|
26 #include <AknFontSpecification.h> |
|
27 |
|
28 #include <uiacceltk/HuiRealPoint.h> |
|
29 #include <uiacceltk/HuiImage.h> |
|
30 #include <uiacceltk/HuiFont.h> |
|
31 #include <uiacceltk/huitextstyle.h> |
|
32 #include <uiacceltk/HuiDisplay.h> |
|
33 #include <uiacceltk/HuiEnv.h> |
|
34 |
|
35 |
|
36 /* Forward declarations. */ |
|
37 class CHuiGc; |
|
38 class CHuiTexture; |
|
39 class CAknPictographInterface; |
|
40 |
|
41 /** |
|
42 * CHuiTextMesh the abstract base class for text meshes. Text meshes store one or more |
|
43 * lines of text in a format suitable for rendering using a low-level graphics API. |
|
44 * The rendering plugin is responsible for choosing the appropriate concrete text |
|
45 * mesh implementation when a new text mesh needs to be created. |
|
46 */ |
|
47 NONSHARABLE_CLASS(CHuiTextMesh) : public CBase, |
|
48 public MHuiDisplayVisibleAreaObserver, |
|
49 public MHuiDisplayDeletionObserver, |
|
50 public MHuiActionObserver |
|
51 { |
|
52 public: |
|
53 |
|
54 /* Types. */ |
|
55 |
|
56 /** Line wrapping and truncation modes. */ |
|
57 enum TLineMode |
|
58 { |
|
59 /** Lines are truncated if they don't fit into the maximum line width. |
|
60 Line breaks must be explicitly defined with line break characters. */ |
|
61 ELineModeTruncate, |
|
62 |
|
63 /** Automatic line wrapping. Text is wrapped onto multiple lines if it doesn't |
|
64 fit into the maximum line width. If there are more lines than |
|
65 allowed by the maximum line count, the extra lines are truncated. |
|
66 Line break characters will also cause line breaks. */ |
|
67 ELineModeWrap |
|
68 }; |
|
69 |
|
70 |
|
71 /* Constructors and destructors. */ |
|
72 |
|
73 /** |
|
74 * Destructor. |
|
75 */ |
|
76 virtual ~CHuiTextMesh(); |
|
77 |
|
78 |
|
79 /* Methods. */ |
|
80 |
|
81 /** |
|
82 * Resets the contents of the text mesh. |
|
83 */ |
|
84 virtual void Reset(); |
|
85 |
|
86 |
|
87 /** |
|
88 * Deletes textures for all rasterized lines. |
|
89 * Derived class should supply an implementation. |
|
90 */ |
|
91 virtual void ResetLines() {} |
|
92 |
|
93 |
|
94 /** |
|
95 * Deletes textures for all rasterized pictograph lines. |
|
96 * Derived class should supply an implementation. |
|
97 */ |
|
98 virtual void ResetPictographLines() {} |
|
99 |
|
100 |
|
101 void SetLineMode(TLineMode aLineMode); |
|
102 |
|
103 TLineMode LineMode() const; |
|
104 |
|
105 /** |
|
106 * Sets the maximum line width, in pixels. Does not rebuild the |
|
107 * mesh. |
|
108 * |
|
109 * @param aMaxLineWidth Maximum line width. |
|
110 * |
|
111 * @return ETrue, if the new width is different than the previous. |
|
112 * The mesh should be rebuilt in that case. |
|
113 */ |
|
114 TBool SetMaxLineWidth(TInt aMaxLineWidth); |
|
115 |
|
116 /** |
|
117 * Returns the maximum line width. |
|
118 */ |
|
119 TInt MaxLineWidth() const; |
|
120 |
|
121 /** |
|
122 * Sets the maximum line count. Does not rebuild the mesh. |
|
123 * |
|
124 * @param aMaxLineCount Maximum line count. |
|
125 * |
|
126 * @return ETrue, if the new count is different than the previous. |
|
127 * The mesh should be rebuilt in that case. |
|
128 */ |
|
129 TBool SetMaxLineCount(TInt aMaxLineCount); |
|
130 |
|
131 /** |
|
132 * Returns the maximum line count. |
|
133 */ |
|
134 TInt MaxLineCount() const; |
|
135 |
|
136 /** |
|
137 * Selects the default font used by the text mesh. |
|
138 * |
|
139 * @param aFont Font texture. |
|
140 */ |
|
141 void SetFontL(const THuiFont& aFont, TBool aRefreshTextures); |
|
142 |
|
143 /** |
|
144 * Prepares the text mesh with a string of text. |
|
145 * |
|
146 * @param aText One or more strings of text. |
|
147 * @param aRasterize EFalse when the extents need to be recalculated, |
|
148 * but the text doesn't need to be re-rendered. |
|
149 * |
|
150 * @todo Support formatting escape sequences. |
|
151 */ |
|
152 void SetTextL(const TDesC& aText, TBool aRasterize); |
|
153 |
|
154 /** |
|
155 * Returns the text string of the mesh. |
|
156 * |
|
157 * @return Pointer to descriptor, or <code>NULL</code>. |
|
158 */ |
|
159 const TDesC* Text() const; |
|
160 |
|
161 /** |
|
162 * Sets the distance of the sharp shadow. The sharp shadow is a |
|
163 * black version of the text drawn with an offset. |
|
164 */ |
|
165 void EnableRasterizedShadow(const TBool aIsEnabled); |
|
166 |
|
167 /** |
|
168 * Determines if the rasterized shadow is enabled. |
|
169 */ |
|
170 TBool RasterizedShadow() const; |
|
171 |
|
172 /** |
|
173 * Returns the extents of the text. |
|
174 */ |
|
175 TSize Extents() const; |
|
176 |
|
177 /** |
|
178 * Draws the text mesh. |
|
179 * |
|
180 * @param aGc Graphics context. |
|
181 * @param aShadowTexture Texture to use for rendering shadows. |
|
182 * @param aShadowOpacity Opacity of shadows. |
|
183 */ |
|
184 virtual void Draw(CHuiGc& aGc, TReal32 aShadowOpacity = 0.f) const __SOFTFP = 0; |
|
185 |
|
186 /** |
|
187 * Sets the text style of the text mesh. This style describes the style |
|
188 * the text is rendered with. The text style has to be created with the text style |
|
189 * manager. If the given text style does not exist, the text style is reverted back |
|
190 * to default text style. |
|
191 * @see CHuiTextStyleManager::CreateTextStyleL |
|
192 * |
|
193 * @param aTextStyleId Text style ID provided by the text style manager. |
|
194 */ |
|
195 void SetTextStyle(TInt aTextStyleId); |
|
196 |
|
197 /** |
|
198 * Retrieves the text style of the text mesh. This style describes the style |
|
199 * the text is rendered with. |
|
200 * @see CHuiTextStyleManager::SetTextStyle |
|
201 * |
|
202 * @param Text style ID provided by the text style manager. |
|
203 */ |
|
204 TInt TextStyle() const; |
|
205 |
|
206 /** |
|
207 * Initializes the pictograph support. |
|
208 * |
|
209 * @param aInterface Interface that can be used for drawing pictographs. |
|
210 */ |
|
211 virtual void InitPictographsL(CAknPictographInterface* aInterface); |
|
212 |
|
213 /** |
|
214 * Updates the mesh pictographs. |
|
215 */ |
|
216 virtual void BuildPictographsL(); |
|
217 |
|
218 /** |
|
219 * Sets the line spacing for multiline text visual when the text wraps around. |
|
220 * |
|
221 * @param aLineSpacing Line spacing between lines in multiline text visual. |
|
222 */ |
|
223 void SetLineSpacing(TInt aLineSpacingInPixels); |
|
224 |
|
225 |
|
226 /** |
|
227 * Calculate scale factors from LCD resolution to TvOut resolution |
|
228 */ |
|
229 void CalculateTvOutScales(); |
|
230 |
|
231 /** |
|
232 * Sets the realted visual |
|
233 * |
|
234 * @param aVisual which owns this text mesh |
|
235 */ |
|
236 void SetRelatedVisual(CHuiVisual* aVisual); |
|
237 |
|
238 /* From MHuiDisplayVisibleAreaObserver */ |
|
239 /** |
|
240 * Display size observer. Is notified when the display is resized. |
|
241 * |
|
242 * @param aDisplay Display that sends the notification. |
|
243 */ |
|
244 void NotifyDisplayVisibleAreaChanged(CHuiDisplay& aDisplay); |
|
245 |
|
246 /* From MHuiDisplayDeletionObserver */ |
|
247 /** |
|
248 * Display deletion observer. Is notified when the display is about to be |
|
249 * destroyed. |
|
250 * |
|
251 * @param aDisplay Display that sends the notification. |
|
252 */ |
|
253 void NotifyDisplayDeletion(CHuiDisplay& aDisplay); |
|
254 |
|
255 /* From MHuiActionObserver */ |
|
256 /** |
|
257 * Called by the scheduler when an action command is executed. |
|
258 * |
|
259 * @param aActionCommand The command that is being executed. |
|
260 * TextVisual is interested in |
|
261 * KHuiActionNewTVOutDisplay command. |
|
262 */ |
|
263 void HandleActionL(const THuiActionCommand& aActionCommand); |
|
264 |
|
265 |
|
266 protected: |
|
267 |
|
268 /* Constructors. */ |
|
269 |
|
270 /** |
|
271 * Default constructor. |
|
272 */ |
|
273 CHuiTextMesh(); |
|
274 |
|
275 /** |
|
276 * 2nd phase constructor. |
|
277 */ |
|
278 void ConstructL(); |
|
279 |
|
280 /* Methods. */ |
|
281 |
|
282 /** |
|
283 * Changes the extents of the text mesh. |
|
284 * |
|
285 * @param aExtents Width and height of the text mesh. |
|
286 */ |
|
287 void SetExtents(const TSize& aExtents); |
|
288 |
|
289 /** |
|
290 * Updates the mesh and the extents. Both text and font must be set |
|
291 * when this is called. |
|
292 * |
|
293 * @param aRasterize Set this to ETrue if text is to be rendered. Set to |
|
294 * EFalse if you only need to calculate text extents. |
|
295 */ |
|
296 virtual void BuildL(TBool aRasterize) = 0; |
|
297 |
|
298 /** |
|
299 * Releases the font associated with this text mesh'es text style. |
|
300 */ |
|
301 void ReleaseFont(); |
|
302 |
|
303 public: |
|
304 |
|
305 /** |
|
306 * Expands the given content rect with shadow. |
|
307 * |
|
308 * @param aRect Content rect to be modified. |
|
309 */ |
|
310 virtual void ExpandRectWithShadow(TRect& aRect) const; |
|
311 |
|
312 /** Internal utility for prerasterized mesh */ |
|
313 virtual void UpdateMeshL(const TDesC8& aBuffer); |
|
314 |
|
315 |
|
316 protected: |
|
317 |
|
318 /** Current text style ID */ |
|
319 TInt iTextStyleId; |
|
320 |
|
321 /** Interface for drawing pictographs, NOT owned */ |
|
322 CAknPictographInterface* iPictographInterface; |
|
323 |
|
324 /** The line spacing for multiline text visual when the text wraps around. */ |
|
325 TInt iLineSpacing; |
|
326 |
|
327 /** Scale factor from LCD resolution to TvOut resolution */ |
|
328 TReal32 iTextMeshScale; |
|
329 |
|
330 // Related text visual |
|
331 CHuiVisual* iVisual; |
|
332 |
|
333 private: |
|
334 |
|
335 /** Line wrapping and truncation mode. */ |
|
336 TLineMode iLineMode; |
|
337 |
|
338 /** Maximum line width. */ |
|
339 TInt iMaxLineWidth; |
|
340 |
|
341 /** TvOut scaled maximum line width. Calculated using scale factors |
|
342 * from LCD resolution to TvOut resolution */ |
|
343 TInt iScaledMaxLineWidth; |
|
344 |
|
345 /** Maximum line count. */ |
|
346 TInt iMaxLineCount; |
|
347 |
|
348 /** Current text string. */ |
|
349 HBufC* iString; |
|
350 |
|
351 /** Extents of the text string using the current font. */ |
|
352 TSize iExtents; |
|
353 |
|
354 /** TvOut scaled extents of the text string using the current font. */ |
|
355 TSize iScaledExtents; |
|
356 |
|
357 /** Are rasterized shadows being used. */ |
|
358 TBool iRasterizedShadow; |
|
359 }; |
|
360 |
|
361 |
|
362 #endif // __HUITEXTMESH_H__ |