|
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: Implementation of CHuiBorderBrush class - a brush that draws |
|
15 * a border at the edges of visuals. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include "uiacceltk/HuiBorderBrush.h" // Class definition |
|
22 #include "uiacceltk/HuiDrawing.h" |
|
23 #include "uiacceltk/HuiVisual.h" |
|
24 |
|
25 |
|
26 EXPORT_C CHuiBorderBrush* CHuiBorderBrush::NewL( |
|
27 TInt aThicknessWidth, TInt aThicknessHeight, |
|
28 TInt aEdgeOffsetX, TInt aEdgeOffsetY) |
|
29 { |
|
30 CHuiBorderBrush* self = NewLC(aThicknessWidth, aThicknessHeight, |
|
31 aEdgeOffsetX, aEdgeOffsetY); |
|
32 CleanupStack::Pop(); |
|
33 return self; |
|
34 } |
|
35 |
|
36 |
|
37 EXPORT_C CHuiBorderBrush* CHuiBorderBrush::NewLC( |
|
38 TInt aThicknessWidth, TInt aThicknessHeight, |
|
39 TInt aEdgeOffsetX, TInt aEdgeOffsetY) |
|
40 { |
|
41 CHuiBorderBrush* self = new (ELeave) |
|
42 CHuiBorderBrush(aThicknessWidth, aThicknessHeight, |
|
43 aEdgeOffsetX, aEdgeOffsetY); |
|
44 CleanupStack::PushL(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 |
|
49 CHuiBorderBrush::CHuiBorderBrush(TInt aThicknessWidth, TInt aThicknessHeight, |
|
50 TInt aEdgeOffsetX, TInt aEdgeOffsetY) |
|
51 : CHuiBrush(), |
|
52 iColor(KRgbWhite), |
|
53 iThickness( TReal32(aThicknessWidth), TReal32(aThicknessHeight)), |
|
54 iEdgeOffset( TReal32(aEdgeOffsetX), TReal32(aEdgeOffsetY)) |
|
55 { |
|
56 SetClipToVisual(EFalse); |
|
57 } |
|
58 |
|
59 EXPORT_C CHuiBorderBrush* CHuiBorderBrush::NewL(const THuiXYMetric& aThickness, |
|
60 const THuiXYMetric& aEdgeOffset) |
|
61 { |
|
62 CHuiBorderBrush* self = NewLC(aThickness, aEdgeOffset); |
|
63 CleanupStack::Pop(); |
|
64 return self; |
|
65 } |
|
66 |
|
67 |
|
68 EXPORT_C CHuiBorderBrush* CHuiBorderBrush::NewLC(const THuiXYMetric& aThickness, |
|
69 const THuiXYMetric& aEdgeOffset) |
|
70 { |
|
71 CHuiBorderBrush* self = new (ELeave) |
|
72 CHuiBorderBrush(aThickness, aEdgeOffset); |
|
73 CleanupStack::PushL(self); |
|
74 return self; |
|
75 } |
|
76 |
|
77 |
|
78 CHuiBorderBrush::CHuiBorderBrush(const THuiXYMetric& aThickness, |
|
79 const THuiXYMetric& aEdgeOffset) |
|
80 : CHuiBrush(), |
|
81 iColor(KRgbWhite), |
|
82 iThickness(aThickness.iX.iMagnitude, aThickness.iY.iMagnitude), |
|
83 iEdgeOffset(aEdgeOffset.iX.iMagnitude, aEdgeOffset.iY.iMagnitude), |
|
84 iThicknessMetric(aThickness), |
|
85 iEdgeOffsetMetric(aEdgeOffset) |
|
86 { |
|
87 SetClipToVisual(EFalse); |
|
88 } |
|
89 |
|
90 |
|
91 CHuiBorderBrush::~CHuiBorderBrush() |
|
92 { |
|
93 } |
|
94 |
|
95 |
|
96 EXPORT_C void CHuiBorderBrush::SetImage(const THuiImage& aImage) |
|
97 { |
|
98 iImage = aImage; |
|
99 SetChanged(); |
|
100 } |
|
101 |
|
102 |
|
103 EXPORT_C void CHuiBorderBrush::SetColor(const TRgb& aColor) |
|
104 { |
|
105 iColor = aColor; |
|
106 SetChanged(); |
|
107 } |
|
108 |
|
109 EXPORT_C void CHuiBorderBrush::SetThickness(const THuiXYMetric& aThickness) |
|
110 { |
|
111 iThicknessMetric = aThickness; |
|
112 iThickness.iX.Set(aThickness.iX.iMagnitude); |
|
113 iThickness.iY.Set(aThickness.iY.iMagnitude); |
|
114 } |
|
115 |
|
116 EXPORT_C void CHuiBorderBrush::SetEdgeOffset(const THuiXYMetric& aEdgeOffset) |
|
117 { |
|
118 iEdgeOffsetMetric = aEdgeOffset; |
|
119 iEdgeOffset.iX.Set(aEdgeOffset.iX.iMagnitude); |
|
120 iEdgeOffset.iY.Set(aEdgeOffset.iY.iMagnitude); |
|
121 } |
|
122 |
|
123 EXPORT_C void CHuiBorderBrush::SetImageOffset(const THuiXYMetric& aImageOffset) |
|
124 { |
|
125 iImageOffsetMetric = aImageOffset; |
|
126 iImageOffset.iX.Set(aImageOffset.iX.iMagnitude); |
|
127 iImageOffset.iY.Set(aImageOffset.iY.iMagnitude); |
|
128 } |
|
129 |
|
130 |
|
131 TBool CHuiBorderBrush::Changed() const |
|
132 { |
|
133 if ( CHuiBrush::Changed() ) |
|
134 { |
|
135 return ETrue; |
|
136 } |
|
137 return iThickness.Changed() || iEdgeOffset.Changed() || iImageOffset.Changed() || iImage.Changed(); |
|
138 } |
|
139 |
|
140 void CHuiBorderBrush::ClearChanged() |
|
141 { |
|
142 CHuiBrush::ClearChanged(); |
|
143 iThickness.ClearChanged(); |
|
144 iEdgeOffset.ClearChanged(); |
|
145 iImageOffset.ClearChanged(); |
|
146 iImage.ClearChanged(); |
|
147 } |
|
148 |
|
149 void CHuiBorderBrush::ExpandVisualRect(TRect& aRect) const |
|
150 { |
|
151 // We need access to visual to convert metric units into pixels, |
|
152 // currently a pointer to visual is provided through separate |
|
153 // method since we want to avoid breaking binary compatibility |
|
154 // of this class. |
|
155 THuiRealPoint edgeOffsetInPixels = EdgeOffsetInPixels(BrushGuide()); |
|
156 aRect.Grow((TInt)edgeOffsetInPixels.iX, |
|
157 (TInt)edgeOffsetInPixels.iY); |
|
158 } |
|
159 |
|
160 |
|
161 void CHuiBorderBrush::Draw(CHuiGc& aGc, const MHuiBrushGuide& aGuide) const |
|
162 { |
|
163 THuiRealRect content = aGuide.BrushRect(); |
|
164 TReal32 opacity = aGuide.BrushOpacity() * iOpacity.Now(); |
|
165 |
|
166 THuiRealPoint edgeOffsetInPixels = EdgeOffsetInPixels(BrushGuide()); |
|
167 THuiRealPoint thicknessInPixels = ThicknessInPixels(BrushGuide()); |
|
168 THuiRealPoint imageOffsetInPixels = ImageOffsetInPixels(BrushGuide()); |
|
169 |
|
170 aGc.SetPenColor(iColor); |
|
171 aGc.SetPenAlpha(TInt(opacity * 255)); |
|
172 |
|
173 if(iImage.HasTexture()) |
|
174 { |
|
175 aGc.Enable(CHuiGc::EFeatureTexturing); |
|
176 iImage.Texture().Bind(); |
|
177 } |
|
178 else |
|
179 { |
|
180 aGc.Disable(CHuiGc::EFeatureTexturing); |
|
181 } |
|
182 aGc.Enable(CHuiGc::EFeatureBlending); |
|
183 |
|
184 // Apply the texture offset manually. |
|
185 aGc.Push(EHuiGcMatrixTexture); |
|
186 aGc.LoadIdentity(EHuiGcMatrixTexture); |
|
187 aGc.Translate(EHuiGcMatrixTexture, |
|
188 -imageOffsetInPixels.iX, -imageOffsetInPixels.iY, 0.f); |
|
189 |
|
190 content.Grow(edgeOffsetInPixels.iX, edgeOffsetInPixels.iY); |
|
191 |
|
192 aGc.DrawBorders(content.Round(), |
|
193 thicknessInPixels.iX, thicknessInPixels.iX, |
|
194 thicknessInPixels.iY, thicknessInPixels.iY, |
|
195 CHuiGc::EBorderFixedCorners, |
|
196 &iImage); |
|
197 |
|
198 aGc.Pop(EHuiGcMatrixTexture); |
|
199 } |
|
200 |
|
201 THuiRealPoint CHuiBorderBrush::ThicknessInPixels(const CHuiVisual* aVisual) const |
|
202 { |
|
203 return PointInPixels(aVisual, iThickness, iThicknessMetric); |
|
204 } |
|
205 |
|
206 THuiRealPoint CHuiBorderBrush::EdgeOffsetInPixels(const CHuiVisual* aVisual) const |
|
207 { |
|
208 return PointInPixels(aVisual, iEdgeOffset, iEdgeOffsetMetric); |
|
209 } |
|
210 |
|
211 THuiRealPoint CHuiBorderBrush::ImageOffsetInPixels(const CHuiVisual* aVisual) const |
|
212 { |
|
213 return PointInPixels(aVisual, iImageOffset, iImageOffsetMetric); |
|
214 } |
|
215 |
|
216 THuiRealPoint CHuiBorderBrush::PointInPixels(const CHuiVisual* aVisual, const THuiTimedPoint& aPoint, const THuiXYMetric& aMetric) const |
|
217 { |
|
218 THuiRealPoint pointInPixels = aPoint.RealNow(); // Init, if no visual available for conversion then defaults to pixels |
|
219 if (aVisual) |
|
220 { |
|
221 THuiXYMetric metric = aMetric; |
|
222 metric.iX.iMagnitude = pointInPixels.iX; |
|
223 metric.iY.iMagnitude = pointInPixels.iY; |
|
224 pointInPixels = aVisual->MetricToPixels(metric); // Convert metric width in pixels |
|
225 } |
|
226 return pointInPixels; |
|
227 } |