1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-21 16:55:01 -05:00

Mouse should be done now. :)

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@8 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Wizzup? 2009-09-02 05:16:29 +00:00
parent 216e8b9639
commit 4cc31f4693
6 changed files with 235 additions and 114 deletions

View File

@ -18,6 +18,9 @@ type
procedure GetMousePos(var X, Y: Integer);
procedure SetMousePos(X, Y: Integer);
procedure MouseButtonAction(X, Y: Integer; mClick: TClickType; mPress: TMousePress);
procedure ClickMouse(X, Y: Integer; mClick: TClickType);
function IsMouseButtonDown(mType: TClickType): Boolean;
public
Client: TObject;
@ -71,5 +74,81 @@ begin
{$ENDIF}
end;
procedure TMInput.MouseButtonAction(X, Y: Integer; mClick: TClickType; mPress: TMousePress);
{$IFDEF LINUX}
var
event : TXEvent;
Garbage : QWord;
Old_Handler: TXErrorHandler;
{$ENDIF}
begin
Self.SetMousePos(X, Y);
{$IFDEF LINUX}
Old_Handler := XSetErrorHandler(@MufasaXErrorHandler);
FillChar(event,sizeof(TXevent),0);
if mPress = mouse_Down then
Event._type:= ButtonPress
else
Event._type:= ButtonRelease;
case mClick of
mouse_Left: Event.xbutton.button:= Button1;
mouse_Middle: Event.xbutton.button:= Button2;
mouse_Right: Event.xbutton.button:= Button3;
end;
event.xbutton.send_event := 1;
event.xbutton.same_screen:= 1;
event.xbutton.subwindow:= 0;
event.xbutton.root := TClient(Client).MWindow.DesktopWindow;
event.xbutton.window := TClient(Client).MWindow.CurWindow;
event.xbutton.x_root:= x;
event.xbutton.y_root:= y;
event.xbutton.x := x;
event.xbutton.y := y;
event.xbutton.state:= 0;
if(XSendEvent(TClient(Client).MWindow.XDisplay, PointerWindow, True, $fff, @event) = 0) then
Writeln('Errorrrr :-(');
XFlush(TClient(Client).MWindow.XDisplay);
XSetErrorHandler(Old_Handler);
{$ENDIF}
end;
// ff omzetten naar MouseButtonDown(), en dan Click gewoon down en dan up.
// holdmouse releasemouse
procedure TMInput.ClickMouse(X, Y: Integer; mClick: TClickType);
begin
Self.MouseButtonAction(X, Y, mClick, mouse_Down);
Self.MouseButtonAction(X, Y, mClick, mouse_Up);
end;
function TMInput.IsMouseButtonDown(mType: TClickType): Boolean;
{$IFDEF LINUX}
var
rootx, rooty, x, y:integer;
root, child: twindow;
xmask: Cardinal;
Old_Handler: TXErrorHandler;
{$ENDIF}
begin
{$IFDEF LINUX}
Old_Handler := XSetErrorHandler(@MufasaXErrorHandler);
XQueryPointer(TClient(Client).MWindow.XDisplay,TClient(Client).MWindow.CurWindow,@root,@child,@rootx,@rooty,@x,@y,@xmask);
case mType of
mouse_Left: Result := (xmask and Button1Mask) <> 0;
mouse_Middle: Result := (xmask and Button2Mask) <> 0;
mouse_Right: Result := (xmask and Button3Mask) <> 0;
end;
XSetErrorHandler(Old_Handler);
{$ENDIF}
end;
end.

View File

@ -15,6 +15,9 @@ type
PRGB32 = ^TRGB32;
TTargetWindowMode = (w_BMP, w_Window, w_HDC, w_ArrayPtr, w_XWindow);
TClickType = (mouse_Left, mouse_Right, mouse_Middle);
TMousePress = (mouse_Down, mouse_Up);
implementation

View File

@ -17,7 +17,10 @@ type
procedure GetDimensions(var W, H: Integer);
function CopyClientToBitmap(xs, ys, xe, ye: integer): TBitmap;
function SetTarget(XWindow: QWord): integer; overload;
{$IFDEF LINUX}
function SetTarget(XWindow: x.TWindow): integer; overload;
{$ENDIF}
function SetTarget(Window: THandle; NewType: TTargetWindowMode): integer; overload;
function SetTarget(ArrPtr: PRGB32): integer; overload;
@ -38,10 +41,10 @@ type
XConnectionNumber: Integer;
// X Window
CurWindow: QWord;
CurWindow: x.TWindow;
// Desktop Window
DesktopWindow: QWord;
DesktopWindow: x.TWindow;
// X Screen
XScreen: PScreen;
@ -253,7 +256,7 @@ begin
end;
end;
function TMWindow.SetTarget(XWindow: QWord): integer; overload;
function TMWindow.SetTarget(XWindow: x.TWindow): integer; overload;
{$IFDEF LINUX}
var
Old_Handler: TXErrorHandler;

View File

@ -30,15 +30,15 @@
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
<Units Count="24">
<Units Count="26">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="project1"/>
<CursorPos X="63" Y="17"/>
<TopLine Value="1"/>
<EditorIndex Value="2"/>
<UsageCount Value="37"/>
<EditorIndex Value="1"/>
<UsageCount Value="42"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
@ -49,7 +49,7 @@
<UnitName Value="TestUnit"/>
<CursorPos X="33" Y="57"/>
<TopLine Value="32"/>
<UsageCount Value="37"/>
<UsageCount Value="42"/>
</Unit1>
<Unit2>
<Filename Value="client.pas"/>
@ -57,15 +57,15 @@
<UnitName Value="Client"/>
<CursorPos X="18" Y="34"/>
<TopLine Value="10"/>
<UsageCount Value="37"/>
<UsageCount Value="42"/>
</Unit2>
<Unit3>
<Filename Value="../cogat/Units/CogatUnits/comptypes.pas"/>
<UnitName Value="CompTypes"/>
<CursorPos X="1" Y="507"/>
<TopLine Value="486"/>
<EditorIndex Value="7"/>
<UsageCount Value="19"/>
<CursorPos X="13" Y="531"/>
<TopLine Value="523"/>
<EditorIndex Value="8"/>
<UsageCount Value="22"/>
<Loaded Value="True"/>
</Unit3>
<Unit4>
@ -74,7 +74,7 @@
<UnitName Value="MufasaTypes"/>
<CursorPos X="52" Y="20"/>
<TopLine Value="1"/>
<UsageCount Value="37"/>
<UsageCount Value="42"/>
</Unit4>
<Unit5>
<Filename Value="window.pas"/>
@ -82,7 +82,7 @@
<UnitName Value="Window"/>
<CursorPos X="4" Y="100"/>
<TopLine Value="85"/>
<UsageCount Value="37"/>
<UsageCount Value="42"/>
</Unit5>
<Unit6>
<Filename Value="../../Documents/fpc/rtl/inc/systemh.inc"/>
@ -96,51 +96,51 @@
<UnitName Value="Input"/>
<CursorPos X="5" Y="20"/>
<TopLine Value="15"/>
<UsageCount Value="36"/>
<UsageCount Value="41"/>
</Unit7>
<Unit8>
<Filename Value="../cogat/Units/CogatUnits/compinput.pas"/>
<UnitName Value="CompInput"/>
<CursorPos X="34" Y="979"/>
<TopLine Value="971"/>
<EditorIndex Value="9"/>
<UsageCount Value="17"/>
<CursorPos X="43" Y="250"/>
<TopLine Value="236"/>
<EditorIndex Value="10"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit8>
<Unit9>
<Filename Value="Units/MMLCore/client.pas"/>
<UnitName Value="Client"/>
<CursorPos X="19" Y="4"/>
<TopLine Value="4"/>
<EditorIndex Value="1"/>
<UsageCount Value="15"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="12"/>
<EditorIndex Value="7"/>
<UsageCount Value="18"/>
<Loaded Value="True"/>
</Unit9>
<Unit10>
<Filename Value="Units/MMLCore/input.pas"/>
<UnitName Value="Input"/>
<CursorPos X="41" Y="20"/>
<TopLine Value="6"/>
<EditorIndex Value="3"/>
<UsageCount Value="15"/>
<CursorPos X="42" Y="141"/>
<TopLine Value="1"/>
<EditorIndex Value="2"/>
<UsageCount Value="18"/>
<Loaded Value="True"/>
</Unit10>
<Unit11>
<Filename Value="Units/MMLCore/mufasatypes.pas"/>
<UnitName Value="MufasaTypes"/>
<CursorPos X="20" Y="17"/>
<CursorPos X="40" Y="19"/>
<TopLine Value="1"/>
<EditorIndex Value="5"/>
<UsageCount Value="15"/>
<EditorIndex Value="3"/>
<UsageCount Value="18"/>
<Loaded Value="True"/>
</Unit11>
<Unit12>
<Filename Value="Units/MMLCore/window.pas"/>
<UnitName Value="Window"/>
<CursorPos X="43" Y="269"/>
<TopLine Value="254"/>
<EditorIndex Value="6"/>
<UsageCount Value="15"/>
<CursorPos X="40" Y="265"/>
<TopLine Value="249"/>
<EditorIndex Value="4"/>
<UsageCount Value="18"/>
<Loaded Value="True"/>
</Unit12>
<Unit13>
@ -149,7 +149,7 @@
<UnitName Value="windowutil"/>
<CursorPos X="45" Y="13"/>
<TopLine Value="1"/>
<UsageCount Value="29"/>
<UsageCount Value="34"/>
</Unit13>
<Unit14>
<Filename Value="../../Documents/lazarus/lcl/graphics.pp"/>
@ -157,7 +157,7 @@
<CursorPos X="15" Y="1287"/>
<TopLine Value="1272"/>
<EditorIndex Value="0"/>
<UsageCount Value="14"/>
<UsageCount Value="17"/>
<Loaded Value="True"/>
</Unit14>
<Unit15>
@ -165,8 +165,8 @@
<UnitName Value="CompBitmaps"/>
<CursorPos X="1" Y="109"/>
<TopLine Value="92"/>
<EditorIndex Value="10"/>
<UsageCount Value="14"/>
<EditorIndex Value="11"/>
<UsageCount Value="17"/>
<Loaded Value="True"/>
</Unit15>
<Unit16>
@ -178,17 +178,22 @@
<Unit17>
<Filename Value="../../Documents/fpc/packages/x11/src/xlib.pp"/>
<UnitName Value="xlib"/>
<CursorPos X="4" Y="1360"/>
<TopLine Value="1345"/>
<UsageCount Value="9"/>
<CursorPos X="47" Y="1272"/>
<TopLine Value="1257"/>
<EditorIndex Value="5"/>
<UsageCount Value="12"/>
<Loaded Value="True"/>
</Unit17>
<Unit18>
<Filename Value="testunit.pas"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="TestUnit"/>
<CursorPos X="15" Y="69"/>
<TopLine Value="43"/>
<EditorIndex Value="4"/>
<UsageCount Value="12"/>
<CursorPos X="84" Y="34"/>
<TopLine Value="28"/>
<EditorIndex Value="6"/>
<UsageCount Value="15"/>
<Loaded Value="True"/>
</Unit18>
<Unit19>
@ -196,20 +201,20 @@
<UnitName Value="CompColors"/>
<CursorPos X="44" Y="914"/>
<TopLine Value="897"/>
<EditorIndex Value="8"/>
<UsageCount Value="12"/>
<EditorIndex Value="9"/>
<UsageCount Value="15"/>
<Loaded Value="True"/>
</Unit19>
<Unit20>
<Filename Value="../../Documents/fpc/packages/x11/src/x.pp"/>
<UnitName Value="x"/>
<CursorPos X="14" Y="41"/>
<TopLine Value="26"/>
<CursorPos X="4" Y="179"/>
<TopLine Value="164"/>
<UsageCount Value="10"/>
</Unit20>
<Unit21>
<Filename Value="../../Documents/fpc/rtl/unix/aliasctp.inc"/>
<CursorPos X="30" Y="50"/>
<CursorPos X="63" Y="45"/>
<TopLine Value="30"/>
<UsageCount Value="10"/>
</Unit21>
@ -227,127 +232,141 @@
<TopLine Value="83"/>
<UsageCount Value="10"/>
</Unit23>
<Unit24>
<Filename Value="testunit.lfm"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<UsageCount Value="10"/>
<SyntaxHighlighter Value="LFM"/>
</Unit24>
<Unit25>
<Filename Value="../../Documents/fpc/rtl/unix/unix.pp"/>
<UnitName Value="Unix"/>
<CursorPos X="63" Y="63"/>
<TopLine Value="56"/>
<UsageCount Value="10"/>
</Unit25>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="49" Column="22" TopLine="30"/>
<Filename Value="../../Documents/fpc/packages/x11/src/xlib.pp"/>
<Caret Line="1272" Column="47" TopLine="1257"/>
</Position1>
<Position2>
<Filename Value="../cogat/Units/CogatUnits/compinput.pas"/>
<Caret Line="6" Column="75" TopLine="1"/>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="76" Column="6" TopLine="47"/>
</Position2>
<Position3>
<Filename Value="../cogat/Units/CogatUnits/compinput.pas"/>
<Caret Line="8" Column="22" TopLine="1"/>
<Caret Line="80" Column="66" TopLine="76"/>
</Position3>
<Position4>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="63" Column="26" TopLine="37"/>
<Caret Line="95" Column="31" TopLine="69"/>
</Position4>
<Position5>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="62" Column="86" TopLine="38"/>
<Caret Line="93" Column="3" TopLine="69"/>
</Position5>
<Position6>
<Filename Value="project1.lpr"/>
<Caret Line="7" Column="69" TopLine="1"/>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="97" Column="63" TopLine="82"/>
</Position6>
<Position7>
<Filename Value="project1.lpr"/>
<Caret Line="10" Column="12" TopLine="1"/>
<Filename Value="../cogat/Units/CogatUnits/compinput.pas"/>
<Caret Line="8" Column="33" TopLine="1"/>
</Position7>
<Position8>
<Filename Value="testunit.pas"/>
<Caret Line="60" Column="29" TopLine="37"/>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="100" Column="29" TopLine="84"/>
</Position8>
<Position9>
<Filename Value="testunit.pas"/>
<Caret Line="35" Column="79" TopLine="32"/>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="106" Column="42" TopLine="89"/>
</Position9>
<Position10>
<Filename Value="testunit.pas"/>
<Caret Line="56" Column="24" TopLine="43"/>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="112" Column="55" TopLine="95"/>
</Position10>
<Position11>
<Filename Value="../cogat/Units/CogatUnits/compcolors.pas"/>
<Caret Line="22" Column="23" TopLine="1"/>
<Filename Value="testunit.pas"/>
<Caret Line="38" Column="69" TopLine="31"/>
</Position11>
<Position12>
<Filename Value="../cogat/Units/CogatUnits/compcolors.pas"/>
<Caret Line="35" Column="29" TopLine="20"/>
<Filename Value="testunit.pas"/>
<Caret Line="60" Column="14" TopLine="37"/>
</Position12>
<Position13>
<Filename Value="Units/MMLCore/window.pas"/>
<Caret Line="18" Column="45" TopLine="1"/>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="22" Column="48" TopLine="1"/>
</Position13>
<Position14>
<Filename Value="../cogat/Units/CogatUnits/comptypes.pas"/>
<Caret Line="115" Column="53" TopLine="101"/>
<Filename Value="testunit.pas"/>
<Caret Line="9" Column="16" TopLine="1"/>
</Position14>
<Position15>
<Filename Value="Units/MMLCore/window.pas"/>
<Caret Line="21" Column="82" TopLine="1"/>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="136" Column="1" TopLine="112"/>
</Position15>
<Position16>
<Filename Value="Units/MMLCore/window.pas"/>
<Caret Line="9" Column="10" TopLine="5"/>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="135" Column="125" TopLine="113"/>
</Position16>
<Position17>
<Filename Value="Units/MMLCore/window.pas"/>
<Caret Line="274" Column="1" TopLine="246"/>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="127" Column="22" TopLine="113"/>
</Position17>
<Position18>
<Filename Value="Units/MMLCore/window.pas"/>
<Caret Line="257" Column="19" TopLine="249"/>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="136" Column="21" TopLine="113"/>
</Position18>
<Position19>
<Filename Value="Units/MMLCore/window.pas"/>
<Caret Line="132" Column="10" TopLine="117"/>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="135" Column="2" TopLine="113"/>
</Position19>
<Position20>
<Filename Value="Units/MMLCore/window.pas"/>
<Caret Line="160" Column="6" TopLine="145"/>
<Filename Value="testunit.pas"/>
<Caret Line="74" Column="3" TopLine="50"/>
</Position20>
<Position21>
<Filename Value="Units/MMLCore/window.pas"/>
<Caret Line="177" Column="23" TopLine="162"/>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="138" Column="31" TopLine="113"/>
</Position21>
<Position22>
<Filename Value="Units/MMLCore/window.pas"/>
<Caret Line="262" Column="39" TopLine="249"/>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="131" Column="45" TopLine="117"/>
</Position22>
<Position23>
<Filename Value="Units/MMLCore/window.pas"/>
<Caret Line="267" Column="34" TopLine="249"/>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="92" Column="13" TopLine="75"/>
</Position23>
<Position24>
<Filename Value="Units/MMLCore/window.pas"/>
<Caret Line="264" Column="3" TopLine="244"/>
<Filename Value="testunit.pas"/>
<Caret Line="51" Column="40" TopLine="34"/>
</Position24>
<Position25>
<Filename Value="Units/MMLCore/window.pas"/>
<Caret Line="262" Column="72" TopLine="244"/>
<Filename Value="Units/MMLCore/input.pas"/>
<Caret Line="142" Column="1" TopLine="120"/>
</Position25>
<Position26>
<Filename Value="Units/MMLCore/window.pas"/>
<Caret Line="63" Column="33" TopLine="41"/>
<Filename Value="../cogat/Units/CogatUnits/compinput.pas"/>
<Caret Line="51" Column="35" TopLine="31"/>
</Position26>
<Position27>
<Filename Value="../cogat/Units/CogatUnits/comptypes.pas"/>
<Caret Line="110" Column="30" TopLine="83"/>
<Filename Value="../cogat/Units/CogatUnits/compinput.pas"/>
<Caret Line="32" Column="35" TopLine="19"/>
</Position27>
<Position28>
<Filename Value="Units/MMLCore/window.pas"/>
<Caret Line="258" Column="28" TopLine="243"/>
<Filename Value="testunit.pas"/>
<Caret Line="75" Column="47" TopLine="58"/>
</Position28>
<Position29>
<Filename Value="Units/MMLCore/window.pas"/>
<Caret Line="273" Column="10" TopLine="252"/>
<Filename Value="testunit.pas"/>
<Caret Line="71" Column="19" TopLine="56"/>
</Position29>
<Position30>
<Filename Value="testunit.pas"/>
<Caret Line="11" Column="14" TopLine="21"/>
<Caret Line="60" Column="3" TopLine="38"/>
</Position30>
</JumpHistory>
</ProjectOptions>

View File

@ -1,3 +1,5 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TForm1','FORMDATA',[
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'%'#1#6'Height'#3#4#2#3'Top'#3#200#0#5'Wid'
+'th'#3#11#3#13'ActiveControl'#7#7'Button1'#7'Caption'#6#5'Form1'#12'ClientHe'

View File

@ -41,26 +41,41 @@ begin
Client.MWindow.GetDimensions(w, h);
writeln(inttostr(w) + ' , ' + inttostr(h));
bmp := Client.MWindow.CopyClientToBitmap(0, 0, w, h);
Client.MWindow.SetTarget(77736320);
Client.MWindow.GetDimensions(w, h);
writeln(inttostr(w) + ' , ' + inttostr(h));
{bmp := Client.MWindow.CopyClientToBitmap(0, 0, w, h);
bmp.SaveToFile('/tmp/test.bmp');
bmp.Free;
}
//Sleep(1000);
{ Client.MInput.GetMousePos(x, y);
writeln(inttostr(x) + ' , ' + inttostr(y)); }
{ Client.MInput.SetMousePos(50, 50);
Client.MInput.GetMousePos(x, y);
writeln(inttostr(x) + ' , ' + inttostr(y));
writeln(inttostr(x) + ' , ' + inttostr(y)); }
Client.MInput.SetMousePos(50, 50);
Client.MInput.GetMousePos(x, y);
writeln(inttostr(x) + ' , ' + inttostr(y));
Client.MInput.ClickMouse(40, 20, mouse_Right);
ptr := Client.MWindow.ReturnData(0, 0, w, h);
{ ptr := Client.MWindow.ReturnData(0, 0, w, h);
for yy := 0 to h - 1 do
for xx := 0 to w - 1 do
begin
{ Do comparison here }
inc(ptr);
end;
Client.MWindow.FreeReturnData;
Client.MWindow.FreeReturnData; }
Client.MInput.IsMouseButtonDown(mouse_Left);
Sleep(1000);
if Client.MInput.IsMouseButtonDown(mouse_Left) then
writeln('Left mouse is down!');
if Client.MInput.IsMouseButtonDown(mouse_Right) then
writeln('Right mouse is down!');
if Client.MInput.IsMouseButtonDown(mouse_Middle) then
writeln('Middle mouse is down!');
Client.Destroy;
writeln('Test completed successfully');
end;