Introduction to GSEvent
The GSEvent structure is the standard object that describes graphics-level events to a class's event handling methods. It can be used in conjunction with the Graphics Services framework to decode details about the event having occurred.
All event methods receive a pointer to a GSEvent structure when notified of an event. The prototype for an event typically follows this standard:
- (void)eventName: (struct _ _GSEvent *)event
{
/* Event handling code */
}
Graphics Services
Whenever an event is received, the object communicates with Graphics Services to get the specifics of the event. The Graphics Services framework provides many different decoding functions to extract the event's details.
Event location
For one-fingered events, the GSEventGetLocationInWindow function returns a CGPoint structure containing the X, Y coordinates where the event occurred. These coordinates are generally offset to the position of the window that received the event. For example, if a window located at the bottom half of the screen, whose origin was 0×240, received an event at 0×0, this means the event actually took place at 0×240 on the screen, which is where the window's 0×0 origin is located.
The GSEventGetLocationInWindow method returns a CGPoint structure, which you can unpack as follows:
CGPoint point = GSEventGetLocationInWindow(event); float x = point.x; float y = point.y;
If a two-fingered gesture is being used, you must call two separate functions to obtain the window coordinates ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access