mouse.tex 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. %
  2. % $Id$
  3. % This file is part of the FPC documentation.
  4. % Copyright (C) 1997, by Michael Van Canneyt
  5. %
  6. % The FPC documentation is free text; you can redistribute it and/or
  7. % modify it under the terms of the GNU Library General Public License as
  8. % published by the Free Software Foundation; either version 2 of the
  9. % License, or (at your option) any later version.
  10. %
  11. % The FPC Documentation is distributed in the hope that it will be useful,
  12. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. % Library General Public License for more details.
  15. %
  16. % You should have received a copy of the GNU Library General Public
  17. % License along with the FPC documentation; see the file COPYING.LIB. If not,
  18. % write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. % Boston, MA 02111-1307, USA.
  20. %
  21. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  22. %
  23. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  24. % The Mouse unit
  25. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  26. \chapter{The MOUSE unit}
  27. \FPCexampledir{mousex}
  28. The \var{Mouse} unit implements a platform independent mouse handling
  29. interface. It is implemented identically on all platforms supported by
  30. \fpc{} and can be enhanced with custom drivers, should this be needed.
  31. \section{Constants, Types and Variables}
  32. \subsection{Constants}
  33. The following constants can be used when mouse drivers need to report
  34. errors:
  35. \begin{verbatim}
  36. const
  37. { We have an errorcode base of 1030 }
  38. errMouseBase = 1030;
  39. errMouseInitError = errMouseBase + 0;
  40. errMouseNotImplemented = errMouseBase + 1;
  41. \end{verbatim}
  42. The following constants describe which action a mouse event describes
  43. \begin{verbatim}
  44. const
  45. MouseActionDown = $0001; { Mouse down event }
  46. MouseActionUp = $0002; { Mouse up event }
  47. MouseActionMove = $0004; { Mouse move event }
  48. \end{verbatim}
  49. The following constants describe the used buttons in a mouse event:
  50. \begin{verbatim}
  51. MouseLeftButton = $01; { Left mouse button }
  52. MouseRightButton = $02; { Right mouse button }
  53. MouseMiddleButton = $04; { Middle mouse button }
  54. \end{verbatim}
  55. The mouse unit has a mechanism to buffer mouse events. The following
  56. constant defines the size of the event buffer:
  57. \begin{verbatim}
  58. MouseEventBufSize = 16;
  59. \end{verbatim}
  60. \subsection{Types}
  61. The \var{TMouseEvent} is the central type of the mouse unit, it is used
  62. to describe the mouse events:
  63. \begin{verbatim}
  64. PMouseEvent=^TMouseEvent;
  65. TMouseEvent=packed record { 8 bytes }
  66. buttons : word;
  67. x,y : word;
  68. Action : word;
  69. end;
  70. \end{verbatim}
  71. The \var{Buttons} field describes which buttons were down when the event
  72. occurred. The \var{x,y} fields describe where the event occurred on the
  73. screen. The \var{Action} describes what action was going on when the event
  74. occurred. The \var{Buttons} and \var{Action} field can be examined using the
  75. above constants.
  76. The following record is used to implement a mouse driver in the
  77. \seep{SetMouseDriver} function:
  78. \begin{verbatim}
  79. TMouseDriver = Record
  80. UseDefaultQueue : Boolean;
  81. InitDriver : Procedure;
  82. DoneDriver : Procedure;
  83. DetectMouse : Function : Byte;
  84. ShowMouse : Procedure;
  85. HideMouse : Procedure;
  86. GetMouseX : Function : Word;
  87. GetMouseY : Function : Word;
  88. GetMouseButtons : Function : Word;
  89. SetMouseXY : procedure (x,y:word);
  90. GetMouseEvent : procedure (var MouseEvent:TMouseEvent);
  91. PollMouseEvent : function (var MouseEvent: TMouseEvent):boolean;
  92. PutMouseEvent : procedure (Const MouseEvent:TMouseEvent);
  93. end;
  94. \end{verbatim}
  95. Its fields will be explained in the section on writing a custom driver.
  96. \subsection{Variables}
  97. The following variables are used to keep the current position and state of
  98. the mouse.
  99. \begin{verbatim}
  100. MouseIntFlag : Byte; { Mouse in int flag }
  101. MouseButtons : Byte; { Mouse button state }
  102. MouseWhereX,
  103. MouseWhereY : Word; { Mouse position }
  104. \end{verbatim}
  105. \section{Functions and procedures}
  106. \begin{function}{DetectMouse}
  107. \Declaration
  108. Function DetectMouse:byte;
  109. \Description
  110. { Detect if a mouse is present, returns the amount of buttons or 0 if no mouse is found }
  111. \Errors
  112. \SeeAlso
  113. \end{function}
  114. \begin{procedure}{DoneMouse}
  115. \Declaration
  116. Procedure DoneMouse;
  117. \Description
  118. { Deinitialize the mouse interface }
  119. \Errors
  120. \SeeAlso
  121. \end{procedure}
  122. \begin{function}{GetMouseButtons}
  123. \Declaration
  124. Function GetMouseButtons:word;
  125. \Description
  126. { Return the current button state of the mouse }
  127. \Errors
  128. \SeeAlso
  129. \end{function}
  130. \begin{procedure}{GetMouseDriver}
  131. \Declaration
  132. Procedure GetMouseDriver(Var Driver : TMouseDriver);
  133. \Description
  134. \Errors
  135. \SeeAlso
  136. \end{procedure}
  137. \begin{procedure}{GetMouseEvent}
  138. \Declaration
  139. Procedure GetMouseEvent(var MouseEvent:TMouseEvent);
  140. \Description
  141. { Returns the last Mouseevent, and waits for one if not available }
  142. \Errors
  143. \SeeAlso
  144. \end{procedure}
  145. \begin{function}{GetMouseX}
  146. \Declaration
  147. Function GetMouseX:word;
  148. \Description
  149. { Return the current X position of the mouse }
  150. \Errors
  151. \SeeAlso
  152. \end{function}
  153. \begin{function}{GetMouseY}
  154. \Declaration
  155. Function GetMouseY:word;
  156. \Description
  157. { Return the current Y position of the mouse }
  158. \Errors
  159. \SeeAlso
  160. \end{function}
  161. \begin{procedure}{HideMouse}
  162. \Declaration
  163. Procedure HideMouse;
  164. \Description
  165. { Hide the mouse cursor }
  166. \Errors
  167. \SeeAlso
  168. \end{procedure}
  169. \begin{procedure}{InitMouse}
  170. \Declaration
  171. Procedure InitMouse;
  172. \Description
  173. { Initialize the mouse interface }
  174. \Errors
  175. \SeeAlso
  176. \end{procedure}
  177. \begin{function}{PollMouseEvent}
  178. \Declaration
  179. Function PollMouseEvent(var MouseEvent: TMouseEvent):boolean;
  180. \Description
  181. { Checks if a Mouseevent is available, and returns it if one is found. If no event is pending, it returns 0 }
  182. \Errors
  183. \SeeAlso
  184. \end{function}
  185. \begin{procedure}{PutMouseEvent}
  186. \Declaration
  187. Procedure PutMouseEvent(const MouseEvent: TMouseEvent);
  188. \Description
  189. { Adds the given MouseEvent to the input queue. Please note that depending on the implementation this can hold only one value (NO FIFOs etc) }
  190. \Errors
  191. \SeeAlso
  192. \end{procedure}
  193. \begin{procedure}{SetMouseDriver}
  194. \Declaration
  195. Procedure SetMouseDriver(Const Driver : TMouseDriver);
  196. \Description
  197. { Sets the mouse driver. }
  198. \Errors
  199. \SeeAlso
  200. \end{procedure}
  201. \begin{procedure}{SetMouseXY}
  202. \Declaration
  203. Procedure SetMouseXY(x,y:word);
  204. \Description
  205. { Place the mouse cursor on x,y }
  206. \Errors
  207. \SeeAlso
  208. \end{procedure}
  209. \begin{procedure}{ShowMouse}
  210. \Declaration
  211. Procedure ShowMouse;
  212. \Description
  213. { Show the mouse cursor }
  214. \Errors
  215. \SeeAlso
  216. \end{procedure}