Game Development Reference
In-Depth Information
{
// Left mouse button or touch screen released
}
}
return 0;
}
// We use this to register the callback function…
s3ePointerRegister(S3E_POINTER_BUTTON_EVENT,
(s3eCallback) ButtonEventCallback, NULL);
// …and this to cancel notifications
s3ePointerUnRegister(S3E_POINTER_BUTTON_EVENT,
(s3eCallback) ButtonEventCallback);
The button event callback's first parameter is a pointer to an
s3ePointerEvent
structure that contains four members. The button that was pressed is stored in a
member called
m_Button
that is of the type
s3ePointerButton
(see the table in
the
Detecting single touch input using polling
section earlier in this chapter for more
details on this enumerated type).
The
m_Pressed
member will be
0
if the button was released and
1
if it was
pressed. You might expect this to be of type
bool
rather than an integer but it
isn't, because this is a C-based API, not C++-based and
bool
is not a part of the
standard C language.
We can also discover the screen position where the event occurred by using the
structure's
m_x
and
m_y
members.
It is also possible to register a callback that will inform us when the user
has performed a pointer motion. We again use the
s3ePointerRegister
/
s3ePointerUnRegister
functions, but this time use
S3E_POINTER_MOTION_EVENT
as the callback type.
The callback function we register will be passed a pointer to an
s3ePointerMotionEvent
structure that consists of just
m_x
and
m_y
members
containing the screen coordinate that is now being pointed at.
Detecting multi-touch input
A multi-touch capable display allows us to detect more than one touched point on
the screen at a time. Every time the screen is touched, the device's OS will assign
that touch point an ID number. As the user moves their finger around the screen, the
coordinates associated with that ID number will be updated until the user removes
their finger from the screen, whereupon that touch will become inactive and the ID
number becomes invalid.
Search WWH ::
Custom Search