Graphics Reference
In-Depth Information
(C): UpdateSimulation()
// Draw the new Hero Ball that is currently being defined
(D): DrawBalls(AllWorldBalls)
if (DefiningNewHeroBall)
(D1): DrawBalls(HeroBall)
// Sets Status Bar with number of balls currently on screen
(E): EchoToStatusBar
} // end of while(UserAction != Quit)
} // end of main() function. Program terminates.
Listing 1.2. (cont.)
As we add additional details to parse and execute the user's commands (B), the
solution must be expanded.The revised solution in Listing 1.2 shows the details
of a central parsing switch statement (B) and the support for all three commands
a user can issue: defining a new HeroBall (B1), selecting a HeroBall (B2), and
adjusting the current HeroBall velocity with the slider bars (B3). Undefined user
actions (e.g., mouse movement with no button pressed) are simply ignored (B4).
Notice that HeroBall creation (B1) involves three user actions: mouse down
(B1), followed by mouse drag (B1-1), and finally mouse up (B1-2). The parsing
of this operation is performed in multiple consecutive passes through the outer
while-loop (A): the first time through, we create the new HeroBall (B1); in the
subsequent passes, we process the actual dragging operation (B1-1). We assume
that mouse drag (B1-1) will never be invoked without the mouse-button-down
(B1) action, and thus the HeroBall is always defined during the dragging opera-
tion. The LeftMouseButtonUp action (B1-2) is an implicit action not defined in
the original specification.
In our implementation, we choose this implicit action to activate the insertion
of the new HeroBall into the AllWorldBalls set. In this way, the HeroBall is
not a member of the AllWorldBalls set until the user has completed the dragging
operation. This delay ensures that the HeroBall 's velocity and position will not
be affected when the UpdateSimulation() procedure updates each ball in the
AllWorldBalls set (C). This means that a user can take the time to drag out a
new HeroBall without worrying that the ball will free fall before the release of the
mouse button. The simple change in the drawing operation (D1) ensures proper
drawing of the new HeroBall before it is inserted into the AllWorldBalls set.
Search WWH ::




Custom Search