Jump to content
Janilabo

IsTextInArea

Recommended Posts

IsTextIn (improved/updated version of IsTextInArea)

function IsTextIn(XS, YS, XE, YE: Integer; var x, y: Integer; S: string; Tolerance, Chars: Integer; TextColor: Integer): Boolean;
var
 b: TSCARBitmap;
begin
 if ((S <> '') and (XS < XE) and (YS < YE)) then
 case ((TextColor < 1) or (TextColor > 16777215)) of
   True:                                  
   try
     b := CreateBitmapMaskFromText(S, Chars);
     Result := FindBitmapMaskTolerance(b, x, y, XS, YS, XE, YE, Tolerance, 0); 
     b.Free;                                                                   
   except
   end;
   False:                                        
   try
     b := CreateBitmapFromText(S, Chars, TextColor);             
     b.TranspColor := 0;
     Result := FindBitmapTol(x, y, b, XS, YS, XE, YE, Tolerance);
     b.Free;
   except
   end;
 end;
end;

 

FindText

function FindText(var X, Y: Integer; S: string; Chars, TextColor, XS, YS, XE, YE, Tol: Integer): Boolean;
var
 b: TSCARBitmap;
begin
 if ((S <> '') and (XS < XE) and (YS < YE)) then
 begin
   try
     case (TextColor <= 0) of
       True:
       begin
         b := CreateBitmapFromText(S, Chars, clWhite);
         ReplaceColor(b, 0, 65280);
         ReplaceColor(b, clWhite, TextColor);
         b.TranspColor := 65280; 
       end;
       False:
       begin
         b := CreateBitmapFromText(S, Chars, TextColor);
         b.TranspColor := 0; 
       end;
     end;                            
     Result := FindBitmapTol(X, Y, b, XS, YS, XE, YE, Tol);
     b.Free;
   except
   end;
 end;
end;

 

FindTextEx

function FindTextEx(var TPA: TPointArray; S: string; Chars, TextColor, XS, YS, XE, YE, Tol: Integer): Boolean;
var
 b: TSCARBitmap;
begin
 if ((S <> '') and (XS < XE) and (YS < YE)) then
 begin
   try
     case (TextColor <= 0) of
       True:
       begin
         b := CreateBitmapFromText(S, Chars, clWhite);
         ReplaceColor(b, 0, 65280);
         ReplaceColor(b, clWhite, TextColor);
         b.TranspColor := 65280; 
       end;
       False:
       begin
         b := CreateBitmapFromText(S, Chars, TextColor);
         b.TranspColor := 0; 
       end;
     end;                            
     Result := FindBitmapTolEx(TPA, b, XS, YS, XE, YE, Tol);
     b.Free;
   except
   end;
 end;
end;

Edited by Janilabo
Updated the function - removed some unused variables. Added FindText(Ex).
Link to comment
Share on other sites

Man, i was going to make a function like this but the ones i keep coming up with took tolong to find anything if the area was any size. Whats the time lik with this one?
Hey shadow mate, these functions work very quickly, because they are based on Freddy's/SCAR's fast bitmap finding functions. :) Speed is just fine, but there is downside though; these need fonts that doesn't contain any randomized spacing between characters of the text you are looking for (good example would be RuneScape uptext)..

 

Updated the topic: Deleted MinSpacing/MaxSpacing, because they were useless here. Also, added FindText and FindTextEx.

 

-Jani

Link to comment
Share on other sites

Hey shadow mate, these functions work very quickly, because they are based on Freddy's/SCAR's fast bitmap finding functions. :) Speed is just fine, but there is downside though; these need fonts that doesn't contain any randomized spacing between characters of the text you are looking for (good example would be RuneScape uptext)..

 

Updated the topic: Deleted MinSpacing/MaxSpacing, because they were useless here. Also, added FindText and FindTextEx.

 

-Jani

 

Nice! Good idea to make these anew/new and use Bitmap functions! FindTextEx was my only contribution to SRL xD...

 

You could in theory do max and min spacing and some other things. But it would be a complex operation. Adding and taking away black space only between the white colors or something like that xD.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...