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.

This begins by creating a new window, and then setting its rectangle (relative to the screen)<br />

to the client area rectangle passed as a parameter. From this point, I use Rect() to find<br />

coordinates relative to the window. This rectangle is smaller than the screen area, as it<br />

doesn't include the areas for menus, toolbars, status bars, and so on.<br />

SetCursor(0,0) sets the board cursor to the top-left square. Set-ZoomL(1000) then<br />

sets the initial zoom factor to one-to-one, using code that we'll look at closely in the next<br />

section. This code calculates all the rectangles used for drawing and pointer event handling.<br />

I then activate the app view window, so that it will respond to draw requests and input<br />

events.<br />

To complete setup, the view needs to know what fleet object to draw and who to tell about<br />

input events. The controller is the object to supply this information, which it does by calling<br />

SetController().<br />

void CFleetView::SetController(TFleet& aFleet, MGameViewCmdHandler&<br />

aCmdHandler)<br />

{<br />

iCmdHandler=&aCmdHandler;<br />

iFleet=&aFleet;<br />

}<br />

This simply stores the pointers to the fleet object and the interface, implemented by the<br />

controller that handles the player's shots at the fleet.<br />

9.4.2 Drawing the View<br />

Many of the CFleetView data members contain sizes that are used for drawing the view.<br />

Shortly, I'll cover how those data members are initialized. First, though, I'll show the drawing<br />

code. The Draw() function draws the view in three stages:<br />

void CFleetView::Draw(const TRect&) const<br />

{<br />

DrawOutside();<br />

DrawBorders();<br />

DrawTiles();<br />

}<br />

DrawOutside() whites out the region outside the board, so that – as required by the<br />

Draw() contract – the entire control is drawn.<br />

DrawBorders() draws the top, bottom, left, and right border around the sea area:<br />

void CFleetView::DrawBorders() const<br />

{<br />

DrawHorizontalBorder(iTopBorder);<br />

DrawHorizontalBorder(iBottomBorder);<br />

DrawVerticalBorder(iLeftBorder);<br />

DrawVerticalBorder(iRightBorder);<br />

}

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

Saved successfully!

Ooh no, something went wrong!