micedemo.cpp is a demo program that utilizes most of the mouse
functions described. main() installs the event handler, runs a text
mode demo, and a graphics mode demo. The event mask is FFh which will
trigger the handler on any mouse event. Since that includes mouse
movement, the default handler that only calls Save() is used to store
the parameters and keep execution time to a minimum.
Both demos (textdemo() and graphicdemo()) call a function that
draws the screen and another that processes mouse events. textscreen()
assumes a color video card and draws a screen with eight different
characters and colors to demonstrate how the cursor masks work. Notice
that the loop that draws the screen actually writes 50 lines of video
even though the demo starts out with 25 lines. A graphical represen-
tation of a three-button mouse is drawn to show the cursor position and
button status. After calling textscreen(), textdemo() prints the infor-
mation from the mouse.Info structure to the screen. The mouse y-limit
is set to full screen (25 lines, which is the default) and the cursor
is turned on with Show(). nexttdemo() is the processing loop for text
mode and is called with the name of text cursor structure and a title
string. nexttdemo() is called with several different cursors and also
for 43/50 line mode.
nexttdemo() first sets the text cursor and prints the title
string. It then runs a loop that process mouse events. A counter that
shows the mouse position calls xPos() and yPos() which read variables
that are continuously updated by the event handler via GetEvent().
Button status is also checked and displayed. Released() is called to
check for a left button release event which will terminate the loop if
the cursor is inside the [Next] box at the time of release. The loop
will also be terminated if the left button is double-clicked anywhere
on the screen. If the right button is double-clicked, the mouse is
disabled until any keyboard key is pressed. Pressing the <Ctrl> key
and the left button will set the global flag "done" which exits the
rest of the text demo and proceeds with the graphics demo.
graphicdemo() works the same way as textdemo(). In addition to trying several cursors, it also tests different mickey-to-pixel ratios. Notice that the ratio of 2 for the jet cursor will cause the cursor to locate on every fourth pixel as it moves across the screen. graphicscreen() paints several background colors as well as black and white boxes in the center. These boxes demonstrate the use of the cursor border created by the screen mask. A graphical representation of a three-button mouse is again drawn to show the cursor position and button status. nextgdemo() sets the graphics cursor and then processes mouse events, checking the position and button status.
The variables LBDN, CBDN, and RBDN are used to compare the cur-
rent button status against the previous button status. The color of
the screen buttons are then toggled if any button status has changed.
(This method is used to avoid screen paints in every pass through the
loop if the button status has not changed. This is not necessary in
text mode because screen writes are much faster.) Buttons are checked
for multi-clicks (up to four) and the color of the screen buttons will
reflect this. Finally, we check for a left button release and see if
the cursor is in the [Next] box, a left button triple-click, and a