|
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Test Animated DLL |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <w32std.h> |
|
20 #include <w32adll.h> |
|
21 #include <bitstd.h> |
|
22 #include "ANIMDLL.H" |
|
23 |
|
24 #define ANIM_TEST_TEXT _L("Testing 123") |
|
25 |
|
26 class CTestAnim : public CWindowAnim |
|
27 { |
|
28 enum {ENumPolyPoints=9}; |
|
29 public: |
|
30 ~CTestAnim(); |
|
31 virtual void ConstructL(TAny *aArgs, TBool aHasFocus); |
|
32 virtual void Animate(TDateTime *aDateTime); |
|
33 virtual void Redraw(); |
|
34 virtual void Command(TInt aOpcode, TAny *aArgs); |
|
35 virtual TInt CommandReplyL(TInt aOpcode, TAny *aArgs); |
|
36 void SetPolyList(const TRect &aRect); |
|
37 void DrawPolyLine(); |
|
38 void DrawBitmap(); |
|
39 void DrawText(); |
|
40 void TweakPolyList(TInt aState); |
|
41 void FocusChanged(TBool aState); |
|
42 void InvalidateText(); |
|
43 void InvalidateBitmap(); |
|
44 //Pure virtual function from MEventHandler |
|
45 virtual TBool OfferRawEvent(const TRawEvent &aRawEvent); |
|
46 private: |
|
47 void AppendTime(TDes& aTimeText,const TTime& aTime) const; |
|
48 private: |
|
49 TPoint iPos; |
|
50 TSize iSize; |
|
51 TInt iColor; |
|
52 TBool iMasked; |
|
53 TRect iPolyRect; |
|
54 TInt iPolyState; |
|
55 TInt iWiggleSize; |
|
56 TPoint iTextPos; |
|
57 TBool iHasFocus; |
|
58 CArrayFixFlat<TPoint> *iPolyList; |
|
59 CFbsBitmap iBitmap1; |
|
60 CFbsBitmap iBitmap2; |
|
61 CFbsBitmap iMask; |
|
62 CFbsFont *iFont; |
|
63 }; |
|
64 |
|
65 class CTestAnimDll : public CAnimDll |
|
66 { |
|
67 public: |
|
68 CAnim *CreateInstanceL(TInt aType); |
|
69 private: |
|
70 }; |
|
71 |
|
72 /*#if defined(__WINS__) |
|
73 #pragma data_seg(".E32_UID") |
|
74 __WINS_UID(0, KWservAnimDllUidValue, 0) |
|
75 #pragma data_seg() |
|
76 #endif*/ |
|
77 |
|
78 EXPORT_C CAnimDll *CreateCAnimDllL() |
|
79 { |
|
80 return(new(ELeave) CTestAnimDll()); |
|
81 } |
|
82 |
|
83 // Instance code // |
|
84 |
|
85 void CTestAnim::Animate(TDateTime *) |
|
86 { |
|
87 if (!iWindowFunctions->IsHidden()) |
|
88 { |
|
89 iWindowFunctions->ActivateGc(); |
|
90 if (iPolyList) |
|
91 DrawPolyLine(); |
|
92 } |
|
93 if (iPolyList) |
|
94 { |
|
95 iPolyState=(iPolyState+1)%4; |
|
96 TweakPolyList(iPolyState); |
|
97 } |
|
98 if (!iWindowFunctions->IsHidden()) |
|
99 { |
|
100 if (iPolyList) |
|
101 DrawPolyLine(); |
|
102 DrawText(); |
|
103 DrawBitmap(); |
|
104 } |
|
105 iColor=(iColor+16)&0xFF; |
|
106 } |
|
107 |
|
108 void CTestAnim::DrawPolyLine() |
|
109 { |
|
110 iGc->SetDrawMode(CGraphicsContext::EDrawModeXOR); |
|
111 iGc->SetPenColor(TRgb(255,255,255)); |
|
112 iGc->DrawPolyLine(iPolyList); |
|
113 iGc->SetDrawMode(CGraphicsContext::EDrawModePEN); |
|
114 iGc->SetPenColor(TRgb(0,0,0)); |
|
115 } |
|
116 |
|
117 void CTestAnim::DrawBitmap() |
|
118 { |
|
119 iGc->SetClippingRegion(TRegionFix<1>(TRect(iPos,iSize))); |
|
120 CFbsBitmap *bitmap=iFunctions->FlashStateOn() ? &iBitmap1 : &iBitmap2; |
|
121 if (iMasked) |
|
122 iGc->BitBltMasked(iPos,bitmap, TRect(iSize), &iMask,EFalse); |
|
123 else |
|
124 iGc->BitBlt(iPos,bitmap); |
|
125 iGc->CancelClippingRegion(); |
|
126 } |
|
127 |
|
128 void CTestAnim::AppendTime(TDes& aTimeText,const TTime& aTime) const |
|
129 { |
|
130 _LIT(TimeFormat,"%:0%H%:1%T%:2%S"); |
|
131 TRAPD(err,aTime.FormatL(aTimeText,TimeFormat)); |
|
132 if (err!=KErrNone) |
|
133 { |
|
134 _LIT(DummyTime,"######"); |
|
135 aTimeText.Append(DummyTime); |
|
136 } |
|
137 } |
|
138 |
|
139 void CTestAnim::DrawText() |
|
140 { |
|
141 if (iHasFocus) |
|
142 { |
|
143 iGc->UseFont(iFont); |
|
144 TBuf<0x20> timebuf; |
|
145 TTime time(iFunctions->SystemTime()); |
|
146 AppendTime(timebuf,time); |
|
147 TRect rect(iTextPos.iX,iTextPos.iY-iFont->AscentInPixels(),iTextPos.iX+iFont->TextWidthInPixels(timebuf),iTextPos.iY-iFont->AscentInPixels()+iFont->HeightInPixels()); |
|
148 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
149 iGc->DrawText(timebuf,rect,iFont->AscentInPixels()); |
|
150 time.UniversalTime(); |
|
151 AppendTime(timebuf,time); |
|
152 rect.Move(0,iFont->HeightInPixels()); |
|
153 iGc->DrawText(timebuf,rect,iFont->AscentInPixels()); |
|
154 } |
|
155 } |
|
156 |
|
157 void CTestAnim::Redraw() |
|
158 { |
|
159 DrawText(); |
|
160 DrawBitmap(); |
|
161 if (iPolyList) |
|
162 DrawPolyLine(); |
|
163 } |
|
164 |
|
165 void CTestAnim::ConstructL(TAny *aArgs, TBool aHasFocus) |
|
166 { |
|
167 iHasFocus=aHasFocus; |
|
168 iPos=((CTAParams *)aArgs)->pos; |
|
169 iFunctions->SetInterval(((CTAParams *)aArgs)->interval); |
|
170 if (iBitmap1.Duplicate(((CTAParams *)aArgs)->bit1)!=KErrNone || |
|
171 iBitmap2.Duplicate(((CTAParams *)aArgs)->bit2)!=KErrNone || |
|
172 iMask.Duplicate(((CTAParams *)aArgs)->mask)!=KErrNone) |
|
173 iFunctions->Panic(); |
|
174 iSize.iWidth=Min(iBitmap1.SizeInPixels().iWidth,iBitmap2.SizeInPixels().iWidth); |
|
175 iSize.iHeight=Min(iBitmap1.SizeInPixels().iHeight,iBitmap2.SizeInPixels().iHeight); |
|
176 iWiggleSize=10; |
|
177 iFont=iFunctions->DuplicateFontL(((CTAParams *)aArgs)->font); |
|
178 } |
|
179 |
|
180 void CTestAnim::SetPolyList(const TRect &aRect) |
|
181 { |
|
182 iPolyRect=aRect; |
|
183 TSize halfsize=aRect.Size(); |
|
184 halfsize.iWidth>>=1; |
|
185 halfsize.iHeight>>=1; |
|
186 (*iPolyList)[0]=aRect.iTl; |
|
187 (*iPolyList)[1]=TPoint(aRect.iTl.iX+iWiggleSize,aRect.iTl.iY+halfsize.iHeight); |
|
188 (*iPolyList)[2]=TPoint(aRect.iTl.iX,aRect.iBr.iY); |
|
189 (*iPolyList)[3]=TPoint(aRect.iTl.iX+halfsize.iWidth,aRect.iBr.iY-iWiggleSize); |
|
190 (*iPolyList)[4]=aRect.iBr; |
|
191 (*iPolyList)[5]=TPoint(aRect.iBr.iX-iWiggleSize,aRect.iTl.iY+halfsize.iHeight); |
|
192 (*iPolyList)[6]=TPoint(aRect.iBr.iX,aRect.iTl.iY); |
|
193 (*iPolyList)[7]=TPoint(aRect.iTl.iX+halfsize.iWidth,aRect.iTl.iY+iWiggleSize); |
|
194 (*iPolyList)[8]=aRect.iTl; |
|
195 TweakPolyList(iPolyState); |
|
196 } |
|
197 |
|
198 void CTestAnim::TweakPolyList(TInt aState) |
|
199 { |
|
200 TSize halfsize=iPolyRect.Size(); |
|
201 halfsize.iWidth>>=1; |
|
202 halfsize.iHeight>>=1; |
|
203 switch(aState) |
|
204 { |
|
205 case 0: |
|
206 (*iPolyList)[7]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iTl.iY+iWiggleSize); |
|
207 (*iPolyList)[1]=TPoint(iPolyRect.iTl.iX,iPolyRect.iTl.iY+halfsize.iHeight); |
|
208 break; |
|
209 case 1: |
|
210 (*iPolyList)[1]=TPoint(iPolyRect.iTl.iX+iWiggleSize,iPolyRect.iTl.iY+halfsize.iHeight); |
|
211 (*iPolyList)[3]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iBr.iY); |
|
212 break; |
|
213 case 2: |
|
214 (*iPolyList)[3]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iBr.iY-iWiggleSize); |
|
215 (*iPolyList)[5]=TPoint(iPolyRect.iBr.iX,iPolyRect.iTl.iY+halfsize.iHeight); |
|
216 break; |
|
217 case 3: |
|
218 (*iPolyList)[5]=TPoint(iPolyRect.iBr.iX-iWiggleSize,iPolyRect.iTl.iY+halfsize.iHeight); |
|
219 (*iPolyList)[7]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iTl.iY); |
|
220 break; |
|
221 } |
|
222 } |
|
223 |
|
224 void CTestAnim::InvalidateText() |
|
225 { |
|
226 TRect invalidate; |
|
227 invalidate.iTl.iX=iTextPos.iX; |
|
228 invalidate.iTl.iY=iTextPos.iY-iFont->AscentInPixels(); |
|
229 invalidate.iBr.iX=iTextPos.iX+iFont->TextWidthInPixels(ANIM_TEST_TEXT); |
|
230 invalidate.iBr.iY=iTextPos.iY+iFont->DescentInPixels(); |
|
231 iWindowFunctions->Invalidate(invalidate); |
|
232 } |
|
233 |
|
234 void CTestAnim::InvalidateBitmap() |
|
235 { |
|
236 iWindowFunctions->Invalidate(TRect(iPos,iSize)); |
|
237 } |
|
238 |
|
239 void CTestAnim::Command(TInt aOpcode, TAny *aArgs) |
|
240 { |
|
241 switch(aOpcode) |
|
242 { |
|
243 case EADllOpcodeMove: |
|
244 { |
|
245 InvalidateBitmap(); |
|
246 iPos=((CTAParams *)aArgs)->pos; |
|
247 iWindowFunctions->ActivateGc(); |
|
248 DrawBitmap(); |
|
249 iFunctions->SetInterval(((CTAParams *)aArgs)->interval); |
|
250 } |
|
251 break; |
|
252 case EADllTextPos: |
|
253 { |
|
254 InvalidateText(); |
|
255 iTextPos=((CTAParams *)aArgs)->pos; |
|
256 iWindowFunctions->ActivateGc(); |
|
257 DrawText(); |
|
258 } |
|
259 break; |
|
260 case EADllToggleBitmapMask: |
|
261 iMasked=!iMasked; |
|
262 InvalidateBitmap(); |
|
263 break; |
|
264 } |
|
265 } |
|
266 |
|
267 TInt CTestAnim::CommandReplyL(TInt aOpcode, TAny *aArgs) |
|
268 { |
|
269 switch(aOpcode) |
|
270 { |
|
271 case EADllOpcodePolyLineRect: |
|
272 iWindowFunctions->ActivateGc(); |
|
273 if (!iPolyList) |
|
274 { |
|
275 iPolyList=new(ELeave) CArrayFixFlat<TPoint>(ENumPolyPoints); |
|
276 TPoint zeropoint; |
|
277 for(TInt i=0;i<ENumPolyPoints;i++) |
|
278 iPolyList->AppendL(zeropoint); |
|
279 } |
|
280 else |
|
281 DrawPolyLine(); |
|
282 SetPolyList(*((TRect *)aArgs)); |
|
283 DrawPolyLine(); |
|
284 break; |
|
285 default: |
|
286 iFunctions->Panic(); |
|
287 } |
|
288 return(KErrNone); |
|
289 } |
|
290 |
|
291 CTestAnim::~CTestAnim() |
|
292 { |
|
293 delete iPolyList; |
|
294 iFunctions->CloseFont(iFont); |
|
295 } |
|
296 |
|
297 void CTestAnim::FocusChanged(TBool aNewState) |
|
298 { |
|
299 iHasFocus=aNewState; |
|
300 InvalidateText(); |
|
301 InvalidateBitmap(); |
|
302 } |
|
303 |
|
304 TBool CTestAnim::OfferRawEvent(const TRawEvent &/*aRawEvent*/) |
|
305 { |
|
306 return EFalse; |
|
307 } |
|
308 |
|
309 // DLL code // |
|
310 |
|
311 CAnim *CTestAnimDll::CreateInstanceL(TInt ) |
|
312 { |
|
313 return(new(ELeave) CTestAnim()); |
|
314 } |
|
315 |
|
316 // Dummy E32Dll needed by E32 to build // |
|
317 |