Graphics Reference
In-Depth Information
The view component is in charge of initiating the drawing to the drawing area
on the application window (e.g., drawing the free-falling balls). More specifically,
the view component is responsible for initializing the graphics API transformation
such that drawing of the model's graphical primitives will appear in the appropri-
ate drawing area. The arrow from the view to the model component in Figure 5.1
signifies that the actual application state redraw must be performed by the model
component. Only the model component knows the details of the entire application
state (e.g., size and location of the free-falling circles), so only the model compo-
nent can redraw the entire application. The view component is also responsible
for transforming user mouse-click positions to a coordinate system that the model
understands (e.g., mouse button clicks for dragging out the HeroBall ).
The top-left external events arrow in Figure 5.1 shows that all external events
are handled by the MainEventLoop() . The relevant events will be forwarded to
the event service routines in the controller component. Because the controller
component is responsible for interacting with the user, the design is typically
based on the event-driven programming model. The solution presented in Sec-
tion 1.6 and the event service routines from Listing 1.7 is an example of a con-
troller component implementation. The arrow from the controller to the model
indicates that most external events eventually change the model component (e.g.,
creating a new HeroBall or changing the current HeroBall velocity). The arrow
from the controller to the view component indicates that the user input point trans-
formation is handled by the view component. Controllers typically return mouse-
click positions in the hardware coordinate system.
In the application model, it is
Hardware coordinate. Re-
call that hardware coordinate
is defined to be one where the
origin is located at the top-left
corner.
more convenient for us to work with a coordinate system with a lower-left origin.
The view component with its transformation functionality has the knowledge to
perform the necessary transformation.
Because the model must understand the transformation set up by the view,
it is important that the model and the view components are implemented based
on the same graphics API. However, this sharing of an underlying supporting
API does not mean that the model and view are an integrated component. On
the contrary, as will be discussed in the following sections, it is advantageous to
clearly distinguish between these two components and to establish well-defined
interfaces between them.
5.2
Applying MVC to the Ball-Shooting Program
With the described MVC framework and the understanding of how responsibili-
ties are shared among the components, we can now refine the solution presented
in Listing 1.7 and complete the design of the ball-shooting program.
Search WWH ::




Custom Search