diff --git a/Source/script/imports/simba.import_async.pas b/Source/script/imports/simba.import_async.pas index 3f4dafb45..a498ab9ed 100644 --- a/Source/script/imports/simba.import_async.pas +++ b/Source/script/imports/simba.import_async.pas @@ -19,7 +19,7 @@ implementation (* ASync ===== -Things that run in the background. +Simple functions that run in the background. ``` procedure ThisIsCalledWhenFinished(constref Result: TASyncHTTPResult); @@ -41,6 +41,7 @@ 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 @@ -48,13 +49,6 @@ procedure _LapeASyncHTTP_Get1(const Params: PParamArray); LAPE_WRAPPER_CALLING_C 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]^)); @@ -65,6 +59,8 @@ 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 @@ -72,13 +68,6 @@ procedure _LapeASyncHTTP_GetFile1(const Params: PParamArray); LAPE_WRAPPER_CALLI 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]^)); @@ -90,6 +79,7 @@ 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 @@ -97,13 +87,6 @@ procedure _LapeASyncHTTP_Post1(const Params: PParamArray); LAPE_WRAPPER_CALLING_ 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]^)); @@ -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 @@ -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 @@ -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 @@ -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); @@ -266,4 +287,4 @@ procedure ImportASync(Compiler: TSimbaScript_Compiler); end; end; -end. \ No newline at end of file +end. diff --git a/Source/script/imports/simba.import_internal.pas b/Source/script/imports/simba.import_internal.pas index c29b1ff96..3e0385454 100644 --- a/Source/script/imports/simba.import_internal.pas +++ b/Source/script/imports/simba.import_internal.pas @@ -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 @@ -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; @@ -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; diff --git a/Source/script/imports/simba.import_threading.pas b/Source/script/imports/simba.import_threading.pas index 0162f0e32..df32af205 100644 --- a/Source/script/imports/simba.import_threading.pas +++ b/Source/script/imports/simba.import_threading.pas @@ -81,6 +81,7 @@ 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 @@ -88,13 +89,6 @@ procedure _LapeThread_Name_Read(const Params: PParamArray; const Result: Pointer 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])^; @@ -178,6 +172,7 @@ 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 @@ -185,13 +180,6 @@ procedure _LapeThread_WaitForTerminate1(const Params: PParamArray); LAPE_WRAPPER 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])^); @@ -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 @@ -325,7 +318,7 @@ procedure ImportThreading(Compiler: TSimbaScript_Compiler); begin with Compiler do begin - ImportingSection := '!Threading'; + ImportingSection := 'Threading'; addGlobalVar( 'record' + LineEnding + @@ -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); @@ -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); @@ -404,7 +395,7 @@ procedure ImportThreading(Compiler: TSimbaScript_Compiler); addGlobalFunc( 'procedure _ScheduleStop(Name: String);', [ - 'var I: Int32;', + 'var I: Integer;', 'begin', ' _ScheduleLock.Enter();', ' try', diff --git a/Source/script/simba.script.pas b/Source/script/simba.script.pas index 5ccae2e06..caf2445f1 100644 --- a/Source/script/simba.script.pas +++ b/Source/script/simba.script.pas @@ -18,7 +18,6 @@ interface simba.script_plugin; type - PSimbaScript = ^TSimbaScript; TSimbaScript = class(TObject) protected FUserTerminated: Boolean; diff --git a/Source/simba.component_button.pas b/Source/simba.component_button.pas index db26931de..0b519cbe6 100644 --- a/Source/simba.component_button.pas +++ b/Source/simba.component_button.pas @@ -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} @@ -54,7 +55,7 @@ TSimbaButton = class(TCustomControl) FImageSpacing: Integer; function HasImage: Boolean; - function ImageSize: TPoint; + function ImageSize: TSize; function CalculateSize: TPoint; procedure MouseEnter; override; @@ -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; @@ -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; @@ -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 @@ -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; diff --git a/Source/simba.inc b/Source/simba.inc index 32c6d11b5..1b7b38d18 100644 --- a/Source/simba.inc +++ b/Source/simba.inc @@ -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} @@ -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'}