1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-25 10:42:20 -05:00

libMML: Vim-ized. Fixed a lot of errors.

This commit is contained in:
Merlijn Wajer 2011-02-06 00:39:45 +01:00
parent 40f6b542c6
commit 45a70eed73
2 changed files with 254 additions and 211 deletions

5
Projects/libmml/Makefile Normal file
View File

@ -0,0 +1,5 @@
.PHONY: default
default:
/home/merlijn/lazarus/lazbuild libmml.lpi

View File

@ -59,9 +59,11 @@ begin
C := TClient.Create(''); C := TClient.Create('');
Result := PtrUInt(C); Result := PtrUInt(C);
except on e : Exception do except on e : Exception do
begin
// FIXME UINT negative // FIXME UINT negative
result := PtrUInt(RESULT_ERROR); result := PtrUInt(RESULT_ERROR);
set_last_error(e.Message); set_last_error(e.message);
end;
end; end;
writeln(format('C: %d, IOManager: %d', [PtrUInt(C), PtrUInt(C.IOManager)])); writeln(format('C: %d, IOManager: %d', [PtrUInt(C), PtrUInt(C.IOManager)]));
end; end;
@ -72,8 +74,10 @@ begin
try try
C.Free; C.Free;
except on e : Exception do except on e : Exception do
begin
result := RESULT_ERROR; result := RESULT_ERROR;
set_last_error(e.message): set_last_error(e.message);
end;
end; end;
end; end;
@ -148,10 +152,12 @@ begin
C.IOManager.GetMousePos(t.x,t.y); C.IOManager.GetMousePos(t.x,t.y);
result := RESULT_OK; result := RESULT_OK;
except on e : Exception do except on e : Exception do
begin
result := RESULT_ERROR; result := RESULT_ERROR;
set_last_error(e.Message); set_last_error(e.Message);
end; end;
end; end;
end;
{ Set mouse position of client C to point t } { Set mouse position of client C to point t }
function set_mouse_pos(C: TClient; var t: tpoint): integer; cdecl; function set_mouse_pos(C: TClient; var t: tpoint): integer; cdecl;
@ -160,10 +166,12 @@ begin
C.IOManager.MoveMouse(t.x,t.y); C.IOManager.MoveMouse(t.x,t.y);
result := RESULT_OK; result := RESULT_OK;
except on e : Exception do except on e : Exception do
begin
result := RESULT_ERROR; result := RESULT_ERROR;
set_last_error(e.Message); set_last_error(e.Message);
end; end;
end; end;
end;
{ Helper function } { Helper function }
@ -181,14 +189,16 @@ function get_mouse_button_state(C: TClient; But: Integer): Integer; cdecl;
begin begin
try try
if C.IOManager.IsMouseButtonDown(ConvIntClickType(But)) then if C.IOManager.IsMouseButtonDown(ConvIntClickType(But)) then
result := MOUSE_DOWN; result := MOUSE_DOWN
else else
result := MOUSE_UP; result := MOUSE_UP;
except on e : Exception do except on e : Exception do
begin
result := RESULT_ERROR; result := RESULT_ERROR;
set_last_error(e.Message); set_last_error(e.Message);
end; end;
end; end;
end;
{ Set the state of a mouse button given client C } { Set the state of a mouse button given client C }
function set_mouse_button_state(C: TClient; But, State, X, Y: Integer): Integer; cdecl; function set_mouse_button_state(C: TClient; But, State, X, Y: Integer): Integer; cdecl;
@ -204,10 +214,12 @@ begin
result := RESULT_OK; result := RESULT_OK;
end; end;
except on e : Exception do except on e : Exception do
begin
result := RESULT_ERROR; result := RESULT_ERROR;
set_last_error(e.Message); set_last_error(e.Message);
end; end;
end; end;
end;
{ Colour } { Colour }
@ -222,10 +234,12 @@ begin
else else
result := RESULT_FALSE; result := RESULT_FALSE;
except on e : Exception do except on e : Exception do
begin
set_last_error(e.message); set_last_error(e.message);
result := RESULT_ERROR; result := RESULT_ERROR;
end; end;
end; end;
end;
{ Find color on client C in area (x1,y1,x2,y2) and return coordinate (if any) in x, y } { Find color on client C in area (x1,y1,x2,y2) and return coordinate (if any) in x, y }
function find_color(C: TClient; var x, y: Integer; function find_color(C: TClient; var x, y: Integer;
@ -237,10 +251,12 @@ begin
else else
result := RESULT_FALSE; result := RESULT_FALSE;
except on e : Exception do except on e : Exception do
begin
set_last_error(e.Message); set_last_error(e.Message);
result := RESULT_ERROR; result := RESULT_ERROR;
end; end;
end; end;
end;
function find_color_tolerance(C: TClient; var x, y: Integer; color: Integer; function find_color_tolerance(C: TClient; var x, y: Integer; color: Integer;
tol, x1, y1, x2, y2: Integer): Integer; cdecl; tol, x1, y1, x2, y2: Integer): Integer; cdecl;
@ -252,10 +268,12 @@ begin
else else
result := RESULT_FALSE; result := RESULT_FALSE;
except on e : Exception do except on e : Exception do
begin
set_last_error(e.Message); set_last_error(e.Message);
result := RESULT_ERROR; result := RESULT_ERROR;
end; end;
end; end;
end;
function find_color_tolerance_optimised(C: TClient; var x, y: Integer; function find_color_tolerance_optimised(C: TClient; var x, y: Integer;
var len: Integer; col: Integer; var len: Integer; col: Integer;
@ -269,10 +287,12 @@ begin
else else
result := RESULT_FALSE; result := RESULT_FALSE;
except on e : Exception do except on e : Exception do
begin
set_last_error(e.message); set_last_error(e.message);
result := RESULT_ERROR; result := RESULT_ERROR;
end; end;
end; end;
end;
function find_colors(C: TClient; var ptr: PPoint; var len: Integer; function find_colors(C: TClient; var ptr: PPoint; var len: Integer;
color, x1, y1, x2, y2: Integer): Integer; cdecl; color, x1, y1, x2, y2: Integer): Integer; cdecl;
@ -283,16 +303,20 @@ begin
try try
C.MFinder.FindColors(TPA, color, x1, y1, x2, y2); C.MFinder.FindColors(TPA, color, x1, y1, x2, y2);
except on e : Exception do except on e : Exception do
begin
set_last_error(e.Message); set_last_error(e.Message);
result := RESULT_ERROR; result := RESULT_ERROR;
end; end;
end;
len := Length(TPA); len := Length(TPA);
if len > 0 then if len > 0 then
result := RESULT_OK result := RESULT_OK
else else
begin
setlength(tpa, 0); setlength(tpa, 0);
exit(RESULT_FALSE); exit(RESULT_FALSE);
end;
ptr := array_to_ptr(Pointer(@TPA[0]), len, sizeof(TPoint)); ptr := array_to_ptr(Pointer(@TPA[0]), len, sizeof(TPoint));
setlength(tpa, 0); setlength(tpa, 0);
@ -316,8 +340,10 @@ begin
if len > 0 then if len > 0 then
result := RESULT_OK result := RESULT_OK
else else
begin
setlength(tpa, 0); setlength(tpa, 0);
exit(RESULT_FALSE); exit(RESULT_FALSE);
end;
ptr := array_to_ptr(Pointer(@TPA[0]), len, sizeof(TPoint)); ptr := array_to_ptr(Pointer(@TPA[0]), len, sizeof(TPoint));
setlength(TPA, 0); setlength(TPA, 0);
@ -343,8 +369,10 @@ begin
if len > 0 then if len > 0 then
result := RESULT_OK result := RESULT_OK
else else
begin
setlength(tpa, 0); setlength(tpa, 0);
exit(RESULT_FALSE); exit(RESULT_FALSE);
end;
ptr := array_to_ptr(Pointer(@TPA[0]), len, sizeof(TPoint)); ptr := array_to_ptr(Pointer(@TPA[0]), len, sizeof(TPoint));
setlength(TPA, 0); setlength(TPA, 0);
@ -352,23 +380,28 @@ end;
function similar_colors(C: TClient; col1, col2, tol: Integer): Integer; cdecl; function similar_colors(C: TClient; col1, col2, tol: Integer): Integer; cdecl;
begin begin
try
if C.MFinder.SimilarColors(col1, col2, tol) then if C.MFinder.SimilarColors(col1, col2, tol) then
result := RESULT_OK result := RESULT_OK
else else
result := RESULT_FALSE; result := RESULT_FALSE;
except on e : Exception do
begin
set_last_error(e.message);
result := RESULT_FALSE;
end;
end;
end; end;
function count_color(C: TClient; out count: Integer; function count_color(C: TClient; out count: Integer;
Color, xs, ys, xe, ye: Integer): Integer; cdecl; Color, xs, ys, xe, ye: Integer): Integer; cdecl;
begin begin
try try
begin
count := C.MFinder.CountColor(Color, xs, ys, xe, ye); count := C.MFinder.CountColor(Color, xs, ys, xe, ye);
if count > 0 then if count > 0 then
result := RESULT_OK result := RESULT_OK
else else
result := RESULT_FALSE; result := RESULT_FALSE;
end;
except on e : Exception do except on e : Exception do
begin begin
set_last_error(e.message); set_last_error(e.message);
@ -388,6 +421,7 @@ begin
result := RESULT_ERROR; result := RESULT_ERROR;
end; end;
end; end;
if count > 0 then if count > 0 then
result := RESULT_OK result := RESULT_OK
else else
@ -415,7 +449,8 @@ function find_color_spiral_tolerance(C: TClient; var x, y: Integer;
tol: Integer): Integer; cdecl; tol: Integer): Integer; cdecl;
begin begin
try try
if C.MFinder.FindColorSpiralTolerance(x, y, col, xs, ys, xe, ye, tol) then if C.MFinder.FindColorSpiralTolerance(x, y, col, xs, ys, xe, ye,
tol) then
result := RESULT_OK result := RESULT_OK
else else
result := RESULT_FALSE; result := RESULT_FALSE;
@ -464,10 +499,8 @@ end;
function set_tolerance_speed(C: TClient; nCTS: Integer): Integer; cdecl; function set_tolerance_speed(C: TClient; nCTS: Integer): Integer; cdecl;
begin begin
try try
begin
C.MFinder.SetToleranceSpeed(nCTS); C.MFinder.SetToleranceSpeed(nCTS);
result := RESULT_OK; result := RESULT_OK;
end;
except on e : Exception do except on e : Exception do
begin begin
set_last_error(e.message); set_last_error(e.message);
@ -479,14 +512,13 @@ end;
function get_tolerance_speed(C: TClient; out cts: Integer): Integer; cdecl; function get_tolerance_speed(C: TClient; out cts: Integer): Integer; cdecl;
begin begin
try try
begin
cts := C.MFinder.GetToleranceSpeed; cts := C.MFinder.GetToleranceSpeed;
result := RESULT_OK; result := RESULT_OK;
end
except on e: Exception do except on e: Exception do
begin begin;
set_last_error(e.message); set_last_error(e.message);
result := RESULT_ERROR; result := RESULT_ERROR;
end
end; end;
end; end;
@ -494,12 +526,10 @@ function set_tolerance_speed_2_modifiers(C: TClient;
nHue, nSat: Extended): Integer; cdecl; nHue, nSat: Extended): Integer; cdecl;
begin begin
try try
begin
C.MFinder.SetToleranceSpeed2Modifiers(nHue, nSat); C.MFinder.SetToleranceSpeed2Modifiers(nHue, nSat);
result := RESULT_OK; result := RESULT_OK;
end;
except on e : Exception do except on e : Exception do
begin begin;
set_last_error(e.message); set_last_error(e.message);
result := RESULT_ERROR; result := RESULT_ERROR;
end; end;
@ -511,26 +541,26 @@ function get_tolerance_speed_2_modifiers(C: TClient; out hueMod: Extended;
var var
h, s: Extended; h, s: Extended;
begin begin
try: try
begin
C.MFinder.GetToleranceSpeed2Modifiers(h, s); C.MFinder.GetToleranceSpeed2Modifiers(h, s);
hueMod := h; hueMod := h;
satMod := s; satMod := s;
result := RESULT_OK; result := RESULT_OK;
end;
except on e : Exception do except on e : Exception do
begin begin;
set_last_error(e.message); set_last_error(e.message);
result := RESULT_ERROR; result := RESULT_ERROR;
end; end;
end; end;
end;
{ DTM } { DTM }
{ FIXME: DTM has not been tested yet! } { FIXME: DTM has not been tested yet! }
{ Create a MDTM} { Create a MDTM}
function create_dtm(PointLen: integer; Points: PMDTMPoint; DTM: TMDTM): integer; cdecl; function create_dtm(PointLen: integer; Points: PMDTMPoint; DTM: TMDTM): integer;
cdecl;
var var
i: integer; i: integer;
begin begin
@ -569,14 +599,11 @@ begin
exit(RESULT_ERROR); exit(RESULT_ERROR);
end; end;
try: try
begin
index := C.MDTMs.AddDTM(DTM); index := C.MDTMs.AddDTM(DTM);
exit(RESULT_OK); exit(RESULT_OK);
end;
except on e : Exception do except on e : Exception do
begin result := RESULT_ERROR;
exit(RESULT_ERROR);
end; end;
end; end;
@ -587,14 +614,15 @@ begin
end; end;
{ Find a DTM given DTM index i, client C in area x1,y1,x2,y2. Return coord at x, y. } { 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; function find_dtm(C: TClient; DTMi: integer; var x, y: integer; x1, y1, x2,
y2: integer): integer; cdecl;
var var
res: boolean; res: boolean;
begin begin
try try
res := C.MFinder.FindDTM(C.MDTMs.DTM[DTMi], x, y, x1, y1, x2, y2); res := C.MFinder.FindDTM(C.MDTMs.DTM[DTMi], x, y, x1, y1, x2, y2);
except on e : Exception do except on e : Exception do
begin begin;
result := RESULT_ERROR; result := RESULT_ERROR;
set_last_error(e.Message); set_last_error(e.Message);
end; end;
@ -607,15 +635,17 @@ begin
end; end;
{ Find a DTM given DTM index i, client C in area x1,y1,x2,y2. Return coord at x, y. } { Find a DTM given DTM index i, client C in area x1,y1,x2,y2. Return coord at x, y. }
function find_dtms(C: TClient; DTMi: integer; ptr: PPoint; x1, y1, x2, y2: integer): integer; cdecl; function find_dtms(C: TClient; DTMi: integer; ptr: PPoint; x1, y1, x2,
y2: integer): integer; cdecl;
var var
res: boolean; res: boolean;
len: integer;
TPA: TPointArray; TPA: TPointArray;
begin begin
try try
res := C.MFinder.FindDTMs(C.MDTMs.DTM[DTMi], TPA, x1, y1, x2, y2); res := C.MFinder.FindDTMs(C.MDTMs.DTM[DTMi], TPA, x1, y1, x2, y2);
except on e : Exception do except on e : Exception do
begin begin;
result := RESULT_ERROR; result := RESULT_ERROR;
set_last_error(e.Message); set_last_error(e.Message);
end; end;
@ -625,14 +655,17 @@ begin
if len > 0 then if len > 0 then
result := RESULT_OK result := RESULT_OK
else else
begin
setlength(tpa, 0); setlength(tpa, 0);
exit(RESULT_FALSE); exit(RESULT_FALSE);
end;
ptr := array_to_ptr(Pointer(@TPA[0]), len, sizeof(TPoint)); ptr := array_to_ptr(Pointer(@TPA[0]), len, sizeof(TPoint));
setlength(TPA, 0); setlength(TPA, 0);
end; end;
function set_array_target(C: TClient; Arr: PRGB32; Size: TPoint): integer; cdecl; function set_array_target(C: TClient; Arr: PRGB32; Size: TPoint): integer;
cdecl;
begin begin
if not assigned(Arr) then if not assigned(Arr) then
begin begin
@ -640,10 +673,15 @@ begin
exit(RESULT_FALSE); exit(RESULT_FALSE);
end; end;
// FIXME: Catch exceptions. try
C.IOManager.SetTarget(Arr, Size); C.IOManager.SetTarget(Arr, Size);
result := RESULT_OK; result := RESULT_OK;
except on e : Exception do
begin;
set_last_error(e.message);
result := RESULT_FALSE;
end;
end;
end; end;
exports exports