Graphics Reference
In-Depth Information
Inconsistent state. When a user adjusts the radius control slider bar, for
a short amount of time, the state of the model (radius of the small circle)
and that of the GUI elements (slider bar value) will be inconsistent. This
is because we do not update the model's state during event services in the
CCircleRadiusControls class. Instead, this update is deferred until the
timer service routine. Because the timer goes off every 25 msec, the user
cannot notice this inconsistency. The advantage of this approach is that the
model and the controller are loosely coupled and it is easy for maintenance
and upgrade.
Paint/Redraw event. Since we are triggering redraw at 25 msec intervals,
the user always sees an up-to-date display. There is no need to service the
Paint/Redraw events.
Tutorial 5.2. Processing Mouse Events
Tutorial 5.2.
Project Name:
D3D _ MouseInput
Library Support:
UWBGL _ MFC _ Lib1
UWBGL _ D3D _ Lib2
Goals. Become familiar with the controller functionality of the Window
Handler class: processing the mouse events.
Approach. Design and develop a simple application with simple mouse
events. This tutorial is a simple circle editor, where:
- left mouse button click position defines the center of the circle;
- left mouse button drag defines the radius of the circle to be from the
center to the current mouse position;
- right mouse button click/drag moves the center of circle to the current
mouse position;
- the application must display the up-to-date circle for the user at all
times.
Figure 5.7.
Tutorial 5.2.
The Model
Hardware coordinate. Re-
call that the mouse positions
returned to us are defined with
origin located at the top-left
corner, whereas our output de-
vice coordinate system has the
origin at the lower-left cor-
ner. In the Win32 environ-
ment, the WindowsClient co-
ordinate also defined the ori-
gin to be the top-left corner.
Figure 5.7 is a screenshot of editing a circle with Tutorial 5.2. From the above
event specifications, we know that the model component of Tutorial 5.2 should
look like Listing 5.12, which shows that the CModel class has a single circle and
has an interface that supports the creation, resizing, and moving of the circle.
The Controller
Design. With the CModel designed as shown in Listing 5.12, the mouse event
services can now be defined as in Listing 5.13.
 
Search WWH ::




Custom Search