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