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