Update contrib.
1 // Copyright (c) 2008-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #include "stressanim.h"
23 #include "stressanimcmd.h"
27 EXPORT_C CAnimDll *CreateCAnimDllL() //lint -e714 Suppress 'not referenced'
30 return new (ELeave) CStressAnimDll();
33 CAnim *CStressAnimDll::CreateInstanceL(TInt /*aType*/)
35 return new (ELeave) CStressWindowAnim();
38 void CStressWindowAnim::Animate(TDateTime *)
44 iLastAnimShot = User::NTickCount();
45 if (!iWindowFunctions->IsHidden())
47 iWindowFunctions->ActivateGc();
55 iPolyState=(iPolyState+1)%4;
56 TweakPolyList(iPolyState);
58 if (!iWindowFunctions->IsHidden())
66 iColor=(iColor+16)&0xFF;
67 iDoAnimation = EFalse;
70 void CStressWindowAnim::DrawPolyLine()
72 iGc->SetDrawMode(CGraphicsContext::EDrawModeXOR);
73 iGc->SetPenColor(TRgb(255,255,255));
74 iGc->DrawPolyLine(static_cast<CArrayFix<TPoint>*>(iPolyList));
75 iGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
76 iGc->SetPenColor(TRgb(0,0,0));
79 void CStressWindowAnim::DrawBitmap()
81 iGc->SetClippingRegion(TRegionFix<1>(TRect(iPos,iSize)));
82 CFbsBitmap *bitmap=iFunctions->FlashStateOn() ? &iBitmap1 : &iBitmap2;
85 iGc->BitBltMasked(iPos,bitmap, TRect(iSize), &iMask,EFalse);
89 iGc->BitBlt(iPos,bitmap);
91 iGc->CancelClippingRegion();
94 void CStressWindowAnim::AppendTime(TDes& aTimeText,const TTime& aTime) const
96 _LIT(TimeFormat,"%:0%H%:1%T%:2%S");
97 TRAPD(err,aTime.FormatL(aTimeText,TimeFormat));
100 _LIT(DummyTime,"######");
101 aTimeText.Append(DummyTime);
105 void CStressWindowAnim::DrawText()
111 TUint64 elapsedMs = iLastAnimShot * iKernelTicksPeriod;
112 TTime time(elapsedMs);
114 AppendTime( timebuf , time );
116 TSize winSize = iWindowFunctions->WindowSize();
118 TInt textWidth = iFont->MeasureText( timebuf );
120 TInt textHalf = textWidth / 2;
122 TInt centerX = winSize.iWidth / 2;
123 TInt centerY = winSize.iHeight / 2;
125 TRect rect(centerX - textHalf, centerY - iFont->AscentInPixels(),
126 centerX + textHalf, centerY - iFont->AscentInPixels() + iFont->HeightInPixels());
129 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
130 iGc->DrawText(timebuf,rect,iFont->AscentInPixels());
131 rect.Move(0,iFont->HeightInPixels());
132 iGc->DrawText(timebuf,rect,iFont->AscentInPixels());
136 void CStressWindowAnim::Redraw()
145 void CStressWindowAnim::ConstructL(TAny *aArgs, TBool aHasFocus)
148 iPos=((TStressTestAnimParams *)aArgs)->pos;
149 iFunctions->SetInterval(((TStressTestAnimParams *)aArgs)->interval);
150 if (iBitmap1.Duplicate(((TStressTestAnimParams *)aArgs)->bit1)!=KErrNone ||
151 iBitmap2.Duplicate(((TStressTestAnimParams *)aArgs)->bit2)!=KErrNone ||
152 iMask.Duplicate(((TStressTestAnimParams *)aArgs)->mask)!=KErrNone)
156 iSize.iWidth=Min(iBitmap1.SizeInPixels().iWidth,iBitmap2.SizeInPixels().iWidth);
157 iSize.iHeight=Min(iBitmap1.SizeInPixels().iHeight,iBitmap2.SizeInPixels().iHeight);
159 iFont=iFunctions->DuplicateFontL(((TStressTestAnimParams *)aArgs)->font);
160 iDoAnimation = ETrue;
161 HAL::Get( HAL::ENanoTickPeriod, iKernelTicksPeriod );
162 iFunctions->SetSync( MAnimGeneralFunctions::ESyncSecond );
165 void CStressWindowAnim::SetPolyList(const TRect &aRect)
168 TSize halfsize=aRect.Size();
169 __ASSERT_ALWAYS(halfsize.iWidth >= 0, Panic(EPanic10));
170 __ASSERT_ALWAYS(halfsize.iHeight >= 0, Panic(EPanic11));
171 halfsize.iWidth>>=1; //lint !e702 Shift right of signed quantity (int)
172 halfsize.iHeight>>=1; //lint !e702 Shift right of signed quantity (int)
173 (*iPolyList)[0]=aRect.iTl;
174 (*iPolyList)[1]=TPoint(aRect.iTl.iX+iWiggleSize,aRect.iTl.iY+halfsize.iHeight);
175 (*iPolyList)[2]=TPoint(aRect.iTl.iX,aRect.iBr.iY);
176 (*iPolyList)[3]=TPoint(aRect.iTl.iX+halfsize.iWidth,aRect.iBr.iY-iWiggleSize);
177 (*iPolyList)[4]=aRect.iBr;
178 (*iPolyList)[5]=TPoint(aRect.iBr.iX-iWiggleSize,aRect.iTl.iY+halfsize.iHeight);
179 (*iPolyList)[6]=TPoint(aRect.iBr.iX,aRect.iTl.iY);
180 (*iPolyList)[7]=TPoint(aRect.iTl.iX+halfsize.iWidth,aRect.iTl.iY+iWiggleSize);
181 (*iPolyList)[8]=aRect.iTl;
182 TweakPolyList(iPolyState);
185 void CStressWindowAnim::TweakPolyList(TInt aState)
187 TSize halfsize=iPolyRect.Size();
188 __ASSERT_ALWAYS(halfsize.iWidth >= 0, Panic(EPanic12));
189 __ASSERT_ALWAYS(halfsize.iHeight >= 0, Panic(EPanic13));
190 halfsize.iWidth>>=1; //lint !e702 Shift right of signed quantity (int)
191 halfsize.iHeight>>=1; //lint !e702 Shift right of signed quantity (int)
195 (*iPolyList)[7]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iTl.iY+iWiggleSize);
196 (*iPolyList)[1]=TPoint(iPolyRect.iTl.iX,iPolyRect.iTl.iY+halfsize.iHeight);
199 (*iPolyList)[1]=TPoint(iPolyRect.iTl.iX+iWiggleSize,iPolyRect.iTl.iY+halfsize.iHeight);
200 (*iPolyList)[3]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iBr.iY);
203 (*iPolyList)[3]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iBr.iY-iWiggleSize);
204 (*iPolyList)[5]=TPoint(iPolyRect.iBr.iX,iPolyRect.iTl.iY+halfsize.iHeight);
207 (*iPolyList)[5]=TPoint(iPolyRect.iBr.iX-iWiggleSize,iPolyRect.iTl.iY+halfsize.iHeight);
208 (*iPolyList)[7]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iTl.iY);
211 __ASSERT_ALWAYS(EFalse, Panic(EPanic14));
216 void CStressWindowAnim::InvalidateText()
219 invalidate.iTl.iX=iTextPos.iX;
220 invalidate.iTl.iY=iTextPos.iY-iFont->AscentInPixels();
221 invalidate.iBr.iX=iTextPos.iX+iFont->TextWidthInPixels(_L("Overstressed ANIM"));
222 invalidate.iBr.iY=iTextPos.iY+iFont->DescentInPixels();
223 iWindowFunctions->Invalidate(invalidate);
226 void CStressWindowAnim::InvalidateBitmap()
228 iWindowFunctions->Invalidate(TRect(iPos,iSize));
231 void CStressWindowAnim::Command(TInt aOpcode, TAny *aArgs)
235 case EADllOpcodeMove:
238 iPos=((TStressTestAnimParams *)aArgs)->pos;
239 iWindowFunctions->ActivateGc();
241 iFunctions->SetInterval(((TStressTestAnimParams *)aArgs)->interval);
247 iTextPos=((TStressTestAnimParams *)aArgs)->pos;
248 iWindowFunctions->ActivateGc();
252 case EADllToggleBitmapMask:
257 __ASSERT_ALWAYS(EFalse, Panic(EPanic15));
262 TInt CStressWindowAnim::CommandReplyL(TInt aOpcode, TAny *aArgs)
269 case EADllOpcodePolyLineRect:
270 iWindowFunctions->ActivateGc();
273 iPolyList=new(ELeave) CArrayFixFlat<TPoint>(ENumPolyPoints);
275 for(TInt i=0;i<ENumPolyPoints;i++)
277 iPolyList->AppendL(zeropoint);
284 SetPolyList(*((TRect *)aArgs));
290 iDoAnimation = ETrue;
300 CStressWindowAnim::~CStressWindowAnim()
303 iFunctions->CloseFont(iFont);
306 void CStressWindowAnim::FocusChanged(TBool aNewState)
313 TBool CStressWindowAnim::OfferRawEvent(const TRawEvent &/*aRawEvent*/)