windowing/windowserver/stdgraphic/W32STDGRAPHIC.CPP
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1995-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 "W32STDGRAPHIC.H"
       
    17 
       
    18 // TWsGraphicAnimation \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
       
    19 
       
    20 EXPORT_C TWsGraphicAnimation::TWsGraphicAnimation():
       
    21 	TWsGraphicMsgFixedBase(TUid::Uid(ETypeId),sizeof(*this)),
       
    22 	iFlags(EStopped)
       
    23 	{
       
    24 	}
       
    25 	
       
    26 EXPORT_C TBool TWsGraphicAnimation::IsPlaying() const
       
    27 	{
       
    28 	return (State() == EPlaying);
       
    29 	}
       
    30 
       
    31 EXPORT_C TBool TWsGraphicAnimation::IsStopped() const
       
    32 	{
       
    33 	return (State() == EStopped);
       
    34 	}
       
    35 
       
    36 EXPORT_C TBool TWsGraphicAnimation::IsStopping() const
       
    37 	{
       
    38 	return (State() == EStopping);
       
    39 	}
       
    40 
       
    41 EXPORT_C TBool TWsGraphicAnimation::IsPaused() const
       
    42 	{
       
    43 	return (State() == EPaused);
       
    44 	}
       
    45 	
       
    46 EXPORT_C TBool TWsGraphicAnimation::Loops() const
       
    47 	{
       
    48 	switch(State())
       
    49 		{
       
    50 		case EPlaying:
       
    51 		case EPaused:
       
    52 			return ((iFlags & ELoop) == ELoop);
       
    53 		default:
       
    54 			return EFalse;
       
    55 		}
       
    56 	}
       
    57 	
       
    58 TUint TWsGraphicAnimation::State() const
       
    59 	{
       
    60 	return (iFlags & EStateMask);
       
    61 	}
       
    62 
       
    63 void TWsGraphicAnimation::SetState(TUint aState)
       
    64 	{
       
    65 	iFlags &= ~EStateMask;
       
    66 	iFlags |= (aState & EStateMask);
       
    67 	}
       
    68 
       
    69    EXPORT_C void TWsGraphicAnimation::Play(TBool aLoop)
       
    70    	{
       
    71    	switch(State())
       
    72    		{
       
    73    		case EStopped:
       
    74    		case EStopping:
       
    75    			SetState(EPlaying);
       
    76 			// fall through
       
    77 		case EPlaying:
       
    78 			iPlay.UniversalTime(); //Start over again
       
    79    			break;
       
    80    		case EPaused:
       
    81    			SetState(EPlaying);
       
    82 			if(aLoop != Loops()) // can't resume a mismatch of looping attribute
       
    83 				{
       
    84 				iPlay.UniversalTime();
       
    85 				}
       
    86 			else // resume
       
    87 				{
       
    88 				TTimeIntervalMicroSeconds delta = iPauseOrStopping.MicroSecondsFrom(iPlay);
       
    89 				iPlay.UniversalTime();
       
    90 				iPlay = iPlay.Int64() - delta.Int64();
       
    91 				break;
       
    92 				}
       
    93 		}
       
    94 	if(aLoop)
       
    95 		{
       
    96 		iFlags |= ELoop;
       
    97 		}
       
    98 	else
       
    99 		{
       
   100 		iFlags &= ~ELoop;
       
   101 		}
       
   102 	}
       
   103 
       
   104 EXPORT_C void TWsGraphicAnimation::Pause()
       
   105 	{
       
   106 	switch(State())
       
   107 	{
       
   108 	case EPlaying:
       
   109 		case EStopping:
       
   110    			SetState(EPaused);
       
   111 			iPauseOrStopping.UniversalTime();
       
   112    			break;
       
   113    		case EStopped:
       
   114    		case EPaused:
       
   115    			break;
       
   116    		}
       
   117 	}
       
   118 
       
   119 EXPORT_C void TWsGraphicAnimation::Stop(TBool aImmediately)
       
   120 	{
       
   121 	if(aImmediately)
       
   122 		{
       
   123 		SetState(EStopped);
       
   124 		}
       
   125 	else
       
   126 		{
       
   127 		switch(State())
       
   128 			{
       
   129 			case EPlaying:
       
   130 				SetState(EStopping);
       
   131 				iPauseOrStopping.UniversalTime();
       
   132 				break;
       
   133 			case EStopped:
       
   134 				break;
       
   135 			case EStopping:
       
   136 				iPauseOrStopping.UniversalTime();
       
   137 				break;
       
   138 			case EPaused:
       
   139 				SetState(EStopping);
       
   140 				TTimeIntervalMicroSeconds delta = iPauseOrStopping.MicroSecondsFrom(iPlay);
       
   141 				iPlay.UniversalTime();
       
   142 				iPlay = iPlay.Int64() - delta.Int64();
       
   143 				iPauseOrStopping.UniversalTime();
       
   144    				break;
       
   145    			}
       
   146    		}
       
   147    	}