|
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 CHuiCanvasGc |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef __HUICANVASGC_H__ |
|
21 #define __HUICANVASGC_H__ |
|
22 |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <uiacceltk/HuiVisual.h> |
|
26 #include <uiacceltk/HuiGc.h> |
|
27 #include <uiacceltk/HuiDisplay.h> |
|
28 #include <uiacceltk/HuiTexture.h> |
|
29 |
|
30 const TInt KHuiCanvasGcRegionGranularity = 10; |
|
31 |
|
32 struct THuiRealLine |
|
33 { |
|
34 THuiRealLine(){} |
|
35 THuiRealLine(const THuiRealPoint& aStart, const THuiRealPoint& aEnd):iStart(aStart),iEnd(aEnd){} |
|
36 |
|
37 THuiRealPoint iStart; |
|
38 THuiRealPoint iEnd; |
|
39 |
|
40 private: |
|
41 TInt iSpare1; |
|
42 TInt iSpare2; |
|
43 }; |
|
44 |
|
45 enum THuiCanvasClipMode |
|
46 { |
|
47 /** Clipping is disabled */ |
|
48 EHuiCanvasClipModeNone, |
|
49 |
|
50 /** Normal clipping, clipping is set immediately when clip methods are called */ |
|
51 EHuiCanvasClipModeNormal, |
|
52 |
|
53 /** Delayed clipping, clipping is actually set just before every CHuiCanvasGc draw operation and only if really needed */ |
|
54 EHuiCanvasClipModeDelayed |
|
55 }; |
|
56 |
|
57 enum THuiCanvasDrawMode |
|
58 { |
|
59 /** Drawing is done by blending */ |
|
60 EHuiCanvasDrawModeBlend, |
|
61 |
|
62 /** Drawing is done by writing alpha values directly without blending */ |
|
63 EHuiCanvasDrawModeNormal |
|
64 }; |
|
65 |
|
66 /* Forward declarations. */ |
|
67 class CHuiCanvasRenderBuffer; |
|
68 class CHuiCanvasVisual; |
|
69 class MHuiTexture; |
|
70 class CHuiTexture; |
|
71 |
|
72 class CHuiCanvasGc : public CBase |
|
73 { |
|
74 public: |
|
75 enum TClipRectVisibility |
|
76 { |
|
77 EFullyOutside, |
|
78 EFullyInside, |
|
79 EPartialOverlap, |
|
80 EUnknown |
|
81 }; |
|
82 |
|
83 /** |
|
84 * Constructor. |
|
85 */ |
|
86 IMPORT_C CHuiCanvasGc(); |
|
87 |
|
88 /** |
|
89 * Destructor. |
|
90 */ |
|
91 IMPORT_C ~CHuiCanvasGc(); |
|
92 |
|
93 /** General */ |
|
94 IMPORT_C virtual void SetGc( CHuiGc& aGc ); |
|
95 IMPORT_C virtual void SetVisual(const CHuiCanvasVisual& aVisual); |
|
96 |
|
97 /** Clipping ops */ |
|
98 IMPORT_C void SetClippingMode(THuiCanvasClipMode aClipMode); |
|
99 IMPORT_C void Clip(const TRect& aClipRect); |
|
100 IMPORT_C void ClipRegion(const TRegion& aClipRegion); |
|
101 IMPORT_C void CancelClipping(); |
|
102 |
|
103 /** Drawing ops. Although these are virtual, render specific code is typically at DoDrawXXX method overrides */ |
|
104 IMPORT_C virtual void DrawImage(const CHuiTexture& aImage, const THuiRealRect& aDestinationRect); |
|
105 IMPORT_C virtual void DrawImage(const CHuiTexture& aImage, const THuiRealRect& aDestinationRect, const THuiRealRect& aSourceRect); |
|
106 IMPORT_C virtual void DrawImage(const CHuiTexture& aImage, const THuiRealRect& aDestinationRect, const THuiRealRect& aSourceRect, CHuiGc::TStretchMode aStretchMode); |
|
107 IMPORT_C virtual void DrawImage(const CHuiCanvasRenderBuffer& aImage, const THuiRealPoint& aDestinationPoint); |
|
108 IMPORT_C virtual void DrawText(const CHuiTextMesh& aTextMesh, const THuiRealRect& aDestinationRect); |
|
109 IMPORT_C virtual void DrawLines(RArray<THuiRealLine>& aLines); |
|
110 IMPORT_C virtual void DrawEllipse(const THuiRealRect& aDestinationRect); |
|
111 IMPORT_C virtual void DrawPoints(RArray<THuiRealPoint>& aPoints); |
|
112 IMPORT_C virtual void DrawPolygon(RArray<THuiRealPoint>& aPoints); |
|
113 IMPORT_C virtual void DrawRects(RArray<THuiRealRect>& aRects); |
|
114 IMPORT_C virtual void DrawPie(const THuiRealRect& aDestinationRect, const THuiRealPoint& aStart, const THuiRealPoint& aEnd); |
|
115 IMPORT_C virtual void DrawArc(const THuiRealRect& aDestinationRect, const THuiRealPoint& aStart, const THuiRealPoint& aEnd); |
|
116 IMPORT_C virtual void DrawRoundRect(const THuiRealRect& aDestinationRect, const THuiRealSize& aSize); |
|
117 |
|
118 /** Setters */ |
|
119 IMPORT_C virtual void SetTextStyle(TInt aStyleId); |
|
120 IMPORT_C virtual void SetPenColor(const TRgb& aColor); |
|
121 IMPORT_C virtual void SetPenWidth(const TReal32& aWidth); |
|
122 IMPORT_C virtual void SetOpacity(const TReal32& aOpacity); |
|
123 IMPORT_C virtual void SetPolygonDrawMode(THuiFillMode aPolygonDrawMode); |
|
124 IMPORT_C virtual void SetPolygonFillTexture(CHuiTexture* aTexture); |
|
125 IMPORT_C virtual void SetPolygonFillTextureOrigin(const TPoint& aOrigin); |
|
126 IMPORT_C virtual void SetTextAlign(THuiAlignHorizontal aAlignHorizontal, THuiAlignVertical aAlignVertical); |
|
127 IMPORT_C virtual void SetDefaults(); |
|
128 IMPORT_C virtual void SetDrawMode(THuiCanvasDrawMode aDrawMode); |
|
129 |
|
130 /** Transformations */ |
|
131 IMPORT_C virtual void LoadIdentity(); |
|
132 IMPORT_C virtual void Translate(const TReal32& aX, const TReal32& aY, const TReal32& aZ); |
|
133 IMPORT_C virtual void Scale(const TReal32& aX, const TReal32& aY, const TReal32& aZ); |
|
134 IMPORT_C virtual void Rotate(const TReal32& aAngle, const TReal32& aX, const TReal32& aY, const TReal32& aZ); |
|
135 IMPORT_C virtual void PushTransformationMatrix(); |
|
136 IMPORT_C virtual void PopTransformationMatrix(); |
|
137 |
|
138 /** Getters */ |
|
139 IMPORT_C virtual TInt TextStyle() const; |
|
140 IMPORT_C virtual TInt TextVerticalAlign() const; |
|
141 IMPORT_C virtual TInt TextHorizontalAlign() const; |
|
142 IMPORT_C virtual TReal32 PenWidth() const; |
|
143 IMPORT_C virtual THuiFillMode PolygonDrawMode() const; |
|
144 IMPORT_C virtual CHuiTexture* PolygonFillTexture() const; |
|
145 IMPORT_C virtual TPoint PolygonFillTextureOrigin() const; |
|
146 |
|
147 /** Background drawing */ |
|
148 IMPORT_C virtual void Clear(const THuiRealRect& aRect); |
|
149 IMPORT_C virtual void ClearWithSkinBackground(const THuiRealRect& aRect); |
|
150 IMPORT_C virtual void ClearWithBackgroundItems(const THuiRealRect& aRect, const RArray<THuiDisplayBackgroundItem>& aItems); |
|
151 |
|
152 /** Render buffer handling */ |
|
153 IMPORT_C virtual CHuiCanvasRenderBuffer* CreateRenderBufferL(const TSize& aSize); |
|
154 IMPORT_C virtual void ClearRenderBuffer( CHuiCanvasRenderBuffer& aImage, const TRect & aRect ); |
|
155 |
|
156 /** Misc */ |
|
157 IMPORT_C void EnableBlendingIfNeeded(const CHuiTexture* aTexture = NULL); |
|
158 |
|
159 /** Misc getters */ |
|
160 CHuiCanvasVisual* Visual() const; |
|
161 TRgb PenColor() const; |
|
162 TReal32 Opacity() const; |
|
163 CHuiGc* Gc() const; |
|
164 THuiCanvasDrawMode DrawMode() const; |
|
165 |
|
166 /** Clipping helpers */ |
|
167 TClipRectVisibility IsClipped(const TRegion& aTestedRegion, const TRegion& aClippingRegion) const; |
|
168 |
|
169 /** Restores gc state (partially) */ |
|
170 void RestoreState() const; |
|
171 |
|
172 /** Restores gc state (uses gc state dirty flags (if renderer supports) to avoid unnecessary restore ops */ |
|
173 IMPORT_C virtual void RestoreFlaggedState() const; |
|
174 |
|
175 /** |
|
176 * Enables (or disables) effective opacity, which means that visuals effective opacity is |
|
177 * used to calculate real pen opacity. By default effective opacity is enabled. |
|
178 * */ |
|
179 void EnableEffectiveOpacity(TBool aEnable); |
|
180 |
|
181 protected: |
|
182 |
|
183 /** Misc clipping related methods */ |
|
184 IMPORT_C virtual TInt MaxNumberOfClipRects() const; |
|
185 IMPORT_C TClipRectVisibility EnableDelayedClippingIfNeeded(const THuiRealRect& aUpdatedRect); |
|
186 IMPORT_C TClipRectVisibility EnableDelayedClippingIfNeeded(const RArray<THuiRealPoint>& aUpdatedPoints); |
|
187 IMPORT_C TClipRectVisibility EnableDelayedClippingIfNeeded(const RArray<THuiRealLine>& aUpdatedLines); |
|
188 IMPORT_C TClipRectVisibility EnableDelayedClippingIfNeeded(const RArray<THuiRealRect>& aUpdatedRects); |
|
189 IMPORT_C void DisableDelayedClippingIfNeeded(); |
|
190 IMPORT_C TBool ClipNext(); |
|
191 |
|
192 /** Drawing ops steup/cleanup helpers */ |
|
193 IMPORT_C void Setup(); |
|
194 IMPORT_C void Cleanup(); |
|
195 |
|
196 /** Clipping helpers */ |
|
197 TClipRectVisibility IsClipped(const TRect& aRect) const; |
|
198 TClipRectVisibility IsClipped(const TPoint& aPoint) const; |
|
199 |
|
200 TClipRectVisibility IsClipped(const TRect& aRect, const TRegion& aClippingRegion) const; |
|
201 TClipRectVisibility IsClipped(const TPoint& aPoint, const TRegion& aClippingRegion) const; |
|
202 |
|
203 /** Drawing ops implementations, render specific code typically overrides these */ |
|
204 IMPORT_C virtual void DoDrawRects(RArray<THuiRealRect>& aRects); |
|
205 IMPORT_C virtual void DoDrawLines(RArray<THuiRealLine>& aLines); |
|
206 IMPORT_C virtual void DoDrawArc(const THuiRealRect& aDestinationRect, const THuiRealPoint& aStart, const THuiRealPoint& aEnd); |
|
207 IMPORT_C virtual void DoDrawRoundRect(const THuiRealRect& aDestinationRect, const THuiRealSize& aSize); |
|
208 IMPORT_C virtual void DoDrawPolygon(RArray<THuiRealPoint>& aPoints); |
|
209 IMPORT_C virtual void DoDrawPoints(RArray<THuiRealPoint>& aPoints); |
|
210 IMPORT_C virtual void DoDrawPie(const THuiRealRect& aDestinationRect, const THuiRealPoint& aStart, const THuiRealPoint& aEnd); |
|
211 IMPORT_C virtual void DoDrawRenderBuffer(const CHuiCanvasRenderBuffer& aImage, const THuiRealPoint& aDestinationPoint); |
|
212 IMPORT_C virtual void DoClearRenderBuffer( CHuiCanvasRenderBuffer& aImage, const TRect & aRect ); |
|
213 |
|
214 protected: |
|
215 |
|
216 /** General attributes */ |
|
217 CHuiGc* iGc; |
|
218 CHuiCanvasVisual* iVisual; |
|
219 |
|
220 /** Drawing attributes */ |
|
221 TRgb iPenColor; |
|
222 TReal32 iPenWidth; |
|
223 TReal32 iOpacity; |
|
224 THuiFillMode iPolygonDrawMode; |
|
225 THuiAlignVertical iVerticalTextAlign; |
|
226 THuiAlignHorizontal iHorizontalTextAlign; |
|
227 TInt iTextStyleId; |
|
228 THuiCanvasDrawMode iDrawMode; |
|
229 |
|
230 /** Clipping attributes */ |
|
231 RRegionBuf<KHuiCanvasGcRegionGranularity> iClippingRegion; |
|
232 THuiCanvasClipMode iClipMode; |
|
233 |
|
234 /** Delayed clipping attributes */ |
|
235 RRegionBuf<KHuiCanvasGcRegionGranularity> iDelayedClipRegion; |
|
236 TInt iDelayedClipCount; |
|
237 TBool iDelayedClipRectPushed; |
|
238 TClipRectVisibility iDelayedClipVisibility; |
|
239 |
|
240 /** Setup/cleanup attributes */ |
|
241 TRgb iOldPencolor; |
|
242 TInt iOldPenAlpha; |
|
243 |
|
244 /** Temp region */ |
|
245 mutable RRegionBuf<KHuiCanvasGcRegionGranularity> iTempRegion; |
|
246 mutable RRegionBuf<KHuiCanvasGcRegionGranularity> iTempRegion2; |
|
247 |
|
248 /** Flag to decide wheter pen alpha is to be multiplied with visual effective opacity */ |
|
249 TBool iEffectiveOpacityEnabled; |
|
250 |
|
251 /** Polygon fill texture, NOT owned */ |
|
252 CHuiTexture* iPolygonFillTexture; |
|
253 TPoint iPolygonFillTextureOrigin; |
|
254 }; |
|
255 |
|
256 #endif |
|
257 |