S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CIMOpenAPIExampleContainer Class Reference

#include <IMOpenAPIExampleContainer.h>

List of all members.

Public Member Functions

void ConstructL (const TRect &aRect)
 ~CIMOpenAPIExampleContainer ()
void SetCellSign (const TGameSign aCellSign, const TInt aCellIndex)
void SetMySign (const TGameSign aMySign)
void SetGameView (const TGameState aDesiredView)
void SetModel (CIMOpenAPIExamplemodel *aModel)
void PlayMove ()
void ActivateL ()
void SizeChanged ()
TInt CountComponentControls () const
CCoeControl * ComponentControl (TInt aIndex) const
void Draw (const TRect &aRect) const
void HandleControlEventL (CCoeControl *aControl, TCoeEvent aEventType)
TKeyResponse OfferKeyEventL (const TKeyEvent &aKeyEvent, TEventCode aType)

Private Member Functions

void LoadMySignBMPL (const TDesC &aImageFile)

Private Attributes

CEikLabel * iTurnIndicator
CEikLabel * iSignIndicator
CFbsBitmap * iCrossSign
CFbsBitmap * iZeroSign
CFbsBitmap * iEmptySign
CFbsBitmap * iMySignBMP
TGameSign iMySign
TFileName iImageFileName
CIMOpenAPIExamplemodel * iModel
CIMOpenAPIExampleGrid * iGamesGrid
CEikButtonGroupContainer * iCba


Detailed Description

CIMOpenAPIExampleContainer container control class. Most important aspect of the class is holding a graphical grid, which displays game actions

Definition at line 40 of file IMOpenAPIExampleContainer.h.


Constructor & Destructor Documentation

CIMOpenAPIExampleContainer::~CIMOpenAPIExampleContainer (   ) 
 

Destructor.

Definition at line 92 of file IMOpenAPIExampleContainer.cpp.

References iCrossSign, iEmptySign, iGamesGrid, iMySignBMP, iSignIndicator, iTurnIndicator, and iZeroSign.

00093     {
00094     delete iTurnIndicator;
00095     iTurnIndicator = NULL;
00096     
00097     delete iSignIndicator;
00098     iSignIndicator = NULL;
00099         
00100     delete iCrossSign;
00101     iCrossSign = NULL;
00102 
00103         delete iMySignBMP;
00104     iMySignBMP = NULL;
00105         
00106     delete iZeroSign;
00107     iZeroSign = NULL;
00108     
00109     delete iEmptySign;
00110     iEmptySign = NULL;
00111         
00112     delete iGamesGrid;
00113     iGamesGrid = NULL;
00114     
00115     }


Member Function Documentation

void CIMOpenAPIExampleContainer::ConstructL (  const TRect &  aRect  ) 
 

EPOC default constructor.

Parameters:
aRect Frame rectangle for container.

Definition at line 52 of file IMOpenAPIExampleContainer.cpp.

References ActivateL(), CIMOpenAPIExampleGrid::ConstructL(), iCrossSign, iEmptySign, iGamesGrid, iImageFileName, iMySign, iMySignBMP, iSignIndicator, iTurnIndicator, iZeroSign, and LoadMySignBMPL().

00053     {
00054     CreateWindowL();
00055 
00056 
00057         iMySign = EZeroSign;
00058 
00059     iTurnIndicator = new (ELeave) CEikLabel;
00060     iTurnIndicator->SetContainerWindowL( *this );
00061     iTurnIndicator->SetTextL(KNullDesC);
00062 
00063     iSignIndicator = new (ELeave) CEikLabel;
00064     iSignIndicator->SetContainerWindowL( *this );
00065     iSignIndicator->SetTextL(KNullDesC);
00066 
00067         
00068         iCrossSign = new (ELeave) CFbsBitmap;
00069         iZeroSign = new (ELeave) CFbsBitmap;
00070         iEmptySign = new (ELeave) CFbsBitmap;
00071         iMySignBMP = new (ELeave) CFbsBitmap;
00072         
00073     iImageFileName = KImageFilePath;
00074     iImageFileName.Append(KImageFileName);
00075         LoadMySignBMPL(iImageFileName);
00076         
00077         // Construct the grid
00078         iGamesGrid = new (ELeave)CIMOpenAPIExampleGrid;
00079         iGamesGrid->SetContainerWindowL(*this);
00080         iGamesGrid->ConstructL(R_IMOPENAPIEXAMPLE_GRID, iImageFileName);
00081         
00082 
00083         SetRect(aRect);
00084     ActivateL();
00085     }

void CIMOpenAPIExampleContainer::SetCellSign (  const TGameSign  aCellSign,
const TInt  aCellIndex
) 
 

SetCellSign. Sets the graphical sign of given cell, either empty,cross or circle

Parameters:
aCellSign sign of the cell aCellIndex position of the cell in the matrix 0 to 8

Definition at line 269 of file IMOpenAPIExampleContainer.cpp.

References iGamesGrid, and CIMOpenAPIExampleGrid::SetCellSign().

00270         {
00271     iGamesGrid->SetCellSign(aCellSign, aCellIndex);
00272     DrawNow();
00273         }

void CIMOpenAPIExampleContainer::SetMySign (  const TGameSign  aMySign  ) 
 

SetMySign. Sets the players own graphical sign either cross or zero

Parameters:
aMySign Users own sign

Definition at line 279 of file IMOpenAPIExampleContainer.cpp.

References iImageFileName, iMySign, and LoadMySignBMPL().

00280         {
00281         iMySign = mysign;
00282         LoadMySignBMPL(iImageFileName);
00283         DrawNow();      
00284         }

void CIMOpenAPIExampleContainer::SetGameView (  const TGameState  aDesiredView  ) 
 

SetGameView. Sets the complete game view according the the give state of the game

Parameters:
aDesiredView state of the game

Definition at line 290 of file IMOpenAPIExampleContainer.cpp.

References iGamesGrid, iMySign, iSignIndicator, iTurnIndicator, CIMOpenAPIExampleGrid::ResetGrid(), and SizeChanged().

00291         {
00292     TBuf<25> iTurnIndicatorString(KNullDesC);
00293         TBuf<25> iSignIndicatorString(KNullDesC);
00294     
00295         switch (desiredView)
00296                 {
00297                 case EStateNotLogin:
00298                         iGamesGrid->MakeVisible(EFalse);
00299                         iSignIndicator->MakeVisible(EFalse);
00300                         StringLoader::Load ( iTurnIndicatorString, R_INFO_MSG_NOT_LOGGEDIN );
00301                         iTurnIndicator->SetTextL(iTurnIndicatorString);
00302                         break;
00303 
00304                 case EStateLoginIdle:
00305                         iGamesGrid->MakeVisible(EFalse);
00306                         iSignIndicator->MakeVisible(EFalse);
00307                         StringLoader::Load ( iTurnIndicatorString, R_INFO_MSG_LOGIN_SUCCESS );
00308                         iTurnIndicator->SetTextL(iTurnIndicatorString);
00309                         break;
00310 
00311                 case EStateChallenged:
00312                         iGamesGrid->MakeVisible(EFalse);
00313                         iSignIndicator->MakeVisible(EFalse);
00314                         StringLoader::Load ( iTurnIndicatorString, R_INFO_MSG_WAITING_FOR_REPLY );
00315                         iTurnIndicator->SetTextL(iTurnIndicatorString);
00316                         break;
00317 
00318                 case EStateReadytoStart:
00319             {
00320                         iGamesGrid->MakeVisible(ETrue);
00321             iGamesGrid->SetDimmed(ETrue);
00322                         iSignIndicator->MakeVisible(ETrue);
00323                         StringLoader::Load ( iSignIndicatorString, R_INFO_MSG_YOUR_SIGN_IS );
00324                         iSignIndicator->SetTextL(iSignIndicatorString);
00325             if (iMySign == ECrossSign)
00326                 StringLoader::Load ( iTurnIndicatorString, R_INFO_MSG_START_GAME );
00327             else
00328                 StringLoader::Load ( iTurnIndicatorString, R_INFO_MSG_WAITING_OPP_TO_START );
00329                         iTurnIndicator->SetTextL(iTurnIndicatorString);
00330                         iGamesGrid->ResetGrid();
00331                         break;
00332             }
00333 
00334                 case EStateWaitingForOppMove:
00335                         iGamesGrid->MakeVisible(ETrue);
00336                         iGamesGrid->SetDimmed(ETrue);
00337                         iSignIndicator->MakeVisible(ETrue);
00338                         StringLoader::Load ( iSignIndicatorString, R_INFO_MSG_YOUR_SIGN_IS );
00339                         iSignIndicator->SetTextL(iSignIndicatorString);
00340                         StringLoader::Load ( iTurnIndicatorString, R_INFO_MSG_OPPONENT_MOVE );
00341                         iTurnIndicator->SetTextL(iTurnIndicatorString);
00342                         break;
00343 
00344 
00345                 case EStateWaitingForOwnMove:
00346                         iGamesGrid->MakeVisible(ETrue);
00347                         iGamesGrid->SetDimmed(EFalse);
00348                         iSignIndicator->MakeVisible(ETrue);
00349                         StringLoader::Load ( iSignIndicatorString, R_INFO_MSG_YOUR_SIGN_IS );
00350                         iSignIndicator->SetTextL(iSignIndicatorString);
00351                         StringLoader::Load ( iTurnIndicatorString, R_INFO_MSG_YOUR_MOVE );
00352                         iTurnIndicator->SetTextL(iTurnIndicatorString);
00353                         break;
00354 
00355                 default:
00356                         break;
00357                 }
00358 
00359         SizeChanged();
00360         DrawNow();
00361         return;
00362         }

void CIMOpenAPIExampleContainer::SetModel (  CIMOpenAPIExamplemodel *  aModel  ) 
 

SetModel. Sets the pointer to model

Parameters:
aModel pointer to CIMOpenAPIExamplemodel

Definition at line 368 of file IMOpenAPIExampleContainer.cpp.

References iModel.

00369     {
00370     iModel = aModel;
00371     }

void CIMOpenAPIExampleContainer::PlayMove (   ) 
 

PlayMove. Plays a move at focused grid index only if that position is empty

Definition at line 255 of file IMOpenAPIExampleContainer.cpp.

References iGamesGrid, iModel, iMySign, CIMOpenAPIExamplemodel::IsIndexPositionEmpty(), CIMOpenAPIExamplemodel::SendPlayedIndex(), and SetCellSign().

00256     {
00257     TInt currentIndex = iGamesGrid->CurrentDataIndex();
00258     if ( iModel->IsIndexPositionEmpty(currentIndex) )
00259         {
00260         SetCellSign(iMySign, currentIndex);
00261         iModel->SendPlayedIndex(currentIndex);
00262         }
00263     }

void CIMOpenAPIExampleContainer::ActivateL (   ) 
 

ActivateL. From CCoeControl

Definition at line 377 of file IMOpenAPIExampleContainer.cpp.

References iCba.

00378         {
00379         CCoeControl::ActivateL();
00380         if(iCba)
00381                 {
00382                 iCba->DrawableWindow()->SetOrdinalPosition(0);
00383                 }
00384         else
00385                 {
00386                 iAvkonAppUi->Cba()->DrawableWindow()->SetOrdinalPosition(0);
00387                 }
00388         }

void CIMOpenAPIExampleContainer::SizeChanged (   ) 
 

From CoeControl,SizeChanged.

Definition at line 122 of file IMOpenAPIExampleContainer.cpp.

References iGamesGrid, iSignIndicator, and iTurnIndicator.

00123     {
00124     TSize selectedImageSize( 91, 91);
00125     TPoint selectedImageTopLeft( 70, 80 );
00126         
00127         iTurnIndicator->SetExtent( TPoint(1,2), iTurnIndicator->MinimumSize() );
00128     iSignIndicator->SetExtent( TPoint(1,30), iSignIndicator->MinimumSize() );
00129         
00130     if (iGamesGrid)
00131                 {
00132                 iGamesGrid->SetExtent (selectedImageTopLeft,selectedImageSize);
00133                 }
00134 
00135     }

TInt CIMOpenAPIExampleContainer::CountComponentControls (   )  const
 

From CoeControl,CountComponentControls.

Definition at line 141 of file IMOpenAPIExampleContainer.cpp.

00142     {
00143     return 3; // return nbr of controls inside this container
00144     }

CCoeControl * CIMOpenAPIExampleContainer::ComponentControl (  TInt  aIndex  )  const
 

From CCoeControl,ComponentControl.

Definition at line 150 of file IMOpenAPIExampleContainer.cpp.

References iGamesGrid, iSignIndicator, and iTurnIndicator.

00151     {
00152     switch ( aIndex )
00153         {
00154         case 0:
00155             return iTurnIndicator;
00156         case 1:
00157             return iSignIndicator;
00158         case 2:
00159                         return iGamesGrid;
00160         default:
00161             return NULL;
00162         }
00163     }

void CIMOpenAPIExampleContainer::Draw (  const TRect &  aRect  )  const
 

From CCoeControl,Draw.

Definition at line 169 of file IMOpenAPIExampleContainer.cpp.

References iMySignBMP.

00170     {
00171     CWindowGc& gc = SystemGc();
00172 
00173     gc.SetPenStyle( CGraphicsContext::ESolidPen );
00174     gc.SetBrushColor( KRgbGreen );
00175     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
00176     gc.DrawRect( aRect );
00177 
00178         // Drawing my sign
00179         TSize selectedImageSize( 15, 15 );
00180     TPoint selectedImageTopLeft( 160, 35 );
00181         TRect mySignPlace( selectedImageTopLeft, selectedImageSize );
00182     gc.DrawBitmap( mySignPlace, iMySignBMP );
00183 
00184 
00185     }

void CIMOpenAPIExampleContainer::HandleControlEventL (  CCoeControl *  aControl,
TCoeEvent  aEventType
) 
 

From MCoeControlObserver Acts upon changes in the hosted control's state.

Parameters:
aControl The control changing its state
aEventType The type of control event

Definition at line 192 of file IMOpenAPIExampleContainer.cpp.

00194     {
00195     }

TKeyResponse CIMOpenAPIExampleContainer::OfferKeyEventL (  const TKeyEvent &  aKeyEvent,
TEventCode  aType
) 
 

From CCoeControl. Sets the complete game view according the the give state of the game

Definition at line 224 of file IMOpenAPIExampleContainer.cpp.

References iGamesGrid, and PlayMove().

00225         {
00226         
00227         // if it's not an event key we're not interested so return not consumed
00228         if (aType != EEventKey)
00229                 return EKeyWasNotConsumed;
00230         
00231         TInt code = aKeyEvent.iCode;
00232 
00233     if ( iGamesGrid && ( !iGamesGrid->IsDimmed() ) ) //&& iGamesGrid->IsFocused()) 
00234         {
00235         if ( code == EKeyOK)
00236             {
00237             PlayMove();
00238             return( EKeyWasConsumed );
00239             }
00240                 else
00241                     {
00242                         TKeyResponse returnValue = iGamesGrid->OfferKeyEventL( aKeyEvent, aType );
00243                     DrawNow();
00244                     return returnValue;
00245             }
00246         }
00247         
00248         return EKeyWasNotConsumed;
00249         }

void CIMOpenAPIExampleContainer::LoadMySignBMPL (  const TDesC &  aImageFile  )  [private]
 

LoadMySignBMPL. Load the MBM file with given filename. MBM file contains images used in this application

Parameters:
aImageFile filename

Definition at line 202 of file IMOpenAPIExampleContainer.cpp.

References iCrossSign, iEmptySign, iMySign, iMySignBMP, and iZeroSign.

00203         {
00204         TInt err;
00205 
00206     err = iCrossSign->Load( aImageFile, 0, ETrue);
00207         User::LeaveIfError(err);
00208 
00209     err = iZeroSign->Load( aImageFile, 1, ETrue);
00210         User::LeaveIfError(err);
00211 
00212     err = iEmptySign->Load( aImageFile, 2, ETrue);
00213         User::LeaveIfError(err);
00214 
00215     err = iMySignBMP->Load( aImageFile, iMySign, ETrue);
00216         User::LeaveIfError(err);
00217 
00218         }


Member Data Documentation

CEikLabel* CIMOpenAPIExampleContainer::iTurnIndicator [private]
 

iTurnIndicator. Pointer to CEikLabel, a text label which shows whos turn it is

Definition at line 154 of file IMOpenAPIExampleContainer.h.

CEikLabel* CIMOpenAPIExampleContainer::iSignIndicator [private]
 

iSignIndicator. Pointer to CEikLabel, shows the players own sign text label

Definition at line 160 of file IMOpenAPIExampleContainer.h.

CFbsBitmap* CIMOpenAPIExampleContainer::iCrossSign [private]
 

iCrossSign. Pointer to CFbsBitmap, Graphic of cross sign

Definition at line 166 of file IMOpenAPIExampleContainer.h.

CFbsBitmap* CIMOpenAPIExampleContainer::iZeroSign [private]
 

iZeroSign. Pointer to CFbsBitmap, Graphic of circle sign

Definition at line 172 of file IMOpenAPIExampleContainer.h.

CFbsBitmap* CIMOpenAPIExampleContainer::iEmptySign [private]
 

iEmptySign. Pointer to CFbsBitmap, Graphic of an empty sign

Definition at line 178 of file IMOpenAPIExampleContainer.h.

CFbsBitmap* CIMOpenAPIExampleContainer::iMySignBMP [private]
 

iMySignBMP. Pointer to CFbsBitmap, Graphic of user's own sign, cross or circle

Definition at line 184 of file IMOpenAPIExampleContainer.h.

TGameSign CIMOpenAPIExampleContainer::iMySign [private]
 

iMySign. User's own sign in enum format

Definition at line 190 of file IMOpenAPIExampleContainer.h.

TFileName CIMOpenAPIExampleContainer::iImageFileName [private]
 

iImageFileName. Name of the image file where images used by this application are stored

Definition at line 196 of file IMOpenAPIExampleContainer.h.

CIMOpenAPIExamplemodel* CIMOpenAPIExampleContainer::iModel [private]
 

iModel. Pointer to CIMOpenAPIExamplemodel

Definition at line 202 of file IMOpenAPIExampleContainer.h.

CIMOpenAPIExampleGrid* CIMOpenAPIExampleContainer::iGamesGrid [private]
 

iGamesGrid. Pointer to CIMOpenAPIExampleGrid, container hold this object

Definition at line 208 of file IMOpenAPIExampleContainer.h.

CEikButtonGroupContainer* CIMOpenAPIExampleContainer::iCba [private]
 

iCba. To help draw screen correctly

Definition at line 214 of file IMOpenAPIExampleContainer.h.


© Nokia 2006

Back to top