sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Test Animated DLL sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "ANIMDLL.H" sl@0: sl@0: #define ANIM_TEST_TEXT _L("Testing 123") sl@0: sl@0: class CTestAnim : public CWindowAnim sl@0: { sl@0: enum {ENumPolyPoints=9}; sl@0: public: sl@0: ~CTestAnim(); sl@0: virtual void ConstructL(TAny *aArgs, TBool aHasFocus); sl@0: virtual void Animate(TDateTime *aDateTime); sl@0: virtual void Redraw(); sl@0: virtual void Command(TInt aOpcode, TAny *aArgs); sl@0: virtual TInt CommandReplyL(TInt aOpcode, TAny *aArgs); sl@0: void SetPolyList(const TRect &aRect); sl@0: void DrawPolyLine(); sl@0: void DrawBitmap(); sl@0: void DrawText(); sl@0: void TweakPolyList(TInt aState); sl@0: void FocusChanged(TBool aState); sl@0: void InvalidateText(); sl@0: void InvalidateBitmap(); sl@0: //Pure virtual function from MEventHandler sl@0: virtual TBool OfferRawEvent(const TRawEvent &aRawEvent); sl@0: private: sl@0: void AppendTime(TDes& aTimeText,const TTime& aTime) const; sl@0: private: sl@0: TPoint iPos; sl@0: TSize iSize; sl@0: TInt iColor; sl@0: TBool iMasked; sl@0: TRect iPolyRect; sl@0: TInt iPolyState; sl@0: TInt iWiggleSize; sl@0: TPoint iTextPos; sl@0: TBool iHasFocus; sl@0: CArrayFixFlat *iPolyList; sl@0: CFbsBitmap iBitmap1; sl@0: CFbsBitmap iBitmap2; sl@0: CFbsBitmap iMask; sl@0: CFbsFont *iFont; sl@0: }; sl@0: sl@0: class CTestAnimDll : public CAnimDll sl@0: { sl@0: public: sl@0: CAnim *CreateInstanceL(TInt aType); sl@0: private: sl@0: }; sl@0: sl@0: /*#if defined(__WINS__) sl@0: #pragma data_seg(".E32_UID") sl@0: __WINS_UID(0, KWservAnimDllUidValue, 0) sl@0: #pragma data_seg() sl@0: #endif*/ sl@0: sl@0: EXPORT_C CAnimDll *CreateCAnimDllL() sl@0: { sl@0: return(new(ELeave) CTestAnimDll()); sl@0: } sl@0: sl@0: // Instance code // sl@0: sl@0: void CTestAnim::Animate(TDateTime *) sl@0: { sl@0: if (!iWindowFunctions->IsHidden()) sl@0: { sl@0: iWindowFunctions->ActivateGc(); sl@0: if (iPolyList) sl@0: DrawPolyLine(); sl@0: } sl@0: if (iPolyList) sl@0: { sl@0: iPolyState=(iPolyState+1)%4; sl@0: TweakPolyList(iPolyState); sl@0: } sl@0: if (!iWindowFunctions->IsHidden()) sl@0: { sl@0: if (iPolyList) sl@0: DrawPolyLine(); sl@0: DrawText(); sl@0: DrawBitmap(); sl@0: } sl@0: iColor=(iColor+16)&0xFF; sl@0: } sl@0: sl@0: void CTestAnim::DrawPolyLine() sl@0: { sl@0: iGc->SetDrawMode(CGraphicsContext::EDrawModeXOR); sl@0: iGc->SetPenColor(TRgb(255,255,255)); sl@0: iGc->DrawPolyLine(iPolyList); sl@0: iGc->SetDrawMode(CGraphicsContext::EDrawModePEN); sl@0: iGc->SetPenColor(TRgb(0,0,0)); sl@0: } sl@0: sl@0: void CTestAnim::DrawBitmap() sl@0: { sl@0: iGc->SetClippingRegion(TRegionFix<1>(TRect(iPos,iSize))); sl@0: CFbsBitmap *bitmap=iFunctions->FlashStateOn() ? &iBitmap1 : &iBitmap2; sl@0: if (iMasked) sl@0: iGc->BitBltMasked(iPos,bitmap, TRect(iSize), &iMask,EFalse); sl@0: else sl@0: iGc->BitBlt(iPos,bitmap); sl@0: iGc->CancelClippingRegion(); sl@0: } sl@0: sl@0: void CTestAnim::AppendTime(TDes& aTimeText,const TTime& aTime) const sl@0: { sl@0: _LIT(TimeFormat,"%:0%H%:1%T%:2%S"); sl@0: TRAPD(err,aTime.FormatL(aTimeText,TimeFormat)); sl@0: if (err!=KErrNone) sl@0: { sl@0: _LIT(DummyTime,"######"); sl@0: aTimeText.Append(DummyTime); sl@0: } sl@0: } sl@0: sl@0: void CTestAnim::DrawText() sl@0: { sl@0: if (iHasFocus) sl@0: { sl@0: iGc->UseFont(iFont); sl@0: TBuf<0x20> timebuf; sl@0: TTime time(iFunctions->SystemTime()); sl@0: AppendTime(timebuf,time); sl@0: TRect rect(iTextPos.iX,iTextPos.iY-iFont->AscentInPixels(),iTextPos.iX+iFont->TextWidthInPixels(timebuf),iTextPos.iY-iFont->AscentInPixels()+iFont->HeightInPixels()); sl@0: iGc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: iGc->DrawText(timebuf,rect,iFont->AscentInPixels()); sl@0: time.UniversalTime(); sl@0: AppendTime(timebuf,time); sl@0: rect.Move(0,iFont->HeightInPixels()); sl@0: iGc->DrawText(timebuf,rect,iFont->AscentInPixels()); sl@0: } sl@0: } sl@0: sl@0: void CTestAnim::Redraw() sl@0: { sl@0: DrawText(); sl@0: DrawBitmap(); sl@0: if (iPolyList) sl@0: DrawPolyLine(); sl@0: } sl@0: sl@0: void CTestAnim::ConstructL(TAny *aArgs, TBool aHasFocus) sl@0: { sl@0: iHasFocus=aHasFocus; sl@0: iPos=((CTAParams *)aArgs)->pos; sl@0: iFunctions->SetInterval(((CTAParams *)aArgs)->interval); sl@0: if (iBitmap1.Duplicate(((CTAParams *)aArgs)->bit1)!=KErrNone || sl@0: iBitmap2.Duplicate(((CTAParams *)aArgs)->bit2)!=KErrNone || sl@0: iMask.Duplicate(((CTAParams *)aArgs)->mask)!=KErrNone) sl@0: iFunctions->Panic(); sl@0: iSize.iWidth=Min(iBitmap1.SizeInPixels().iWidth,iBitmap2.SizeInPixels().iWidth); sl@0: iSize.iHeight=Min(iBitmap1.SizeInPixels().iHeight,iBitmap2.SizeInPixels().iHeight); sl@0: iWiggleSize=10; sl@0: iFont=iFunctions->DuplicateFontL(((CTAParams *)aArgs)->font); sl@0: } sl@0: sl@0: void CTestAnim::SetPolyList(const TRect &aRect) sl@0: { sl@0: iPolyRect=aRect; sl@0: TSize halfsize=aRect.Size(); sl@0: halfsize.iWidth>>=1; sl@0: halfsize.iHeight>>=1; sl@0: (*iPolyList)[0]=aRect.iTl; sl@0: (*iPolyList)[1]=TPoint(aRect.iTl.iX+iWiggleSize,aRect.iTl.iY+halfsize.iHeight); sl@0: (*iPolyList)[2]=TPoint(aRect.iTl.iX,aRect.iBr.iY); sl@0: (*iPolyList)[3]=TPoint(aRect.iTl.iX+halfsize.iWidth,aRect.iBr.iY-iWiggleSize); sl@0: (*iPolyList)[4]=aRect.iBr; sl@0: (*iPolyList)[5]=TPoint(aRect.iBr.iX-iWiggleSize,aRect.iTl.iY+halfsize.iHeight); sl@0: (*iPolyList)[6]=TPoint(aRect.iBr.iX,aRect.iTl.iY); sl@0: (*iPolyList)[7]=TPoint(aRect.iTl.iX+halfsize.iWidth,aRect.iTl.iY+iWiggleSize); sl@0: (*iPolyList)[8]=aRect.iTl; sl@0: TweakPolyList(iPolyState); sl@0: } sl@0: sl@0: void CTestAnim::TweakPolyList(TInt aState) sl@0: { sl@0: TSize halfsize=iPolyRect.Size(); sl@0: halfsize.iWidth>>=1; sl@0: halfsize.iHeight>>=1; sl@0: switch(aState) sl@0: { sl@0: case 0: sl@0: (*iPolyList)[7]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iTl.iY+iWiggleSize); sl@0: (*iPolyList)[1]=TPoint(iPolyRect.iTl.iX,iPolyRect.iTl.iY+halfsize.iHeight); sl@0: break; sl@0: case 1: sl@0: (*iPolyList)[1]=TPoint(iPolyRect.iTl.iX+iWiggleSize,iPolyRect.iTl.iY+halfsize.iHeight); sl@0: (*iPolyList)[3]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iBr.iY); sl@0: break; sl@0: case 2: sl@0: (*iPolyList)[3]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iBr.iY-iWiggleSize); sl@0: (*iPolyList)[5]=TPoint(iPolyRect.iBr.iX,iPolyRect.iTl.iY+halfsize.iHeight); sl@0: break; sl@0: case 3: sl@0: (*iPolyList)[5]=TPoint(iPolyRect.iBr.iX-iWiggleSize,iPolyRect.iTl.iY+halfsize.iHeight); sl@0: (*iPolyList)[7]=TPoint(iPolyRect.iTl.iX+halfsize.iWidth,iPolyRect.iTl.iY); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CTestAnim::InvalidateText() sl@0: { sl@0: TRect invalidate; sl@0: invalidate.iTl.iX=iTextPos.iX; sl@0: invalidate.iTl.iY=iTextPos.iY-iFont->AscentInPixels(); sl@0: invalidate.iBr.iX=iTextPos.iX+iFont->TextWidthInPixels(ANIM_TEST_TEXT); sl@0: invalidate.iBr.iY=iTextPos.iY+iFont->DescentInPixels(); sl@0: iWindowFunctions->Invalidate(invalidate); sl@0: } sl@0: sl@0: void CTestAnim::InvalidateBitmap() sl@0: { sl@0: iWindowFunctions->Invalidate(TRect(iPos,iSize)); sl@0: } sl@0: sl@0: void CTestAnim::Command(TInt aOpcode, TAny *aArgs) sl@0: { sl@0: switch(aOpcode) sl@0: { sl@0: case EADllOpcodeMove: sl@0: { sl@0: InvalidateBitmap(); sl@0: iPos=((CTAParams *)aArgs)->pos; sl@0: iWindowFunctions->ActivateGc(); sl@0: DrawBitmap(); sl@0: iFunctions->SetInterval(((CTAParams *)aArgs)->interval); sl@0: } sl@0: break; sl@0: case EADllTextPos: sl@0: { sl@0: InvalidateText(); sl@0: iTextPos=((CTAParams *)aArgs)->pos; sl@0: iWindowFunctions->ActivateGc(); sl@0: DrawText(); sl@0: } sl@0: break; sl@0: case EADllToggleBitmapMask: sl@0: iMasked=!iMasked; sl@0: InvalidateBitmap(); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: TInt CTestAnim::CommandReplyL(TInt aOpcode, TAny *aArgs) sl@0: { sl@0: switch(aOpcode) sl@0: { sl@0: case EADllOpcodePolyLineRect: sl@0: iWindowFunctions->ActivateGc(); sl@0: if (!iPolyList) sl@0: { sl@0: iPolyList=new(ELeave) CArrayFixFlat(ENumPolyPoints); sl@0: TPoint zeropoint; sl@0: for(TInt i=0;iAppendL(zeropoint); sl@0: } sl@0: else sl@0: DrawPolyLine(); sl@0: SetPolyList(*((TRect *)aArgs)); sl@0: DrawPolyLine(); sl@0: break; sl@0: default: sl@0: iFunctions->Panic(); sl@0: } sl@0: return(KErrNone); sl@0: } sl@0: sl@0: CTestAnim::~CTestAnim() sl@0: { sl@0: delete iPolyList; sl@0: iFunctions->CloseFont(iFont); sl@0: } sl@0: sl@0: void CTestAnim::FocusChanged(TBool aNewState) sl@0: { sl@0: iHasFocus=aNewState; sl@0: InvalidateText(); sl@0: InvalidateBitmap(); sl@0: } sl@0: sl@0: TBool CTestAnim::OfferRawEvent(const TRawEvent &/*aRawEvent*/) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: // DLL code // sl@0: sl@0: CAnim *CTestAnimDll::CreateInstanceL(TInt ) sl@0: { sl@0: return(new(ELeave) CTestAnim()); sl@0: } sl@0: sl@0: // Dummy E32Dll needed by E32 to build // sl@0: