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.

So far, we have suggested that you only need Draw() to do all your application's drawing.<br />

Draw() gets called when necessary for system- initiated redraws, and you can use<br />

DrawNow() to call Draw() for application-initiated redraws. However, there's a big problem<br />

with this simplistic approach: it makes applications impossible to use.<br />

Firstly, it makes them slow, because you do too much redrawing in response to the most<br />

trivial updates. Secondly, it makes them ugly, because the draw-everything approach usually<br />

causes unacceptable flicker while the display is drawn and redrawn.<br />

Important<br />

The art of graphics, in general, is making it look pretty. The art of onscreen<br />

graphics is redrawing quickly and without flicker – and knowing<br />

when to stop optimizing.<br />

We'll use the Battleships views to show the most important considerations involved here.<br />

Many Symbian OS applications are more complicated than Battleships and take these<br />

considerations much further than I have done. In some cases, such as layout and updating<br />

rich text, the logic is hideously complicated. Symbian OS provides a single, reusable<br />

component for this purpose – FORM – so that application authors don't have to invent their<br />

own.<br />

The most important cases for updating the views are as follows:<br />

� When we start the game, bring the game to the foreground, or reload a game, we have<br />

to draw everything.<br />

� When most events take place in the game, we have to redraw the status view.<br />

� When something is hit, we have to reflect it in a fleet view – either my fleet or the<br />

opponent's fleet.<br />

� When the cursor is moved (on the opponent's fleet view), we have to move the<br />

highlight quickly from the old cursor location to the new one.<br />

Let's examine each of these in turn.<br />

11.4.1 Drawing Everything<br />

The draw-everything situations are fairly easy. The status view is very quick to draw and I<br />

don't need to do anything special. I had more trouble with the fleet view, pictured in Figure<br />

11.7:

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

Saved successfully!

Ooh no, something went wrong!