home *** CD-ROM | disk | FTP | other *** search
- ' **************************************************************************
- '
- ' M O U S E X . B A S
- '
- ' This program serves as an example of mouse programming using the QBSCR
- ' libraries. It is the same example referenced in chapter 11, "Mouse
- ' Programming Techniques," of the QBSCR 2.0 documentation.
- '
- ' This program, all source code, libraries, and executables, are copyright
- ' (c) 1992 by Tony Martin
- '
- ' Compilation Instructions:
- ' -------------------------
- ' Load this program into QB with the following command:
- '
- ' QB MOUSEX.BAS /L QBSCR20
- '
- ' You may then compile it to an EXE or run it from the environment.
- '
- ' **************************************************************************
-
- ' ***
- ' *** Load the QBSCR inlude files.
- ' ***
- '$INCLUDE: 'qbscr.inc'
- '$INCLUDE: 'mouse.bi'
-
- ' ***
- ' *** First, determine if the mouse exists. If not, display a message and
- ' *** exit.
- ' ***
- mouseExists% = MouseInit%
- IF (mouseExists% = FALSE) THEN
- PRINT "Sorry, but a mouse, which is required for this program, was not detected."
- END
- END IF
-
- ' ***
- ' *** If the machine we're running on can display color, then set our color
- ' *** variables to interesting values. If not, then set them to monochrome.
- ' ***
- IF ColorChk THEN
- fg% = 7
- bg% = 1
- ELSE
- fg% = 0
- bg% = 7
- END IF
-
- ' ***
- ' *** Display a window for the status information.
- ' ***
- MakeWindow 10, 16, 15, 65, fg%, bg%, 0, 0, -1, 0, " Mouse Example "
- Center " Hit any mouse button to exit ", 15
-
- ' ***
- ' *** Determine and display initial mouse position. The vx%, vy% pair
- ' *** store the mouse VIRTUAL SCREEN coordinates. The real screen coords
- ' *** will be calculated and then displayed. And, as long as we're at it,
- ' *** we'll save the current position so we can use it later, when we want
- ' *** to know when to update our display information.
- ' ***
- MousePosition vx%, vy%
- LOCATE 12, 20, 0
- PRINT "Virtual Coords: X:"; vx%; " Y:"; vy%; " ";
- LOCATE 13, 20, 0
- PRINT "Real Coords: X:"; (vx% \ 8) + 1; " Y:"; (vy% \ 8) + 1; " ";
- oldvx% = vx%
- oldvy% = vy%
-
- ' ***
- ' *** Clear out any mouse button presses from the mouse buffers.
- ' ***
- MouseButtonPressInfo LEFTBUTTON, numLeftPresses%, vx%, vy%
- MouseButtonPressInfo RIGHTBUTTON, numRightPresses%, vx%, vy%
- numLeftPresses% = 0
- numRightPresses% = 0
-
- ' ***
- ' *** Now we're finally ready to sit and wait on mouse events. Since we're
- ' *** done displaying for the moment, we can show the mouse cursor, which
- ' *** will be done before the loop starts. Then we'll watch for mouse button
- ' *** presses to tell the loop when to end. All the while we'll be watching
- ' *** for changes in the mouse location. If it changes, then we'll update
- ' *** the display with new position information.
- ' ***
- done% = FALSE
- MouseShow
- WHILE done% = FALSE
-
- ' ***
- ' *** First thing to do in our loop is look for mouse movement. If it
- ' *** has moved, update the display with new position info.
- ' ***
- MousePosition vx%, vy%
- IF (vx% <> oldvx%) OR (vy% <> oldvy%) THEN
- MouseHide ' *** Turn mouse off while we display.
- LOCATE 12, 20, 0
- PRINT "Virtual Coords: X:"; vx%; " Y:"; vy%; " ";
- LOCATE 13, 20, 0
- PRINT "Real Coords: X:"; (vx% \ 8) + 1; " Y:"; (vy% \ 8) + 1; " ";
- MouseShow ' *** Turn Mouse back on.
- oldvx% = vx% ' *** Update old position variables.
- oldvy% = vy%
- END IF
-
- ' ***
- ' *** Now check to see if either mouse button has been pressed. If so,
- ' *** then set done% to TRUE, so the loop, and thus the program, will end.
- ' ***
- MouseButtonPressInfo 0, numLeftPresses%, vx%, vy%
- MouseButtonPressInfo 1, numRightPresses%, vx%, vy%
- IF (numRightPresses% <> 0) OR (numLeftPresses% <> 0) THEN
- done% = TRUE
- END IF
-
- WEND
-
- ' ***
- ' *** At this point, our program is done running, and we need only to do a
- ' *** little clean up. We will turn the mouse off, clear the screen, and
- ' *** then end.
- ' ***
- MouseHide
- COLOR 7, 0
- CLS
- END
-
-