1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-08-13 16:53:59 -04:00
Simba/Projects/MMLLib/libmml.lpr

208 lines
3.9 KiB
ObjectPascal
Raw Normal View History

library libmml;
{$mode objfpc}{$H+}
uses
2010-03-26 10:20:50 -04:00
cmem,Classes,interfaces,graphics,client,sysutils,MufasaTypes,dtmutil;
{$R *.res}
2010-03-26 07:22:08 -04:00
type
PTPoint = ^TPoint;
2010-03-30 18:24:16 -04:00
Const
RESULT_OK = 0;
RESULT_FALSE = 1;
RESULT_ERROR = -1;
MOUSE_UP = 0;
MOUSE_DOWN = 1;
2010-03-30 18:24:16 -04:00
var
C: TClient;
2010-03-30 18:24:16 -04:00
gr: Pointer;
last_error: PChar;
function init: integer; cdecl;
begin
2010-03-30 18:24:16 -04:00
C:=TClient.Create('');
result:=0;
end;
2010-03-30 18:24:16 -04:00
{ Mouse }
function getMousePos(var t: tpoint): integer; cdecl;
2010-03-30 18:24:16 -04:00
begin
2010-03-30 18:24:16 -04:00
try
C.IOManager.GetMousePos(t.x,t.y);
result := RESULT_OK;
except on e : Exception do
begin
result := RESULT_ERROR;
last_error := PChar(e.Message);
end;
end;
end;
function setMousePos(var t: tpoint): integer; cdecl;
begin
try
2010-05-31 19:59:48 -04:00
C.IOManager.MoveMouse(t.x,t.y);
result := RESULT_OK;
except on e : Exception do
begin
result := RESULT_ERROR;
last_error := PChar(e.Message);
end;
end;
end;
function ConvIntClickType(Int : Integer) : TClickType;inline;
begin
2010-03-30 18:24:16 -04:00
case int of
0 : result := mouse_Left;
1 : result := mouse_Right;
2: result := mouse_Middle;
2010-03-30 18:24:16 -04:00
end;
end;
2010-03-30 18:24:16 -04:00
function getMouseButtonState(But: Integer): Integer;
begin
try
if C.IOManager.IsMouseButtonDown(ConvIntClickType(But)) then
result := MOUSE_DOWN;
except on e : Exception do
begin
result := RESULT_ERROR;
last_error := PChar(e.Message);
end;
end;
end;
function setMouseButtonState(But, State, X, Y: Integer): Integer;
begin
try
if State = MOUSE_UP then
begin
C.IOManager.ReleaseMouse(X, Y, ConvIntClickType(But));
result := RESULT_OK;
end else if state = MOUSE_DOWN then
begin
C.IOManager.HoldMouse(X, Y, ConvIntClickType(But));
result := RESULT_OK;
end;
except on e : Exception do
begin
result := RESULT_ERROR;
last_error := PChar(e.Message);
end;
end;
end;
2010-03-30 18:24:16 -04:00
2010-05-31 20:03:25 -04:00
function findColor(var x, y: integer; color, x1, y1, x2, y2: integer): integer;
2010-05-31 19:59:48 -04:00
begin
2010-05-31 20:03:25 -04:00
try
if C.MFinder.FindColor(x, y, color, x1, y1, x2, y2) then
result := RESULT_OK
else
result := RESULT_FALSE;
2010-05-31 20:03:25 -04:00
except on e : Exception do
begin
result := RESULT_ERROR;
last_error := PChar(e.Message);
end;
end;
2010-05-31 19:59:48 -04:00
end;
function findColorTolerance(var x, y: integer; color, tol, x1, y1, x2, y2: integer): integer;
2010-03-26 10:20:50 -04:00
begin
try
if C.MFinder.FindColorTolerance(x, y, color, x1, y1, x2, y2, tol) then
result := RESULT_OK
else
result := RESULT_FALSE;
except on e : Exception do
begin
result := RESULT_ERROR;
last_error := PChar(e.Message);
end;
end;
2010-03-26 10:20:50 -04:00
end;
function findColors(var ptr: PTPoint; color, x1, y1, x2, y2: integer): integer;
2010-03-30 18:24:16 -04:00
var
TPA: TPointArray;
2010-03-30 18:24:16 -04:00
begin
try
C.MFinder.FindColors(TPA, color, x1, y1, x2, y2);
except on e : Exception do
begin
result := RESULT_ERROR;
last_error := PChar(e.Message);
end;
end;
ptr := AllocMem(sizeof(tpoint) * (length(TPA) + 1));
PInteger(ptr)[0] := length(TPA);
Move(TPA[0], ptr[1], length(TPA)*sizeof(tpoint));
2010-03-30 18:24:16 -04:00
end;
function findColorsTolerance(var ptr: PTPoint; color, tol, x1, y1, x2, y2: integer): integer;
2010-03-30 18:24:16 -04:00
var
TPA: TPointArray;
2010-03-30 18:24:16 -04:00
begin
try
C.MFinder.FindColorsTolerance(TPA, color, x1, y1, x2, y2, tol);
except on e : Exception do
begin
result := RESULT_ERROR;
last_error := PChar(e.Message);
end;
end;
ptr := AllocMem(sizeof(tpoint) * (length(TPA) + 1));
PInteger(ptr)[0] := length(TPA);
Move(TPA[0], ptr[1], length(TPA)*sizeof(tpoint));
2010-03-30 18:24:16 -04:00
end;
procedure fpc_freemem_(p:pointer); cdecl;
begin
freemem(pointer(ptruint(p)));
end;
function fpc_allocmem_(size: ptruint): pointer; cdecl;
begin
result:= AllocMem(size);
2010-03-30 18:24:16 -04:00
end;
function fpc_reallocmem_(size: ptruint; ptr: pointer): pointer;
begin
result:= ReAllocMem(ptr, size);
2010-03-30 18:24:16 -04:00
end;
exports
init,
2010-05-31 19:59:48 -04:00
{ Mouse }
getMousePos,
setMousePos,
getMouseButtonState,
setMouseButtonState,
2010-05-31 19:59:48 -04:00
{ Finder }
findColor,
findColors,
2010-06-27 18:20:35 -04:00
findColorTolerance,
findColorsTolerance,
2010-05-31 19:59:48 -04:00
{ Mem Management }
2010-03-30 18:24:16 -04:00
fpc_freemem_,
fpc_allocmem_,
fpc_reallocmem_;
begin
end.