Daniel
2009-07-23 06:29:21
Just adding more functionality for bitmaps :)
Create a new file inside of your SCARs SRLs' core directory called "Bitmap.scar" (without the quotes). Open it within SCAR and copy and paste the following, making sure to save after copying and pasting.
After that (after the save), open up SRL.scar inside your SRL include directory. Once you've done that, go take a look at Line 27. Make a new line after that (by making Line 27 the active line, then pressing the End button on your keyboard followed by your Enter/Return key) and put:
{.include SRL/SRL/Core/Bitmap.scar}
Now save SRL.scar, and you can now use those functions within your script :D
Hope you like ;)
Create a new file inside of your SCARs SRLs' core directory called "Bitmap.scar" (without the quotes). Open it within SCAR and copy and paste the following, making sure to save after copying and pasting.
//-----------------------------------------------------------------//
//-- RSRL Resource Library --//
//-- ยป Bitmap Routines --//
//-----------------------------------------------------------------//
// * function FindBitmapMaskToleranceRotatedEx: Boolean; // * by Dan's The Man
// * function FindBitmapMaskToleranceRotated: Boolean; // * by Dan's The Man
// * function CountBitmapMaskTolerance: Cardinal; // * by Dan's The Man
// * function FindBitmapMaskRotated: Boolean; // * by Dan's The Man
// * function CountBitmapMask: Cardinal; // * by Dan's The Man
// * procedure RotateBitmap2; // * by Dan's The Man
// * function FindToleranceFromBitmapIn: Boolean; // * by Dan's The Man
// * function FindToleranceFromBitmap: Boolean; // * by Dan's The Man
// * procedure FindBitmapsToleranceIn // * by Dan's The Man
// * procedure FindBitmapsTolerance // * by Dan's The Man
// * function FindBitmapInPointsTolerance // * by Dan's The Man
// * function FindBitmapInPoints // * by Dan's The Man
// * function FindBitmapPointsTolerance // * by Dan's The Man
// * function FindBitmapPoints // * by Dan's The Man
// * procedure FindBitmapsPointsToleranceSkipBoxArrayIn(BMPs: /*
// TIntegerArray; var Points: T2DPointArray; x1, y1, x2, * by Dan's The Man
// y2: Integer; SkipBoxes: TBoxArray; Tolerance: Word); */
// * function FindBitmapToleranceSkipBoxArray(BMP: Integer; /*
// var x, y: Integer; x1, y1, x2, y2: Integer; SkipBoxes: * by Dan's The Man
// TBoxArray; Tolerance: Word): Boolean; */
// * function FindBitmapSkipBoxArray(BMP: Integer; var x, y: /*
// Integer; x1, y1, x2, y2: Integer; SkipBoxes: TBoxArray) * by Dan's The Man
// : Boolean; */
// * function FindBitmapToleranceSkipBox(BMP: Integer; var x, /*
// y: Integer; x1, y1, x2, y2: Integer; SkipBox: TBox; * by Dan's The Man
// Tolerance: Word): Boolean; */
// * function FindBitmapSkipBox(BMP: Integer; var x, y: Integer; {
// x1, y1, x2, y2: Integer; SkipBox: TBox): Boolean; * by Dan's The Man }
{*******************************************************************************
function function FindBitmapMaskToleranceRotatedEx: Boolean;
By: Dan's The Man
Description: Continues rotating the bitmap Mask by Incr (parametre specified) degrees
until the bitmap is found within x1, y1, x2 and y2. Results False if bitmap
cannot be found. Stores found coordinates in X and Y.
*******************************************************************************}
function FindBitmapMaskToleranceRotatedEx(Mask: Integer; var x, y: Integer; x1,
y1, x2, y2: Integer; Tolerance, ContourTolerance: Integer; Incr: Extended): Boolean;
var
Fl: Extended;
begin
repeat
Result := FindBitmapMaskTolerance(RotateBitmap(Mask, Fl), x, y, x1, y1, x2,
y2, Tolerance, ContourTolerance);
if(Result) then
Exit;
Fl := Fl + Radians(Incr);
Until(Degrees(Fl) >= Degrees(Radians(360) + Radians(Incr)));
end;
{*******************************************************************************
function FindBitmapMaskToleranceRotated: Boolean;
By: Dan's The Man
Description: Continues rotating the bitmap Mask .5 degrees until the bitmap is found
within x1, y1, x2 and y2. Results False if bitmap cannot be found. Stores
found coordinates in X and Y.
*******************************************************************************}
function FindBitmapMaskToleranceRotated(Mask: Integer; var x, y: Integer; x1,
y1, x2, y2: Integer; Tolerance, ContourTolerance: Integer): Boolean;
begin
Result := FindBitmapMaskToleranceRotatedEx(Mask, x, y, x1, y1, x2, y2, Tolerance,
ContourTolerance, 0.5);
end;
{*******************************************************************************
function CountBitmapMaskTolerance: Cardinal;
By: Dan's The Man
Description: Returns the amount of bitmap Masks' found in x1, y1, x2 and y2.
*******************************************************************************}
function CountBitmapMaskTolerance(Mask: Integer; x1, y1, x2, y2: Integer; Tolerance,
ContourTolerance: Integer): Cardinal;
var
xx, yy, w, h: Integer;
TP: TPoint;
FX: Boolean;
begin
xx := x1;
yy := y1;
GetBitmapSize(Mask, w, h);
repeat
Result := Result + Integer(FindBitmapMaskTolerance(Mask, TP.X, TP.Y, xx, yy, xx + w,
yy + h, Tolerance, ContourTolerance));
xx := xx + w;
FX := XX >= (x2 - w);
if(FX) then
begin
xx := x1;
yy := yy + h;
FX := False;
end;
if(yy > y2 - h) then
Exit;
Until(False);
end;
{*******************************************************************************
function FindBitmapMaskRotated: Boolean;
By: Dan's The Man
Description: Continues rotating the bitmap Mask .5 degrees until the bitmap is found
within x1, y1, x2 and y2. Results False if bitmap cannot be found. Stores
found coordinates in X and Y. Does not search for tolerance comparisons.
*******************************************************************************}
function FindBitmapMaskRotated(Mask: Integer; var x, y: Integer; x1, y1, x2,
y2: Integer): Boolean;
begin
Result := FindBitmapMaskToleranceRotatedEx(Mask, x, y, x1, y1, x2, y2, 0,
0, 0.5);
end;
{*******************************************************************************
function CountBitmapMask: Cardinal;
By: Dan's The Man
Description: Returns the amount of bitmap Masks' found in x1, y1, x2 and y2.
Does not search for tolerance comparisons.
*******************************************************************************}
function CountBitmapMask(Mask: Integer; x1, y1, x2, y2: Integer): Cardinal;
begin
Result := CountBitmapMaskTolerance(Mask, x1, y1, x2, y2, 0, 0);
end;
{*******************************************************************************
procedure RotateBitmap2;
By: Dan's The Man
Description: Modifies the bitmap BMP by rotating every Angle (parametre specified)
degrees.
*******************************************************************************}
procedure RotateBitmap2(var BMP: Integer; Angle: Single);
begin
BMP := RotateBitmap(BMP, Angle);
end;
{*******************************************************************************
function FindToleranceFromBitmapIn: Boolean;
By: Dan's The Man
Description: Returns true if the bitmap BMP was successfully found within the bounds
x1, y1, x2 and y2. Loops through finding the bitmap increasing the tolerance
each round. If bitmap is found, the Tolerance parametre returns the tolerance
of which the bitmap was found.
*******************************************************************************}
function FindToleranceFromBitmapIn(BMP: Integer; var x, y: Integer; x1, y1,
x2, y2: Integer; var Tolerance: Integer): Boolean;
var
i: Integer;
begin
repeat
Result := FindBitmapToleranceIn(BMP, x, y, x1, y1, x2, y2, i);
if(Result) then
begin
Tolerance := i;
Exit;
end;
Inc(i);
Until(i > 255);
end;
{*******************************************************************************
function FindToleranceFromBitmap: Boolean;
By: Dan's The Man
Description: Returns true if the bitmap BMP was successfully found within the
client bounds. Loops through finding the bitmap increasing the tolerance each
round. If bitmap is found, the Tolerance parametre returns the tolerance of
which the bitmap was found.
*******************************************************************************}
function FindToleranceFromBitmap(BMP: Integer; var x, y: Integer; var
Tolerance: Integer): Boolean;
var
cw, ch: Integer;
begin
GetClientDimensions(cw, ch);
Result := FindToleranceFromBitmapIn(BMP, x, y, 0, 0, cw, ch, Tolerance);
end;
{*******************************************************************************
procedure FindBitmapsToleranceIn;
By: Dan's The Man
Description: Finds multiple bitmaps storing them in the multi-dimensional array,
Points, within the bounds x1, y1, x2 and y2.
*******************************************************************************}
procedure FindBitmapsToleranceIn(BMPs: TIntegerArray; var Points: T2DPointArray;
x1, y1, x2, y2: Integer; Tolerance: Integer);
var
i, bI, xx, yy, cbw, cbh: Integer;
begin
bI := High(BMPs);
for i := 0 to bI do
begin
xx := x1;
yy := y1;
GetBitmapSize(BMPs[i], cbw, cbh);
repeat
FindBitmapToleranceIn(BMPs[i], Points[i][High(Points) + 1].X,
Points[i][High(Points) + 1].Y, xx, yy, xx + cbw, yy + cbh, Tolerance);
xx := xx + cbw;
if(xx > x2 - cbw) then
begin
yy := yy + cbh;
xx := x1;
if(yy > y2 - cbh) then
yy := y1;
end;
Until((xx = x1) and (yy = y1));
end;
end;
{*******************************************************************************
procedure FindBitmapsTolerance;
By: Dan's The Man
Description: Finds multiple bitmaps storing them in the multi-dimensional array,
Points, within the client bounds.
*******************************************************************************}
procedure FindBitmapsTolerance(BMPs: TIntegerArray; var Points: T2DPointArray;
Tolerance: Integer);
var
cw, ch: Integer;
begin
GetClientDimensions(cw, ch);
FindBitmapsToleranceIn(BMPs, Points, 0, 0, cw, ch, Tolerance);
end;
{*******************************************************************************
function FindBitmapInPointsTolerance: TPointArray;
By: Dan's The Man
Description: Results the multiple coordinates BMP was found within the bounds
x1, y1, x2 and y2.
*******************************************************************************}
function FindBitmapInPointsTolerance(BMP: Integer; x1, y1, x2, y2: Integer;
Tolerance: Integer): TPointArray;
var
T2DP: T2DPointArray;
begin
FindBitmapsToleranceIn([BMP], T2DP, x1, y1, x2, y2, Tolerance);
Result := T2DP[0];
end;
{*******************************************************************************
function FindBitmapInPoints: TPointArray;
By: Dan's The Man
Description: Results the multiple coordinates BMP was found within the bounds
x1, y1, x2 and y2. Does not require tolerance.
*******************************************************************************}
function FindBitmapInPoints(BMP: Integer; x1, y1, x2, y2: Integer): TPointArray;
var
T2DP: T2DPointArray;
begin
FindBitmapsToleranceIn([BMP], T2DP, x1, y1, x2, y2, 0);
Result := T2DP[0];
end;
{*******************************************************************************
function FindBitmapPointsTolerance: TPointArray;
By: Dan's The Man
Description: Results the multiple coordinates BMP was found within the client
bounds.
*******************************************************************************}
function FindBitmapPointsTolerance(BMP: Integer; Tolerance: Integer): TPointArray;
var
cw, ch: Integer;
T2DP: T2DPointArray;
begin
GetClientDimensions(cw, ch);
FindBitmapsToleranceIn([BMP], T2DP, 0, 0, cw, ch, Tolerance);
Result := T2DP[0];
end;
{*******************************************************************************
function FindBitmapPoints: TPointArray;
By: Dan's The Man
Description: Results the multiple coordinates BMP was found within the client
bounds. Does not require tolerance.
*******************************************************************************}
function FindBitmapPoints(BMP: Integer): TPointArray;
var
cw, ch: Integer;
T2DP: T2DPointArray;
begin
GetClientDimensions(cw, ch);
FindBitmapsToleranceIn([BMP], T2DP, 0, 0, cw, ch, 0);
Result := T2DP[0];
end;
{*******************************************************************************
procedure FindBitmapsPointsToleranceSkipBoxArrayIn(BMPs: TIntegerArray;
var Points: T2DPointArray; x1, y1, x2, y2: Integer; SkipBoxes: TBoxArray;
Tolerance: Word);
By: Dan's The Man
Description:
- BMPs = List of bitmaps in SCARs integer format to find.
- Points[BMPs[i]] = Points where BMPs[i] was found.
- x1, y1, x2, y2 = Search area bounds (will automatically swap larger).
- SkipBoxes = The TBox array which contains the areas in the search to skip.
- Tolerance = Tolerance for bitmap search.
*******************************************************************************}
procedure FindBitmapsPointsToleranceSkipBoxArrayIn(BMPs: TIntegerArray;
var Points: T2DPointArray; x1, y1, x2, y2: Integer; SkipBoxes: TBoxArray;
Tolerance: Word);
var
I, bS: Integer;
miX, miY, mX, mY: Integer;
bW, bH: Integer;
cX, cY, cbX, cbY: Integer;
iiSB: Boolean;
Count, bCount, hL: Integer;
begin
SetLength(Points, Length(BMPs));
cX := -1;
cY := -1;
hL := 0;
bS := High(SkipBoxes);
miX := Min(x1, x2);
miY := Min(y1, y1);
mX := Max(x2, x1);
mY := Max(y2, y1);
cbX := miX;
cbY := miY;
repeat
repeat
iiSB := False;
for i := 0 to bS do
if((InRange(cbX, SkipBoxes[i].X1, SkipBoxes[i].X2)) and
(InRange(cbY, SkipBoxes[i].Y1, SkipBoxes[i].Y2))) then
begin
iiSB := True;
Break;
end;
if(not(iiSB)) then
if(FindBitmapToleranceIn(BMPs[Count], cX, cY, cbX, cbY, cbX + bW, cbY + bH,
Tolerance)) then
begin
SetLength(Points[Count], hL + 1);
Points[Count][hL] := IntToPoint(cX, cY);
Inc(hL);
end;
IncEx(cbX, bW);
if(cbX > mX) then
begin
cbX := miX;
IncEx(cbY, bH);
end;
Until(cbY + bH > mY);
Inc(Count);
Until(Count = bCount);
end;
{*******************************************************************************
function FindBitmapToleranceSkipBoxArray(BMP: Integer; var x, y: Integer;
x1, y1, x2, y2: Integer; SkipBoxes: TBoxArray; Tolerance: Word): Boolean;
By: Dan's The Man
Description: Finds bitmap BMP with Tolerance in the search bounds (x1, y1, x2,
y2) skipping the array of Boxes. X and Y results coordinates BMP was found,
-1, -1 if nothing found.
*******************************************************************************}
function FindBitmapToleranceSkipBoxArray(BMP: Integer; var x, y: Integer;
x1, y1, x2, y2: Integer; SkipBoxes: TBoxArray; Tolerance: Word): Boolean;
var
I, bS: Integer;
miX, miY, mX, mY: Integer;
bW, bH: Integer;
cbX, cbY: Integer;
iiSB: Boolean;
begin
Result := False;
x := -1;
y := -1;
bS := High(SkipBoxes);
GetBitmapSize(BMP, bW, bH);
miX := Min(x1, x2);
miY := Min(y1, y1);
mX := Max(x2, x1);
mY := Max(y2, y1);
cbX := miX;
cbY := miY;
repeat
iiSB := False;
for i := 0 to bS do
if((InRange(cbX, SkipBoxes[i].X1, SkipBoxes[i].X2)) and
(InRange(cbY, SkipBoxes[i].Y1, SkipBoxes[i].Y2))) then
begin
iiSB := True;
Break;
end;
if(not(iiSB)) then
Result := FindBitmapToleranceIn(BMP, x, y, cbX, cbY, cbX + bW, cbY + bH,
Tolerance);
if(Result) then
Exit;
IncEx(cbX, bW);
if(cbX > mX) then
begin
cbX := miX;
IncEx(cbY, bH);
end;
Until(cbY + bH > mY);
end;
{*******************************************************************************
function FindBitmapSkipBoxArray(BMP: Integer; var x, y: Integer; x1, y1, x2,
y2: Integer; SkipBoxes: TBoxArray): Boolean;
By: Dan's The Man
Description: Finds bitmap BMP without Tolerance in the search bounds (x1, y1, x2,
y2) skipping the array of Boxes. X and Y results coordinates BMP was found,
-1, -1 if nothing found.
*******************************************************************************}
function FindBitmapSkipBoxArray(BMP: Integer; var x, y: Integer; x1, y1, x2,
y2: Integer; SkipBoxes: TBoxArray): Boolean;
begin
Result := FindBitmapToleranceSkipBoxArray(BMP, x, y, x1, y1, x2, y2, SkipBoxes,
0);
end;
{*******************************************************************************
function FindBitmapToleranceSkipBox(BMP: Integer; var x, y: Integer; x1, y1,
x2, y2: Integer; SkipBox: TBox; Tolerance: Word): Boolean;
By: Dan's The Man
Description: Finds bitmap BMP with Tolerance in the search bounds (x1, y1, x2,
y2) skipping the Boxe. X and Y results coordinates BMP was found, -1, -1 if
nothing found.
*******************************************************************************}
function FindBitmapToleranceSkipBox(BMP: Integer; var x, y: Integer; x1, y1,
x2, y2: Integer; SkipBox: TBox; Tolerance: Word): Boolean;
begin
Result := FindBitmapToleranceSkipBoxArray(BMP, x, y, x1, y1, x2, y2, [SkipBox],
Tolerance);
end;
{*******************************************************************************
function FindBitmapToleranceSkipBox(BMP: Integer; var x, y: Integer; x1, y1,
x2, y2: Integer; SkipBox: TBox; Tolerance: Word): Boolean;
By: Dan's The Man
Description: Finds bitmap BMP without Tolerance in the search bounds (x1, y1, x2,
y2) skipping the Boxe. X and Y results coordinates BMP was found, -1, -1 if
nothing found.
*******************************************************************************}
function FindBitmapSkipBox(BMP: Integer; var x, y: Integer; x1, y1, x2, y2: Integer;
SkipBox: TBox): Boolean;
begin
Result := FindBitmapToleranceSkipBoxArray(BMP, x, y, x1, y1, x2, y2, [SkipBox],
0);
end;After that (after the save), open up SRL.scar inside your SRL include directory. Once you've done that, go take a look at Line 27. Make a new line after that (by making Line 27 the active line, then pressing the End button on your keyboard followed by your Enter/Return key) and put:
{.include SRL/SRL/Core/Bitmap.scar}
Now save SRL.scar, and you can now use those functions within your script :D
Hope you like ;)