Graphics Reference
In-Depth Information
element (i.e., which element is active). The application is responsible for creating
a controller for any region on the window for which it wants to receive events
directly from the GUI API.
5.3 Expanding the Ball-Shooting Program
One interesting characteristic of the MVC solution presented in Section 5.2 is that
the model component does not have any knowledge of the view or the controller
components. This clean interface allows us to expand our solution by inserting
additional view/controller pairs. For example, Figure 5.2 shows an extension to
the ball-shooting program given in Figure I.2. It has an additional small view next
to the quit button. The small view is exactly the same as the original large view,
except that it covers a smaller area on the application window. Listing 5.4 shows
that, with our MVC solution design, we can implement the small view by creating
a new instance of
CViewController
in the
CMainAppController
class. The
only other requirement is to define a new
CUIDrawArea
(
smallDrawingArea
).
Because this is a highly GUI API-dependent operation, as in Listing 5.3, we
defer the details of this operation to the actual implementation.
Ball-Shooting Simulation Program
Original
Large View
Small View
window area
Small
View
Velocity (X)
12.48 (Pixel/Sec)
Velocity (Y)
9.12 (Pixel/Sec)
Currently there are 5 balls on screen.
Status:
QUIT
Figure 5.2.
The ball-shooting program with large and small views.
Search WWH ::
Custom Search