2009-09-04 00:26:56 -04:00
|
|
|
unit TestUnit;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
2009-09-12 02:24:59 -04:00
|
|
|
StdCtrls, SynEdit, SynHighlighterPas, SynMemo, Client, MufasaTypes,
|
2009-09-12 15:00:21 -04:00
|
|
|
mmlpsthread, mmlthread;
|
2009-09-04 00:26:56 -04:00
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TForm1 }
|
|
|
|
|
|
|
|
TForm1 = class(TForm)
|
|
|
|
Button1: TButton;
|
2009-09-12 02:24:59 -04:00
|
|
|
SynEdit1: TSynEdit;
|
|
|
|
SynFreePascalSyn1: TSynFreePascalSyn;
|
|
|
|
SynMemo1: TSynMemo;
|
2009-09-04 00:26:56 -04:00
|
|
|
procedure Button1Click(Sender: TObject);
|
2009-09-12 14:50:10 -04:00
|
|
|
procedure FormCreate(Sender: TObject);
|
2009-09-12 02:24:59 -04:00
|
|
|
procedure SynMemo1Change(Sender: TObject);
|
2009-09-04 00:26:56 -04:00
|
|
|
private
|
|
|
|
{ private declarations }
|
|
|
|
public
|
|
|
|
{ public declarations }
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
Form1: TForm1;
|
|
|
|
|
|
|
|
implementation
|
2009-09-09 03:08:58 -04:00
|
|
|
uses
|
|
|
|
lclintf;
|
2009-09-04 00:26:56 -04:00
|
|
|
|
|
|
|
type
|
|
|
|
TMyThread = class(TThread)
|
|
|
|
private
|
|
|
|
protected
|
|
|
|
procedure Execute; override;
|
|
|
|
public
|
|
|
|
Constructor Create(CreateSuspended : boolean);
|
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TMyThread.Create(CreateSuspended : boolean);
|
|
|
|
begin
|
|
|
|
FreeOnTerminate := True;
|
|
|
|
inherited Create(CreateSuspended);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMyThread.Execute;
|
2009-09-04 02:06:58 -04:00
|
|
|
|
2009-09-04 15:18:13 -04:00
|
|
|
Const
|
2009-09-04 02:06:58 -04:00
|
|
|
fsFromBeginning = 0; // offset must be pos or 0
|
|
|
|
fsFromCurrent = 1; // offset pos or neg
|
|
|
|
fsFromEnd = 2; // offset only neg or 0
|
|
|
|
|
|
|
|
// put somewhese else
|
2009-09-04 15:18:13 -04:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
TestPath = 'c:/test';
|
2009-09-04 03:04:42 -04:00
|
|
|
DirectorySeperator = '\';
|
|
|
|
DS = '\';
|
|
|
|
ExeExt = '.exe';
|
2009-09-04 15:18:13 -04:00
|
|
|
{$ENDIF}
|
|
|
|
{$IFDEF LINUX}
|
|
|
|
TestPath = '/tmp/test';
|
|
|
|
DirectorySeperator = '/';
|
|
|
|
DS = '/';
|
|
|
|
ExeExt = '';
|
|
|
|
{$ENDIF}
|
2009-09-04 00:26:56 -04:00
|
|
|
Var
|
|
|
|
Client: TClient;
|
2009-09-09 03:08:58 -04:00
|
|
|
w,h, x, y, xx, yy, i,t1,t2:integer;
|
2009-09-04 00:26:56 -04:00
|
|
|
bmp: TBitmap;
|
|
|
|
ReturnData : TRetData;
|
|
|
|
arr: Array Of Integer;
|
|
|
|
LoopY,LoopX : integer;
|
|
|
|
|
2009-09-04 02:06:58 -04:00
|
|
|
s, s2: string;
|
|
|
|
myFile, myFile2: Integer;
|
|
|
|
|
|
|
|
|
2009-09-04 00:26:56 -04:00
|
|
|
begin
|
|
|
|
while (not Terminated) do
|
|
|
|
begin
|
|
|
|
|
|
|
|
Writeln('Creating the client');
|
|
|
|
Client := TClient.Create;
|
2009-09-09 03:08:58 -04:00
|
|
|
//Client.MWindow.SetTarget(77594696);
|
2009-09-04 00:26:56 -04:00
|
|
|
Writeln('Getting the dimensions');
|
|
|
|
Client.MWindow.GetDimensions(w, h);
|
2009-09-09 03:08:58 -04:00
|
|
|
t1 := lclintf.gettickcount;
|
|
|
|
for i := 0 to 100 do
|
|
|
|
Client.MFinder.FindColor(x, y, 123456, 0, 0, w, h);
|
|
|
|
t2 := lclintf.gettickcount;
|
|
|
|
writeln(inttostr(round((t2 - t1) / 101)));
|
|
|
|
|
|
|
|
//break;
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-04 00:26:56 -04:00
|
|
|
writeln(inttostr(w) + ' , ' + inttostr(h));
|
|
|
|
Writeln('Setting target');
|
|
|
|
// Client.MWindow.SetTarget(67232,w_window);
|
|
|
|
|
|
|
|
{ SetLength(Arr, 9);
|
|
|
|
for i := 0 to high(arr) do
|
|
|
|
arr[i] := $FFFFFF;
|
|
|
|
|
|
|
|
Client.MWIndow.SetTarget(PRGB32(@Arr[0]), Point(3, 3)); }
|
|
|
|
|
|
|
|
// Client.MWindow.ActivateClient;
|
|
|
|
|
|
|
|
Client.MWindow.GetDimensions(w, h);
|
|
|
|
Writeln('Copying BMP');
|
|
|
|
bmp := Client.MWindow.CopyClientToBitmap(0, 0, w, h);
|
|
|
|
Writeln('Saving BMP');
|
|
|
|
|
|
|
|
{$IFDEF WINDOWS}
|
|
|
|
bmp.SaveToFile('c:\test1.bmp');
|
|
|
|
{$ENDIF}
|
|
|
|
{$IFDEF LINUX}
|
|
|
|
bmp.SaveToFile('/tmp/test1.bmp');
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
writeln('Copied Bitmap');
|
|
|
|
|
|
|
|
Client.MInput.GetMousePos(x, y);
|
|
|
|
writeln(inttostr(x) + ' , ' + inttostr(y));
|
|
|
|
|
|
|
|
Client.MInput.SetMousePos(50, 50);
|
|
|
|
Client.MInput.GetMousePos(x, y);
|
|
|
|
writeln(inttostr(x) + ' , ' + inttostr(y));
|
|
|
|
|
|
|
|
Client.MInput.ClickMouse(60, 60, mouse_Right);
|
|
|
|
|
|
|
|
LoopX:= w div 2;
|
|
|
|
LoopY:= h div 2;
|
|
|
|
bmp.SetSize(Loopx + 1, Loopy + 1);
|
|
|
|
ReturnData := Client.MWindow.ReturnData(0, 0, Loopx + 1, Loopy + 1);
|
|
|
|
|
|
|
|
SetLength(Arr,(Loopy + 1) * (Loopx + 1));
|
|
|
|
|
|
|
|
for yy := 0 to Loopy do
|
|
|
|
begin;
|
|
|
|
for xx := 0 to Loopx do
|
|
|
|
begin
|
|
|
|
{ Do comparison here }
|
2009-09-04 14:39:18 -04:00
|
|
|
Arr[yy * (loopx) + xx] :=RGBToColor(ReturnData.Ptr^.B,ReturnData.Ptr^.G,ReturnData.Ptr^.R);
|
2009-09-04 00:26:56 -04:00
|
|
|
|
2009-09-04 01:17:52 -04:00
|
|
|
// .Canvas not thread stable on linux. (use fpImage and fpCanvas)
|
2009-09-04 00:26:56 -04:00
|
|
|
//Bmp.Canvas.Pixels[xx,yy] := RGBToColor(ReturnData.Ptr^.R,ReturnData.Ptr^.G,ReturnData.Ptr^.B);
|
|
|
|
|
|
|
|
inc(ReturnData.Ptr);
|
|
|
|
end;
|
|
|
|
Inc(ReturnData.Ptr,ReturnData.IncPtrWith);
|
|
|
|
end;
|
2009-09-04 14:39:18 -04:00
|
|
|
bmp.Free;
|
2009-09-04 00:26:56 -04:00
|
|
|
|
2009-09-04 14:39:18 -04:00
|
|
|
Client.MWindow.SetTarget(@Arr[0], Point(loopx, loopy));
|
|
|
|
writeln(inttostr(loopx) + ' , ' + inttostr(loopy));
|
|
|
|
Client.MWindow.GetDimensions(W, H);
|
|
|
|
writeln(inttostr(w) + ' , ' + inttostr(h));
|
|
|
|
|
|
|
|
Bmp := Client.MWindow.CopyClientToBitmap(0, 0, loopx, loopy);
|
2009-09-04 00:26:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
{$IFDEF WINDOWS}
|
|
|
|
bmp.SaveToFile('c:\test2.bmp');
|
|
|
|
{$ENDIF}
|
|
|
|
{$IFDEF LINUX}
|
|
|
|
bmp.SaveToFile('/tmp/test2.bmp');
|
|
|
|
{$ENDIF}
|
2009-09-04 01:17:52 -04:00
|
|
|
|
2009-09-04 00:26:56 -04:00
|
|
|
Bmp.free;
|
|
|
|
|
|
|
|
// Client.MWIndow.SetTarget(PRGB32(@Arr[0]), Point(Loopx + 1, Loopy + 1));
|
|
|
|
Client.MWindow.FreeReturnData;
|
|
|
|
|
2009-09-09 03:08:58 -04:00
|
|
|
Client.MInput.IsMouseButtonDown(mouse_Right);
|
2009-09-04 01:17:52 -04:00
|
|
|
// Sleep(1000);
|
2009-09-04 00:26:56 -04:00
|
|
|
if Client.MInput.IsMouseButtonDown(mouse_Left) then
|
|
|
|
writeln('Left mouse is down!');
|
|
|
|
if Client.MInput.IsMouseButtonDown(mouse_Right) then
|
|
|
|
writeln('Right mouse is down!');
|
|
|
|
if Client.MInput.IsMouseButtonDown(mouse_Middle) then
|
|
|
|
writeln('Middle mouse is down!');
|
2009-09-04 02:06:58 -04:00
|
|
|
|
|
|
|
|
|
|
|
with Client.MFiles do
|
|
|
|
begin
|
|
|
|
s := ExtractFileDir(Application.ExeName);
|
|
|
|
Writeln('Our current path is: ' + s);
|
|
|
|
If DirectoryExists(s) Then
|
|
|
|
writeln('Directory ' + s + ' exists.');
|
|
|
|
|
|
|
|
If FileExists(s + DirectorySeperator + 'Cogat' + ExeExt) Then
|
|
|
|
writeln('We exist!');
|
|
|
|
|
|
|
|
myFile := CreateFile(TestPath);
|
|
|
|
WriteFileString(myFile, 'wat');
|
|
|
|
WriteFileString(myFile, 'watnumber2');
|
|
|
|
CloseFile(myFile);
|
|
|
|
|
|
|
|
myFile := OpenFile(TestPath, False);
|
|
|
|
ReadFileString(myFile, s2, 2);
|
|
|
|
writeln('s2: ' + s2);
|
|
|
|
CloseFile(myFile);
|
|
|
|
|
|
|
|
myFile := CreateFile(TestPath + '2');
|
|
|
|
WriteFileString(myFile, 'wat222');
|
|
|
|
|
|
|
|
CloseFile(myFile);
|
|
|
|
|
|
|
|
// TestPath now contains; 'watwatnumber2'. We will make it write 'number',
|
|
|
|
// and then 2.
|
|
|
|
myFile := OpenFile(TestPath, False);
|
|
|
|
SetFileCharPointer(myFile, 6, fsFromBeginning);
|
|
|
|
ReadFileString(myFile, s2, 6);
|
|
|
|
writeln('s2: ' + s2);
|
|
|
|
s2 := '';
|
|
|
|
|
|
|
|
SetFileCharPointer(myFile, -1, fsFromEnd);
|
|
|
|
ReadFileString(myFile, s2, 1);
|
|
|
|
writeln('s2: ' + s2);
|
|
|
|
CloseFile(myFile);
|
|
|
|
// myFile2 should be -1.
|
|
|
|
myFile := RewriteFile(TestPath, False);
|
|
|
|
myFile2 := RewriteFile(TestPath, False);
|
|
|
|
writeln(inttostr(myFile) + ' : ' + inttostr(myFile2));
|
|
|
|
|
|
|
|
// myFile2 should be -1.
|
|
|
|
myFile2 := OpenFile(TestPath, False);
|
|
|
|
writeln(inttostr(myFile) + ' : ' + inttostr(myFile2));
|
|
|
|
|
|
|
|
// Now, we will test EndOfFile, and FileSize.
|
|
|
|
|
|
|
|
While Not EndOfFile(myFile) Do
|
|
|
|
Begin
|
|
|
|
ReadFileString(myFile, s2, 1);
|
|
|
|
Writeln(s2);
|
|
|
|
End;
|
|
|
|
|
|
|
|
CloseFile(myFile);
|
|
|
|
writeln('wat');
|
|
|
|
|
|
|
|
|
|
|
|
end;
|
2009-09-04 00:26:56 -04:00
|
|
|
Client.Destroy;
|
|
|
|
writeln('Test completed successfully');
|
|
|
|
break;
|
2009-09-04 01:17:52 -04:00
|
|
|
|
2009-09-04 00:26:56 -04:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TForm1 }
|
|
|
|
|
|
|
|
procedure TForm1.Button1Click(Sender: TObject);
|
|
|
|
Var
|
2009-09-11 14:32:57 -04:00
|
|
|
//MyThread: TMyThread;
|
2009-09-12 02:24:59 -04:00
|
|
|
// MMLThread: TMMLThread;
|
|
|
|
MMLPSThread : TMMLPSThread;
|
2009-09-04 00:26:56 -04:00
|
|
|
|
|
|
|
begin
|
2009-09-11 14:32:57 -04:00
|
|
|
{ MyThread := TMyThread.Create(True);
|
|
|
|
MyThread.Resume; }
|
2009-09-12 02:24:59 -04:00
|
|
|
{ MMLThread := TMMLThread.Create(True);
|
|
|
|
MMLThread.Resume;}
|
|
|
|
MMLPSThread := TMMLPSThread.Create(True);
|
2009-09-12 14:50:10 -04:00
|
|
|
// MMLPSThread.Client.MWindow.SetTarget();
|
2009-09-12 02:24:59 -04:00
|
|
|
MMLPSThread.SetPSScript(SynEdit1.Lines.Text);
|
|
|
|
MMLPSThread.SetDebug(SynMemo1);
|
2009-09-12 15:00:58 -04:00
|
|
|
//MMLPSThread.Client.MWindow.SetTarget(65052451);
|
2009-09-12 02:24:59 -04:00
|
|
|
MMLPSThread.Resume;
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2009-09-12 14:50:10 -04:00
|
|
|
procedure TForm1.FormCreate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2009-09-12 02:24:59 -04:00
|
|
|
procedure TForm1.SynMemo1Change(Sender: TObject);
|
|
|
|
begin
|
|
|
|
|
2009-09-04 00:26:56 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
initialization
|
|
|
|
{$I testunit.lrs}
|
|
|
|
|
|
|
|
end.
|
|
|
|
|