mouse.tex 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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{Constants, types and variables}
  30. The following constants are defined (to be used in e.g. the
  31. \seef{GetLastButtonPress} call).
  32. \begin{verbatim}
  33. LButton = 1; {left button}
  34. RButton = 2; {right button}
  35. MButton = 4; {middle button}
  36. \end{verbatim}
  37. The following variable exist:
  38. \begin{verbatim}
  39. MouseFound: Boolean;
  40. \end{verbatim}
  41. it is set to \var{True} or \var{False} in the unit's initialization code.
  42. \section{Functions and procedures}
  43. \function{GetLastButtonPress}{(Button: Longint; Var x,y:Longint)}{Longint}{
  44. \var{GetLastButtonPress}
  45. Stores the position where \var{Button} was last pressed in \var{x} and
  46. \var{y} and returns
  47. the number of times this button has been pressed since the last call to this
  48. function with \var{Button} as parameter. For \var{Button} you can use the
  49. \var{LButton}, \var{RButton} and \var{MButton} constants for resp. the left,
  50. right and middle button.
  51. For two-button mice, checking the status of the middle button seems to give
  52. and clear the stats of the right button.
  53. }{None.}{\seef{GetLastButtonRelease}}
  54. \latex{\inputlisting{mouseex/mouse5.pp}}
  55. \html{\input{mouseex/mouse5.tex}}
  56. \function{GetLastButtonRelease}{(Button: Longint; Var x,y:Longint)}{Longint}{
  57. \var{GetLastButtonRelease}
  58. stores the position where \var{Button} was last released in \var{x} and
  59. \var{y} and returns
  60. the number of times this button has been released since the last call to this
  61. function with \var{Button} as parameter. For button you can use the
  62. \var{LButton}, \var{RButton} and \var{MButton} constants for resp.
  63. the left, right and middle button.
  64. For two-button mice, checking the stats of the middle button seems to give
  65. and clear the stats of the right button.
  66. }{None.}{\seef{GetLastButtonPress}}
  67. For an example, see \seef{GetLastButtonPress}.
  68. \procedure{GetMouseState}{(Var x, y, buttons: Longint)}{
  69. \var{GetMouseState} Returns information on the current mouse position
  70. and which buttons are currently pressed.
  71. \var{x} and \var{y} return the mouse cursor coordinates in pixels.
  72. \var{Buttons} is a bitmask. Check the example program to see how you can get the
  73. necessary information from it.
  74. }{None.}{\seef{LPressed}, \seef{MPressed}, \seef{RPressed},
  75. \seep{SetMousePos}}
  76. \latex{\inputlisting{mouseex/mouse3.pp}}
  77. \html{\input{mouseex/mouse3.tex}}
  78. \Procedure{HideMouse}{
  79. \var{HideMouse} makes the mouse cursor invisible.
  80. Multiple calls to HideMouse will require just as many calls to ShowMouse to
  81. make the mouse cursor again visible.
  82. }{None.}{\seep{ShowMouse}, \seep{SetMouseHideWindow}}
  83. For an example, see \seep{ShowMouse}.
  84. \Procedure{InitMouse}{
  85. \var{InitMouse}
  86. Initializes the mouse driver sets the variable \var{MouseFound} depending on
  87. whether or not a mouse is found.
  88. This is Automatically called at the start of your program.
  89. You should never have to call it, unless you want to reset everything to
  90. its default values.
  91. }{None.}{\var{MouseFound} variable.}
  92. \latex{\inputlisting{mouseex/mouse1.pp}}
  93. \html{\input{mouseex/mouse1.tex}}
  94. \Function{LPressed}{Boolean}{
  95. \var{LPressed} returns \var{True} if the left mouse button is pressed.
  96. This is simply a wrapper for the GetMouseState procedure.
  97. }{None.}{\seep{GetMouseState}, \seef{MPressed}, \seef{RPressed}}
  98. For an example, see \seep{GetMouseState}.
  99. \Function{MPressed}{Boolean}{
  100. \var{MPressed} returns \var{True} if the middle mouse button is pressed.
  101. This is simply a wrapper for the GetMouseState procedure.
  102. }{None.}{\seep{GetMouseState}, \seef{LPressed}, \seef{RPressed}}
  103. For an example, see \seep{GetMouseState}.
  104. \Function{RPressed}{Boolean}{
  105. \var{RPressed} returns \var{True} if the right mouse button is pressed.
  106. This is simply a wrapper for the GetMouseState procedure.
  107. }{None.}{\seep{GetMouseState}, \seef{LPressed}, \seef{MPressed}}
  108. For an example, see \seep{GetMouseState}.
  109. \procedure{SetMouseAscii}{(Ascii: Byte)}{
  110. \var{SetMouseAscii}
  111. sets the \var{Ascii} value of the character that depicts the mouse cursor in
  112. text mode.
  113. The difference between this one and \seep{SetMouseShape}, is that the foreground
  114. and background colors stay the same and that the Ascii code you enter is the
  115. character that you will get on screen; there's no XOR'ing.
  116. }{None}{\seep{SetMouseShape}}
  117. \latex{\inputlisting{mouseex/mouse8.pp}}
  118. \html{\input{mouseex/mouse8.tex}}
  119. \procedure{SetMouseHideWindow}{(xmin,ymin,xmax,ymax: Longint)}{
  120. \var{SetMouseHideWindow}
  121. defines a rectangle on screen with top-left corner at (\var{xmin,ymin}) and
  122. botto-right corner at (\var{xmax,ymax}),which causes the mouse cursor to be
  123. turned off when it is moved into it.
  124. When the mouse is moved into the specified region, it is turned off until you
  125. call \var{ShowMouse} again. However, when you've called \seep{ShowMouse}, you'll have to
  126. call \var{SetMouseHideWindow} again to redefine the hide window...
  127. This may be annoying, but it's the way it's implemented in the mouse driver.
  128. While \var{xmin, ymin, xmax} and \var{ymax} are Longint parameters,
  129. only the lower 16 bits are used.
  130. }{None.}{\seep{ShowMouse}, \seep{HideMouse}}
  131. \latex{nputlisting{mouseex/mouse1.pp}}
  132. \html{\input{mouseex/mouse1.tex}}
  133. \procedure{SetMousePos}{(x,y:Longint)}{
  134. \var{SetMosusePos} sets the position of the mouse cursor on the screen.
  135. \var{x} is the horizontal position in pixels, \var{y} the vertical position
  136. in pixels. The upper-left hand corner of the screen is the origin.
  137. While \var{x} and \var{y} are longints, only the lower 16 bits are used.
  138. }{None.}{\seep{GetMouseState}}
  139. \latex{\inputlisting{mouseex/mouse4.pp}}
  140. \html{\input{mouseex/mouse4.tex}}
  141. \procedure{SetMouseShape}{(ForeColor,BackColor,Ascii: Byte)}{
  142. \var{SetMouseShape}
  143. defines how the mouse cursor looks in textmode
  144. The character and its attributes that are on the mouse cursor's position on
  145. screen are XOR'ed with resp. \var{ForeColor}, \var{BackColor} and
  146. \var{Ascii}. Set them all to 0 for a "transparent" cursor.
  147. }{None.}{\seep{SetMouseAscii}}
  148. \latex{\inputlisting{mouseex/mouse7.pp}}
  149. \html{\input{mouseex/mouse7.tex}}
  150. \procedure{SetMouseSpeed}{(Horizontal, Vertical: Longint)}{
  151. \var{SetMouseSpeed} sets the mouse speed in mickeys per 8 pixels.
  152. A mickey is the smallest measurement unit handled by a mouse. With this
  153. procedure you can set how many mickeys the mouse should move to move the
  154. cursor 8 pixels horizontally of vertically. The default values are 8 for
  155. horizontal and 16 for vertical movement.
  156. While this procedure accepts longint parameters, only the low 16 bits are
  157. actually used.
  158. }{None.}{}
  159. \latex{\inputlisting{mouseex/mouse10.pp}}
  160. \html{\input{mouseex/mouse10.tex}}
  161. \procedure{SetMouseWindow}{(xmin,ymin,xmax,ymax: Longint)}{
  162. \var{SetMousWindow}
  163. defines a rectangle on screen with top-left corner at (\var{xmin,ymin}) and
  164. botto-right corner at (\var{xmax,ymax}), out of which the mouse
  165. cursor can't move.
  166. This procedure is simply a wrapper for the \seep{SetMouseXRange} and
  167. \seep{SetMouseYRange} procedures.
  168. While \var{xmin, ymin, xmax} and \var{ymax} are Longint parameters,
  169. only the lower 16 bits are used.
  170. }{None.}{\seep{SetMouseXRange}, \seep{SetMouseYRange}}
  171. For an example, see \seep{SetMouseXRange}.
  172. \procedure{SetMouseXRange}{(Min, Max: Longint)}{
  173. \var{SetMouseXRange}
  174. sets the minimum (\var{Min}) and maximum (\var{Max}) horizontal coordinates in between which the
  175. mouse cursor can move.
  176. While \var{Min} and \var{Max} are Longint parameters, only the lower 16 bits
  177. are used.
  178. }{None.}{\seep{SetMouseYRange}, \seep{SetMouseWindow}}
  179. \latex{\inputlisting{mouseex/mouse6.pp}}
  180. \html{\input{mouseex/mouse6.tex}}
  181. \procedure{SetMouseYRange}{(Min, Max: Longint)}{
  182. \var{SetMouseYRange}
  183. sets the minimum (\var{Min}) and maximum (\var{Max}) vertical coordinates in between which the
  184. mouse cursor can move.
  185. While \var{Min} and \var{Max} are Longint parameters, only the lower 16 bits
  186. are used.
  187. }{None.}{\seep{SetMouseXRange}, \seep{SetMouseWindow}}
  188. For an example, see \seep{SetMouseXRange}.
  189. \Procedure{ShowMouse}{
  190. \var{ShowMouse} makes the mouse cursor visible.
  191. At the start of your progam, the mouse is invisible.
  192. }{None.}{\seep{HideMouse},\seep{SetMouseHideWindow}}
  193. \latex{\inputlisting{mouseex/mouse2.pp}}
  194. \html{\input{mouseex/mouse2.tex}}