windowing/windowserver/test/MBMANIM.CPP
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1999-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 // Anim DLL to animate a bitmap
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "MBMCMD.H"
       
    19 #include "MBMANIM.H"
       
    20 
       
    21 #define DEFAUlT_LINE_WIDTH 4
       
    22 #define DEFAUlT_MASK_WIDTH_FACTOR 3
       
    23 #define DEFAUlT_END_POINT_FACTOR 2
       
    24 #define BLACK TRgb::Gray2(0)
       
    25 #define WHITE TRgb::Gray2(1)
       
    26 
       
    27 
       
    28 EXPORT_C CAnimDll *CreateCAnimDllL()
       
    29 	{
       
    30 	return(new(ELeave) CAnimateMbmAnimDll());
       
    31 	}
       
    32 
       
    33 
       
    34 /*CAnimateMbmAnimDll*/
       
    35 
       
    36 CAnim *CAnimateMbmAnimDll::CreateInstanceL(TInt /*aType*/)
       
    37 	{
       
    38 	return new(ELeave) CAnimateMbm();
       
    39 	}
       
    40 
       
    41 
       
    42 /*CAnimTimer*/
       
    43 
       
    44 void CAnimTimer::ConstructL()
       
    45 	{
       
    46 	CTimer::ConstructL();
       
    47 	}
       
    48 
       
    49 void CAnimTimer::DoCancel()
       
    50 	{}
       
    51 
       
    52 void CAnimTimer::RunL()
       
    53 	{
       
    54 	iAnimator->Animate();
       
    55 	}
       
    56 
       
    57 
       
    58 /*CAnimateMbm*/
       
    59 
       
    60 CAnimateMbm::~CAnimateMbm()
       
    61 	{
       
    62 	delete iTimer;
       
    63 	delete iBitmap;
       
    64 	}
       
    65 
       
    66 void CAnimateMbm::ConstructL(TAny *, TBool )
       
    67 	{
       
    68 	iTimer=new(ELeave) CAnimTimer(this);
       
    69 	iTimer->ConstructL();
       
    70 	CActiveScheduler::Add(iTimer);
       
    71 	iInterval=100000;		//0.1 secs
       
    72 	iBitmap=new(ELeave) CFbsBitmap();
       
    73 	iWindowFunctions->SetRect(TRect(0,0,20,20));
       
    74 	}
       
    75 
       
    76 void CAnimateMbm::Animate()
       
    77 	{
       
    78 	if (!iRunning)
       
    79 		return;
       
    80 	iTimer->After(iInterval);
       
    81 	++iIndex;
       
    82 	while(LoadBitmap()!=KErrNone)
       
    83 		iIndex=0;
       
    84 	iWindowFunctions->ActivateGc();
       
    85 	Redraw();
       
    86 	WindowFunctions()->DeactivateGc();
       
    87 	WindowFunctions()->Update();
       
    88 	}
       
    89 
       
    90 TBool CAnimateMbm::OfferRawEvent(const TRawEvent& /*aRawEvent*/)
       
    91 	{
       
    92 	return EFalse;
       
    93 	}
       
    94 
       
    95 void CAnimateMbm::Animate(TDateTime* /*aDateTime*/)
       
    96 	{
       
    97 	}
       
    98 
       
    99 void CAnimateMbm::Redraw()
       
   100 	{
       
   101 	iGc->BitBlt(TPoint(),iBitmap);
       
   102 	/*if (1>0)
       
   103 		{
       
   104 		iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   105 		iGc->SetBrushColor(TRgb::Gray16(iIndex));
       
   106 		iGc->DrawRect(TRect(5,5,300,300));
       
   107 		}*/
       
   108 	}
       
   109 
       
   110 void CAnimateMbm::Command(TInt aOpcode,TAny* /*aParams*/)
       
   111 	{
       
   112 	switch (aOpcode)
       
   113 		{
       
   114 	case EMbmOpDeactivate:
       
   115 		//iFunctions->SetSync(MAnimGeneralFunctions::ESyncNone);
       
   116 		if (iRunning)
       
   117 			{
       
   118 			WindowFunctions()->ActivateGc();
       
   119 			WindowFunctions()->DeactivateGc();
       
   120 			iRunning=EFalse;
       
   121 			}
       
   122 		break;
       
   123 	case EMbmOpFaster:
       
   124 		iInterval=(19*iInterval.Int())/20;
       
   125 		break;
       
   126 	case EMbmOpSlower:
       
   127 		iInterval=(21*iInterval.Int())/20;
       
   128 		break;
       
   129 	default:
       
   130 		iFunctions->Panic();
       
   131 		}
       
   132 	}
       
   133 
       
   134 void CAnimateMbm::FocusChanged(TBool )
       
   135 	{
       
   136 	}
       
   137 
       
   138 TInt CAnimateMbm::CommandReplyL(TInt aOpcode,TAny* aParams)
       
   139 	{
       
   140 	switch (aOpcode)
       
   141 		{
       
   142 	case EMbmOpActivate:
       
   143 		//iFunctions->SetSync(MAnimGeneralFunctions::ESyncSecond);
       
   144 		if (!iRunning)
       
   145 			{
       
   146 			iRunning=ETrue;
       
   147 			}
       
   148 		iTimer->After(iInterval);
       
   149 		break;
       
   150 	case EMbmOpSetFileName:
       
   151 		iName=*STATIC_CAST(TBuf<32>*,aParams);
       
   152 		iIndex=0;
       
   153 		User::LeaveIfError(LoadBitmap());
       
   154 		break;
       
   155 	default:
       
   156 		iFunctions->Panic();
       
   157 		}
       
   158 	return KErrNone;
       
   159 	}