mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-22 09:12:19 -05:00
Ben, either get rid of those run parameters in your compiler options or stop commiting project1.lpi please ^_^.
Added a copydata parameter to TRawTarget.create. (This now fixes a memory leak in Unfreeze). Also please get rid of those two extra spaces in front of everything, so anti-pascal-syntax ^^. Also fixed the bug in IsTargetValid. git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@452 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
parent
3d4131af95
commit
2b8721e6b0
@ -65,7 +65,7 @@ interface
|
|||||||
| Currently this uses the pointer as-is, but it might be needed to make a local copy... }
|
| Currently this uses the pointer as-is, but it might be needed to make a local copy... }
|
||||||
TRawTarget = class(TTarget)
|
TRawTarget = class(TTarget)
|
||||||
public
|
public
|
||||||
constructor Create(rgb: prgb32; w,h: integer);
|
constructor Create(rgb: prgb32; w,h: integer; CopyData : boolean);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
procedure GetTargetDimensions(var w, h: integer); override;
|
procedure GetTargetDimensions(var w, h: integer); override;
|
||||||
@ -73,6 +73,7 @@ interface
|
|||||||
|
|
||||||
private
|
private
|
||||||
rgb: prgb32;
|
rgb: prgb32;
|
||||||
|
freedata : boolean;
|
||||||
w,h: integer;
|
w,h: integer;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -246,387 +247,394 @@ implementation
|
|||||||
|
|
||||||
//***implementation*** TIOManager
|
//***implementation*** TIOManager
|
||||||
|
|
||||||
constructor TIOManager_Abstract.Create(plugin_dir: string);
|
constructor TIOManager_Abstract.Create(plugin_dir: string);
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
eios_controller.AddAndLoadPath(plugin_dir);
|
||||||
|
keymouse:= nil;
|
||||||
|
image:= nil;
|
||||||
|
frozen:= nil;
|
||||||
|
NativeInit;
|
||||||
|
SetDesktop;
|
||||||
|
{
|
||||||
|
self.create;
|
||||||
|
eios_controller.AddAndLoadPath(plugin_dir);
|
||||||
|
}
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TIOManager_Abstract.Create;
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
keymouse:= nil;
|
||||||
|
image:= nil;
|
||||||
|
frozen:= nil;
|
||||||
|
NativeInit;
|
||||||
|
SetDesktop;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TIOManager_Abstract.Destroy;
|
||||||
|
begin
|
||||||
|
if bothsame then keymouse.Destroy() else
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
keymouse.Free();
|
||||||
eios_controller.AddAndLoadPath(plugin_dir);
|
image.Free();
|
||||||
keymouse:= nil;
|
end;
|
||||||
image:= nil;
|
if IsFrozen then frozen.Destroy();
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TIOManager_Abstract.SetImageTarget(target: TTarget);
|
||||||
|
begin
|
||||||
|
if IsFrozen then
|
||||||
|
raise Exception.Create('You cannot set a target when Frozen');
|
||||||
|
if not(bothsame) then image.Free();
|
||||||
|
image:= target;
|
||||||
|
bothsame:= false;
|
||||||
|
end;
|
||||||
|
procedure TIOManager_Abstract.SetKeyMouseTarget(target: TTarget);
|
||||||
|
begin
|
||||||
|
if not(bothsame) then keymouse.Free();
|
||||||
|
keymouse:= target;
|
||||||
|
bothsame:= false;
|
||||||
|
end;
|
||||||
|
procedure TIOManager_Abstract.SetBothTargets(target: TTarget);
|
||||||
|
begin
|
||||||
|
if IsFrozen then
|
||||||
|
raise Exception.Create('You cannot set a target when Frozen');
|
||||||
|
if bothsame then image.Destroy() else
|
||||||
|
begin
|
||||||
|
image.Free();
|
||||||
|
keymouse.Free();
|
||||||
|
end;
|
||||||
|
image:= target;
|
||||||
|
keymouse:= target;
|
||||||
|
bothsame:= true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TIOManager_Abstract.SetFrozen(makefrozen: boolean);
|
||||||
|
var
|
||||||
|
w,h: integer;
|
||||||
|
buffer: TRetData;
|
||||||
|
begin
|
||||||
|
if (makefrozen) and (IsFrozen) then
|
||||||
|
raise Exception.Create('The window is already frozen.');
|
||||||
|
//BenLand100 edit: I say we leave this exception out. POLS
|
||||||
|
//if not(isfrozen) and (frozen = nil) then
|
||||||
|
// raise Exception.Create('The window is not frozen.');
|
||||||
|
if makefrozen then //No need for the Frozen = nil check, already done above with the exception.
|
||||||
|
begin
|
||||||
|
frozen:= image;
|
||||||
|
frozen.GetTargetDimensions(w,h);
|
||||||
|
buffer:= frozen.ReturnData(0,0,w,h);
|
||||||
|
image:= TRawTarget.Create(buffer.Ptr,w,h,true);
|
||||||
|
frozen.FreeReturnData;
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
image.Free();
|
||||||
|
image:= frozen;
|
||||||
frozen:= nil;
|
frozen:= nil;
|
||||||
NativeInit;
|
|
||||||
SetDesktop;
|
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TIOManager_Abstract.Create;
|
function TIOManager_Abstract.IsFrozen: boolean;
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
result:= frozen <> nil;
|
||||||
keymouse:= nil;
|
end;
|
||||||
image:= nil;
|
|
||||||
frozen:= nil;
|
|
||||||
NativeInit;
|
|
||||||
SetDesktop;
|
|
||||||
end;
|
|
||||||
|
|
||||||
destructor TIOManager_Abstract.Destroy;
|
|
||||||
begin
|
|
||||||
if bothsame then keymouse.Destroy() else
|
|
||||||
begin
|
|
||||||
keymouse.Free();
|
|
||||||
image.Free();
|
|
||||||
end;
|
|
||||||
if frozen <> nil then frozen.Destroy();
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TIOManager_Abstract.SetImageTarget(target: TTarget);
|
|
||||||
begin
|
|
||||||
if frozen <> nil then
|
|
||||||
raise Exception.Create('You cannot set a target when Frozen');
|
|
||||||
if not(bothsame) then image.Free();
|
|
||||||
image:= target;
|
|
||||||
bothsame:= false;
|
|
||||||
end;
|
|
||||||
procedure TIOManager_Abstract.SetKeyMouseTarget(target: TTarget);
|
|
||||||
begin
|
|
||||||
if not(bothsame) then keymouse.Free();
|
|
||||||
keymouse:= target;
|
|
||||||
bothsame:= false;
|
|
||||||
end;
|
|
||||||
procedure TIOManager_Abstract.SetBothTargets(target: TTarget);
|
|
||||||
begin
|
|
||||||
if frozen <> nil then
|
|
||||||
raise Exception.Create('You cannot set a target when Frozen');
|
|
||||||
if bothsame then image.Destroy() else
|
|
||||||
begin
|
|
||||||
image.Free();
|
|
||||||
keymouse.Free();
|
|
||||||
end;
|
|
||||||
image:= target;
|
|
||||||
keymouse:= target;
|
|
||||||
bothsame:= true;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TIOManager_Abstract.SetFrozen(makefrozen: boolean);
|
|
||||||
var
|
|
||||||
w,h: integer;
|
|
||||||
buffer: TRetData;
|
|
||||||
begin
|
|
||||||
if (makefrozen) and (frozen <> nil) then
|
|
||||||
raise Exception.Create('The window is already frozen.');
|
|
||||||
//BenLand100 edit: I say we leave this exception out. POLS
|
|
||||||
//if not(isfrozen) and (frozen = nil) then
|
|
||||||
// raise Exception.Create('The window is not frozen.');
|
|
||||||
if not(makefrozen) then
|
|
||||||
begin
|
|
||||||
image.Free();
|
|
||||||
image:= frozen;
|
|
||||||
frozen:= nil;
|
|
||||||
end else if frozen = nil then
|
|
||||||
begin
|
|
||||||
frozen:= image;
|
|
||||||
frozen.GetTargetDimensions(w,h);
|
|
||||||
buffer:= frozen.ReturnData(0,0,w,h);
|
|
||||||
GetMem(freezebuffer, w * h * sizeof(TRGB32));
|
|
||||||
Move(buffer.Ptr[0], freezebuffer[0], w*h*sizeof(TRGB32));
|
|
||||||
frozen.FreeReturnData;
|
|
||||||
image:= TRawTarget.Create(freezebuffer,w,h);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TIOManager_Abstract.IsFrozen: boolean;
|
function TIOManager_Abstract.GetColor(x,y : integer) : TColor; begin result:= image.GetColor(x,y); end;
|
||||||
begin
|
function TIOManager_Abstract.ReturnData(xs,ys,width,height: integer): TRetData; begin result:= image.ReturnData(xs,ys,width,height); end;
|
||||||
result:= frozen <> nil;
|
procedure TIOManager_Abstract.FreeReturnData; begin image.freeReturnData(); end;
|
||||||
end;
|
|
||||||
|
|
||||||
function TIOManager_Abstract.GetColor(x,y : integer) : TColor; begin result:= image.GetColor(x,y); end;
|
function TIOManager_Abstract.SetTarget(ArrPtr: PRGB32; Size: TPoint): integer; begin SetImageTarget(TRawTarget.Create(ArrPtr,Size.X,Size.Y,false)); end;
|
||||||
function TIOManager_Abstract.ReturnData(xs,ys,width,height: integer): TRetData; begin result:= image.ReturnData(xs,ys,width,height); end;
|
function TIOManager_Abstract.SetTarget(bmp : TMufasaBitmap) : integer; begin SetImageTarget(TRawTarget.Create(bmp.FData,bmp.width,bmp.height,false)); end;
|
||||||
procedure TIOManager_Abstract.FreeReturnData; begin image.freeReturnData(); end;
|
function TIOManager_Abstract.SetTarget(name: string; initargs: pointer): integer;
|
||||||
|
var
|
||||||
function TIOManager_Abstract.SetTarget(ArrPtr: PRGB32; Size: TPoint): integer; begin SetImageTarget(TRawTarget.Create(ArrPtr,Size.X,Size.Y)); end;
|
client: TEIOS_Client;
|
||||||
function TIOManager_Abstract.SetTarget(bmp : TMufasaBitmap) : integer; begin SetImageTarget(TRawTarget.Create(bmp.FData,bmp.width,bmp.height)); end;
|
begin
|
||||||
function TIOManager_Abstract.SetTarget(name: string; initargs: pointer): integer;
|
if not eios_controller.ClientExists(name) then raise Exception.Create('EIOS Client by specified name does not exist');
|
||||||
var
|
client:= eios_controller.GetClient(name);
|
||||||
client: TEIOS_Client;
|
SetBothTargets(TEIOS_Target.Create(client, initargs));
|
||||||
begin
|
end;
|
||||||
if not eios_controller.ClientExists(name) then raise Exception.Create('EIOS Client by specified name does not exist');
|
|
||||||
client:= eios_controller.GetClient(name);
|
|
||||||
SetBothTargets(TEIOS_Target.Create(client, initargs));
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TIOManager_Abstract.TargetValid: Boolean;
|
|
||||||
begin
|
|
||||||
result:= false;
|
|
||||||
if (keymouse <> nil) and (image <> nil) then
|
|
||||||
begin
|
|
||||||
|
|
||||||
end;
|
function TIOManager_Abstract.TargetValid: Boolean;
|
||||||
end;
|
begin
|
||||||
|
result:= false;
|
||||||
|
if (keymouse <> nil) and (image <> nil) then
|
||||||
|
result := (keymouse.TargetValid and image.TargetValid);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TIOManager_Abstract.GetDimensions(var W, H: Integer); begin image.GetTargetDimensions(w,h) end;
|
procedure TIOManager_Abstract.GetDimensions(var W, H: Integer); begin image.GetTargetDimensions(w,h) end;
|
||||||
procedure TIOManager_Abstract.ActivateClient; begin {lolwat} end;
|
procedure TIOManager_Abstract.ActivateClient; begin {lolwat} end;
|
||||||
|
|
||||||
procedure TIOManager_Abstract.GetMousePos(var X, Y: Integer); begin keymouse.GetMousePosition(x,y) end;
|
procedure TIOManager_Abstract.GetMousePos(var X, Y: Integer); begin keymouse.GetMousePosition(x,y) end;
|
||||||
procedure TIOManager_Abstract.SetMousePos(X, Y: Integer); begin keymouse.MoveMouse(x,y); end;
|
procedure TIOManager_Abstract.SetMousePos(X, Y: Integer); begin keymouse.MoveMouse(x,y); end;
|
||||||
procedure TIOManager_Abstract.HoldMouse(x,y : integer; button: TClickType); begin keymouse.ReleaseMouse(x,y,button); end;
|
procedure TIOManager_Abstract.HoldMouse(x,y : integer; button: TClickType); begin keymouse.ReleaseMouse(x,y,button); end;
|
||||||
procedure TIOManager_Abstract.ReleaseMouse(x,y : integer; button: TClickType); begin keymouse.ReleaseMouse(x,y,button); end;
|
procedure TIOManager_Abstract.ReleaseMouse(x,y : integer; button: TClickType); begin keymouse.ReleaseMouse(x,y,button); end;
|
||||||
procedure TIOManager_Abstract.ClickMouse(X, Y: Integer; button: TClickType);
|
procedure TIOManager_Abstract.ClickMouse(X, Y: Integer; button: TClickType);
|
||||||
begin
|
begin
|
||||||
HoldMouse(x,y,button);
|
HoldMouse(x,y,button);
|
||||||
//BenLand100 note: probably should wait here
|
//BenLand100 note: probably should wait here
|
||||||
ReleaseMouse(x,y,button);
|
ReleaseMouse(x,y,button);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TIOManager_Abstract.KeyUp(key: Word); begin keymouse.ReleaseKey(key) end;
|
||||||
|
procedure TIOManager_Abstract.KeyDown(key: Word); begin keymouse.HoldKey(key) end;
|
||||||
|
procedure TIOManager_Abstract.PressKey(key: Word); begin keyup(key); keydown(key); end;
|
||||||
|
procedure TIOManager_Abstract.SendText(text: string); begin keymouse.SendString(text); end;
|
||||||
|
function TIOManager_Abstract.isKeyDown(key: Word): Boolean; begin result:= keymouse.IsKeyHeld(key); end;
|
||||||
|
|
||||||
procedure TIOManager_Abstract.KeyUp(key: Word); begin keymouse.ReleaseKey(key) end;
|
|
||||||
procedure TIOManager_Abstract.KeyDown(key: Word); begin keymouse.HoldKey(key) end;
|
|
||||||
procedure TIOManager_Abstract.PressKey(key: Word); begin keyup(key); keydown(key); end;
|
|
||||||
procedure TIOManager_Abstract.SendText(text: string); begin keymouse.SendString(text); end;
|
|
||||||
function TIOManager_Abstract.isKeyDown(key: Word): Boolean; begin result:= keymouse.IsKeyHeld(key); end;
|
|
||||||
|
|
||||||
//***implementation*** TTarget
|
//***implementation*** TTarget
|
||||||
|
|
||||||
procedure TTarget.GetTargetDimensions(var w, h: integer); begin raise Exception.Create('GetTargetDimensions not avaliable for this target'); end;
|
|
||||||
function TTarget.GetColor(x,y : integer) : TColor;
|
|
||||||
begin
|
|
||||||
with ReturnData(x,y,1,1) do
|
|
||||||
Result := RGBToColor(Ptr[0].r,Ptr[0].g,Ptr[0].b);
|
|
||||||
FreeReturnData;
|
|
||||||
end;
|
|
||||||
function TTarget.ReturnData(xs, ys, width, height: Integer): TRetData; begin raise Exception.Create('ReturnData not avaliable for this target'); end;
|
|
||||||
procedure TTarget.FreeReturnData; begin {do nothing by default} end;
|
|
||||||
procedure TTarget.ActivateClient; begin raise Exception.Create('ActivateClient not avaliable for this target'); end;
|
|
||||||
function TTarget.TargetValid: boolean; begin result:= true; end;
|
|
||||||
|
|
||||||
procedure TTarget.GetMousePosition(var x,y: integer); begin raise Exception.Create('GetMousePosition not avaliable for this target'); end;
|
procedure TTarget.GetTargetDimensions(var w, h: integer); begin raise Exception.Create('GetTargetDimensions not avaliable for this target'); end;
|
||||||
procedure TTarget.MoveMouse(x,y: integer); begin raise Exception.Create('MoveMouse not avaliable for this target'); end;
|
function TTarget.GetColor(x,y : integer) : TColor;
|
||||||
procedure TTarget.HoldMouse(x,y: integer; button: TClickType); begin raise Exception.Create('HoldMouse not avaliable for this target'); end;
|
begin
|
||||||
procedure TTarget.ReleaseMouse(x,y: integer; button: TClickType); begin raise Exception.Create('ReleaseMouse not avaliable for this target'); end;
|
with ReturnData(x,y,1,1) do
|
||||||
|
Result := RGBToColor(Ptr[0].r,Ptr[0].g,Ptr[0].b);
|
||||||
|
FreeReturnData;
|
||||||
|
end;
|
||||||
|
function TTarget.ReturnData(xs, ys, width, height: Integer): TRetData; begin raise Exception.Create('ReturnData not avaliable for this target'); end;
|
||||||
|
procedure TTarget.FreeReturnData; begin {do nothing by default} end;
|
||||||
|
procedure TTarget.ActivateClient; begin raise Exception.Create('ActivateClient not avaliable for this target'); end;
|
||||||
|
function TTarget.TargetValid: boolean; begin result:= true; end;
|
||||||
|
|
||||||
|
procedure TTarget.GetMousePosition(var x,y: integer); begin raise Exception.Create('GetMousePosition not avaliable for this target'); end;
|
||||||
|
procedure TTarget.MoveMouse(x,y: integer); begin raise Exception.Create('MoveMouse not avaliable for this target'); end;
|
||||||
|
procedure TTarget.HoldMouse(x,y: integer; button: TClickType); begin raise Exception.Create('HoldMouse not avaliable for this target'); end;
|
||||||
|
procedure TTarget.ReleaseMouse(x,y: integer; button: TClickType); begin raise Exception.Create('ReleaseMouse not avaliable for this target'); end;
|
||||||
|
|
||||||
|
procedure TTarget.SendString(str: string); begin raise Exception.Create('SendString not avaliable for this target'); end;
|
||||||
|
procedure TTarget.HoldKey(key: integer); begin raise Exception.Create('HoldKey not avaliable for this target'); end;
|
||||||
|
procedure TTarget.ReleaseKey(key: integer); begin raise Exception.Create('ReleaseKey not avaliable for this target'); end;
|
||||||
|
function TTarget.IsKeyHeld(key: integer): boolean; begin raise Exception.Create('IsKeyHeld not avaliable for this target'); end;
|
||||||
|
|
||||||
procedure TTarget.SendString(str: string); begin raise Exception.Create('SendString not avaliable for this target'); end;
|
|
||||||
procedure TTarget.HoldKey(key: integer); begin raise Exception.Create('HoldKey not avaliable for this target'); end;
|
|
||||||
procedure TTarget.ReleaseKey(key: integer); begin raise Exception.Create('ReleaseKey not avaliable for this target'); end;
|
|
||||||
function TTarget.IsKeyHeld(key: integer): boolean; begin raise Exception.Create('IsKeyHeld not avaliable for this target'); end;
|
|
||||||
|
|
||||||
//***implementation*** TEIOS_Target
|
//***implementation*** TEIOS_Target
|
||||||
|
|
||||||
constructor TEIOS_Target.Create(client: TEIOS_Client; initval: pointer); begin
|
constructor TEIOS_Target.Create(client: TEIOS_Client; initval: pointer); begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
self.client:= client;
|
self.client:= client;
|
||||||
if Pointer(client.RequestTarget) <> nil then
|
if Pointer(client.RequestTarget) <> nil then
|
||||||
self.target:= client.RequestTarget(initval);
|
self.target:= client.RequestTarget(initval);
|
||||||
if Pointer(client.GetImageBuffer) <> nil then
|
if Pointer(client.GetImageBuffer) <> nil then
|
||||||
self.buffer:= client.GetImageBuffer(target)
|
self.buffer:= client.GetImageBuffer(target)
|
||||||
else
|
else
|
||||||
self.buffer:= nil;
|
self.buffer:= nil;
|
||||||
GetTargetDimensions(self.width,self.height);
|
GetTargetDimensions(self.width,self.height);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TEIOS_Target.Destroy; begin
|
destructor TEIOS_Target.Destroy; begin
|
||||||
client.ReleaseTarget(self.target);
|
client.ReleaseTarget(self.target);
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TEIOS_Target.GetTargetDimensions(var w, h: integer);
|
||||||
|
begin
|
||||||
|
if Pointer(client.GetTargetDimensions) <> nil then
|
||||||
|
client.GetTargetDimensions(target,w,h)
|
||||||
|
else
|
||||||
|
inherited GetTargetDimensions(w,h);
|
||||||
|
end;
|
||||||
|
function TEIOS_Target.ReturnData(xs, ys, width, height: Integer): TRetData;
|
||||||
|
begin
|
||||||
|
if Pointer(client.UpdateImageBufferBounds) <> nil then
|
||||||
|
client.UpdateImageBufferBounds(target,xs,ys,xs+width,ys+height)
|
||||||
|
else if Pointer(client.UpdateImageBuffer) <> nil then
|
||||||
|
client.UpdateImageBuffer(target)
|
||||||
|
else begin
|
||||||
|
{no update command exported}
|
||||||
end;
|
end;
|
||||||
|
result.Ptr := buffer;
|
||||||
procedure TEIOS_Target.GetTargetDimensions(var w, h: integer);
|
result.RowLen:= self.width;
|
||||||
|
result.IncPtrWith:= result.RowLen - width;
|
||||||
|
Inc(result.Ptr, ys * result.RowLen + xs);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TEIOS_Target.GetMousePosition(var x,y: integer);
|
||||||
|
begin
|
||||||
|
if Pointer(client.GetMousePosition) <> nil then
|
||||||
|
client.GetMousePosition(target,x,y)
|
||||||
|
else
|
||||||
|
inherited GetMousePosition(x,y);
|
||||||
|
end;
|
||||||
|
procedure TEIOS_Target.MoveMouse(x,y: integer);
|
||||||
|
begin
|
||||||
|
if Pointer(client.MoveMouse) <> nil then
|
||||||
|
client.MoveMouse(target,x,y)
|
||||||
|
else
|
||||||
|
inherited MoveMouse(x,y);
|
||||||
|
end;
|
||||||
|
procedure TEIOS_Target.HoldMouse(x,y: integer; button: TClickType);
|
||||||
|
begin
|
||||||
|
if Pointer(client.HoldMouse) <> nil then
|
||||||
begin
|
begin
|
||||||
if Pointer(client.GetTargetDimensions) <> nil then
|
case button of
|
||||||
client.GetTargetDimensions(target,w,h)
|
mouse_Left: client.HoldMouse(target,x,y,true);
|
||||||
else
|
mouse_Middle: raise Exception.Create('EIOS does not implement the middle mouse button.');
|
||||||
inherited GetTargetDimensions(w,h);
|
mouse_Right: client.HoldMouse(target,x,y,false);
|
||||||
end;
|
|
||||||
function TEIOS_Target.ReturnData(xs, ys, width, height: Integer): TRetData;
|
|
||||||
begin
|
|
||||||
if Pointer(client.UpdateImageBufferBounds) <> nil then
|
|
||||||
client.UpdateImageBufferBounds(target,xs,ys,xs+width,ys+height)
|
|
||||||
else if Pointer(client.UpdateImageBuffer) <> nil then
|
|
||||||
client.UpdateImageBuffer(target)
|
|
||||||
else begin
|
|
||||||
{no update command exported}
|
|
||||||
end;
|
end;
|
||||||
result.Ptr := buffer;
|
end else
|
||||||
result.RowLen:= self.width;
|
inherited HoldMouse(x,y,button);
|
||||||
result.IncPtrWith:= result.RowLen - width;
|
end;
|
||||||
Inc(result.Ptr, ys * result.RowLen + xs);
|
procedure TEIOS_Target.ReleaseMouse(x,y: integer; button: TClickType);
|
||||||
end;
|
begin
|
||||||
|
if Pointer(client.ReleaseMouse) <> nil then
|
||||||
|
begin
|
||||||
|
case button of
|
||||||
|
mouse_Left: client.ReleaseMouse(target,x,y,true);
|
||||||
|
mouse_Middle: raise Exception.Create('EIOS does not implement the middle mouse button.');
|
||||||
|
mouse_Right: client.ReleaseMouse(target,x,y,false);
|
||||||
|
end;
|
||||||
|
end else
|
||||||
|
inherited ReleaseMouse(x,y,button);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TEIOS_Target.GetMousePosition(var x,y: integer);
|
procedure TEIOS_Target.SendString(str: string);
|
||||||
begin
|
begin
|
||||||
if Pointer(client.GetMousePosition) <> nil then
|
if Pointer(client.SendString) <> nil then
|
||||||
client.GetMousePosition(target,x,y)
|
client.SendString(target,PChar(str))
|
||||||
else
|
else
|
||||||
inherited GetMousePosition(x,y);
|
inherited SendString(str);
|
||||||
end;
|
end;
|
||||||
procedure TEIOS_Target.MoveMouse(x,y: integer);
|
procedure TEIOS_Target.HoldKey(key: integer);
|
||||||
begin
|
begin
|
||||||
if Pointer(client.MoveMouse) <> nil then
|
if Pointer(client.HoldKey) <> nil then
|
||||||
client.MoveMouse(target,x,y)
|
client.HoldKey(target,key)
|
||||||
else
|
else
|
||||||
inherited MoveMouse(x,y);
|
inherited HoldKey(key);
|
||||||
end;
|
end;
|
||||||
procedure TEIOS_Target.HoldMouse(x,y: integer; button: TClickType);
|
procedure TEIOS_Target.ReleaseKey(key: integer);
|
||||||
begin
|
begin
|
||||||
if Pointer(client.HoldMouse) <> nil then
|
if Pointer(client.ReleaseKey) <> nil then
|
||||||
begin
|
client.ReleaseKey(target,key)
|
||||||
case button of
|
else
|
||||||
mouse_Left: client.HoldMouse(target,x,y,true);
|
inherited ReleaseKey(key);
|
||||||
mouse_Middle: raise Exception.Create('EIOS does not implement the middle mouse button.');
|
end;
|
||||||
mouse_Right: client.HoldMouse(target,x,y,false);
|
function TEIOS_Target.IsKeyHeld(key: integer): boolean;
|
||||||
end;
|
begin
|
||||||
end else
|
if Pointer(client.IsKeyHeld) <> nil then
|
||||||
inherited HoldMouse(x,y,button);
|
result:= client.IsKeyHeld(target,key)
|
||||||
end;
|
else
|
||||||
procedure TEIOS_Target.ReleaseMouse(x,y: integer; button: TClickType);
|
result:= inherited IsKeyHeld(key);
|
||||||
begin
|
end;
|
||||||
if Pointer(client.ReleaseMouse) <> nil then
|
|
||||||
begin
|
|
||||||
case button of
|
|
||||||
mouse_Left: client.ReleaseMouse(target,x,y,true);
|
|
||||||
mouse_Middle: raise Exception.Create('EIOS does not implement the middle mouse button.');
|
|
||||||
mouse_Right: client.ReleaseMouse(target,x,y,false);
|
|
||||||
end;
|
|
||||||
end else
|
|
||||||
inherited ReleaseMouse(x,y,button);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TEIOS_Target.SendString(str: string);
|
|
||||||
begin
|
|
||||||
if Pointer(client.SendString) <> nil then
|
|
||||||
client.SendString(target,PChar(str))
|
|
||||||
else
|
|
||||||
inherited SendString(str);
|
|
||||||
end;
|
|
||||||
procedure TEIOS_Target.HoldKey(key: integer);
|
|
||||||
begin
|
|
||||||
if Pointer(client.HoldKey) <> nil then
|
|
||||||
client.HoldKey(target,key)
|
|
||||||
else
|
|
||||||
inherited HoldKey(key);
|
|
||||||
end;
|
|
||||||
procedure TEIOS_Target.ReleaseKey(key: integer);
|
|
||||||
begin
|
|
||||||
if Pointer(client.ReleaseKey) <> nil then
|
|
||||||
client.ReleaseKey(target,key)
|
|
||||||
else
|
|
||||||
inherited ReleaseKey(key);
|
|
||||||
end;
|
|
||||||
function TEIOS_Target.IsKeyHeld(key: integer): boolean;
|
|
||||||
begin
|
|
||||||
if Pointer(client.IsKeyHeld) <> nil then
|
|
||||||
result:= client.IsKeyHeld(target,key)
|
|
||||||
else
|
|
||||||
result:= inherited IsKeyHeld(key);
|
|
||||||
end;
|
|
||||||
|
|
||||||
//***implementation*** TRawTarget
|
//***implementation*** TRawTarget
|
||||||
|
|
||||||
constructor TRawTarget.Create(rgb: prgb32; w,h: integer);
|
constructor TRawTarget.Create(rgb: prgb32; w,h: integer; CopyData : boolean);
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
self.w:= w;
|
||||||
|
self.h:= h;
|
||||||
|
self.freedata:= copydata;
|
||||||
|
if CopyData then
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
GetMem(self.rgb,w*h*sizeof(TRGB32));
|
||||||
|
Move(rgb[0],self.rgb[0],w*h*sizeof(TRGB32));
|
||||||
|
end else
|
||||||
self.rgb:= rgb;
|
self.rgb:= rgb;
|
||||||
self.w:= w;
|
end;
|
||||||
self.h:= h;
|
|
||||||
end;
|
destructor TRawTarget.Destroy;
|
||||||
|
begin
|
||||||
destructor TRawTarget.Destroy;
|
if freedata then
|
||||||
begin
|
Freemem(self.rgb,w*h*sizeof(TRGB32));
|
||||||
{do nothing}
|
inherited Destroy;
|
||||||
inherited Destroy;
|
end;
|
||||||
end;
|
|
||||||
|
procedure TRawTarget.GetTargetDimensions(var w, h: integer);
|
||||||
procedure TRawTarget.GetTargetDimensions(var w, h: integer);
|
begin
|
||||||
begin
|
w:= self.w;
|
||||||
w:= self.w;
|
h:= self.h;
|
||||||
h:= self.h;
|
end;
|
||||||
end;
|
|
||||||
|
function TRawTarget.ReturnData(xs, ys, width, height: Integer): TRetData;
|
||||||
function TRawTarget.ReturnData(xs, ys, width, height: Integer): TRetData;
|
begin
|
||||||
begin
|
result.Ptr := rgb;
|
||||||
result.Ptr := rgb;
|
result.RowLen:= self.w;
|
||||||
result.RowLen:= self.w;
|
result.IncPtrWith:= result.RowLen - width;
|
||||||
result.IncPtrWith:= result.RowLen - width;
|
Inc(result.Ptr, ys * result.RowLen + xs);
|
||||||
Inc(result.Ptr, ys * result.RowLen + xs);
|
end;
|
||||||
end;
|
|
||||||
|
|
||||||
//***implementation*** TEIOS_Controller
|
//***implementation*** TEIOS_Controller
|
||||||
|
|
||||||
constructor TEIOS_Controller.Create();
|
|
||||||
begin
|
|
||||||
inherited Create;
|
|
||||||
end;
|
|
||||||
|
|
||||||
destructor TEIOS_Controller.Destroy;
|
constructor TEIOS_Controller.Create();
|
||||||
var
|
begin
|
||||||
i: integer;
|
inherited Create;
|
||||||
begin
|
end;
|
||||||
SetLength(plugs,0);
|
|
||||||
inherited Destroy;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TEIOS_Controller.InitPlugin(plugin: TLibHandle): boolean;
|
destructor TEIOS_Controller.Destroy;
|
||||||
var
|
var
|
||||||
GetName: procedure(name: pchar); stdcall;
|
i: integer;
|
||||||
buffer: pchar;
|
begin
|
||||||
idx: integer;
|
SetLength(plugs,0);
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TEIOS_Controller.InitPlugin(plugin: TLibHandle): boolean;
|
||||||
|
var
|
||||||
|
GetName: procedure(name: pchar); stdcall;
|
||||||
|
buffer: pchar;
|
||||||
|
idx: integer;
|
||||||
|
begin
|
||||||
|
Pointer(GetName) := GetProcAddress(plugin, PChar('EIOS_GetName'));
|
||||||
|
if Pointer(GetName) = nil then begin result:= false; exit; end;
|
||||||
|
idx:= Length(plugs);
|
||||||
|
SetLength(plugs,idx+1);
|
||||||
|
buffer:= stralloc(255);
|
||||||
|
GetName(buffer);
|
||||||
|
plugs[idx].name:= buffer;
|
||||||
|
strdispose(buffer);
|
||||||
|
{link in all eios methods that *might* exist}
|
||||||
|
with plugs[idx].client do
|
||||||
begin
|
begin
|
||||||
Pointer(GetName) := GetProcAddress(plugin, PChar('EIOS_GetName'));
|
Pointer(RequestTarget):= GetProcAddress(plugin, PChar('EIOS_RequestTarget'));
|
||||||
if Pointer(GetName) = nil then begin result:= false; exit; end;
|
Pointer(ReleaseTarget):= GetProcAddress(plugin, PChar('EIOS_ReleaseTarget'));
|
||||||
idx:= Length(plugs);
|
|
||||||
SetLength(plugs,idx+1);
|
Pointer(GetTargetDimensions):= GetProcAddress(plugin, PChar('EIOS_GetTargetDimensions'));
|
||||||
buffer:= stralloc(255);
|
Pointer(GetImageBuffer):= GetProcAddress(plugin, PChar('EIOS_GetImageBuffer'));
|
||||||
GetName(buffer);
|
Pointer(UpdateImageBuffer):= GetProcAddress(plugin, PChar('EIOS_UpdateImageBuffer'));
|
||||||
plugs[idx].name:= buffer;
|
Pointer(UpdateImageBufferBounds):= GetProcAddress(plugin, PChar('EIOS_UpdateImageBufferBounds'));
|
||||||
strdispose(buffer);
|
|
||||||
{link in all eios methods that *might* exist}
|
Pointer(GetMousePosition):= GetProcAddress(plugin, PChar('EIOS_GetMousePosition'));
|
||||||
with plugs[idx].client do
|
Pointer(MoveMouse):= GetProcAddress(plugin, PChar('EIOS_MoveMouse'));
|
||||||
|
Pointer(HoldMouse):= GetProcAddress(plugin, PChar('EIOS_HoldMouse'));
|
||||||
|
Pointer(ReleaseMouse):= GetProcAddress(plugin, PChar('EIOS_ReleaseMouse'));
|
||||||
|
|
||||||
|
Pointer(SendString):= GetProcAddress(plugin, PChar('EIOS_SendString'));
|
||||||
|
Pointer(HoldKey):= GetProcAddress(plugin, PChar('EIOS_HoldKey'));
|
||||||
|
Pointer(ReleaseKey):= GetProcAddress(plugin, PChar('EIOS_ReleaseKey'));
|
||||||
|
Pointer(IsKeyHeld):= GetProcAddress(plugin, PChar('EIOS_IsKeyHeld'));
|
||||||
|
end;
|
||||||
|
{done linking in methods}
|
||||||
|
result:= true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TEIOS_Controller.FindClient(name: string): integer;
|
||||||
|
var
|
||||||
|
i: integer;
|
||||||
|
begin
|
||||||
|
for i:= 0 to length(plugs) - 1 do
|
||||||
|
if plugs[i].name = name then
|
||||||
begin
|
begin
|
||||||
Pointer(RequestTarget):= GetProcAddress(plugin, PChar('EIOS_RequestTarget'));
|
result:= i;
|
||||||
Pointer(ReleaseTarget):= GetProcAddress(plugin, PChar('EIOS_ReleaseTarget'));
|
exit;
|
||||||
|
|
||||||
Pointer(GetTargetDimensions):= GetProcAddress(plugin, PChar('EIOS_GetTargetDimensions'));
|
|
||||||
Pointer(GetImageBuffer):= GetProcAddress(plugin, PChar('EIOS_GetImageBuffer'));
|
|
||||||
Pointer(UpdateImageBuffer):= GetProcAddress(plugin, PChar('EIOS_UpdateImageBuffer'));
|
|
||||||
Pointer(UpdateImageBufferBounds):= GetProcAddress(plugin, PChar('EIOS_UpdateImageBufferBounds'));
|
|
||||||
|
|
||||||
Pointer(GetMousePosition):= GetProcAddress(plugin, PChar('EIOS_GetMousePosition'));
|
|
||||||
Pointer(MoveMouse):= GetProcAddress(plugin, PChar('EIOS_MoveMouse'));
|
|
||||||
Pointer(HoldMouse):= GetProcAddress(plugin, PChar('EIOS_HoldMouse'));
|
|
||||||
Pointer(ReleaseMouse):= GetProcAddress(plugin, PChar('EIOS_ReleaseMouse'));
|
|
||||||
|
|
||||||
Pointer(SendString):= GetProcAddress(plugin, PChar('EIOS_SendString'));
|
|
||||||
Pointer(HoldKey):= GetProcAddress(plugin, PChar('EIOS_HoldKey'));
|
|
||||||
Pointer(ReleaseKey):= GetProcAddress(plugin, PChar('EIOS_ReleaseKey'));
|
|
||||||
Pointer(IsKeyHeld):= GetProcAddress(plugin, PChar('EIOS_IsKeyHeld'));
|
|
||||||
end;
|
end;
|
||||||
{done linking in methods}
|
result:= -1;
|
||||||
result:= true;
|
end;
|
||||||
end;
|
|
||||||
|
|
||||||
function TEIOS_Controller.FindClient(name: string): integer;
|
function TEIOS_Controller.ClientExists(name: string): boolean;
|
||||||
var
|
begin
|
||||||
i: integer;
|
result:= FindClient(name) >= 0;
|
||||||
begin
|
end;
|
||||||
for i:= 0 to length(plugs) - 1 do
|
|
||||||
if plugs[i].name = name then
|
|
||||||
begin
|
|
||||||
result:= i;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
result:= -1;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TEIOS_Controller.ClientExists(name: string): boolean;
|
|
||||||
begin
|
|
||||||
result:= FindClient(name) >= 0;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TEIOS_Controller.GetClient(name: string): TEIOS_Client;
|
|
||||||
var
|
|
||||||
i: integer;
|
|
||||||
begin
|
|
||||||
i:= FindClient(name);
|
|
||||||
if i >= 0 then
|
|
||||||
result:= plugs[i].client
|
|
||||||
end;
|
|
||||||
|
|
||||||
initialization
|
function TEIOS_Controller.GetClient(name: string): TEIOS_Client;
|
||||||
eios_controller:= TEIOS_Controller.Create;
|
var
|
||||||
finalization
|
i: integer;
|
||||||
eios_controller.Free;
|
begin
|
||||||
|
i:= FindClient(name);
|
||||||
|
if i >= 0 then
|
||||||
|
result:= plugs[i].client
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
eios_controller:= TEIOS_Controller.Create;
|
||||||
|
finalization
|
||||||
|
eios_controller.Free;
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user