home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / basic / QBSCR20.ZIP / MOUSEX.BAS < prev    next >
Encoding:
BASIC Source File  |  1992-07-08  |  4.0 KB  |  129 lines

  1. ' **************************************************************************
  2. '
  3. '                            M O U S E X . B A S
  4. '
  5. ' This program serves as an example of mouse programming using the QBSCR
  6. ' libraries.  It is the same example referenced in chapter 11, "Mouse
  7. ' Programming Techniques," of the QBSCR 2.0 documentation.
  8. '
  9. ' This program, all source code, libraries, and executables, are copyright
  10. ' (c) 1992 by Tony Martin
  11. '
  12. ' Compilation Instructions:
  13. ' -------------------------
  14. ' Load this program into QB with the following command:
  15. '
  16. '                          QB MOUSEX.BAS /L QBSCR20
  17. '
  18. ' You may then compile it to an EXE or run it from the environment.
  19. '
  20. ' **************************************************************************
  21.  
  22. ' ***
  23. ' *** Load the QBSCR inlude files.
  24. ' ***
  25. '$INCLUDE: 'qbscr.inc'
  26. '$INCLUDE: 'mouse.bi'
  27.  
  28. ' ***
  29. ' *** First, determine if the mouse exists.  If not, display a message and
  30. ' *** exit.
  31. ' ***
  32. mouseExists% = MouseInit%
  33. IF (mouseExists% = FALSE) THEN
  34.     PRINT "Sorry, but a mouse, which is required for this program, was not detected."
  35.     END
  36. END IF
  37.  
  38. ' ***
  39. ' *** If the machine we're running on can display color, then set our color
  40. ' *** variables to interesting values.  If not, then set them to monochrome.
  41. ' ***
  42. IF ColorChk THEN
  43.     fg% = 7
  44.     bg% = 1
  45. ELSE
  46.     fg% = 0
  47.     bg% = 7
  48. END IF
  49.  
  50. ' ***
  51. ' *** Display a window for the status information.
  52. ' ***
  53. MakeWindow 10, 16, 15, 65, fg%, bg%, 0, 0, -1, 0, " Mouse Example "
  54. Center " Hit any mouse button to exit ", 15
  55.  
  56. ' ***
  57. ' *** Determine and display initial mouse position.  The vx%, vy% pair
  58. ' *** store the mouse VIRTUAL SCREEN coordinates.  The real screen coords
  59. ' *** will be calculated and then displayed.  And, as long as we're at it,
  60. ' *** we'll save the current position so we can use it later, when we want
  61. ' *** to know when to update our display information.
  62. ' ***
  63. MousePosition vx%, vy%
  64. LOCATE 12, 20, 0
  65. PRINT "Virtual Coords: X:"; vx%; "  Y:"; vy%; "    ";
  66. LOCATE 13, 20, 0
  67. PRINT "Real Coords:    X:"; (vx% \ 8) + 1; "  Y:"; (vy% \ 8) + 1; "    ";
  68. oldvx% = vx%
  69. oldvy% = vy%
  70.  
  71. ' ***
  72. ' *** Clear out any mouse button presses from the mouse buffers.
  73. ' ***
  74. MouseButtonPressInfo LEFTBUTTON, numLeftPresses%, vx%, vy%
  75. MouseButtonPressInfo RIGHTBUTTON, numRightPresses%, vx%, vy%
  76. numLeftPresses% = 0
  77. numRightPresses% = 0
  78.  
  79. ' ***
  80. ' *** Now we're finally ready to sit and wait on mouse events.  Since we're
  81. ' *** done displaying for the moment, we can show the mouse cursor, which
  82. ' *** will be done before the loop starts.  Then we'll watch for mouse button
  83. ' *** presses to tell the loop when to end.  All the while we'll be watching
  84. ' *** for changes in the mouse location.  If it changes, then we'll update
  85. ' *** the display with new position information.
  86. ' ***
  87. done% = FALSE
  88. MouseShow
  89. WHILE done% = FALSE
  90.  
  91.     ' ***
  92.     ' *** First thing to do in our loop is look for mouse movement.  If it
  93.     ' *** has moved, update the display with new position info.
  94.     ' ***
  95.     MousePosition vx%, vy%
  96.     IF (vx% <> oldvx%) OR (vy% <> oldvy%) THEN
  97.         MouseHide      ' *** Turn mouse off while we display.
  98.         LOCATE 12, 20, 0
  99.         PRINT "Virtual Coords: X:"; vx%; "  Y:"; vy%; "    ";
  100.         LOCATE 13, 20, 0
  101.         PRINT "Real Coords:    X:"; (vx% \ 8) + 1; "  Y:"; (vy% \ 8) + 1; "    ";
  102.         MouseShow      ' *** Turn Mouse back on.
  103.         oldvx% = vx%   ' *** Update old position variables.
  104.         oldvy% = vy%
  105.     END IF
  106.  
  107.     ' ***
  108.     ' *** Now check to see if either mouse button has been pressed.  If so,
  109.     ' *** then set done% to TRUE, so the loop, and thus the program, will end.
  110.     ' ***
  111.     MouseButtonPressInfo 0, numLeftPresses%, vx%, vy%
  112.     MouseButtonPressInfo 1, numRightPresses%, vx%, vy%
  113.     IF (numRightPresses% <> 0) OR (numLeftPresses% <> 0) THEN
  114.         done% = TRUE
  115.     END IF
  116.  
  117. WEND
  118.  
  119. ' ***
  120. ' *** At this point, our program is done running, and we need only to do a
  121. ' *** little clean up.  We will turn the mouse off, clear the screen, and
  122. ' *** then end.
  123. ' ***
  124. MouseHide
  125. COLOR 7, 0
  126. CLS
  127. END
  128.  
  129.