home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / tipi / mouse.tpi < prev    next >
Text File  |  1993-11-02  |  2KB  |  99 lines

  1. # MOUSE.TPI
  2. # Demos the use of the MOUSE instruction
  3. # 9/21/93 by Kent Peterson
  4.  
  5.  
  6. define InitMouse ( -- n )
  7. # Checks if a mouse is available and initializes it.
  8. # This should be called before you try to do anything
  9. # with a mouse.
  10. # If n is 0, there is no mouse
  11.  0 0 0 0 mouse
  12.  drop drop drop
  13. enddef
  14.  
  15. define MouseButtons ( -- n )
  16. # Returns the current state of the mouse buttons
  17. # if n = 0 no buttons are pressed
  18. # if n = 1 the left button is pressed
  19. # if n = 2 the right button is pressed
  20. # if n = 3 both buttons are pressed
  21.  3 0 0 0 mouse
  22.  drop drop swap drop
  23. enddef
  24.  
  25. define MouseCol ( -- col )
  26. # Returns the column of the mouse cursor
  27.  3 0 0 0 mouse
  28.  drop swap drop swap drop 8 /
  29. enddef
  30.  
  31. define MouseRow ( -- row )
  32. # Returns the row of the mouse cursor
  33.  3 0 0 0 mouse
  34.  swap drop swap drop swap drop 8 /
  35. enddef
  36.  
  37. define ShowMouse ( -- )
  38. # Makes the mouse cursor visible
  39.  1 0 0 0 mouse
  40.  drop drop drop drop
  41. enddef
  42.  
  43. define HideMouse ( -- )
  44. # Makes the mouse cursor visible
  45.  2 0 0 0 mouse
  46.  drop drop drop drop
  47. enddef
  48.  
  49. define StackVoodoo ( n m x -- )
  50. # This is a weird little instruction to put the stack
  51. # into the proper form and then calls MOUSE.
  52.  rot rot 0 rot 8 * rot 8 * swap
  53.  mouse drop drop drop drop
  54. enddef
  55.  
  56. define MouseLocate ( row col -- )
  57. # Places the mouse at row, col.
  58.  4 StackVoodoo
  59. enddef
  60.  
  61. define MouseRowLimit ( leftrow rightrow -- )
  62. # Limits the mouse travel to the area from leftrow to rightrow.
  63.  8 StackVoodoo
  64. enddef
  65.  
  66. define MouseColLimit ( leftcol rightcol -- )
  67. # Limits the mouse travel to the area from leftcol to rightcol.
  68.  7 StackVoodoo
  69. enddef
  70.  
  71.  
  72. InitMouse not if "No Mouse!" print$ bye endif
  73.  
  74. 5 20 MouseRowLimit
  75. 10 70 MouseColLimit
  76.  
  77. 10 45 MouseLocate
  78.  
  79. 0 cursor # hide the normal cursor
  80. ShowMouse
  81.  
  82. cls
  83. "Press any key to end the program" print$
  84.  
  85. begin
  86.  2 0 locate "Mouse Row is " print$ MouseRow print "  " print$ cr
  87.             "Mouse Column is " print$ MouseCol print "  " print$ cr
  88.             "The following buttons are pressed " print$
  89.       MouseButtons
  90.       case 1 of "LEFT " endof
  91.            2 of "RIGHT" endof
  92.            3 of "BOTH " endof
  93.            default "NONE "
  94.       endcase
  95.       print$
  96. key until
  97. HideMouse
  98. 1 cursor
  99.