03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

void CGameAppUi::HandleCommandL(TInt aCommand)<br />

{<br />

switch (aCommand)<br />

{<br />

case EEikCmdExit:<br />

SaveL();<br />

Exit();<br />

break;<br />

...<br />

}<br />

}<br />

This calls CEikAppUi::SaveL(), which ensures that the framework saves the document<br />

data (by calling CGameDocument::StoreL()).<br />

As we've seen, I implemented document restore by creating a new controller and deleting<br />

the old one. This means that the app UI's pointer to the controller then becomes invalid. To<br />

help the app UI cope with this type of circumstance, the framework defines a<br />

HandleModelChangeL()function, which it calls when a new document is loaded. I<br />

implement it here to get an up-to-date value for the pointer to the controller.<br />

void CGameAppUi::HandleModelChangeL()<br />

{<br />

// Change pointers to new objects<br />

iController = (STATIC_CAST(CGameDocument*, Document()))-><br />

iController;<br />

iAppView->SetController(iController);<br />

}<br />

First, I use the document to find out my new controller, and then I pass on this information to<br />

the app view. Without this, you won't keep the app UI and app view up-to-date when the<br />

model changes.<br />

9.9 Two Player Battleships<br />

You'll have gathered from the discussion so far that through the application, document, and<br />

app UI frameworks the OS knows a lot about the running applications, and that it can have<br />

quite fine control of their operations. The exception so far seems to have been the<br />

application views: they've just been ordinary control objects, about which the operating<br />

system has no special knowledge or control. To fill this gap, Symbian OS v6 introduced the<br />

view architecture, which allows the operating system and other applications to<br />

communicate directly with an application's views.<br />

I'll demonstrate how to use the view architecture by extending Solo Ships into a two-player<br />

game. In that version, there'll be two different views for each player, one that shows the<br />

opposition fleet, and one that shows the player's own fleet. Along the way, I'll also briefly<br />

look at making views more interesting by using bitmap graphics and sound.<br />

9.9.1 View Architecture

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!