Graphics Reference
In-Depth Information
1.5
Servicing of Events
As we have seen, event service routines handle events forwarded to our applica-
tion. These routines are the core of our programming solution. In the presence of
relevant events, the MainEventLoop() calls these functions and passes the con-
trol back to our program code. For this reason, these service routines are also
referred to as callback functions.
1.5.1
Registration of Event Service Routines
An application program registers callback functions with the GUI system by pass-
ing the address of the function to the GUI system. This is the registration mecha-
nism implied in Listing 1.5. Simple GUI systems (e.g., GLUT or FLTK) usually
support this form of registration mechanism. The advantage of this mechanism is
that it is easy to understand, straightforward to program, and often contributes to
a small memory footprint in the resulting program. The main disadvantage of this
mechanism is the lack of organizational structure for the callback functions.
In commercial GUI systems, user applications typically must work with a
large number of events. A structured organization of the service routines can
greatly increase the programmability of the GUI system. Modern commercial
GUI systems often present their APIs through an object-oriented language inter-
face (e.g., C++ for MFC, Java for Java Swing). For these systems, many event
service routines are integrated as methods in the class hierarchies of the GUI sys-
tem. In these cases, registration of event service routines may be implemented as
subclassing and overriding corresponding virtual functions in the GUI system. In
this way, the event service routines are organized according to the functionality of
GUI elements.
The details of the different registration mechanisms will be demonstrated in
Chapter 2 when we examine the implementation details.
1.5.2
Characteristics of Event Service Routines
Event service routines are simply functions in our program. However, these func-
tions also serve an important role as the server of events. The following are guide-
lines one should take into account when implementing event service routines.
• An event service routine should only service the triggering event and return
the control back to the MainEventLoop() immediately. This may seem to
be a no-brainer. However, because of our familiarity with control-driven
Search WWH ::




Custom Search