mouse.tex 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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 X coordinates you give to the
  17. driver and divide the ones you get from it by 2 in that mode.
  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/functions 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. \begin{function}{GetLastButtonPress}
  44. \Declaration
  45. Function GetLastButtonPress (Button: Longint; Var x,y:Longint) : Longint;
  46. \Description
  47. \var{GetLastButtonPress}
  48. Stores the position where \var{Button} was last pressed in \var{x} and
  49. \var{y} and returns
  50. the number of times this button has been pressed since the last call to this
  51. function with \var{Button} as parameter. For \var{Button} you can use the
  52. \var{LButton}, \var{RButton} and \var{MButton} constants for resp. the left,
  53. right and middle button.
  54. For two-button mice, checking the status of the middle button seems to give
  55. and clear the stats of the right button.
  56. \Errors
  57. None.
  58. \SeeAlso
  59. \seef{GetLastButtonRelease}
  60. \end{function}
  61. \latex{\lstinputlisting{mouseex/mouse5.pp}}
  62. \html{\input{mouseex/mouse5.tex}}
  63. \begin{function}{GetLastButtonRelease}
  64. \Declaration
  65. Function GetLastButtonRelease (Button: Longint; Var x,y:Longint) : Longint;
  66. \Description
  67. \var{GetLastButtonRelease}
  68. stores the position where \var{Button} was last released in \var{x} and
  69. \var{y} and returns
  70. the number of times this button has been released since the last call to this
  71. function with \var{Button} as parameter. For button you can use the
  72. \var{LButton}, \var{RButton} and \var{MButton} constants for resp.
  73. the left, right and middle button.
  74. For two-button mice, checking the stats of the middle button seems to give
  75. and clear the stats of the right button.
  76. \Errors
  77. None.
  78. \SeeAlso
  79. \seef{GetLastButtonPress}
  80. \end{function}
  81. For an example, see \seef{GetLastButtonPress}.
  82. \begin{procedure}{GetMouseState}
  83. \Declaration
  84. Procedure GetMouseState (Var x, y, buttons: Longint);
  85. \Description
  86. \var{GetMouseState} Returns information on the current mouse position
  87. and which buttons are currently pressed.
  88. \var{x} and \var{y} return the mouse cursor coordinates in pixels.
  89. \var{Buttons} is a bitmask. Check the example program to see how you can get the
  90. necessary information from it.
  91. \Errors
  92. None.
  93. \SeeAlso
  94. \seef{LPressed}, \seef{MPressed}, \seef{RPressed},
  95. \seep{SetMousePos}
  96. \end{procedure}
  97. \latex{\lstinputlisting{mouseex/mouse3.pp}}
  98. \html{\input{mouseex/mouse3.tex}}
  99. \begin{procedure}{HideMouse}
  100. \Declaration
  101. Procedure HideMouse ;
  102. \Description
  103. \var{HideMouse} makes the mouse cursor invisible.
  104. Multiple calls to HideMouse will require just as many calls to ShowMouse to
  105. make the mouse cursor again visible.
  106. \Errors
  107. None.
  108. \SeeAlso
  109. \seep{ShowMouse}, \seep{SetMouseHideWindow}
  110. \end{procedure}
  111. For an example, see \seep{ShowMouse}.
  112. \begin{procedure}{InitMouse}
  113. \Declaration
  114. Procedure InitMouse ;
  115. \Description
  116. \var{InitMouse}
  117. Initializes the mouse driver sets the variable \var{MouseFound} depending on
  118. whether or not a mouse is found.
  119. This is Automatically called at the start of your program.
  120. You should never have to call it, unless you want to reset everything to
  121. its default values.
  122. \Errors
  123. None.
  124. \SeeAlso
  125. \var{MouseFound} variable.
  126. \end{procedure}
  127. \latex{\lstinputlisting{mouseex/mouse1.pp}}
  128. \html{\input{mouseex/mouse1.tex}}
  129. \begin{function}{LPressed}
  130. \Declaration
  131. Function LPressed : Boolean;
  132. \Description
  133. \var{LPressed} returns \var{True} if the left mouse button is pressed.
  134. This is simply a wrapper for the GetMouseState procedure.
  135. \Errors
  136. None.
  137. \SeeAlso
  138. \seep{GetMouseState}, \seef{MPressed}, \seef{RPressed}
  139. \end{function}
  140. For an example, see \seep{GetMouseState}.
  141. \begin{function}{MPressed}
  142. \Declaration
  143. Function MPressed : Boolean;
  144. \Description
  145. \var{MPressed} returns \var{True} if the middle mouse button is pressed.
  146. This is simply a wrapper for the GetMouseState procedure.
  147. \Errors
  148. None.
  149. \SeeAlso
  150. \seep{GetMouseState}, \seef{LPressed}, \seef{RPressed}
  151. \end{function}
  152. For an example, see \seep{GetMouseState}.
  153. \begin{function}{RPressed}
  154. \Declaration
  155. Function RPressed : Boolean;
  156. \Description
  157. \var{RPressed} returns \var{True} if the right mouse button is pressed.
  158. This is simply a wrapper for the GetMouseState procedure.
  159. \Errors
  160. None.
  161. \SeeAlso
  162. \seep{GetMouseState}, \seef{LPressed}, \seef{MPressed}
  163. \end{function}
  164. For an example, see \seep{GetMouseState}.
  165. \begin{procedure}{SetMouseAscii}
  166. \Declaration
  167. Procedure SetMouseAscii (Ascii: Byte);
  168. \Description
  169. \var{SetMouseAscii}
  170. sets the \var{Ascii} value of the character that depicts the mouse cursor in
  171. text mode.
  172. The difference between this one and \seep{SetMouseShape}, is that the foreground
  173. and background colors stay the same and that the Ascii code you enter is the
  174. character that you will get on screen; there's no XOR'ing.
  175. \Errors
  176. None
  177. \SeeAlso
  178. \seep{SetMouseShape}
  179. \end{procedure}
  180. \latex{\lstinputlisting{mouseex/mouse8.pp}}
  181. \html{\input{mouseex/mouse8.tex}}
  182. \begin{procedure}{SetMouseHideWindow}
  183. \Declaration
  184. Procedure SetMouseHideWindow (xmin,ymin,xmax,ymax: Longint);
  185. \Description
  186. \var{SetMouseHideWindow}
  187. defines a rectangle on screen with top-left corner at (\var{xmin,ymin}) and
  188. botto-right corner at (\var{xmax,ymax}),which causes the mouse cursor to be
  189. turned off when it is moved into it.
  190. When the mouse is moved into the specified region, it is turned off until you
  191. call \var{ShowMouse} again. However, once you've called \seep{ShowMouse}, you'll have to
  192. call \var{SetMouseHideWindow} again to redefine the hide window...
  193. This may be annoying, but it's the way it's implemented in the mouse driver.
  194. While \var{xmin, ymin, xmax} and \var{ymax} are Longint parameters,
  195. only the lower 16 bits are used.
  196. \Errors
  197. None.
  198. \SeeAlso
  199. \seep{ShowMouse}, \seep{HideMouse}
  200. \end{procedure}
  201. \latex{nputlisting{mouseex/mouse9.pp}}
  202. \html{\input{mouseex/mouse9.tex}}
  203. \begin{procedure}{SetMousePos}
  204. \Declaration
  205. Procedure SetMousePos (x,y:Longint);
  206. \Description
  207. \var{SetMosusePos} sets the position of the mouse cursor on the screen.
  208. \var{x} is the horizontal position in pixels, \var{y} the vertical position
  209. in pixels. The upper-left hand corner of the screen is the origin.
  210. While \var{x} and \var{y} are longints, only the lower 16 bits are used.
  211. \Errors
  212. None.
  213. \SeeAlso
  214. \seep{GetMouseState}
  215. \end{procedure}
  216. \latex{\lstinputlisting{mouseex/mouse4.pp}}
  217. \html{\input{mouseex/mouse4.tex}}
  218. \begin{procedure}{SetMouseShape}
  219. \Declaration
  220. Procedure SetMouseShape (ForeColor,BackColor,Ascii: Byte);
  221. \Description
  222. \var{SetMouseShape}
  223. defines how the mouse cursor looks in textmode
  224. The character and its attributes that are on the mouse cursor's position on
  225. screen are XOR'ed with resp. \var{ForeColor}, \var{BackColor} and
  226. \var{Ascii}. Set them all to 0 for a "transparent" cursor.
  227. \Errors
  228. None.
  229. \SeeAlso
  230. \seep{SetMouseAscii}
  231. \end{procedure}
  232. \latex{\lstinputlisting{mouseex/mouse7.pp}}
  233. \html{\input{mouseex/mouse7.tex}}
  234. \begin{procedure}{SetMouseSpeed}
  235. \Declaration
  236. Procedure SetMouseSpeed (Horizontal, Vertical: Longint);
  237. \Description
  238. \var{SetMouseSpeed} sets the mouse speed in mickeys per 8 pixels.
  239. A mickey is the smallest measurement unit handled by a mouse. With this
  240. procedure you can set how many mickeys the mouse should move to move the
  241. cursor 8 pixels horizontally of vertically. The default values are 8 for
  242. horizontal and 16 for vertical movement.
  243. While this procedure accepts longint parameters, only the low 16 bits are
  244. actually used.
  245. \Errors
  246. None.
  247. \SeeAlso
  248. \end{procedure}
  249. \latex{\lstinputlisting{mouseex/mouse10.pp}}
  250. \html{\input{mouseex/mouse10.tex}}
  251. \begin{procedure}{SetMouseWindow}
  252. \Declaration
  253. Procedure SetMouseWindow (xmin,ymin,xmax,ymax: Longint);
  254. \Description
  255. \var{SetMousWindow}
  256. defines a rectangle on screen with top-left corner at (\var{xmin,ymin}) and
  257. botto-right corner at (\var{xmax,ymax}), out of which the mouse
  258. cursor can't move.
  259. This procedure is simply a wrapper for the \seep{SetMouseXRange} and
  260. \seep{SetMouseYRange} procedures.
  261. While \var{xmin, ymin, xmax} and \var{ymax} are Longint parameters,
  262. only the lower 16 bits are used.
  263. \Errors
  264. None.
  265. \SeeAlso
  266. \seep{SetMouseXRange}, \seep{SetMouseYRange}
  267. \end{procedure}
  268. For an example, see \seep{SetMouseXRange}.
  269. \begin{procedure}{SetMouseXRange}
  270. \Declaration
  271. Procedure SetMouseXRange (Min, Max: Longint);
  272. \Description
  273. \var{SetMouseXRange}
  274. sets the minimum (\var{Min}) and maximum (\var{Max}) horizontal coordinates in between which the
  275. mouse cursor can move.
  276. While \var{Min} and \var{Max} are Longint parameters, only the lower 16 bits
  277. are used.
  278. \Errors
  279. None.
  280. \SeeAlso
  281. \seep{SetMouseYRange}, \seep{SetMouseWindow}
  282. \end{procedure}
  283. \latex{\lstinputlisting{mouseex/mouse6.pp}}
  284. \html{\input{mouseex/mouse6.tex}}
  285. \begin{procedure}{SetMouseYRange}
  286. \Declaration
  287. Procedure SetMouseYRange (Min, Max: Longint);
  288. \Description
  289. \var{SetMouseYRange}
  290. sets the minimum (\var{Min}) and maximum (\var{Max}) vertical coordinates in between which the
  291. mouse cursor can move.
  292. While \var{Min} and \var{Max} are Longint parameters, only the lower 16 bits
  293. are used.
  294. \Errors
  295. None.
  296. \SeeAlso
  297. \seep{SetMouseXRange}, \seep{SetMouseWindow}
  298. \end{procedure}
  299. For an example, see \seep{SetMouseXRange}.
  300. \begin{procedure}{ShowMouse}
  301. \Declaration
  302. Procedure ShowMouse ;
  303. \Description
  304. \var{ShowMouse} makes the mouse cursor visible.
  305. At the start of your progam, the mouse is invisible.
  306. \Errors
  307. None.
  308. \SeeAlso
  309. \seep{HideMouse},\seep{SetMouseHideWindow}
  310. \end{procedure}
  311. \latex{\lstinputlisting{mouseex/mouse2.pp}}
  312. \html{\input{mouseex/mouse2.tex}}