lafagnosticuifoundation/animation/src/SpriteAnimationClient.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2004-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 //
       
    15 
       
    16 #include <e32std.h>
       
    17 
       
    18 #include "SpriteAnimationClient.h"
       
    19 #include "AnimationConfig.h"
       
    20 #include "AnimationCmd.h"
       
    21 
       
    22 /** 
       
    23 Constructor.
       
    24 @param aAnimDll A reference to the DLL that runs the animation 
       
    25 */
       
    26 RSpriteAnimationClient::RSpriteAnimationClient(RAnimDll& aAnimDll) : RAnim(aAnimDll),iBuf(NULL,0,0)
       
    27 	{
       
    28 	}
       
    29 
       
    30 RSpriteAnimationClient::~RSpriteAnimationClient()
       
    31 	{
       
    32 	User::Free((TAny *)iBuf.Ptr());
       
    33 	}
       
    34 
       
    35 /** 
       
    36 Completes construction of an animation object.
       
    37  
       
    38 This must be done after calling RSpriteAnimationClient(), and before an
       
    39 application attempts any other communication with the server.
       
    40 
       
    41 @param aWindow A reference to the container control window that will hold the
       
    42 animation.
       
    43 */
       
    44 void RSpriteAnimationClient::ConstructL(const RWsSprite& aDevice, const TDesC8& aDataType)
       
    45 	{
       
    46 	User::LeaveIfError(RAnim::Construct(aDevice, 0, aDataType));
       
    47 	}
       
    48 	
       
    49 /** 
       
    50 Completes construction of an animation object.
       
    51  
       
    52 This must be done after calling RSpriteAnimationClient(), and before an
       
    53 application attempts any other communication with the server.
       
    54 
       
    55 @param aWindow A reference to the container control window that will hold the
       
    56 animation.
       
    57 */
       
    58 void RSpriteAnimationClient::ConstructL(const RWsSprite& aDevice, const TDesC8& aDataType, TInt aHostHandle)
       
    59 	{
       
    60 	User::LeaveIfError(RAnim::Construct(aDevice, 0, aDataType));
       
    61 	TPckgBuf<TInt> pckg;
       
    62 	pckg() = aHostHandle;
       
    63 	Command(EAnimationCmdHostHandle, pckg);
       
    64 	}
       
    65 
       
    66 
       
    67 /** Starts the animation.*/
       
    68 void RSpriteAnimationClient::Start(const TAnimationConfig& aConfig)
       
    69 	{
       
    70 	TPckgBuf<TAnimationConfig> Pckg;
       
    71 	Pckg() = aConfig;
       
    72 	Command(EAnimationCmdStart, Pckg);
       
    73 	}
       
    74 
       
    75 /** Stops the animation.*/
       
    76 void RSpriteAnimationClient::Stop()
       
    77 	{
       
    78 	Command(EAnimationCmdStop);
       
    79 	}
       
    80 
       
    81 /** Pause the animation.*/
       
    82 void RSpriteAnimationClient::Pause()
       
    83 	{
       
    84 	Command(EAnimationCmdPause);
       
    85 	}
       
    86 	
       
    87 /** Resume a paused animation.*/
       
    88 void RSpriteAnimationClient::Resume()
       
    89 	{
       
    90 	Command(EAnimationCmdResume);
       
    91 	}
       
    92 
       
    93 /** Hold an animation.*/
       
    94 void RSpriteAnimationClient::Hold()
       
    95 	{
       
    96 	Command(EAnimationCmdHold);
       
    97 	}
       
    98 
       
    99 /** Resume a held animation.*/
       
   100 void RSpriteAnimationClient::Unhold()
       
   101 	{
       
   102 	Command(EAnimationCmdUnhold);
       
   103 	}
       
   104 
       
   105 /** Freeze the server side ticker.*/
       
   106 void RSpriteAnimationClient::Freeze()
       
   107 	{
       
   108 	Command(EAnimationCmdFreeze);
       
   109 	}
       
   110 
       
   111 /** Unfreeze the server side ticker.*/
       
   112 void RSpriteAnimationClient::Unfreeze()
       
   113 	{
       
   114 	Command(EAnimationCmdUnfreeze);
       
   115 	}
       
   116 
       
   117 TSize RSpriteAnimationClient::Size()
       
   118 	{
       
   119 	const TInt reply = CommandReply(EAnimationCmdSize);
       
   120 	TSize size(0,0);
       
   121 
       
   122 	if (reply > 0)
       
   123 		{
       
   124 		size.iWidth = reply >> 16;
       
   125 		size.iHeight = reply & ((1 << 16)-1);
       
   126 		}
       
   127 
       
   128 	return size;
       
   129 	}
       
   130 
       
   131 /** Send animation data to the animation.*/
       
   132 void RSpriteAnimationClient::SendEventL(TInt aEvent, const TAny* aData, TInt aDataLength)
       
   133 	{
       
   134 	SetMinBufferSizeL(sizeof(TInt) * 2 + aDataLength);
       
   135 	iBuf.SetLength(0);
       
   136 	iBuf.Append((TUint8*)&aEvent,sizeof(TInt));
       
   137 	iBuf.Append((TUint8*)&aDataLength,sizeof(TInt));
       
   138 	iBuf.Append((TUint8*)aData, aDataLength);
       
   139 	User::LeaveIfError(CommandReply(EAnimationCmdDataEvent, iBuf));
       
   140 	}
       
   141 
       
   142 void RSpriteAnimationClient::SetMinBufferSizeL(TInt aSize)
       
   143 	{
       
   144 	if (aSize > iBuf.MaxSize())
       
   145 		{
       
   146 		const TUint8* ptr = iBuf.Ptr();
       
   147 		iBuf.Set((TUint8 *)User::AllocL(aSize),0,aSize);
       
   148 		User::Free((TAny*)ptr);	
       
   149 		}
       
   150 	}
       
   151