Handling Input from the Screen

Some UIQ smartphones, such as the Sony Ericsson P1i, support touchscreen input, which can be used to add another mode of user interaction to a game. Screen events can be detected and handled in much the same way as keypad input, by overriding CCoeControl::HandlePointer-EventL() as shown below. In the example given, to capture events that occur in the close vicinity of a particular point on the screen, an area of the screen is constructed, ten pixels square, and centered on the point in question. When a pointer-down screen event occurs, if the point at which the tap occurred lies within the square, the user input is stored in a bitmask in the same way as for a key press.

void CSkeletonUIQView::HandlePointerEventL(const TPointerEvent&

aPointerEvent)

if (TPointerEvent::EButton1Up == aPointerEvent.iType) {// Pointer up events clear the screen iKeyState = 0x00000000; // clear all previous selections }

else if (TPointerEvent::EButton1Down == aPointerEvent.iType) {

TRect drawRect( Rect());

TInt width = drawRect.Width();

TInt height = drawRect.Height();

TPoint offset(10,10); // 10x10 square around the screen position TPoint k1(width/4, height/2);

TRect rect1(TPoint(k1-offset), TPoint(k1+offset));

if (rect1.Contains(aPointerEvent.iPosition)) {

iKeyState | = KKey1;

return; // stored the event, so return }

TPoint k2(width/2, height/2);

TRect rect2(TPoint(k2-offset), TPoint(k2+offset));

if (rect2.Contains(aPointerEvent.iPosition)) {

iKeyState | = KKey2;

return; // stored the event, so return }

... // Other numbers similarly inspected

// Pointer events for other areas of the screen are ignored // Pass them to the base class

CCoeControl::HandlePointerEventL(aPointerEvent) ; }

Figure 2.2 illustrates the Skeleton example in the UIQ emulator. The mouse is clicked and held on, or near, the '8' digit to simulate a tap and hold on the screen. The event is detected through CSkele-tonUIQView::HandlePointerEventL() as shown above for digits '1' and '2.' The iKeyState member variable is updated to reflect the screen event, and next time the game loop runs and the screen is updated, the display for that digit highlights that the stylus is held to the screen. When the stylus (or mouse click, in the case of the emulator) is released, a pointer-up event is received and the highlight is removed.

Km

d>

0s

fmm

21 fps

2

3

4

5

B

8%

9

0

More

Figure 2.2 Handling a pointer event received from a screen tap

Figure 2.2 Handling a pointer event received from a screen tap

0 0

Post a comment

  • Receive news updates via email from this site