mouse.tex 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. \chapter{The Mouse unit}
  2. The mouse unit provides basic Mouse handling under Dos (Go32v1 and Go32v2)
  3. Some general remarks about the mouse unit:
  4. \begin{itemize}
  5. \item The mouse driver does not know when the text screen scrolls. This results
  6. in unerased mouse cursors on the screen when the screen scrolls while the
  7. mouse cursor is visible. The solution is to hide the mouse cursor (using
  8. HideMouse) when you write something to the screen and to show it again
  9. afterwards (using ShowMouse).
  10. \item All Functions/Procedures that return and/or accept coordinates of the mouse
  11. cursor, always do so in pixels and zero based (so the upper left corner of
  12. the screen is (0,0)). To get the (column, row) in standard text mode, divide
  13. both x and y by 8 (and add 1 if you want to have it 1 based).
  14. \item The real resolution of graphic modes and the one the mouse driver uses can
  15. differ. For example, mode 13h (320*200 pixels) is handled by the mouse driver
  16. as 640*200, so you will have to multiply the coordinates you give to the
  17. driver and divide the ones you get from it by 2.
  18. \item By default the mouse unit is compiled with the conditional define
  19. MouseCheck. This causes every procedure/function of the unit to check the
  20. MouseFound variable prior to doing anything. Of course this is not necessary,
  21. so if you are sure you are not calling any mouse unit procedures when no
  22. mouse is found, you can recompile the mouse unit without this conditional
  23. define.
  24. \item
  25. You will notice that several procedures/functinos have longint sized
  26. parameters while only the lower 16 bits are used. This is because FPC is
  27. a 32 bit compiler and consequently 32 bit parameters result in faster code.
  28. \end{itemize}
  29. \section{Functions and procedures}
  30. \function{GetLastButtonPress}{(Button: Longint; Var x,y:Longint)}{Longint}{
  31. \var{GetLastButtonPress}
  32. Stores the position where \var{Button} was last pressed in \var{x} and
  33. \var{y} and returns
  34. the number of times this button has been pressed since the last call to this
  35. function with \var{Button} as parameter. For \var{Button} you can use the
  36. \var{LButton}, \var{RButton} and \var{MButton} constants for resp. the left,
  37. right and middle button.
  38. For two-button mice, checking the status of the middle button seems to give
  39. and clear the stats of the right button.
  40. }{None.}{\seef{GetLastButtonRelease}}
  41. \input {mouseex/mouse5.tex}
  42. \function{GetLastButtonRelease}{(Button: Longint; Var x,y:Longint)}{Longint}{
  43. \var{GetLastButtonRelease}
  44. stores the position where \var{Button} was last released in \var{x} and
  45. \var{y} and returns
  46. the number of times this button has been released since the last call to this
  47. function with \var{Button} as parameter. For button you can use the
  48. \var{LButton}, \var{RButton} and \var{MButton} constants for resp.
  49. the left, right and middle button.
  50. For two-button mice, checking the stats of the middle button seems to give
  51. and clear the stats of the right button.
  52. }{None.}{\seef{GetLastButtonPress}}
  53. For an example, see \seef{GetLastButtonPress}.
  54. \procedure{GetMouseState}{(Var x, y, buttons: Longint)}{
  55. \var{GetMouseState} Returns information on the current mouse position
  56. and which buttons are currently pressed.
  57. \var{x} and \var{y} return the mouse cursor coordinates in pixels.
  58. \var{Buttons} is a bitmask. Check the example program to see how you can get the
  59. necessary information from it.
  60. }{None.}{\seef{LPressed}, \seef{MPressed}, \seef{RPressed},
  61. \seep{SetMousePos}}
  62. \input {mouseex/mouse3.tex}
  63. \Procedure{HideMouse}{
  64. \var{HideMouse} makes the mouse cursor invisible.
  65. Multiple calls to HideMouse will require just as many calls to ShowMouse to
  66. make the mouse cursor again visible.
  67. }{None.}{\seep{ShowMouse}, \seep{SetMouseHideWindow}}
  68. For an example, see \seep{ShowMouse}.
  69. \Procedure{InitMouse}{
  70. \var{InitMouse}
  71. Initializes the mouse driver sets the variable \var{MouseFound} depending on
  72. whether or not a mouse is found.
  73. This is Automatically called at the start of your program.
  74. You should never have to call it, unless you want to reset everything to
  75. its default values.
  76. }{None.}{\var{MouseFound} variable.}
  77. \input {mouseex/mouse1.tex}
  78. \Function{LPressed}{Boolean}{
  79. \var{LPressed} returns \var{True} if the left mouse button is pressed.
  80. This is simply a wrapper for the GetMouseState procedure.
  81. }{None.}{\seep{GetMouseState}, \seef{MPressed}, \seef{RPressed}}
  82. For an example, see \seep{GetMouseState}.
  83. \Function{MPressed}{Boolean}{
  84. \var{MPressed} returns \var{True} if the middle mouse button is pressed.
  85. This is simply a wrapper for the GetMouseState procedure.
  86. }{None.}{\seep{GetMouseState}, \seef{LPressed}, \seef{RPressed}}
  87. For an example, see \seep{GetMouseState}.
  88. \Function{RPressed}{Boolean}{
  89. \var{RPressed} returns \var{True} if the right mouse button is pressed.
  90. This is simply a wrapper for the GetMouseState procedure.
  91. }{None.}{\seep{GetMouseState}, \seef{LPressed}, \seef{MPressed}}
  92. For an example, see \seep{GetMouseState}.
  93. \procedure{SetMouseAscii}{(Ascii: Byte)}{
  94. \var{SetMouseAscii}
  95. sets the \var{Ascii} value of the character that depicts the mouse cursor in
  96. text mode.
  97. The difference between this one and \seep{SetMouseShape}, is that the foreground
  98. and background colors stay the same and that the Ascii code you enter is the
  99. character that you will get on screen; there's no XOR'ing.
  100. }{None}{\seep{SetMouseShape}}
  101. \input {mouseex/mouse8.tex}
  102. \procedure{SetMouseHideWindow}{(xmin,ymin,xmax,ymax: Longint)}{
  103. \var{SetMouseHideWindow}
  104. defines a rectangle on screen with top-left corner at (\var{xmin,ymin}) and
  105. botto-right corner at (\var{xmax,ymax}),which causes the mouse cursor to be
  106. turned off when it is moved into it.
  107. When the mouse is moved into the specified region, it is turned off until you
  108. call \var{ShowMouse} again. However, when you've called \seep{ShowMouse}, you'll have to
  109. call \var{SetMouseHideWindow} again to redefine the hide window...
  110. This may be annoying, but it's the way it's implemented in the mouse driver.
  111. While \var{xmin, ymin, xmax} and \var{ymax} are Longint parameters,
  112. only the lower 16 bits are used.
  113. }{None.}{\seep{ShowMouse}, \seep{HideMouse}}
  114. \input{mouseex/mouse1.tex}
  115. \procedure{SetMousePos}{(x,y:Longint)}{
  116. \var{SetMosusePos} sets the position of the mouse cursor on the screen.
  117. \var{x} is the horizontal position in pixels, \var{y} the vertical position
  118. in pixels. The upper-left hand corner of the screen is the origin.
  119. While \var{x} and \var{y} are longints, only the lower 16 bits are used.
  120. }{None.}{\seep{GetMouseState}}
  121. \input {mouseex/mouse4.tex}
  122. \procedure{SetMouseShape}{(ForeColor,BackColor,Ascii: Byte)}{
  123. \var{SetMouseShape}
  124. defines how the mouse cursor looks in textmode
  125. The character and its attributes that are on the mouse cursor's position on
  126. screen are XOR'ed with resp. \var{ForeColor}, \var{BackColor} and
  127. \var{Ascii}. Set them all to 0 for a "transparent" cursor.
  128. }{None.}{\seep{SetMouseAscii}}
  129. \input {mouseex/mouse7.tex}
  130. \procedure{SetMouseSpeed}{(Horizontal, Vertical: Longint)}{
  131. \var{SetMouseSpeed} sets the mouse speed in mickeys per 8 pixels.
  132. A mickey is the smallest measurement unit handled by a mouse. With this
  133. procedure you can set how many mickeys the mouse should move to move the
  134. cursor 8 pixels horizontally of vertically. The default values are 8 for
  135. horizontal and 16 for vertical movement.
  136. While this procedure accepts longint parameters, only the low 16 bits are
  137. actually used.
  138. }{None.}{}
  139. \input {mouseex/mouse10.tex}
  140. \procedure{SetMouseWindow}{(xmin,ymin,xmax,ymax: Longint)}{
  141. \var{SetMousWindow}
  142. defines a rectangle on screen with top-left corner at (\var{xmin,ymin}) and
  143. botto-right corner at (\var{xmax,ymax}), out of which the mouse
  144. cursor can't move.
  145. This procedure is simply a wrapper for the \seep{SetMouseXRange} and
  146. \seep{SetMouseYRange} procedures.
  147. While \var{xmin, ymin, xmax} and \var{ymax} are Longint parameters,
  148. only the lower 16 bits are used.
  149. }{None.}{\seep{SetMouseXRange}, \seep{SetMouseYRange}}
  150. For an example, see \seep{SetMouseXRange}.
  151. \procedure{SetMouseXRange}{(Min, Max: Longint)}{
  152. \var{SetMouseXRange}
  153. sets the minimum (\var{Min}) and maximum (\var{Max}) horizontal coordinates in between which the
  154. mouse cursor can move.
  155. While \var{Min} and \var{Max} are Longint parameters, only the lower 16 bits
  156. are used.
  157. }{None.}{\seep{SetMouseYRange}, \seep{SetMouseWindow}}
  158. \input {mouseex/mouse6.tex}
  159. \procedure{SetMouseYRange}{(Min, Max: Longint)}{
  160. \var{SetMouseYRange}
  161. sets the minimum (\var{Min}) and maximum (\var{Max}) vertical coordinates in between which the
  162. mouse cursor can move.
  163. While \var{Min} and \var{Max} are Longint parameters, only the lower 16 bits
  164. are used.
  165. }{None.}{\seep{SetMouseXRange}, \seep{SetMouseWindow}}
  166. For an example, see \seep{SetMouseXRange}.
  167. \Procedure{ShowMouse}{
  168. \var{ShowMouse} makes the mouse cursor visible.
  169. At the start of your progam, the mouse is invisible.
  170. }{None.}{\seep{HideMouse},\seep{SetMouseHideWindow}}
  171. \input{mouseex/mouse2.tex}