|
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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "uiacceltk/HuiDropShadowBrush.h" // Class definition |
|
21 #include "uiacceltk/HuiDrawing.h" |
|
22 #include "uiacceltk/HuiVisual.h" |
|
23 #include "uiacceltk/HuiUtil.h" |
|
24 |
|
25 |
|
26 /** Default shadow softness. */ |
|
27 const TReal32 KHuiDropShadowBrushSoftness = 3.f; |
|
28 |
|
29 /** Default shadow opacity. */ |
|
30 const TReal32 KHuiDropShadowBrushOpacity = 100.f/255.f; |
|
31 |
|
32 |
|
33 EXPORT_C CHuiDropShadowBrush* CHuiDropShadowBrush::NewL(const THuiMetric& aDepth) |
|
34 { |
|
35 CHuiDropShadowBrush* self = NewLC(aDepth); |
|
36 CleanupStack::Pop(); |
|
37 return self; |
|
38 } |
|
39 |
|
40 |
|
41 EXPORT_C CHuiDropShadowBrush* CHuiDropShadowBrush::NewLC(const THuiMetric& aDepth) |
|
42 { |
|
43 CHuiDropShadowBrush* self = new (ELeave) CHuiDropShadowBrush(aDepth); |
|
44 CleanupStack::PushL(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 |
|
49 EXPORT_C CHuiDropShadowBrush* CHuiDropShadowBrush::NewL(TInt aDepth) |
|
50 { |
|
51 CHuiDropShadowBrush* self = NewLC(aDepth); |
|
52 CleanupStack::Pop(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 |
|
57 EXPORT_C CHuiDropShadowBrush* CHuiDropShadowBrush::NewLC(TInt aDepth) |
|
58 { |
|
59 CHuiDropShadowBrush* self = new (ELeave) CHuiDropShadowBrush(aDepth); |
|
60 CleanupStack::PushL(self); |
|
61 return self; |
|
62 } |
|
63 |
|
64 CHuiDropShadowBrush::CHuiDropShadowBrush(const THuiMetric& aDepth) |
|
65 : CHuiBrush(), |
|
66 iSoftness(KHuiDropShadowBrushSoftness), |
|
67 iDepth(aDepth.iMagnitude), |
|
68 iDepthMetric(aDepth), |
|
69 iSoftnessMetric(KHuiDropShadowBrushSoftness), |
|
70 iColor(TRgb(0, 0, 110)) |
|
71 { |
|
72 SetClipToVisual(EFalse); |
|
73 iOpacity.Set(KHuiDropShadowBrushOpacity); |
|
74 } |
|
75 |
|
76 CHuiDropShadowBrush::CHuiDropShadowBrush(TInt aDepth) |
|
77 : CHuiBrush(), |
|
78 iSoftness(KHuiDropShadowBrushSoftness), |
|
79 iDepth(TReal32(aDepth)), |
|
80 iDepthMetric(aDepth), |
|
81 iSoftnessMetric(KHuiDropShadowBrushSoftness), |
|
82 iColor(TRgb(0, 0, 110)) |
|
83 { |
|
84 SetClipToVisual(EFalse); |
|
85 iOpacity.Set(KHuiDropShadowBrushOpacity); |
|
86 } |
|
87 |
|
88 |
|
89 CHuiDropShadowBrush::~CHuiDropShadowBrush() |
|
90 { |
|
91 } |
|
92 |
|
93 TBool CHuiDropShadowBrush::Changed() const |
|
94 { |
|
95 if ( CHuiBrush::Changed() ) |
|
96 { |
|
97 return ETrue; |
|
98 } |
|
99 return iSoftness.Changed() || iDepth.Changed(); |
|
100 } |
|
101 |
|
102 void CHuiDropShadowBrush::ClearChanged() |
|
103 { |
|
104 CHuiBrush::ClearChanged(); |
|
105 iSoftness.ClearChanged(); |
|
106 iDepth.ClearChanged(); |
|
107 } |
|
108 |
|
109 void CHuiDropShadowBrush::Draw(CHuiGc& aGc, const MHuiBrushGuide& aGuide) const |
|
110 { |
|
111 THuiRealRect realRect = aGuide.BrushRect(); |
|
112 TReal32 opacity = aGuide.BrushOpacity() * iOpacity.Now(); |
|
113 TReal32 distanceInPixels = DepthInPixels(BrushGuide()); |
|
114 TReal32 softnessInPixels = SoftnessInPixels(BrushGuide()); |
|
115 |
|
116 TReal32 borderWidth = (softnessInPixels + distanceInPixels/2.f); //distance; |
|
117 |
|
118 aGc.Push(EHuiGcMatrixModel); |
|
119 aGc.Translate(EHuiGcMatrixModel, distanceInPixels, distanceInPixels, 0.0f); |
|
120 |
|
121 borderWidth = Min( borderWidth, realRect.Width()/2.f ); |
|
122 borderWidth = Min( borderWidth, realRect.Height()/2.f ); |
|
123 |
|
124 aGc.SetPenColor(iColor); |
|
125 aGc.SetPenAlpha(TInt(opacity * 255)); |
|
126 |
|
127 const CHuiTexture* shadowTexture = NULL; |
|
128 TInt err = aGuide.BrushSkin().GetTexture(EHuiSkinShadowTexture, shadowTexture); |
|
129 if (err!=KErrNone) |
|
130 { |
|
131 ASSERT(EFalse); // failed to get the shadow texture - unable to proceed! |
|
132 return; |
|
133 } |
|
134 THuiImage dropShadowImage(*shadowTexture); |
|
135 |
|
136 aGc.Disable(CHuiGc::EFeatureDepthWrite); |
|
137 |
|
138 TRect roundedRect = realRect.Round(); |
|
139 // draw drop shadow borders |
|
140 aGc.DrawBorders(roundedRect, borderWidth, borderWidth, borderWidth, borderWidth, |
|
141 CHuiGc::EBorderImage, &dropShadowImage); |
|
142 |
|
143 aGc.Disable(CHuiGc::EFeatureTexturing); |
|
144 roundedRect.Shrink( HUI_ROUND_FLOAT_TO_INT(borderWidth), HUI_ROUND_FLOAT_TO_INT(borderWidth)); |
|
145 aGc.DrawRect(roundedRect); |
|
146 aGc.Enable(CHuiGc::EFeatureDepthWrite); |
|
147 |
|
148 aGc.Pop(EHuiGcMatrixModel); |
|
149 } |
|
150 |
|
151 |
|
152 void CHuiDropShadowBrush::ExpandVisualRect(TRect& aRect) const |
|
153 { |
|
154 TReal32 depthInPixels = DepthInPixels(BrushGuide()); |
|
155 |
|
156 if ( depthInPixels > 0 ) |
|
157 { |
|
158 // Currently support only drop shadow on the bottom right of the visual |
|
159 aRect.iBr.iX += HUI_ROUND_FLOAT_TO_INT( depthInPixels ); |
|
160 aRect.iBr.iY += HUI_ROUND_FLOAT_TO_INT( depthInPixels ); |
|
161 } |
|
162 } |
|
163 |
|
164 EXPORT_C void CHuiDropShadowBrush::SetDepth(const THuiMetric& aDepth) |
|
165 { |
|
166 iDepthMetric = aDepth; |
|
167 iDepth.Set(aDepth.iMagnitude); |
|
168 } |
|
169 |
|
170 EXPORT_C void CHuiDropShadowBrush::SetSoftness(const THuiMetric& aSoftness) |
|
171 { |
|
172 iSoftnessMetric = aSoftness; |
|
173 iSoftness.Set(aSoftness.iMagnitude); |
|
174 } |
|
175 |
|
176 EXPORT_C void CHuiDropShadowBrush::SetColor(const TRgb& aColor) |
|
177 { |
|
178 iColor = aColor; |
|
179 } |
|
180 |
|
181 TReal32 CHuiDropShadowBrush::DepthInPixels(const CHuiVisual* aVisual) const |
|
182 { |
|
183 return ValueInPixels(aVisual, iDepth); |
|
184 } |
|
185 |
|
186 TReal32 CHuiDropShadowBrush::SoftnessInPixels(const CHuiVisual* aVisual) const |
|
187 { |
|
188 return ValueInPixels(aVisual, iSoftness); |
|
189 } |
|
190 |
|
191 TReal32 CHuiDropShadowBrush::ValueInPixels(const CHuiVisual* aVisual, const THuiTimedValue& aValue) const |
|
192 { |
|
193 TReal32 valueInPixels = aValue.Now(); // Default to old pixel width |
|
194 if (aVisual) |
|
195 { |
|
196 THuiMetric metric = iDepthMetric; |
|
197 metric.iMagnitude = valueInPixels; |
|
198 valueInPixels = aVisual->MetricToPixels(THuiXYMetric(metric, metric)).iX; // Calculate metric width in pixels |
|
199 } |
|
200 return valueInPixels; |
|
201 } |
|
202 |