i
i
i
i
i
i
i
i
19.4. Example Implementations 505
// Forward declaration of mouse event service routines
void ServiceMouse(int button, int state, int x, int y); // service mouse button click
void ServiceActiveMouse(int x, int y); // service mouse drag
class MainUIWindow {
UserInterface UI; // This is Linkage Code generated by Fluid (GUI Builder)
// This object services events geneated by GUI elements
Model *TheModel; // The application State (Figure 11)
FlGlutWindow *LargeView; // These are View/Controller pairs that understand graphics
FlGlutWindow *SmallView; // outputs (GDC) and mouse events (controller)
MainUIWindow(Model *m) { // The constructor
TheModel = m; // Sets the model …
LargeView = new FlGlutWindow(TheModel); // Create LargeView
LargeView->mouse = ServiceMouse; // callback functions for service mouse events
LargeView->motion = ServiceActiveMouse;
// Create SmallView … exactly the same as LargeView (not shown)
glutTimeFunc( // set up timer and services ) // Set up timer …
}
};
Figure 19.22. MainUIWindow based on OpenGL and FLTK.
the rest of the program source code system and is associated with Fluid (the GUI
builder). At the conclusion of the GUI layout design, Fluid generates new source
code files to be included with the rest of the application development environment.
Since these source code files are controlled and generated by the GUI builder, the
application developer must invoke the GUI builder in order to update/maintain
the event service routines. In this way, FLTK implements external service linkage
as described in Section 19.4.1. In our implementation, we instruct Fluid to create
a UserInterface class (.h and .cpp files) for the integration with the rest of our
application development environment.
Figure 19.22 shows the MainUIWindow implementation with OpenGL and
FLTK. In this case, graphics operations are performed through OpenGL and user
interface operations are supported by FLTK. As described, the UserInterface ob-
ject in the MainUIWindow is created by Fluid for servicing GUI events. The-
Model is the application state as detailed in Figure 19.11. The two FlGlutWindow
objects are based on a predefined FLTK class designed specifically for support-
ing drawing with OpenGL. The constructor of MainUIWindow shows that the
mouse event services are registered via a callback mechanism. As discussed in
Section 19.2.4, the FLTK (Fast Light ToolKit) is an example of a light weight
GUI API. Here, we see examples of using callback as a registration mechanism
for receiving user events.
FlGlutWindow is a FLTK pre-defined Fl
Glut Window class object (see Fig-
ure 19.23) designed specifically to support drawing with OpenGL. Each instance
of a FlGlutWindow object is a combination of a controller (e.g., to receive mouse
events) and a Graphics Device Context (GDC). We see that the draw() function