Graphics Reference
In-Depth Information
For many of us, when we were first introduced to computer programming, we
learned that the program should always start and end with the main() function—
when the main() function returns, all the work must have been completed and
the program terminates. Since the overall control remains internal to the main()
function during the entire lifetime of the program, this approach to solving prob-
lems is referred to as the control-driven programming or the internal control
model approach. As we will see, an alternative paradigm, event-driven program-
ming or an external control model approach, is the more appropriate way to design
solutions to interactive programs.
In this chapter, we will first formulate a solution to the (2D) ball-shooting pro-
gram based on the perhaps more familiar control-driven programming model. We
will then analyze the solution, identify shortcomings, and describe the motivation
for the external control model or event-driven programming approach.
An event-driven program that interacts with users requires the support of a
graphical user interface (GUI) system. A GUI system implements standard func-
tionality of event-driven user-interactive programs and presents this functionality
as a software library through an application programming interface (API). Exam-
ples of GUI APIs include Java Swing Library, OpenGL Utility ToolKit (GLUT),
The Fast Light ToolKit (FLTK), and Microsoft Foundation Classes (MFC).
Through the discussion in this chapter, we will gain insights into GUI systems.
We will understand the standard functionality of event-driven user-interactive pro-
grams and the functionality that the GUI API must include. In the next chapter,
we will look at examples of popular modern GUI APIs, analyze how these GUI
systems support concepts learned in this chapter, and experiment with implement-
ing programs with these GUI APIs.
The pseudocode that follows is C++/Java-like. We assume typical function-
ality from the operating system ( OperatingSystem:: ) and from a GUI system
( GUISystem:: ). The purpose of the pseudocode is to assist us in analyzing the
foundation control structure (i.e., if/while/case) of the solution. For this rea-
son, the details of application- and graphics-specific operations are intentionally
glossed over. For example, the details of how to implement UpdateSimulation()
are purposely omitted.
1.1
Control-Driven Programming
The main advantage of control-driven programming is that it is fairly straightfor-
ward to translate a verbal description of a solution to a program control structure.
In this case, we verbalize our solution as follows:
Search WWH ::




Custom Search