|
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: Defines CHuiLinearGradientBrush - a Brush that is able to |
|
15 * draw linear color gradients. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef __HUIGRADIENTBRUSH_H__ |
|
22 #define __HUIGRADIENTBRUSH_H__ |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <uiacceltk/HuiBrush.h> |
|
26 #include <uiacceltk/HuiSkin.h> |
|
27 #include <uiacceltk/HuiGc.h> |
|
28 #include <uiacceltk/HuiImage.h> |
|
29 |
|
30 |
|
31 /** |
|
32 * Linear gradient brush. Draws a sequence of colors in a linear gradient. |
|
33 */ |
|
34 NONSHARABLE_CLASS(CHuiGradientBrush) : public CHuiBrush |
|
35 { |
|
36 public: |
|
37 |
|
38 /** Linear gradient directions. */ |
|
39 enum TDirection |
|
40 { |
|
41 EDirectionUp, |
|
42 EDirectionRight, |
|
43 EDirectionDown, |
|
44 EDirectionLeft |
|
45 }; |
|
46 |
|
47 /* Constructors and destructor. */ |
|
48 |
|
49 /** |
|
50 * Constructor. |
|
51 */ |
|
52 IMPORT_C static CHuiGradientBrush* NewL(); |
|
53 |
|
54 /** |
|
55 * Constructor. The new brush is left on the cleanup stack. |
|
56 */ |
|
57 IMPORT_C static CHuiGradientBrush* NewLC(); |
|
58 |
|
59 /** |
|
60 * Destructor. |
|
61 */ |
|
62 ~CHuiGradientBrush(); |
|
63 |
|
64 |
|
65 /* Methods. */ |
|
66 |
|
67 /** |
|
68 * Sets the gradient direction. |
|
69 */ |
|
70 IMPORT_C void SetDirection(TDirection aDirection); |
|
71 |
|
72 /** |
|
73 * Replaces all colors with a single color. |
|
74 * |
|
75 * @param aColor Solid color for the gradient. |
|
76 * @param aOpacity Opacity. |
|
77 */ |
|
78 IMPORT_C virtual void SetColor(const TRgb& aColor, TReal32 aOpacity = 1.0) __SOFTFP; |
|
79 |
|
80 /** |
|
81 * Sets the image for the gradient. By default, no image is used. The image |
|
82 * can be cleared with <code>SetImage(THuiImage())</code>. |
|
83 * |
|
84 * @param aImage Image to use in the gradient. |
|
85 */ |
|
86 IMPORT_C virtual void SetImage(const THuiImage& aImage); |
|
87 |
|
88 /** |
|
89 * Returns a color from the gradient. |
|
90 */ |
|
91 IMPORT_C virtual TRgb Color(TInt aIndex) const; |
|
92 |
|
93 /** |
|
94 * Returns an opacity value from the gradient. |
|
95 */ |
|
96 IMPORT_C virtual TReal32 Opacity(TInt aIndex) const __SOFTFP; |
|
97 |
|
98 /** |
|
99 * Returns the image of the gradient brush. |
|
100 */ |
|
101 IMPORT_C virtual const THuiImage& Image() const; |
|
102 |
|
103 /** |
|
104 * Appends a new color for the entire gradient. The caller must |
|
105 * append colors in the correct order, by ascending position. |
|
106 * |
|
107 * @param aPosition Position of the color. |
|
108 * @param aColor Color at the position. |
|
109 * @param aOpacity Opacity at the position. |
|
110 */ |
|
111 IMPORT_C virtual void AppendColorL(TReal32 aPosition, const TRgb& aColor, |
|
112 TReal32 aOpacity = 1.0) __SOFTFP; |
|
113 |
|
114 /** |
|
115 * Draw the brush. |
|
116 */ |
|
117 virtual void Draw(CHuiGc& aGc, const MHuiBrushGuide& aGuide) const; |
|
118 |
|
119 |
|
120 protected: |
|
121 |
|
122 /* Constructors. */ |
|
123 |
|
124 /** |
|
125 * Constructor. |
|
126 */ |
|
127 CHuiGradientBrush(); |
|
128 |
|
129 /** |
|
130 * Second-phase constructor. |
|
131 */ |
|
132 void ConstructL(); |
|
133 |
|
134 |
|
135 private: |
|
136 |
|
137 /* Private data */ |
|
138 |
|
139 /** One color in the gradient. */ |
|
140 struct SColor |
|
141 { |
|
142 /** Position in the range 0..1. */ |
|
143 TReal32 iPosition; |
|
144 |
|
145 /** RGB color. */ |
|
146 TRgb iColor; |
|
147 |
|
148 /** Opacity. */ |
|
149 TReal32 iOpacity; |
|
150 }; |
|
151 |
|
152 |
|
153 private: |
|
154 |
|
155 /* Private methods */ |
|
156 |
|
157 |
|
158 private: |
|
159 |
|
160 /** Direction of a linear gradient. */ |
|
161 TDirection iDirection; |
|
162 |
|
163 /** Array of gradient colors. */ |
|
164 RArray<SColor> iColors; |
|
165 |
|
166 /** Image for the gradient. */ |
|
167 THuiImage iImage; |
|
168 |
|
169 }; |
|
170 |
|
171 #endif // __HUIGRADIENTBRUSH_H__ |