|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
#include <SIPExGameContainer.h>
Public Member Functions | |
| CSIPExGameContainer (CSIPExEngine &aEngine) | |
| void | ConstructL (const TRect &aRect) |
| ~CSIPExGameContainer () | |
Private Member Functions | |
| 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) |
| void | HandleResourceChange (TInt aType) |
| TTypeUid::Ptr | MopSupplyObject (TTypeUid aId) |
| void | DrawGame (CWindowGc &aGc, const TRect &aRect) const |
| void | DrawBoard (CWindowGc &aGc, const TRect &aRect) const |
| void | DrawCursor (CWindowGc &aGc, const TRect &aRect) const |
| void | CalculateBoardDimensions (const TRect &aRect) |
Private Attributes | |
| CSIPExEngine & | iEngine |
| CAknsBasicBackgroundControlContext * | iBgContext |
| TInt | iXOffset |
| TInt | iYOffset |
| TInt | iBoxW |
| TInt | iMidW |
Definition at line 32 of file SIPExGameContainer.h.
|
|
C++ default constructor
Definition at line 38 of file SIPExGameContainer.cpp. 00039 : iEngine( aEngine ) 00040 { 00041 // no implementation required 00042 }
|
|
|
Destructor. Definition at line 70 of file SIPExGameContainer.cpp. References iBgContext. 00071 { 00072 delete iBgContext; 00073 }
|
|
|
EPOC default constructor.
Definition at line 49 of file SIPExGameContainer.cpp. References CalculateBoardDimensions(), and iBgContext. 00050 { 00051 CalculateBoardDimensions( aRect ); 00052 00053 iBgContext = 00054 CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain, 00055 aRect, 00056 ETrue ); 00057 00058 CreateWindowL(); 00059 00060 SetRect( aRect ); 00061 00062 ActivateL(); 00063 }
|
|
|
From CoeControl,SizeChanged. Definition at line 80 of file SIPExGameContainer.cpp.
|
|
|
From CoeControl,CountComponentControls. Definition at line 89 of file SIPExGameContainer.cpp.
|
|
|
From CCoeControl,ComponentControl. Definition at line 98 of file SIPExGameContainer.cpp.
|
|
|
From CCoeControl,Draw. Definition at line 107 of file SIPExGameContainer.cpp. References DrawGame(). 00108 { 00109 CWindowGc& gc = SystemGc(); 00110 00111 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); 00112 gc.SetBrushColor( KRgbWhite ); 00113 gc.Clear(); 00114 00115 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); 00116 MAknsControlContext* cc = AknsDrawUtils::ControlContext( this ); 00117 00118 AknsDrawUtils::Background( skin, cc, this, gc, aRect ); 00119 00120 DrawGame( gc, aRect ); 00121 }
|
|
||||||||||||
|
From CCoeControl, HandleControlEventL. Definition at line 264 of file SIPExGameContainer.cpp.
|
|
||||||||||||
|
From CCoeControl, OfferKeyEvent. Definition at line 275 of file SIPExGameContainer.cpp. References CSIPExEngine::CursorLeft(), CSIPExEngine::CursorPressed(), CSIPExEngine::CursorRight(), and iEngine. 00278 { 00279 if( aType == EEventKeyUp ) 00280 { 00281 switch( aKeyEvent.iScanCode ) 00282 { 00283 case EStdKeyLeftArrow: 00284 iEngine.CursorLeft(); 00285 DrawDeferred(); 00286 return EKeyWasConsumed; 00287 case EStdKeyRightArrow: 00288 iEngine.CursorRight(); 00289 DrawDeferred(); 00290 return EKeyWasConsumed; 00291 case EStdKeyDownArrow: 00292 case EStdKeyEnter: 00293 case EStdKeyDevice7: // FLOWTHROUGH 00294 iEngine.CursorPressed(); 00295 DrawDeferred(); 00296 return EKeyWasConsumed; 00297 default: 00298 return EKeyWasNotConsumed; 00299 } 00300 } 00301 00302 return EKeyWasNotConsumed; 00303 }
|
|
|
From CCoeControl, HandleResourceChange. Definition at line 310 of file SIPExGameContainer.cpp. References CalculateBoardDimensions(), and iBgContext. 00311 { 00312 CCoeControl::HandleResourceChange( aType ); 00313 00314 if ( aType == KEikDynamicLayoutVariantSwitch ) 00315 { 00316 TRect mainPaneRect; 00317 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, 00318 mainPaneRect ); 00319 SetRect( mainPaneRect ); 00320 00321 CalculateBoardDimensions( mainPaneRect ); 00322 00323 if ( iBgContext ) 00324 { 00325 iBgContext->SetRect( mainPaneRect ); 00326 } 00327 00328 DrawNow(); 00329 } 00330 }
|
|
|
From CCoeControl, MopSupplyObject. Definition at line 337 of file SIPExGameContainer.cpp. References iBgContext. 00338 { 00339 if ( aId.iUid == MAknsControlContext::ETypeId ) 00340 { 00341 return MAknsControlContext::SupplyMopObject( aId, iBgContext ); 00342 } 00343 return CCoeControl::MopSupplyObject( aId ); 00344 }
|
|
||||||||||||
|
Drawing game. Decides if the cursor or board will be drawn.
Definition at line 129 of file SIPExGameContainer.cpp. References DrawBoard(), CSIPExEngine::DrawBoard(), DrawCursor(), CSIPExEngine::DrawCursor(), and iEngine. 00130 { 00131 if( iEngine.DrawBoard() ) 00132 { 00133 DrawBoard( aGc, aRect ); 00134 00135 if( iEngine.DrawCursor() ) 00136 { 00137 DrawCursor( aGc, aRect ); 00138 } 00139 } 00140 }
|
|
||||||||||||
|
Drawing the game board
Definition at line 147 of file SIPExGameContainer.cpp. References CSIPExEngine::BoardValue(), iBoxW, iEngine, iMidW, iXOffset, and iYOffset. 00148 { 00149 CWindowGc& gc = aGc; 00150 00151 gc.SetPenSize( TSize(1,1) ); 00152 gc.SetPenStyle( CGraphicsContext::ESolidPen ); 00153 gc.SetPenColor( TRgb(0,0,0) ); 00154 gc.SetBrushColor( TRgb(0,0,255) ); 00155 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); 00156 00157 00158 TPoint p1 = aRect.iTl; 00159 p1.iX = p1.iX + iXOffset; 00160 p1.iY = p1.iY + iYOffset; 00161 00162 TPoint p2 = aRect.iBr; 00163 p2.iX = p1.iX + ( ( KBoxCountX * iBoxW ) + ( ( KBoxCountX + 1 ) * iMidW ) ); 00164 p2.iY = p1.iY + ( ( KBoxCountY * iBoxW ) + ( ( KBoxCountY + 1 ) * iMidW ) ); 00165 TRect box2 = TRect(p1, p2); 00166 gc.DrawRect( box2 ); 00167 00168 00169 gc.SetPenColor( TRgb(0,0,0) ); 00170 gc.SetBrushColor( TRgb(255,255,255) ); 00171 gc.SetPenStyle( CGraphicsContext::ESolidPen ); 00172 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); 00173 00174 for (TInt i=0 ; i < KBoxCountX; i++) 00175 { 00176 for (TInt j=0 ; j < KBoxCountY; j++) 00177 { 00178 p1 = aRect.iTl; 00179 p2 = aRect.iBr; 00180 00181 p1.iX = p1.iX + iXOffset + iMidW + (i*iMidW) + (i*iBoxW); 00182 p1.iY = p1.iY + iYOffset + iMidW + (j*iMidW) + (j*iBoxW); 00183 00184 p2.iX = p1.iX + iBoxW; 00185 p2.iY = p1.iY + iBoxW; 00186 00187 if ( iEngine.BoardValue( i, j ) == -1 ) 00188 { 00189 gc.SetBrushColor( TRgb(255,255,255) ); 00190 } 00191 else if ( iEngine.BoardValue( i, j ) == 1 ) 00192 { 00193 gc.SetBrushColor( TRgb(255,0,0) ); 00194 } 00195 else if ( iEngine.BoardValue( i, j ) == 2 ) 00196 { 00197 gc.SetBrushColor( TRgb(0,255,0) ); 00198 } 00199 else { /* Nothing to do */ } 00200 00201 TRect rect( p1, p2 ); 00202 gc.DrawEllipse( rect ); 00203 } 00204 } 00205 }
|
|
||||||||||||
|
Drawing the game cursor.
Definition at line 212 of file SIPExGameContainer.cpp. References CSIPExEngine::Cursor(), iBoxW, iEngine, iMidW, iXOffset, and iYOffset. 00213 { 00214 CWindowGc& gc = aGc; 00215 00216 gc.SetPenColor(TRgb(0,0,0)); 00217 gc.SetBrushColor(TRgb(255,0,0)); 00218 gc.SetPenStyle(CGraphicsContext::ESolidPen); 00219 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); 00220 00221 00222 TInt i = iEngine.Cursor(); 00223 00224 TPoint p1 = aRect.iTl; 00225 TPoint p2 = aRect.iBr; 00226 00227 p1.iX = p1.iX + iXOffset + iMidW + (i*iMidW) + (i*iBoxW); 00228 p1.iY = p1.iY + iYOffset - iBoxW; 00229 00230 p2.iX = p1.iX + iBoxW; 00231 p2.iY = p1.iY + iBoxW; 00232 00233 TRect rect( p1, p2 ); 00234 gc.DrawEllipse( rect ); 00235 }
|
|
|
Calculating game board dimensions.
Definition at line 241 of file SIPExGameContainer.cpp. References iBoxW, iMidW, iXOffset, and iYOffset. 00242 { 00243 TInt boxAndMid( 0 ); 00244 if ( aRect.Height() < aRect.Width() ) 00245 { 00246 boxAndMid = ( aRect.Height() ) / ( KBoxCountY + 2 ); 00247 iXOffset = ( aRect.Width() - KBoxCountX * boxAndMid ) / 2; 00248 } 00249 else 00250 { 00251 boxAndMid = aRect.Width() / ( KBoxCountX + 2 ); 00252 iXOffset = boxAndMid; 00253 } 00254 iYOffset = 2 * boxAndMid; 00255 00256 iMidW = boxAndMid / 4; 00257 iBoxW = boxAndMid - iMidW; 00258 }
|
|
© Nokia 2006 |