Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Oct 27, 2024
1 parent dad4856 commit 1cb81a4
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 78 deletions.
71 changes: 46 additions & 25 deletions Source/script/imports/simba.import_async.pas
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ implementation
(*
ASync
=====
Things that run in the background.
Simple functions that run in the background.
```
procedure ThisIsCalledWhenFinished(constref Result: TASyncHTTPResult);
Expand All @@ -41,20 +41,14 @@ procedure ThisIsCalledWhenFinished(constref Result: TASyncHTTPResult);
-------------
```
procedure ASync.HTTPGet(URL: String; OnFinish: TASyncHTTPFinishEvent; OnProgress: TASyncHTTPProgressEvent = nil); static;
procedure ASync.HTTPGet(URL: String; RequestHeaders: TStringArray; OnFinish: TASyncHTTPFinishEvent; OnProgress: TASyncHTTPProgressEvent = nil); static;
```
*)
procedure _LapeASyncHTTP_Get1(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
ASyncHTTP.Get(PString(Params^[0])^, [], TASyncHTTPFinishEvent(Params^[1]^), TASyncHTTPProgressEvent(Params^[3]^));
end;

(*
ASync.HTTPGet
-------------
```
procedure ASync.HTTPGet(URL: String; RequestHeaders: TStringArray; OnFinish: TASyncHTTPFinishEvent; OnProgress: TASyncHTTPProgressEvent = nil); static;
```
*)
procedure _LapeASyncHTTP_Get2(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
ASyncHTTP.Get(PString(Params^[0])^, PStringArray(Params^[1])^, TASyncHTTPFinishEvent(Params^[2]^), TASyncHTTPProgressEvent(Params^[3]^));
Expand All @@ -65,20 +59,15 @@ procedure _LapeASyncHTTP_Get2(const Params: PParamArray); LAPE_WRAPPER_CALLING_C
-----------------
```
procedure ASync.HTTPGetFile(URL: String; DestFile: String; OnFinish: TASyncHTTPFinishEvent; OnProgress: TASyncHTTPProgressEvent = nil); static;
procedure ASync.HTTPGetFile(URL: String; RequestHeaders: TStringArray; DestFile: String; OnFinish: TASyncHTTPFinishEvent; OnProgress: TASyncHTTPProgressEvent = nil); static;
```
*)
procedure _LapeASyncHTTP_GetFile1(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
ASyncHTTP.GetFile(PString(Params^[0])^, [], PString(Params^[1])^, TASyncHTTPFinishEvent(Params^[2]^), TASyncHTTPProgressEvent(Params^[3]^));
end;

(*
ASync.HTTPGetFile
-----------------
```
procedure ASync.HTTPGetFile(URL: String; RequestHeaders: TStringArray; DestFile: String; OnFinish: TASyncHTTPFinishEvent; OnProgress: TASyncHTTPProgressEvent = nil); static;
```
*)
procedure _LapeASyncHTTP_GetFile2(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
ASyncHTTP.GetFile(PString(Params^[0])^, PStringArray(Params^[1])^, PString(Params^[2])^,TASyncHTTPFinishEvent(Params^[3]^), TASyncHTTPProgressEvent(Params^[4]^));
Expand All @@ -90,20 +79,14 @@ procedure _LapeASyncHTTP_GetFile2(const Params: PParamArray); LAPE_WRAPPER_CALLI
--------------
```
procedure ASync.HTTPPost(URL, Data: String; OnFinish: TASyncHTTPFinishEvent); static;
procedure ASync.HTTPPost(URL: String; RequestHeaders: TStringArray; Data: String; RequestHeaders: TStringArray; OnFinish: TASyncHTTPFinishEvent); static;
```
*)
procedure _LapeASyncHTTP_Post1(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
ASyncHTTP.Post(PString(Params^[0])^, [], PString(Params^[1])^, TASyncHTTPFinishEvent(Params^[2]^));
end;

(*
ASync.HTTPPost
--------------
```
procedure ASync.HTTPPost(URL: String; RequestHeaders: TStringArray; Data: String; RequestHeaders: TStringArray; OnFinish: TASyncHTTPFinishEvent); static;
```
*)
procedure _LapeASyncHTTP_Post2(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
ASyncHTTP.Post(PString(Params^[0])^, PStringArray(Params^[1])^, PString(Params^[2])^, TASyncHTTPFinishEvent(Params^[3]^));
Expand All @@ -114,7 +97,9 @@ procedure _LapeASyncHTTP_Post2(const Params: PParamArray); LAPE_WRAPPER_CALLING_
---------------
```
procedure ASync.MouseMove(Target: TTarget; Dest: TPoint; Accuracy: Double = 1);
procedure ASync.MouseMove(Dest: TPoint; Accuracy: Double = 1);
```
Moves the mouse on another thread, so the script can do other things such as updating the destination.
*)
procedure _LapeASyncMouse_Move(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
Expand All @@ -137,7 +122,7 @@ procedure _LapeASyncMouse_MouseChangeDest(const Params: PParamArray); LAPE_WRAPP
ASync.MouseMoving
-----------------
```
function ASync.MouseMoving: Boolean;
property ASync.MouseMoving: Boolean;
```
*)
procedure _LapeASyncMouse_IsMoving(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
Expand Down Expand Up @@ -181,6 +166,42 @@ procedure _LapeASyncUnZip_Unzip(const Params: PParamArray); LAPE_WRAPPER_CALLING
ASyncUnzip.Unzip(PString(Params^[0])^, PString(Params^[1])^, TASyncUnzipFinishEvent(Params^[2]^), TASyncUnzipProgressEvent(Params^[3]^));
end;

(*
ASync.Schedules
---------------
```
function ASync.Schedules: TStringArray; static;
```
Returns all running schedules.
*)

(*
ASync.ScheduleEvery
-------------------
```
function ASync.ScheduleEvery(Name: String; Method: procedure of object; Interval: Integer); static;
```
Schedule a method to be called every `interval` (in milliseconds).
*)

(*
ASync.ScheduleEvery
-------------------
```
function ASync.ScheduleEvery(Name: String; Method: procedure(Params: TPointerArray) of object; Params: TPointerArray; Interval: Integer); static;
```
ScheduleEvery with passing parameters to the method (as TPointerArray).
*)

(*
ASync.ScheduleStop
------------------
```
procedure ASync.ScheduleStop(Name: String); static;
```
Stop a scheduled method.
*)

procedure ImportASync(Compiler: TSimbaScript_Compiler);
begin
with Compiler do
Expand All @@ -197,7 +218,7 @@ procedure ImportASync(Compiler: TSimbaScript_Compiler);
'end;'
]);
addGlobalFunc('procedure ASync.MouseChangeDest(Dest: TPoint); static;', @_LapeASyncMouse_MouseChangeDest);
addGlobalFunc('function ASync.MouseMoving: Boolean; static;', @_LapeASyncMouse_IsMoving);
addGlobalFunc('property ASync.MouseMoving: Boolean; static;', @_LapeASyncMouse_IsMoving);
addGlobalFunc('procedure ASync.MouseWaitMoving; static;', @_LapeASyncMouse_WaitMoving);
addGlobalFunc('procedure ASync.MouseStop; static;', @_LapeASyncMouse_Stop);

Expand Down Expand Up @@ -266,4 +287,4 @@ procedure ImportASync(Compiler: TSimbaScript_Compiler);
end;
end;

end.
end.
6 changes: 3 additions & 3 deletions Source/script/imports/simba.import_internal.pas
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ implementation
simba.vartype_pointarray, simba.vartype_ordarray, simba.vartype_stringarray;

type
PProcessID = ^TProcessID;
PSimbaScript = ^TSimbaScript;

procedure _LapeWrite(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
Expand Down Expand Up @@ -348,7 +348,7 @@ procedure _LapeGetSimbaPID(const Params: PParamArray; const Result: Pointer); LA
begin
if (SimbaCommunication = nil) then
SimbaException('GetSimbaPID requires Simba communication');
PProcessID(Result)^ := SimbaCommunication.GetSimbaPID();
TProcessID(Result^) := SimbaCommunication.GetSimbaPID();
end;
end;

Expand All @@ -358,7 +358,7 @@ procedure _LapeGetSimbaTargetPID(const Params: PParamArray; const Result: Pointe
begin
if (SimbaCommunication = nil) then
SimbaException('GetSimbaTargetPID requires Simba communication');
PProcessID(Result)^ := SimbaCommunication.GetSimbaTargetPID();
TProcessID(Result^) := SimbaCommunication.GetSimbaTargetPID();
end;
end;

Expand Down
29 changes: 10 additions & 19 deletions Source/script/imports/simba.import_threading.pas
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,14 @@ procedure _LapeCreateThreadScheduleEx(const Params: PParamArray; const Result: P
------------
```
property TThread.Name: String;
property TThread.Name(Value: String);
```
*)
procedure _LapeThread_Name_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PString(Result)^ := PSimbaThread(Params^[0])^.Name;
end;

(*
TThread.Name
------------
```
property TThread.Name(Value: String);
```
*)
procedure _LapeThread_Name_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
PSimbaThread(Params^[0])^.Name := PString(Params^[1])^;
Expand Down Expand Up @@ -178,20 +172,14 @@ procedure _LapeThread_Terminate(const Params: PParamArray); LAPE_WRAPPER_CALLING
------------------------
```
procedure TThread.WaitForTerminate;
function TThread.WaitForTerminate(Timeout: Int32): Boolean;
```
*)
procedure _LapeThread_WaitForTerminate1(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
PSimbaThread(Params^[0])^.WaitFor();
end;

(*
TThread.WaitForTerminate
------------------------
```
function TThread.WaitForTerminate(Timeout: Int32): Boolean;
```
*)
procedure _LapeThread_WaitForTerminate2(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PBoolean(Result)^ := PSimbaThread(Params^[0])^.WaitForTerminate(PInteger(Params^[1])^);
Expand Down Expand Up @@ -275,6 +263,11 @@ procedure _LapeLock_Free(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
```
function CurrentThread: TThread;
```
Returns the current thread instance.
```{note}
This will return nil if called outside of a script created thread.
```
*)
procedure _LapeCurrentThread(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
Expand Down Expand Up @@ -325,7 +318,7 @@ procedure ImportThreading(Compiler: TSimbaScript_Compiler);
begin
with Compiler do
begin
ImportingSection := '!Threading';
ImportingSection := 'Threading';

addGlobalVar(
'record' + LineEnding +
Expand All @@ -337,8 +330,6 @@ procedure ImportThreading(Compiler: TSimbaScript_Compiler);
'CPUInfo'
).isConstant := True;

ImportingSection := 'Threading';

addGlobalType('strict Pointer', 'TThread');
addGlobalFunc('property TThread.Name: String', @_LapeThread_Name_Read);
addGlobalFunc('property TThread.Name(Value: String)', @_LapeThread_Name_Write);
Expand All @@ -360,7 +351,7 @@ procedure ImportThreading(Compiler: TSimbaScript_Compiler);

addGlobalFunc('function CurrentThread: TThread', @_LapeCurrentThread);

ImportingSection := '!Threading';
ImportingSection := '!Hidden';

addGlobalVar(Emitter, '_CodeEmitter').isConstant := True;
addGlobalFunc('function _CreateThread(Emitter: Pointer; Method: procedure of object; OnTerminate: procedure(Thread: TThread) of object): TThread;', @_LapeCreateThread);
Expand Down Expand Up @@ -404,7 +395,7 @@ procedure ImportThreading(Compiler: TSimbaScript_Compiler);

addGlobalFunc(
'procedure _ScheduleStop(Name: String);', [
'var I: Int32;',
'var I: Integer;',
'begin',
' _ScheduleLock.Enter();',
' try',
Expand Down
1 change: 0 additions & 1 deletion Source/script/simba.script.pas
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ interface
simba.script_plugin;

type
PSimbaScript = ^TSimbaScript;
TSimbaScript = class(TObject)
protected
FUserTerminated: Boolean;
Expand Down
33 changes: 15 additions & 18 deletions Source/simba.component_button.pas
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
interface

uses
Classes, SysUtils, Controls, StdCtrls, Buttons, Graphics, LMessages, ImgList;
Classes, SysUtils, Controls, StdCtrls, Buttons, Graphics, LMessages, ImgList,
simba.base;

type
{$push}
Expand Down Expand Up @@ -54,7 +55,7 @@ TSimbaButton = class(TCustomControl)
FImageSpacing: Integer;

function HasImage: Boolean;
function ImageSize: TPoint;
function ImageSize: TSize;
function CalculateSize: TPoint;

procedure MouseEnter; override;
Expand Down Expand Up @@ -286,18 +287,14 @@ function TSimbaButton.HasImage: Boolean;
Result := (FImage <> ESimbaButtonImage.NONE) or (FImageIndex > -1);
end;

function TSimbaButton.ImageSize: TPoint;
function TSimbaButton.ImageSize: TSize;
begin
if (FImage <> ESimbaButtonImage.NONE) then
begin
Result.X := LCLGlyphs.WidthForPPI[FImageList.Width, Font.PixelsPerInch];
Result.Y := LCLGlyphs.HeightForPPI[FImageList.Width, Font.PixelsPerInch];
end
Result := LCLGlyphs.SizeForPPI[LCLGlyphs.Width, Font.PixelsPerInch]
else if (FImageIndex > -1) then
begin
Result.X := FImageList.WidthForPPI[FImageList.Width, Font.PixelsPerInch];
Result.Y := FImageList.HeightForPPI[FImageList.Width, Font.PixelsPerInch];
end;
Result := FImageList.SizeForPPI[FImageList.Width, Font.PixelsPerInch]
else
Result := TSize.Create(0, 0);
end;

function TSimbaButton.CalculateSize: TPoint;
Expand All @@ -319,9 +316,9 @@ function TSimbaButton.CalculateSize: TPoint;
if HasImage then
begin
Result.X += FImageSpacing;
Result.X += ImageSize.X;
if ImageSize.Y > Result.Y then
Result.Y := ImageSize.Y;
Result.X += ImageSize.Width;
if ImageSize.Height > Result.Y then
Result.Y := ImageSize.Height;
end;

Result.X += XPadding * 2;
Expand Down Expand Up @@ -384,12 +381,12 @@ procedure TSimbaButton.Paint;
begin
if (Caption = '') then
begin
ImgPoint.X := R.Left + (R.Width div 2) - (ImageSize.X div 2);
ImgPoint.Y := R.Top + (R.Height div 2) - (ImageSize.Y div 2);
ImgPoint.X := R.Left + (R.Width div 2) - (ImageSize.Width div 2);
ImgPoint.Y := R.Top + (R.Height div 2) - (ImageSize.Height div 2);
end else
begin
ImgPoint.X := R.Left;
ImgPoint.Y := R.CenterPoint.Y - (ImageSize.Y div 2);
ImgPoint.Y := R.CenterPoint.Y - (ImageSize.Height div 2);
end;

if (FImage <> ESimbaButtonImage.NONE) then
Expand All @@ -408,7 +405,7 @@ procedure TSimbaButton.Paint;

R := ClientRect;
if HasImage then
R.Left += ImageSize.X + FImageSpacing;
R.Left += ImageSize.Width + FImageSpacing;

Canvas.TextRect(R, 0,0, Caption, Style);
end;
Expand Down
18 changes: 6 additions & 12 deletions Source/simba.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@

{$IFOPT D+}
{$DEFINE SIMBA_HAS_DEBUGINFO}
{$ELSE}
{$IFDEF SIMBA_MAX_OPTIMIZATION} // -O4 can do "unsafe" optimizations so this is not globally enabled.
{.$OPTIMIZATION LEVEL4}
{$ENDIF}
{$ENDIF}

{$WARN 4046 ERROR} // stop compiling on creating a class with an abstract method

// Set in project options > custom options.. "-CfSSE"
//{$IF Defined(CPU386)}
// {$FPUTYPE SSE3}
Expand All @@ -29,13 +23,13 @@
{$MODESWITCH ARRAYOPERATORS}
{$MODESWITCH NESTEDPROCVARS}

{$DEFINE SIMBA_MAJOR := 2000} // this should be 980 even if SimbaVersion is 981, etc
{$DEFINE SIMBA_VERSION := 2000}
{$DEFINE SIMBA_MAJOR := 2000} // this should be 980 even if SimbaVersion is 981, etc
{$DEFINE SIMBA_VERSION := 2000}

{$DEFINE SIMBA_GITHUB_URL := 'https://github.com/Villavu/Simba'}
{$DEFINE SIMBA_BUGS_URL := 'https://github.com/Villavu/Simba/issues'}
{$DEFINE SIMBA_DOCS_URL := 'https://villavu.github.io/Simba/'}
{$DEFINE SIMBA_PACKAGES_URL := 'https://raw.githubusercontent.com/Villavu/Simba-Package-List/main/list'}
{$DEFINE SIMBA_GITHUB_URL := 'https://github.com/Villavu/Simba'}
{$DEFINE SIMBA_BUGS_URL := 'https://github.com/Villavu/Simba/issues'}
{$DEFINE SIMBA_DOCS_URL := 'https://villavu.github.io/Simba/'}
{$DEFINE SIMBA_PACKAGES_URL := 'https://raw.githubusercontent.com/Villavu/Simba-Package-List/main/list'}

{$IFDEF DARWIN}
{$DEFINE SIMBA_ANALYTICS_URL := 'https://olly.best/simba.php'}
Expand Down

0 comments on commit 1cb81a4

Please sign in to comment.