2010-03-25 20:36:09 -04:00
|
|
|
library libmml;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
uses
|
2010-11-30 20:05:50 -05:00
|
|
|
cmem,Classes,interfaces,graphics,client,sysutils,MufasaTypes,dtmutil, dtm;
|
2010-03-25 20:36:09 -04:00
|
|
|
|
|
|
|
{$R *.res}
|
|
|
|
|
2010-03-30 18:24:16 -04:00
|
|
|
Const
|
|
|
|
RESULT_OK = 0;
|
2010-06-01 07:40:51 -04:00
|
|
|
RESULT_FALSE = 1;
|
2010-04-01 19:48:06 -04:00
|
|
|
RESULT_ERROR = -1;
|
|
|
|
|
|
|
|
MOUSE_UP = 0;
|
|
|
|
MOUSE_DOWN = 1;
|
2010-03-30 18:24:16 -04:00
|
|
|
|
2010-03-25 20:36:09 -04:00
|
|
|
var
|
2010-09-12 08:28:19 -04:00
|
|
|
last_error: String;
|
2010-09-05 14:43:45 -04:00
|
|
|
debug: boolean;
|
2010-03-30 18:24:16 -04:00
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
{ This must be called on Library load }
|
|
|
|
|
2010-11-30 20:05:50 -05:00
|
|
|
function init: integer; cdecl;
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
|
|
|
last_error := '';
|
|
|
|
debug := true;
|
|
|
|
result := RESULT_OK;
|
|
|
|
end;
|
2010-03-30 18:24:16 -04:00
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
procedure set_last_error(s: string);
|
|
|
|
begin
|
|
|
|
last_error := s;
|
|
|
|
if debug then
|
|
|
|
writeln('ERROR: ' + s);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Validate the TClient. If it is NULL, set last error and return false }
|
2010-09-05 14:43:45 -04:00
|
|
|
function validate_client(C: TClient): boolean; inline;
|
2010-03-25 20:36:09 -04:00
|
|
|
begin
|
2010-09-05 14:43:45 -04:00
|
|
|
result := Assigned(C);
|
|
|
|
if not result then
|
|
|
|
begin
|
2010-09-12 08:28:19 -04:00
|
|
|
last_error := 'PClient is NULL';
|
2010-09-05 14:43:45 -04:00
|
|
|
if debug then
|
|
|
|
writeln(last_error);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
{
|
|
|
|
Create a TClient.
|
|
|
|
You can use multiple, but you'll have to manage them yourself.
|
|
|
|
}
|
2010-09-05 14:43:45 -04:00
|
|
|
function create_client: PtrUInt; cdecl;
|
|
|
|
var
|
|
|
|
C: TClient;
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
C := TClient.Create('');
|
|
|
|
Result := PtrUInt(C);
|
|
|
|
except on e : Exception do
|
|
|
|
begin
|
2010-12-01 16:12:45 -05:00
|
|
|
// FIXME UINT negative
|
2010-09-05 14:43:45 -04:00
|
|
|
result := PtrUInt(RESULT_ERROR);
|
2010-12-01 16:12:45 -05:00
|
|
|
set_last_error(e.Message);
|
2010-09-05 14:43:45 -04:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
writeln(format('C: %d, IOManager: %d', [PtrUInt(C), PtrUInt(C.IOManager)]));
|
|
|
|
end;
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
{ Destroy a TClient }
|
2010-11-30 20:05:50 -05:00
|
|
|
function destroy_client(C: TClient): integer; cdecl;
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
2010-12-01 16:12:45 -05:00
|
|
|
|
2010-09-05 14:43:45 -04:00
|
|
|
C.Free;
|
|
|
|
end;
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
{ Set (verbose) debug on/off }
|
|
|
|
procedure set_debug(v: Boolean); cdecl;
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
|
|
|
debug := v;
|
|
|
|
end;
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
{ Get debug }
|
|
|
|
function get_debug: boolean; cdecl;
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
|
|
|
exit(debug);
|
|
|
|
end;
|
|
|
|
|
2010-09-12 08:28:19 -04:00
|
|
|
{
|
|
|
|
VERY IMPORTANT: If you use get_last_error, you must immediately store the
|
|
|
|
resulting string somewhere else. As soon as you do other calls, the last error
|
|
|
|
may be reset or assigned a different memory position, making your old
|
|
|
|
pointer invalid.
|
|
|
|
}
|
2010-11-30 20:05:50 -05:00
|
|
|
function get_last_error: pchar; cdecl;
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
2010-09-12 08:28:19 -04:00
|
|
|
exit(@last_error[1]);
|
2010-09-05 14:43:45 -04:00
|
|
|
end;
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
{ Turn an array into a pointer. The pointer memory is not managed by FPC, so we can pass
|
|
|
|
it along happily. It'll have to be freed by the external control though }
|
2010-11-30 20:05:50 -05:00
|
|
|
function array_to_ptr(ptr: Pointer; size: PtrUInt; objsize: PtrUInt): Pointer; cdecl;
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
|
|
|
result := GetMem(objsize * size);
|
|
|
|
Move(ptr^, result^, objsize * size);
|
|
|
|
end;
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
{ Free memory previously allocated by libMML }
|
2010-11-30 20:05:50 -05:00
|
|
|
function free_ptr(ptr: pointer): boolean; cdecl;
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
|
|
|
result := Assigned(ptr);
|
|
|
|
if not result then
|
|
|
|
begin
|
2010-12-01 16:12:45 -05:00
|
|
|
set_last_error('TClient is NULL');
|
2010-09-05 14:43:45 -04:00
|
|
|
if debug then
|
|
|
|
writeln(last_error);
|
|
|
|
end else
|
2010-09-12 09:06:11 -04:00
|
|
|
FreeMem(ptr);
|
2010-09-05 14:43:45 -04:00
|
|
|
end;
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
{ Allocate memory with libMML }
|
2010-11-30 20:05:50 -05:00
|
|
|
function alloc_mem(size, objsize: PtrUInt): Pointer; cdecl;
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
|
|
|
result := GetMem(size * objsize);
|
|
|
|
end;
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
{ Reallocate memory with libMML }
|
2010-11-30 20:05:50 -05:00
|
|
|
function realloc_mem(ptr: Pointer; size, objsize: PtrUInt): Pointer; cdecl;
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
2010-09-12 09:06:11 -04:00
|
|
|
result := ReAllocMem(ptr, size*objsize);
|
2010-03-25 20:36:09 -04:00
|
|
|
end;
|
|
|
|
|
2010-03-30 18:24:16 -04:00
|
|
|
{ Mouse }
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
{ Returns mouse position of client C to point t }
|
2010-09-05 14:43:45 -04:00
|
|
|
function get_mouse_pos(C: TClient; var t: tpoint): integer; cdecl;
|
2010-03-30 18:24:16 -04:00
|
|
|
|
2010-03-25 20:36:09 -04:00
|
|
|
begin
|
2010-09-05 14:43:45 -04:00
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
|
2010-03-30 18:24:16 -04:00
|
|
|
try
|
|
|
|
C.IOManager.GetMousePos(t.x,t.y);
|
|
|
|
result := RESULT_OK;
|
|
|
|
except on e : Exception do
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
|
|
|
result := RESULT_ERROR;
|
2010-12-01 16:12:45 -05:00
|
|
|
set_last_error(e.Message);
|
2010-09-05 14:43:45 -04:00
|
|
|
end;
|
2010-03-30 18:24:16 -04:00
|
|
|
end;
|
2010-03-25 20:36:09 -04:00
|
|
|
end;
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
{ Set mouse position of client C to point t }
|
2010-09-05 14:43:45 -04:00
|
|
|
function set_mouse_pos(C: TClient; var t: tpoint): integer; cdecl;
|
2010-04-01 19:48:06 -04:00
|
|
|
begin
|
2010-09-05 14:43:45 -04:00
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
|
2010-04-01 19:48:06 -04:00
|
|
|
try
|
2010-05-31 19:59:48 -04:00
|
|
|
C.IOManager.MoveMouse(t.x,t.y);
|
2010-04-01 19:48:06 -04:00
|
|
|
result := RESULT_OK;
|
|
|
|
except on e : Exception do
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
|
|
|
result := RESULT_ERROR;
|
2010-12-01 16:12:45 -05:00
|
|
|
set_last_error(e.Message);
|
2010-09-05 14:43:45 -04:00
|
|
|
end;
|
2010-04-01 19:48:06 -04:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
|
|
|
|
{ Helper function }
|
2010-09-05 14:43:45 -04:00
|
|
|
function ConvIntClickType(Int : Integer) : TClickType; inline;
|
2010-04-01 19:48:06 -04:00
|
|
|
begin
|
2010-03-30 18:24:16 -04:00
|
|
|
case int of
|
2010-04-01 19:48:06 -04:00
|
|
|
0 : result := mouse_Left;
|
|
|
|
1 : result := mouse_Right;
|
|
|
|
2: result := mouse_Middle;
|
2010-03-30 18:24:16 -04:00
|
|
|
end;
|
2010-04-01 19:48:06 -04:00
|
|
|
end;
|
2010-03-30 18:24:16 -04:00
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
{ Return the state of a mouse button given client C }
|
2010-11-30 20:05:50 -05:00
|
|
|
function get_mouse_button_state(C: TClient; But: Integer): Integer; cdecl;
|
2010-04-01 19:48:06 -04:00
|
|
|
begin
|
2010-09-05 14:43:45 -04:00
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
|
2010-04-01 19:48:06 -04:00
|
|
|
try
|
|
|
|
if C.IOManager.IsMouseButtonDown(ConvIntClickType(But)) then
|
|
|
|
result := MOUSE_DOWN;
|
|
|
|
except on e : Exception do
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
|
|
|
result := RESULT_ERROR;
|
2010-12-01 16:12:45 -05:00
|
|
|
set_last_error(e.Message);
|
2010-09-05 14:43:45 -04:00
|
|
|
end;
|
2010-04-01 19:48:06 -04:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
{ Set the state of a mouse button given client C }
|
2010-11-30 20:05:50 -05:00
|
|
|
function set_mouse_button_state(C: TClient; But, State, X, Y: Integer): Integer; cdecl;
|
2010-04-01 19:48:06 -04:00
|
|
|
begin
|
2010-09-05 14:43:45 -04:00
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
|
2010-04-01 19:48:06 -04:00
|
|
|
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
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
|
|
|
result := RESULT_ERROR;
|
2010-12-01 16:12:45 -05:00
|
|
|
set_last_error(e.Message);
|
2010-09-05 14:43:45 -04:00
|
|
|
end;
|
2010-04-01 19:48:06 -04:00
|
|
|
end;
|
|
|
|
end;
|
2010-03-30 18:24:16 -04:00
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
|
|
|
|
{ Colour }
|
|
|
|
|
2010-12-03 08:25:58 -05:00
|
|
|
function get_color(C: TClient; x, y: Integer;
|
|
|
|
out color: Integer): Integer; cdecl;
|
2010-12-01 16:12:45 -05:00
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
try
|
|
|
|
begin
|
2010-12-03 08:25:58 -05:00
|
|
|
color := C.IOManager.GetColor(x, y);
|
|
|
|
if color > -1 then
|
|
|
|
result := RESULT_OK
|
|
|
|
else
|
|
|
|
result := RESULT_FALSE;
|
|
|
|
end;
|
|
|
|
except on e : Exception do
|
|
|
|
begin
|
|
|
|
set_last_error(e.message);
|
2010-12-01 16:12:45 -05:00
|
|
|
result := RESULT_ERROR;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-12-03 08:25:58 -05:00
|
|
|
function find_color(C: TClient; var x, y: Integer;
|
|
|
|
color, x1, y1, x2, y2: Integer): Integer; cdecl;
|
2010-05-31 19:59:48 -04:00
|
|
|
begin
|
2010-09-05 14:43:45 -04:00
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
|
2010-05-31 20:03:25 -04:00
|
|
|
try
|
2010-06-01 07:40:51 -04:00
|
|
|
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
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
2010-12-01 16:12:45 -05:00
|
|
|
set_last_error(e.Message);
|
2010-12-03 08:25:58 -05:00
|
|
|
result := RESULT_ERROR;
|
2010-09-05 14:43:45 -04:00
|
|
|
end;
|
2010-05-31 20:03:25 -04:00
|
|
|
end;
|
2010-05-31 19:59:48 -04:00
|
|
|
end;
|
|
|
|
|
2010-12-03 08:25:58 -05:00
|
|
|
function find_color_tolerance(C: TClient; var x, y: Integer; color: Integer;
|
|
|
|
tol, x1, y1, x2, y2: Integer): Integer; cdecl;
|
2010-09-05 14:43:45 -04:00
|
|
|
|
2010-03-26 10:20:50 -04:00
|
|
|
begin
|
2010-09-05 14:43:45 -04:00
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
|
2010-06-01 07:40:51 -04:00
|
|
|
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
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
2010-12-01 16:12:45 -05:00
|
|
|
set_last_error(e.Message);
|
2010-12-03 08:25:58 -05:00
|
|
|
result := RESULT_ERROR;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function find_color_tolerance_optimised(C: TClient; var x, y: Integer;
|
|
|
|
var len: Integer; col: Integer;
|
|
|
|
x1, y1, x2, y2: Integer;
|
|
|
|
tol: Integer): Integer; cdecl;
|
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
try
|
|
|
|
if C.MFinder.FindColorToleranceOptimised(x, y, col, x1, y1, x2, y2,
|
|
|
|
tol) then
|
|
|
|
result := RESULT_OK
|
|
|
|
else
|
|
|
|
result := RESULT_FALSE;
|
|
|
|
except on e : Exception do
|
|
|
|
begin
|
|
|
|
set_last_error(e.message);
|
|
|
|
result := RESULT_ERROR;
|
2010-09-05 14:43:45 -04:00
|
|
|
end;
|
2010-06-01 07:40:51 -04:00
|
|
|
end;
|
2010-03-26 10:20:50 -04:00
|
|
|
end;
|
|
|
|
|
2010-12-03 08:25:58 -05:00
|
|
|
function find_colors(C: TClient; var ptr: PPoint; var len: Integer;
|
|
|
|
color, x1, y1, x2, y2: Integer): Integer; cdecl;
|
2010-03-30 18:24:16 -04:00
|
|
|
var
|
2010-06-01 07:40:51 -04:00
|
|
|
TPA: TPointArray;
|
2010-03-30 18:24:16 -04:00
|
|
|
begin
|
2010-09-05 14:43:45 -04:00
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
|
|
|
|
SetLength(TPA, 0);
|
2010-06-01 07:40:51 -04:00
|
|
|
try
|
|
|
|
C.MFinder.FindColors(TPA, color, x1, y1, x2, y2);
|
|
|
|
except on e : Exception do
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
2010-12-01 16:12:45 -05:00
|
|
|
set_last_error(e.Message);
|
2010-12-03 08:25:58 -05:00
|
|
|
result := RESULT_ERROR;
|
2010-09-05 14:43:45 -04:00
|
|
|
end;
|
2010-06-01 07:40:51 -04:00
|
|
|
end;
|
2010-09-05 14:43:45 -04:00
|
|
|
|
|
|
|
len := Length(TPA);
|
|
|
|
ptr := array_to_ptr(Pointer(@TPA[0]), len, sizeof(TPoint));
|
2010-12-03 08:25:58 -05:00
|
|
|
if len > 0 then
|
|
|
|
result := RESULT_OK
|
|
|
|
else
|
|
|
|
result := RESULT_FALSE;
|
2010-09-05 14:43:45 -04:00
|
|
|
setlength(tpa, 0);
|
2010-03-30 18:24:16 -04:00
|
|
|
end;
|
|
|
|
|
2010-11-30 20:05:50 -05:00
|
|
|
function find_colors_tolerance(C: TClient; var ptr: PPoint; var len: Integer;
|
2010-12-03 08:25:58 -05:00
|
|
|
color, tol, x1, y1, x2, y2: Integer): Integer; cdecl;
|
2010-03-30 18:24:16 -04:00
|
|
|
var
|
2010-06-01 07:40:51 -04:00
|
|
|
TPA: TPointArray;
|
2010-03-30 18:24:16 -04:00
|
|
|
begin
|
2010-09-05 14:43:45 -04:00
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
|
2010-06-01 07:40:51 -04:00
|
|
|
try
|
|
|
|
C.MFinder.FindColorsTolerance(TPA, color, x1, y1, x2, y2, tol);
|
|
|
|
except on e : Exception do
|
2010-09-05 14:43:45 -04:00
|
|
|
begin
|
2010-12-01 16:12:45 -05:00
|
|
|
set_last_error(e.Message);
|
2010-12-03 08:25:58 -05:00
|
|
|
result := RESULT_ERROR;
|
2010-09-05 14:43:45 -04:00
|
|
|
end;
|
2010-06-01 07:40:51 -04:00
|
|
|
end;
|
2010-03-30 18:24:16 -04:00
|
|
|
|
2010-09-05 14:43:45 -04:00
|
|
|
len := Length(TPA);
|
|
|
|
ptr := array_to_ptr(Pointer(@TPA[0]), len, sizeof(TPoint));
|
2010-12-03 08:25:58 -05:00
|
|
|
if len > 0 then
|
|
|
|
result := RESULT_OK
|
|
|
|
else
|
|
|
|
result := RESULT_FALSE;
|
|
|
|
setlength(TPA, 0);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function find_colors_tolerance_optimised(C: TClient; var ptr: PPoint;
|
|
|
|
var len: Integer; col: Integer;
|
|
|
|
x1, y1, x2, y2: Integer;
|
|
|
|
tol: Integer): Integer; cdecl;
|
|
|
|
var
|
|
|
|
TPA: TPointArray;
|
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
try
|
|
|
|
C.MFinder.FindColorsToleranceOptimised(TPA, col, x1, y1, x2, y2, tol);
|
|
|
|
except on e : Exception do
|
|
|
|
begin
|
|
|
|
set_last_error(e.message);
|
|
|
|
result := RESULT_ERROR;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
len := Length(TPA);
|
|
|
|
ptr := array_to_ptr(Pointer(@TPA[0]), len, sizeof(TPoint));
|
|
|
|
if len > 0 then
|
|
|
|
result := RESULT_OK
|
|
|
|
else
|
|
|
|
result := RESULT_FALSE;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function similar_colors(C: TClient; col1, col2, tol: Integer): Integer; cdecl;
|
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
if C.MFinder.SimilarColors(col1, col2, tol) then
|
|
|
|
result := RESULT_OK
|
|
|
|
else
|
|
|
|
result := RESULT_FALSE;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function count_color(C: TClient; out count: Integer;
|
|
|
|
Color, xs, ys, xe, ye: Integer): Integer; cdecl;
|
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
try
|
|
|
|
begin
|
|
|
|
count := C.MFinder.CountColor(Color, xs, ys, xe, ye);
|
|
|
|
if count > 0 then
|
|
|
|
result := RESULT_OK
|
|
|
|
else
|
|
|
|
result := RESULT_FALSE;
|
|
|
|
end;
|
|
|
|
except on e : Exception do
|
|
|
|
begin
|
|
|
|
set_last_error(e.message);
|
|
|
|
result := RESULT_ERROR;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function count_color_tolerance(C: TClient; out count: Integer; col: Integer;
|
|
|
|
xs, ys, xe, ye, tol: Integer): Integer; cdecl;
|
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
try
|
|
|
|
count := C.MFinder.CountColorTolerance(col, xs, ys, xe, ye, tol);
|
|
|
|
except on e : Exception do
|
|
|
|
begin
|
|
|
|
set_last_error(e.message);
|
|
|
|
result := RESULT_ERROR;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if count > 0 then
|
|
|
|
result := RESULT_OK
|
|
|
|
else
|
|
|
|
result := RESULT_FALSE;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function find_color_spiral(C: TClient; var x, y: Integer;
|
|
|
|
col, xs, ys, xe, ye: Integer): Integer; cdecl;
|
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
try
|
|
|
|
if C.MFinder.FindColorSpiral(x, y, col, xs, ys, xe, ye) then
|
|
|
|
result := RESULT_OK
|
|
|
|
else
|
|
|
|
result := RESULT_FALSE;
|
|
|
|
except on e : Exception do
|
|
|
|
begin
|
|
|
|
set_last_error(e.message);
|
|
|
|
result := RESULT_ERROR;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function find_color_spiral_tolerance(C: TClient; var x, y: Integer;
|
|
|
|
col, xs, ys, xe, ye: Integer;
|
|
|
|
tol: Integer): Integer; cdecl;
|
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
try
|
|
|
|
if C.MFinder.FindColorSpiralTolerance(x, y, col, xs, ys, xe, ye, tol) then
|
|
|
|
result := RESULT_OK
|
|
|
|
else
|
|
|
|
result := RESULT_FALSE;
|
|
|
|
except on e : Exception do
|
|
|
|
begin
|
|
|
|
set_last_error(e.message);
|
|
|
|
result := RESULT_ERROR;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function find_colored_area(C: TClient; var x, y: Integer;
|
|
|
|
col, xs, ys, xe, ye, minA: Integer): Integer; cdecl;
|
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
try
|
|
|
|
if C.MFinder.FindColoredArea(x, y, col, xs, ys, xe, ye, minA) then
|
|
|
|
result := RESULT_OK
|
|
|
|
else
|
|
|
|
result := RESULT_FALSE;
|
|
|
|
except on e : Exception do
|
|
|
|
begin
|
|
|
|
set_last_error(e.message);
|
|
|
|
result := RESULT_ERROR;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function find_colored_area_tolerance(C: TClient; var x, y: Integer;
|
|
|
|
col, xs, ys, xe, ye, minA: Integer;
|
|
|
|
tol: Integer): Integer; cdecl;
|
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
try
|
|
|
|
if C.MFinder.FindColoredAreaTolerance(x, y, col,
|
|
|
|
xs, ys, xe, ye, minA, tol) then
|
|
|
|
result := RESULT_OK
|
|
|
|
else
|
|
|
|
result := RESULT_FALSE;
|
|
|
|
except on e : Exception do
|
|
|
|
begin
|
|
|
|
set_last_error(e.message);
|
|
|
|
result := RESULT_ERROR;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function set_tolerance_speed(C: TClient; nCTS: Integer): Integer; cdecl;
|
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
try
|
|
|
|
begin
|
|
|
|
C.MFinder.SetToleranceSpeed(nCTS);
|
|
|
|
result := RESULT_OK;
|
|
|
|
end;
|
|
|
|
except on e : Exception do
|
|
|
|
begin
|
|
|
|
set_last_error(e.message);
|
|
|
|
result := RESULT_ERROR;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function get_tolerance_speed(C: TClient; out cts: Integer): Integer; cdecl;
|
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
cts := C.MFinder.GetToleranceSpeed;
|
|
|
|
result := RESULT_OK;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function set_tolerance_speed_2_modifiers(C: TClient;
|
|
|
|
nHue, nSat: Extended): Integer; cdecl;
|
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
try
|
|
|
|
begin
|
|
|
|
C.MFinder.SetToleranceSpeed2Modifiers(nHue, nSat);
|
|
|
|
result := RESULT_OK;
|
|
|
|
end;
|
|
|
|
except on e : Exception do
|
|
|
|
begin
|
|
|
|
set_last_error(e.message);
|
|
|
|
result := RESULT_ERROR;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function get_tolerance_speed_2_modifiers(C: TClient; out hueMod: Extended;
|
|
|
|
out satMod: Extended): Integer; cdecl;
|
|
|
|
var
|
|
|
|
h, s: Extended;
|
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
C.MFinder.GetToleranceSpeed2Modifiers(h, s);
|
|
|
|
hueMod := h;
|
|
|
|
satMod := s;
|
2010-09-05 14:43:45 -04:00
|
|
|
result := RESULT_OK;
|
2010-03-30 18:24:16 -04:00
|
|
|
end;
|
|
|
|
|
2010-11-30 20:05:50 -05:00
|
|
|
{ DTM }
|
|
|
|
|
|
|
|
{ FIXME: DTM has not been tested yet! }
|
|
|
|
|
|
|
|
{ Create a MDTM}
|
2010-12-01 16:12:45 -05:00
|
|
|
function create_dtm(PointLen: integer; Points: PMDTMPoint; DTM: TMDTM): integer; cdecl;
|
2010-11-30 20:05:50 -05:00
|
|
|
var
|
|
|
|
i: integer;
|
|
|
|
begin
|
|
|
|
DTM := TMDTM.Create;
|
|
|
|
for i := 0 to PointLen - 1 do
|
|
|
|
DTM.AddPoint(Points[i]);
|
|
|
|
|
|
|
|
if DTM.Valid then
|
|
|
|
exit(RESULT_OK);
|
|
|
|
|
|
|
|
DTM.Free;
|
2010-12-01 16:12:45 -05:00
|
|
|
set_last_error('Invalid DTM');
|
2010-11-30 20:05:50 -05:00
|
|
|
result := RESULT_ERROR;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Delete a MDTM. Don't delete it if it is managed! use remove_dtm instead }
|
2010-12-01 16:12:45 -05:00
|
|
|
function delete_dtm(C: TClient; DTM: TMDTM): integer; cdecl;
|
2010-11-30 20:05:50 -05:00
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if not assigned(DTM) then
|
|
|
|
begin
|
2010-12-01 16:12:45 -05:00
|
|
|
set_last_error('DTM is NULL');
|
2010-11-30 20:05:50 -05:00
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
|
|
|
|
DTM.Free;
|
|
|
|
|
|
|
|
result := RESULT_OK;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Add a previously created DTM to the DTM Manager }
|
2010-12-01 16:12:45 -05:00
|
|
|
function add_dtm(C: TClient; DTM: TMDTM; var index: integer): integer; cdecl;
|
2010-11-30 20:05:50 -05:00
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if not assigned(DTM) then
|
|
|
|
begin
|
2010-12-01 16:12:45 -05:00
|
|
|
set_last_error('DTM is NULL');
|
2010-11-30 20:05:50 -05:00
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
index := C.MDTMs.AddDTM(DTM);
|
2010-11-30 20:05:50 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
{ Remove a previously added DTM from the DTM manager. This also frees the DTM }
|
2010-12-01 16:12:45 -05:00
|
|
|
function remove_dtm(C: TClient; DTMi: integer): integer; cdecl;
|
2010-11-30 20:05:50 -05:00
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
|
|
|
|
C.MDTMs.FreeDTM(DTMi);
|
|
|
|
end;
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
{ Find a DTM given DTM index i, client C in area x1,y1,x2,y2. Return coord at x, y. }
|
|
|
|
function find_dtm(C: TClient; DTMi: integer; var x, y: integer; x1, y1, x2, y2: integer): integer; cdecl;
|
2010-11-30 20:05:50 -05:00
|
|
|
var
|
|
|
|
res: boolean;
|
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
|
|
|
|
try
|
|
|
|
res := C.MFinder.FindDTM(C.MDTMs.DTM[DTMi], x, y, x1, y1, x2, y2);
|
|
|
|
except on e : Exception do
|
|
|
|
begin
|
|
|
|
result := RESULT_ERROR;
|
2010-12-01 16:12:45 -05:00
|
|
|
set_last_error(e.Message);
|
2010-11-30 20:05:50 -05:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if res then
|
|
|
|
result := RESULT_OK
|
|
|
|
else
|
|
|
|
result := RESULT_FALSE;
|
|
|
|
end;
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
function set_array_target(C: TClient; Arr: PRGB32; Size: TPoint): integer; cdecl;
|
|
|
|
begin
|
|
|
|
if not validate_client(C) then
|
|
|
|
begin
|
|
|
|
exit(RESULT_ERROR);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if not assigned(Arr) then
|
|
|
|
begin
|
|
|
|
set_last_error('Arr is not assigned');
|
|
|
|
exit(RESULT_FALSE);
|
|
|
|
end;
|
|
|
|
|
2010-12-03 08:25:58 -05:00
|
|
|
// FIXME: Catch exceptions.
|
2010-12-01 16:12:45 -05:00
|
|
|
C.IOManager.SetTarget(Arr, Size);
|
|
|
|
|
|
|
|
result := RESULT_OK;
|
|
|
|
end;
|
2010-11-30 20:05:50 -05:00
|
|
|
|
2010-09-05 14:43:45 -04:00
|
|
|
exports
|
2010-03-30 18:24:16 -04:00
|
|
|
|
2010-09-05 14:43:45 -04:00
|
|
|
init,
|
|
|
|
create_client,
|
2010-12-01 16:12:45 -05:00
|
|
|
destroy_client,
|
2010-09-05 14:43:45 -04:00
|
|
|
get_last_error,
|
|
|
|
get_debug,
|
|
|
|
set_debug,
|
|
|
|
alloc_mem,
|
|
|
|
realloc_mem,
|
|
|
|
free_ptr,
|
2010-03-30 18:24:16 -04:00
|
|
|
|
2010-09-05 14:43:45 -04:00
|
|
|
get_mouse_pos, set_mouse_pos,
|
|
|
|
get_mouse_button_state, set_mouse_button_state,
|
2010-03-30 18:24:16 -04:00
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
get_color,
|
|
|
|
|
2010-09-05 14:43:45 -04:00
|
|
|
find_color, find_color_tolerance,
|
|
|
|
|
2010-12-01 16:12:45 -05:00
|
|
|
find_colors, find_colors_tolerance,
|
|
|
|
|
|
|
|
create_dtm, delete_dtm, add_dtm, remove_dtm,
|
|
|
|
|
|
|
|
find_dtm,
|
|
|
|
|
|
|
|
set_array_target;
|
2010-03-25 20:36:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
begin
|
2010-12-03 08:25:58 -05:00
|
|
|
end.
|