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.

TEventCode is the type of window server event that is being handled; it can be one of<br />

EEventKey, EEventKeyDown, or EEventKeyUp. For ordinary event handling, most<br />

controls are interested in EEventKey.<br />

If key down is relevant to your application, then the auto repeat count in the TKeyEvent<br />

might also be of interest. It tells you how many auto repeats you have missed since you<br />

handled the last key event.<br />

12.1.2 Handling Pointer Events<br />

Here's how COppFleetView handles pointer events:<br />

void COppFleetView::HandlePointerEventL(const TPointerEvent&<br />

}<br />

aPointerEvent)<br />

{<br />

// Check whether we're interested<br />

if(aPointerEvent.iType == TPointerEvent::EButton1Down &&<br />

iData.iSeaArea.Contains(aPointerEvent.iPosition))<br />

{<br />

// Identify the tile that was hit<br />

TInt x=(aPointerEvent.iPosition.iX-iData.iSeaArea.iTl.iX)/<br />

iData.iTileSize;<br />

TInt y=(aPointerEvent.iPosition.iY-iData.iSeaArea.iTl.iY)/<br />

iData.iTileSize;<br />

// Move cursor if necessary<br />

TBool iCursorMoved=(x!=iCursorX || y!=iCursorY);<br />

SetCursor(x,y);<br />

// Hit square unless it's already known<br />

if (iFleet.IsKnown(x,y))<br />

else<br />

}<br />

{<br />

iEikonEnv->InfoMsg(R_GAME_ALREADY_KNOWN);<br />

if (iCursorMoved)<br />

}<br />

DrawTilesNow();<br />

iData.iCmdHandler.ViewCmdHitFleet(x,y);<br />

Like OfferKeyEventL(), HandlePointerEventL() is called on a control if the<br />

framework thinks the pointer event ought to be handled. Generally, that means the control is<br />

not dimmed or invisible, and it's the control with the smallest area that surrounds the<br />

coordinates of the pointer event. Unlike OfferKeyEventL(), HandlePointerEventL()<br />

requires the control to handle the pointer event or ignore it. The event is not offered to be

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

Saved successfully!

Ooh no, something went wrong!