Nokia N97 SDK
Example Applications Guide

CImage Class Reference

#include <serverimage.h>

Inheritance diagram for CImage:

MTimeoutNotify List of all members.

Detailed Description

CImage. An instance of class CImage encapsulates the functionality of the bouncing square on the screen.

Definition at line 52 of file serverimage.h.


Public Member Functions

  CImage ()
virtual  ~CImage ()
void  ConstructL (TAny *aArgs, TBool aHasFocus)
TInt  CommandReplyL (TInt aCommand, TAny *aArgs)
void  Command (TInt aCommand, TAny *aArgs)
void  Redraw ()
void  Animate (TDateTime *aDateTime)
void  FocusChanged (TBool aState)
TBool  OfferRawEvent (const TRawEvent &aRawEvent)
void  TimedOut ()

Private Attributes

CTimeOutTimer *  iServerTimer
TPoint  iNewPoint
TPoint  iLastPoint
TSize  iSize
TRect  iScreenSize
TBool  iAnimationReset
TBool  iDrawn
TBool  iDeltaX
TBool  iDeltaY


Constructor & Destructor Documentation

CImage::CImage (   ) 
 

CImage() Construct the object, forced to be public.

Definition at line 36 of file serverimage.cpp.

00037     {
00038     // No implementation required
00039     }

CImage::~CImage (   )  [virtual]
 

~CImage() Virtual destructor.

Definition at line 86 of file serverimage.cpp.

References iServerTimer.

00087     {
00088     // If the CTimer derived object exists and has an outstanding request,
00089     // cancel it.
00090     if ( iServerTimer )
00091         {
00092         iServerTimer->Cancel();
00093         }
00094 
00095     // Then delete the timer object
00096     delete iServerTimer;
00097     iServerTimer = NULL;
00098     }


Member Function Documentation

void CImage::ConstructL (  TAny *  aArgs,
TBool  aHasFocus
) 
 

ConstructL() Complete animation server object construction (called by windows server).

Parameters:
aArgs  any arguments required during construction (passed from client through window server)
aHasFocus  true if the animation has window server focus.

Definition at line 46 of file serverimage.cpp.

References iAnimationReset, iDeltaX, iDeltaY, iDrawn, iLastPoint, iNewPoint, iScreenSize, iServerTimer, iSize, and CTimeOutTimer::NewL().

00047     {
00048     // Initialise starting points to the top left hand corner
00049     iLastPoint.SetXY( 0, 0 );
00050     iNewPoint.SetXY( 1, 1 );
00051 
00052     // Set up how far the shape moves each timer event
00053     iDeltaX = KStepSize;
00054     iDeltaY = KStepSize;
00055 
00056     // Animation reset not requested by user
00057     iAnimationReset = EFalse;
00058 
00059     // initiates an initial position update
00060     iDrawn = ETrue;
00061 
00062     // Set the rectangles size
00063     iSize.SetSize( 20,20 );
00064 
00065     // Store the screen size
00066     iScreenSize = iWindowFunctions->WindowSize();
00067 
00068     // Set the screen visible
00069     iWindowFunctions->SetVisible( ETrue );
00070 
00071     // We are using a timer, not the built in synchronising, so turn it off
00072     iFunctions->SetSync( MAnimGeneralFunctions::ESyncNone );
00073 
00074     // Create the timeout timer
00075     iServerTimer = CTimeOutTimer::NewL( EPriorityHigh, *this );
00076 
00077     // Set the timeout period
00078     iServerTimer->After( KTimerPeriod );
00079     }

TInt CImage::CommandReplyL (  TInt  aCommand,
TAny *  aArgs
) 
 

CommandReplyL() Perform aCommand with optional additional arguments aArgs and return a reply (called by windows server). Note! This method can return an error, so any actions that can leave should use this method and not Command (). This command is not buffered and so requests from the client side are performed immediately. For these reason these functions should not take a long time.

Parameters:
aCommand  the command to perform
aArgs  any additional arguments required.

Definition at line 196 of file serverimage.cpp.

00197     {
00198     return aOpcode;
00199     }

void CImage::Command (  TInt  aCommand,
TAny *  aArgs
) 
 

Command() Perform aCommand with optional additional arguments aArgs. Note! Because there is no way to return an error from this method, it is important that these commands should not be able to fail or leave. This command is buffered and so may have been requested by the client side an unknown period ago.

Parameters:
aCommand  the command to perform
aArgs  any additional arguments required

Definition at line 206 of file serverimage.cpp.

References iAnimationReset, and iScreenSize.

00207     {
00208     switch ( aOpcode )
00209         {
00210     case KAnimationReset:
00211         // Set a flag to reset the animation back to the top left
00212         iAnimationReset = ETrue;
00213         break;
00214         
00215     case KResolutionChange:
00216         iAnimationReset = ETrue;
00217         iScreenSize = iWindowFunctions->WindowSize();
00218         break;
00219 
00220     default:
00221         User::Panic( KAnimation, EPanicAnimationServer );
00222         break;
00223         }
00224     }

void CImage::Redraw (   ) 
 

Redraw() Redraw the animation object, called by the Windows Server.

Definition at line 105 of file serverimage.cpp.

References iDrawn, iLastPoint, iNewPoint, and iSize.

00106     {
00107     // get the background colour
00108     TLogicalRgb backgroundColour( TLogicalRgb::ESystemBackgroundColor );
00109 
00110     // Clear the old image.
00111     iGc->SetPenSize( TSize( 3,3 ) );
00112     iGc->SetPenColor( backgroundColour );
00113     iGc->DrawRect( TRect( iLastPoint, iSize ) );
00114 
00115     // Draw a shape at the new position
00116     iGc->SetPenSize( TSize( 1,1 ) );
00117     iGc->SetPenColor( KRgbBlack );
00118     iGc->DrawRect( TRect( iNewPoint, iSize ) );
00119 
00120     // signal that the current position has been drawn
00121     iDrawn = ETrue;
00122     }

void CImage::Animate (  TDateTime *  aDateTime  ) 
 

Animate() Animate the object, normally called by the Windows Server at a fixed period

Definition at line 138 of file serverimage.cpp.

References iAnimationReset, iDeltaX, iDeltaY, iDrawn, iLastPoint, iNewPoint, iScreenSize, and iSize.

00139     {
00140 
00141     // if the last position has been drawn, update the position
00142     if ( iDrawn )
00143         {
00144         // this position has not been drawn, so clear the flag
00145         iDrawn = EFalse;
00146 
00147 
00148         // Save the current position, so we can rub it out later
00149         iLastPoint = iNewPoint;
00150 
00151         // Check current position, 
00152         // reverse the direction if either limit is reached
00153         if ( ( iNewPoint.iX == iScreenSize.iTl.iX ) ||
00154            ( ( iNewPoint.iX + iSize.iWidth ) == iScreenSize.iBr.iX ) )
00155             {
00156             iDeltaX = -iDeltaX;
00157             }
00158 
00159         // Setup the next X coordinate
00160         iNewPoint.iX += iDeltaX;
00161 
00162         // Repeat for y coordinate
00163         if ( ( iNewPoint.iY == iScreenSize.iTl.iY ) ||
00164            ( ( iNewPoint.iY + iSize.iHeight ) == iScreenSize.iBr.iY ) )
00165             {
00166             iDeltaY = -iDeltaY;
00167             }
00168         iNewPoint.iY += iDeltaY;
00169 
00170         // Check for user requested reset
00171         if ( iAnimationReset )
00172             {
00173             iNewPoint.iX = 1;
00174             iNewPoint.iY = 1;
00175             iDeltaX = KStepSize;
00176             iDeltaY = KStepSize;
00177             iAnimationReset = EFalse;
00178             }
00179 
00180 
00181         // Alternative method, works well on the MARM target, jumps on the
00182         // windows emulator, simply uncomment and recompile
00183         //iFunctions->ActivateGc();
00184         //Redraw();
00185 
00186         // Force a draw to be performed by declaring the screen invalid
00187         iWindowFunctions->Invalidate( iScreenSize );
00188         }
00189     }

void CImage::FocusChanged (  TBool  aState  ) 
 

FocusChanged() Handle the event when the focus changes.

Parameters:
aState  TRUE if the Animation Server has focus

Definition at line 129 of file serverimage.cpp.

00130     {
00131     }

TBool CImage::OfferRawEvent (  const TRawEvent &  aRawEvent  ) 
 

OfferRawEvent() For handling raw events. Not used in this example so return false.

Definition at line 245 of file serverimage.cpp.

00246     {
00247     return ETrue;
00248     }

void CImage::TimedOut (   )  [virtual]
 

TimedOut() Handle timer time out

Implements MTimeoutNotify.

Definition at line 231 of file serverimage.cpp.

References iServerTimer.

00232     {
00233     // Reset the timer timeout period
00234     iServerTimer->After( KTimerPeriod );
00235 
00236     // Call the animation function for this image
00237     iFunctions->Animate( 0 );
00238     }


Member Data Documentation

CTimeOutTimer* CImage::iServerTimer [private]
 

iServerTimer Animation timer object Owned by CImage object.

Definition at line 148 of file serverimage.h.

Referenced by ConstructL(), TimedOut(), and ~CImage().

TPoint CImage::iNewPoint [private]
 

iNewPoint The square's current position

Definition at line 154 of file serverimage.h.

Referenced by Animate(), ConstructL(), and Redraw().

TPoint CImage::iLastPoint [private]
 

iLastPoint The square's last position

Definition at line 160 of file serverimage.h.

Referenced by Animate(), ConstructL(), and Redraw().

TSize CImage::iSize [private]
 

iSize The square's size

Definition at line 166 of file serverimage.h.

Referenced by Animate(), ConstructL(), and Redraw().

TRect CImage::iScreenSize [private]
 

iScreenSize The screen size

Definition at line 172 of file serverimage.h.

Referenced by Animate(), Command(), and ConstructL().

TBool CImage::iAnimationReset [private]
 

iAnimationReset Should the animation be reset back to the beginning

Definition at line 178 of file serverimage.h.

Referenced by Animate(), Command(), and ConstructL().

TBool CImage::iDrawn [private]
 

iDrawn Has the animation been drawn

Definition at line 184 of file serverimage.h.

Referenced by Animate(), ConstructL(), and Redraw().

TBool CImage::iDeltaX [private]
 

iDeltaX x coordinate step

Definition at line 190 of file serverimage.h.

Referenced by Animate(), and ConstructL().

TBool CImage::iDeltaY [private]
 

iDeltaY y coordinate step

Definition at line 196 of file serverimage.h.

Referenced by Animate(), and ConstructL().


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top