mouse.inc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. Var
  12. CurrentMouseDriver : TMouseDriver;
  13. MouseInitialized : Boolean;
  14. // Mouse queue event mechanism
  15. PendingMouseEvent : array[0..MouseEventBufSize-1] of TMouseEvent;
  16. PendingMouseHead,
  17. PendingMouseTail : PMouseEvent;
  18. PendingMouseEvents : byte;
  19. LastMouseEvent : TMouseEvent;
  20. Procedure ClearMouseEventQueue;
  21. begin
  22. PendingMouseHead:=@PendingMouseEvent;
  23. PendingMouseTail:=@PendingMouseEvent;
  24. PendingMouseEvents:=0;
  25. FillChar(LastMouseEvent,sizeof(TMouseEvent),0);
  26. end;
  27. procedure InitMouse;
  28. begin
  29. If Not MouseInitialized then
  30. begin
  31. If Assigned(CurrentMouseDriver.InitDriver) Then
  32. CurrentMouseDriver.InitDriver();
  33. ClearMouseEventQueue;
  34. MouseInitialized:=True;
  35. end;
  36. end;
  37. procedure DoneMouse;
  38. begin
  39. If MouseInitialized then
  40. begin
  41. If Assigned(CurrentMouseDriver.DoneDriver) Then
  42. CurrentMouseDriver.DoneDriver();
  43. ClearMouseEventQueue;
  44. MouseInitialized:=False;
  45. end;
  46. end;
  47. function DetectMouse:byte;
  48. begin
  49. If Assigned(CurrentMouseDriver.DetectMouse) Then
  50. DetectMouse:=CurrentMouseDriver.DetectMouse()
  51. else
  52. DetectMouse:=0;
  53. end;
  54. procedure ShowMouse;
  55. begin
  56. If Assigned(CurrentMouseDriver.ShowMouse) Then
  57. CurrentMouseDriver.ShowMouse();
  58. end;
  59. procedure HideMouse;
  60. begin
  61. If Assigned(CurrentMouseDriver.HideMouse) Then
  62. CurrentMouseDriver.HideMouse();
  63. end;
  64. function GetMouseX:word;
  65. begin
  66. If Assigned(CurrentMouseDriver.GetMouseX) Then
  67. GetMouseX:=CurrentMouseDriver.GetMouseX()
  68. else
  69. GetMouseX:=0;
  70. end;
  71. function GetMouseY:word;
  72. begin
  73. If Assigned(CurrentMouseDriver.GetMouseY) Then
  74. GetMouseY:=CurrentMouseDriver.GetMouseY()
  75. else
  76. GetMouseY:=0;
  77. end;
  78. function GetMouseButtons:word;
  79. begin
  80. If Assigned(CurrentMouseDriver.GetMouseButtons) Then
  81. GetMouseButtons:=CurrentMouseDriver.GetMouseButtons()
  82. else
  83. GetMouseButtons:=0;
  84. end;
  85. procedure SetMouseXY(x,y:word);
  86. begin
  87. If Assigned(CurrentMouseDriver.SetMouseXY) Then
  88. CurrentMouseDriver.SetMouseXY(X,Y)
  89. end;
  90. Procedure GetPendingEvent(Var MouseEvent:TMouseEvent);
  91. begin
  92. MouseEvent:=PendingMouseHead^;
  93. inc(PendingMouseHead);
  94. if PtrInt(PendingMouseHead)=Ptrint(@PendingMouseEvent)+sizeof(PendingMouseEvent) then
  95. PendingMouseHead:=@PendingMouseEvent;
  96. dec(PendingMouseEvents);
  97. if (LastMouseEvent.x<>MouseEvent.x) or
  98. (LastMouseEvent.y<>MouseEvent.y) then
  99. MouseEvent.Action:=MouseActionMove;
  100. if (LastMouseEvent.Buttons<>MouseEvent.Buttons) then
  101. begin
  102. if (LastMouseEvent.Buttons=0) then
  103. MouseEvent.Action:=MouseActionDown
  104. else
  105. MouseEvent.Action:=MouseActionUp;
  106. end;
  107. LastMouseEvent:=MouseEvent;
  108. end;
  109. procedure GetMouseEvent(var MouseEvent:TMouseEvent);
  110. begin
  111. if CurrentMouseDriver.UseDefaultQueue then
  112. begin
  113. if (PendingMouseEvents>0) then
  114. GetPendingEvent(MouseEvent)
  115. else
  116. FillChar(MouseEvent,sizeof(MouseEvent),0);
  117. end
  118. else
  119. If Assigned(CurrentMouseDriver.GetMouseEvent) Then
  120. begin
  121. CurrentMouseDriver.GetMouseEvent(MouseEvent);
  122. LastMouseEvent:=MouseEvent;
  123. end
  124. else
  125. FillChar(MouseEvent,sizeof(TMouseEvent),0);
  126. end;
  127. procedure PutMouseEvent(const MouseEvent: TMouseEvent);
  128. begin
  129. if CurrentMouseDriver.UseDefaultQueue then
  130. begin
  131. PendingMouseTail^:=MouseEvent;
  132. inc(PendingMouseTail);
  133. if PtrInt(PendingMouseTail)=Ptrint(@PendingMouseEvent)+sizeof(PendingMouseEvent) then
  134. PendingMouseTail:=@PendingMouseEvent;
  135. inc(PendingMouseEvents);
  136. end
  137. else
  138. If Assigned(CurrentMouseDriver.PutMouseEvent) then
  139. CurrentMouseDriver.PutMouseEvent(MouseEvent);
  140. end;
  141. function PollMouseEvent(var MouseEvent: TMouseEvent):boolean;
  142. begin
  143. if (CurrentMouseDriver.UseDefaultQueue) and
  144. (PendingMouseEvents>0) then
  145. begin
  146. MouseEvent:=PendingMouseHead^;
  147. PollMouseEvent:=true;
  148. end
  149. else
  150. If Assigned(CurrentMouseDriver.PollMouseEvent) Then
  151. begin
  152. PollMouseEvent:=CurrentMouseDriver.PollMouseEvent(MouseEvent);
  153. // Put it in queue, so next poll/get will be faster.
  154. // Only if an event was found PM
  155. // If PollMouseEvent then
  156. // PutMouseEvent(MouseEvent);
  157. // This is all wrong, because the Event might already
  158. // have been pushed in the Event Array.
  159. end
  160. else
  161. PollMouseEvent:=false;
  162. end;
  163. Procedure SetMouseDriver(Const Driver : TMouseDriver);
  164. begin
  165. If Not MouseInitialized then
  166. CurrentMouseDriver:=Driver;
  167. end;
  168. Procedure GetMouseDriver(Var Driver : TMouseDriver);
  169. begin
  170. Driver:=CurrentMouseDriver;
  171. end;
  172. {
  173. $Log$
  174. Revision 1.6 2004-05-01 20:52:29 peter
  175. * ptrint fixes
  176. Revision 1.5 2004/04/22 20:59:23 peter
  177. * longint to ptrint
  178. Revision 1.4 2002/09/07 15:07:45 peter
  179. * old logs removed and tabs fixed
  180. }