1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-22 01:02:17 -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} \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.) 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. 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. 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. 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. 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} \end{document}

View File

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

View File

@ -7,7 +7,7 @@ uses
cthreads, cmem, cthreads, cmem,
{$ENDIF}{$ENDIF} {$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset 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} {$IFDEF WINDOWS}{$R project1.rc}{$ENDIF}

View File

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

View File

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

View File

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