1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-25 02:32:19 -05:00

Finder class.

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@32 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Wizzup? 2009-09-05 20:08:52 +00:00
parent 480d77896b
commit 036f11e249
7 changed files with 238 additions and 93 deletions

View File

@ -114,10 +114,13 @@ At this point it is unsure if the Input class will also take care of Sockets and
\section{More On The Core Classes}
The previously mentioned MML classes are considered to be the absolute core of the library. (Although one could argue that even the Colour class isn't part of the core classes.)
With these classes most functions that Mufasa will contain can be created. if you can make FindColor, you can make FindColorsSpiralTolerance, they don't really differ a lot. The same goes for DTM's, OCR and Bitmaps. Mouse and keyboard functions will be done with the Input class.
The MML contains more classes, and they will mainly utilize the previous mentioned classes.
It is essential to understand the Classes architecture to fully understand Mufasa.
Before work on other classes will be done, the core classes must be finished and stable.
A good rule of thumb is the following: any units that make extensive use of Compiler Directives, are considered a core unit.
\end{document}

View File

@ -6,9 +6,8 @@
<MainUnit Value="0"/>
<TargetFileExt Value=""/>
<Title Value="Mufasa Stand Alone"/>
<Icon Value="0"/>
<UseXPManifest Value="True"/>
<ActiveEditorIndexAtStart Value="1"/>
<ActiveEditorIndexAtStart Value="2"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
@ -30,15 +29,15 @@
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
<Units Count="45">
<Units Count="48">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="project1"/>
<CursorPos X="43" Y="15"/>
<CursorPos X="74" Y="10"/>
<TopLine Value="1"/>
<EditorIndex Value="0"/>
<UsageCount Value="60"/>
<UsageCount Value="63"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
@ -167,10 +166,10 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="TestUnit"/>
<CursorPos X="1" Y="45"/>
<TopLine Value="41"/>
<CursorPos X="39" Y="131"/>
<TopLine Value="119"/>
<EditorIndex Value="1"/>
<UsageCount Value="26"/>
<UsageCount Value="29"/>
<Loaded Value="True"/>
</Unit18>
<Unit19>
@ -299,10 +298,10 @@
<Filename Value="../../Units/MMLCore/client.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="Client"/>
<CursorPos X="91" Y="24"/>
<TopLine Value="1"/>
<EditorIndex Value="3"/>
<UsageCount Value="25"/>
<CursorPos X="35" Y="33"/>
<TopLine Value="23"/>
<EditorIndex Value="4"/>
<UsageCount Value="28"/>
<Loaded Value="True"/>
</Unit37>
<Unit38>
@ -311,8 +310,8 @@
<UnitName Value="MufasaTypes"/>
<CursorPos X="3" Y="16"/>
<TopLine Value="1"/>
<EditorIndex Value="2"/>
<UsageCount Value="25"/>
<EditorIndex Value="3"/>
<UsageCount Value="28"/>
<Loaded Value="True"/>
</Unit38>
<Unit39>
@ -320,18 +319,18 @@
<UnitName Value="compFiles"/>
<CursorPos X="18" Y="8"/>
<TopLine Value="1"/>
<EditorIndex Value="7"/>
<UsageCount Value="22"/>
<EditorIndex Value="9"/>
<UsageCount Value="24"/>
<Loaded Value="True"/>
</Unit39>
<Unit40>
<Filename Value="../../Units/MMLCore/files.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="files"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<EditorIndex Value="6"/>
<UsageCount Value="26"/>
<CursorPos X="1" Y="79"/>
<TopLine Value="63"/>
<EditorIndex Value="7"/>
<UsageCount Value="29"/>
<Loaded Value="True"/>
</Unit40>
<Unit41>
@ -339,9 +338,9 @@
<IsPartOfProject Value="True"/>
<UnitName Value="Window"/>
<CursorPos X="35" Y="227"/>
<TopLine Value="196"/>
<EditorIndex Value="4"/>
<UsageCount Value="25"/>
<TopLine Value="204"/>
<EditorIndex Value="5"/>
<UsageCount Value="28"/>
<Loaded Value="True"/>
</Unit41>
<Unit42>
@ -356,137 +355,167 @@
<UnitName Value="CompTypes"/>
<CursorPos X="80" Y="9"/>
<TopLine Value="1"/>
<EditorIndex Value="8"/>
<UsageCount Value="12"/>
<EditorIndex Value="10"/>
<UsageCount Value="14"/>
<Loaded Value="True"/>
</Unit43>
<Unit44>
<Filename Value="../../Units/MMLCore/windowutil.pas"/>
<UnitName Value="windowutil"/>
<CursorPos X="35" Y="109"/>
<TopLine Value="80"/>
<EditorIndex Value="5"/>
<UsageCount Value="11"/>
<CursorPos X="39" Y="19"/>
<TopLine Value="9"/>
<EditorIndex Value="6"/>
<UsageCount Value="13"/>
<Loaded Value="True"/>
</Unit44>
<Unit45>
<Filename Value="../../Units/MMLCore/input.pas"/>
<UnitName Value="Input"/>
<CursorPos X="3" Y="160"/>
<TopLine Value="149"/>
<EditorIndex Value="8"/>
<UsageCount Value="12"/>
<Loaded Value="True"/>
</Unit45>
<Unit46>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="finder"/>
<CursorPos X="51" Y="94"/>
<TopLine Value="84"/>
<EditorIndex Value="2"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit46>
<Unit47>
<Filename Value="../../../lazarus/lcl/graphics.pp"/>
<UnitName Value="Graphics"/>
<CursorPos X="17" Y="2298"/>
<TopLine Value="2282"/>
<UsageCount Value="10"/>
</Unit47>
</Units>
<JumpHistory Count="29" HistoryIndex="28">
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="../../Units/MMLCore/files.pas"/>
<Caret Line="41" Column="46" TopLine="31"/>
<Filename Value="testunit.pas"/>
<Caret Line="211" Column="1" TopLine="182"/>
</Position1>
<Position2>
<Filename Value="../../Units/MMLCore/files.pas"/>
<Caret Line="463" Column="34" TopLine="448"/>
<Filename Value="testunit.pas"/>
<Caret Line="154" Column="49" TopLine="140"/>
</Position2>
<Position3>
<Filename Value="../../Units/MMLCore/files.pas"/>
<Caret Line="34" Column="12" TopLine="30"/>
<Filename Value="testunit.pas"/>
<Caret Line="155" Column="8" TopLine="140"/>
</Position3>
<Position4>
<Filename Value="../../Units/MMLCore/files.pas"/>
<Caret Line="46" Column="19" TopLine="31"/>
<Filename Value="testunit.pas"/>
<Caret Line="160" Column="23" TopLine="145"/>
</Position4>
<Position5>
<Filename Value="../../Units/MMLCore/files.pas"/>
<Caret Line="72" Column="19" TopLine="50"/>
<Filename Value="../../../cogat/Units/CogatUnits/compfiles.pas"/>
<Caret Line="8" Column="18" TopLine="1"/>
</Position5>
<Position6>
<Filename Value="../../Units/MMLCore/files.pas"/>
<Caret Line="37" Column="11" TopLine="21"/>
<Filename Value="testunit.pas"/>
<Caret Line="29" Column="14" TopLine="11"/>
</Position6>
<Position7>
<Filename Value="../../Units/MMLCore/files.pas"/>
<Caret Line="38" Column="96" TopLine="28"/>
<Filename Value="testunit.pas"/>
<Caret Line="161" Column="39" TopLine="146"/>
</Position7>
<Position8>
<Filename Value="../../Units/MMLCore/files.pas"/>
<Caret Line="417" Column="42" TopLine="402"/>
<Filename Value="testunit.pas"/>
<Caret Line="29" Column="20" TopLine="16"/>
</Position8>
<Position9>
<Filename Value="../../Units/MMLCore/files.pas"/>
<Caret Line="449" Column="1" TopLine="431"/>
<Filename Value="testunit.pas"/>
<Caret Line="51" Column="14" TopLine="46"/>
</Position9>
<Position10>
<Filename Value="../../Units/MMLCore/client.pas"/>
<Caret Line="37" Column="18" TopLine="12"/>
<Filename Value="testunit.pas"/>
<Caret Line="54" Column="17" TopLine="48"/>
</Position10>
<Position11>
<Filename Value="../../Units/MMLCore/files.pas"/>
<Caret Line="20" Column="29" TopLine="11"/>
<Filename Value="../../Units/MMLCore/client.pas"/>
<Caret Line="31" Column="71" TopLine="14"/>
</Position11>
<Position12>
<Filename Value="testunit.pas"/>
<Caret Line="211" Column="1" TopLine="182"/>
<Caret Line="137" Column="62" TopLine="121"/>
</Position12>
<Position13>
<Filename Value="testunit.pas"/>
<Caret Line="154" Column="49" TopLine="140"/>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="157" Column="52" TopLine="141"/>
</Position13>
<Position14>
<Filename Value="testunit.pas"/>
<Caret Line="155" Column="8" TopLine="140"/>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="232" Column="59" TopLine="217"/>
</Position14>
<Position15>
<Filename Value="testunit.pas"/>
<Caret Line="160" Column="23" TopLine="145"/>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="236" Column="29" TopLine="217"/>
</Position15>
<Position16>
<Filename Value="../../../cogat/Units/CogatUnits/compfiles.pas"/>
<Caret Line="8" Column="18" TopLine="1"/>
<Filename Value="../../Units/MMLCore/client.pas"/>
<Caret Line="1" Column="1" TopLine="1"/>
</Position16>
<Position17>
<Filename Value="testunit.pas"/>
<Caret Line="29" Column="14" TopLine="11"/>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="106" Column="10" TopLine="91"/>
</Position17>
<Position18>
<Filename Value="testunit.pas"/>
<Caret Line="161" Column="39" TopLine="146"/>
<Filename Value="../../Units/MMLCore/windowutil.pas"/>
<Caret Line="21" Column="37" TopLine="1"/>
</Position18>
<Position19>
<Filename Value="testunit.pas"/>
<Caret Line="29" Column="20" TopLine="16"/>
<Caret Line="45" Column="1" TopLine="41"/>
</Position19>
<Position20>
<Filename Value="testunit.pas"/>
<Caret Line="51" Column="14" TopLine="46"/>
<Caret Line="48" Column="5" TopLine="38"/>
</Position20>
<Position21>
<Filename Value="testunit.pas"/>
<Caret Line="54" Column="17" TopLine="48"/>
<Filename Value="../../Units/MMLCore/windowutil.pas"/>
<Caret Line="109" Column="35" TopLine="86"/>
</Position21>
<Position22>
<Filename Value="../../Units/MMLCore/client.pas"/>
<Caret Line="31" Column="71" TopLine="14"/>
<Filename Value="../../Units/MMLCore/windowutil.pas"/>
<Caret Line="34" Column="34" TopLine="24"/>
</Position22>
<Position23>
<Filename Value="testunit.pas"/>
<Caret Line="137" Column="62" TopLine="121"/>
<Filename Value="../../Units/MMLCore/files.pas"/>
<Caret Line="1" Column="1" TopLine="1"/>
</Position23>
<Position24>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="157" Column="52" TopLine="141"/>
<Filename Value="../../Units/MMLCore/files.pas"/>
<Caret Line="213" Column="5" TopLine="203"/>
</Position24>
<Position25>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="232" Column="59" TopLine="217"/>
<Filename Value="../../Units/MMLCore/input.pas"/>
<Caret Line="1" Column="1" TopLine="1"/>
</Position25>
<Position26>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="236" Column="29" TopLine="217"/>
<Filename Value="../../Units/MMLCore/client.pas"/>
<Caret Line="8" Column="53" TopLine="1"/>
</Position26>
<Position27>
<Filename Value="../../Units/MMLCore/client.pas"/>
<Caret Line="1" Column="1" TopLine="1"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="35" Column="5" TopLine="31"/>
</Position27>
<Position28>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="106" Column="10" TopLine="91"/>
<Filename Value="testunit.pas"/>
<Caret Line="131" Column="39" TopLine="119"/>
</Position28>
<Position29>
<Filename Value="../../Units/MMLCore/windowutil.pas"/>
<Caret Line="21" Column="37" TopLine="1"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="92" Column="48" TopLine="75"/>
</Position29>
<Position30>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="84" Column="12" TopLine="64"/>
</Position30>
</JumpHistory>
</ProjectOptions>
<CompilerOptions>

View File

@ -7,7 +7,7 @@ uses
cthreads, cmem,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, LResources, Window, files, MufasaTypes, Client, TestUnit;
Forms, LResources, Window, files, MufasaTypes, Client, TestUnit, finder;
{$IFDEF WINDOWS}{$R project1.rc}{$ENDIF}

View File

@ -1,7 +1,7 @@
object Form1: TForm1
Left = 320
Left = 237
Height = 527
Top = 238
Top = 190
Width = 779
ActiveControl = Button1
Caption = 'Form1'

View File

@ -1,10 +1,10 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TForm1','FORMDATA',[
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'@'#1#6'Height'#3#15#2#3'Top'#3#238#0#5'Wi'
+'dth'#3#11#3#13'ActiveControl'#7#7'Button1'#7'Caption'#6#5'Form1'#12'ClientH'
+'eight'#3#15#2#11'ClientWidth'#3#11#3#8'Position'#7#14'poScreenCenter'#10'LC'
+'LVersion'#6#6'0.9.29'#0#7'TButton'#7'Button1'#4'Left'#2'E'#6'Height'#2#25#3
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3#237#0#6'Height'#3#15#2#3'Top'#3#190#0#5'W'
+'idth'#3#11#3#13'ActiveControl'#7#7'Button1'#7'Caption'#6#5'Form1'#12'Client'
+'Height'#3#15#2#11'ClientWidth'#3#11#3#8'Position'#7#14'poScreenCenter'#10'L'
+'CLVersion'#6#6'0.9.29'#0#7'TButton'#7'Button1'#4'Left'#2'E'#6'Height'#2#25#3
+'Top'#2' '#5'Width'#2'K'#7'Caption'#6#7'Button1'#7'OnClick'#7#12'Button1Clic'
+'k'#8'TabOrder'#2#0#0#0#0
]);

View File

@ -5,7 +5,7 @@ unit Client;
interface
uses
Classes, SysUtils, MufasaTypes, Window, Input, Files;
Classes, SysUtils, MufasaTypes, Window, Input, Files, Finder;
type
TClient = class(TObject)
@ -16,6 +16,7 @@ type
MWindow: TMWindow;
MInput: TMInput;
MFiles: TMFiles;
MFinder: TMFinder;
end;
@ -29,10 +30,12 @@ begin
MWindow := TMWindow.Create(Self);
MInput := TMInput.Create(Self);
MFiles := TMFiles.Create;
MFinder := TMFinder.Create(Self);
end;
destructor TClient.Destroy;
begin
MFinder.Destroy;
MFiles.Destroy;
MInput.Destroy;
MWindow.Destroy;

110
Units/MMLCore/finder.pas Normal file
View File

@ -0,0 +1,110 @@
unit finder;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
{ TMFinder Class }
{
Should be 100% independant, as all platform dependant code is in the
Window and Input classes.
Let's try not to use any OS-specific defines here? ;)
}
type
TMFinder = class(TObject)
constructor Create(aClient: TObject);
destructor Destroy; override;
public
// Possibly turn x, y into a TPoint var.
function FindColor(var x, y: Integer; Color, x1, y1, x2, y2: Integer): Boolean;
protected
Client: TObject;
private
end;
implementation
uses
Client, // For the Client Casts.
MufasaTypes // Types
;
constructor TMFinder.Create(aClient: TObject);
begin
inherited Create;
Self.Client := aClient;
end;
destructor TMFinder.Destroy;
begin
inherited;
end;
function TMFinder.FindColor(Var x, y: Integer; Color, x1, y1, x2, y2: Integer): Boolean;
var
PtrData: TRetData;
Ptr: PRGB32;
PtrInc: Integer;
dX, dY, clR, clG, clB, xx, yy: Integer;
begin
// checks for valid x1,y1,x2,y2? (may involve GetDimensions)
{if bla > bla) then etc }
// calculate delta x and y
dX := x2 - x1;
dY := y2 - y1;
//next, convert the color to r,g,b
{
ColorToRGB(Color, clR, clG, clB);
}
PtrData := TClient(Client).MWindow.ReturnData(x1, y1, dX, dY);
// Do we want to "cache" these vars?
// We will, for now. Easier to type.
Ptr := PtrData.Ptr;
PtrInc := PtrData.IncPtrWith;
for yy := 0 to dY do
begin
for xx := 0 to dX do
begin
// Colour comparison here. Possibly with tolerance? ;)
if (Ptr^.R = clR) and (Ptr^.G = clG) and (Ptr^.B = clB) then
begin
{
If we are only looking for one colour, result = true, free data, exit.
Else, add to the "hit" tpa, and increate the count.
}
Result := True;
x := xx;
y := yy;
TClient(Client).MWindow.FreeReturnData;
Exit;
end;
Inc(Ptr);
end;
Inc(Ptr, PtrInc)
end;
TClient(Client).MWindow.FreeReturnData;
end;
end.