From 63688345a8b2f0559d02e8f2d99ae8e07ed64f8d Mon Sep 17 00:00:00 2001 From: Olly Date: Sun, 17 Sep 2023 20:46:53 +0100 Subject: [PATCH] docs + version bump --- DocGen/source/plugins/plugin-cpp.rst | 43 +++++++++------ DocGen/source/plugins/writing-plugins.rst | 18 +++++- .../tutorials/Input & Finder Target.rst | 52 ++++++++++++++++++ DocGen/source/tutorials/index.rst | 3 +- Source/Simba.lpi | 5 +- Source/Simba.res | Bin 30592 -> 30592 bytes .../macosbundle/Simba.app/Contents/Info.plist | 4 +- .../simba/simba.import_matchtemplate.pas | 4 +- Source/script/simba.scriptthread.pas | 18 ------ Source/simba.ide_initialization.pas | 15 ++--- Source/simba.inc | 4 +- 11 files changed, 111 insertions(+), 55 deletions(-) create mode 100644 DocGen/source/tutorials/Input & Finder Target.rst diff --git a/DocGen/source/plugins/plugin-cpp.rst b/DocGen/source/plugins/plugin-cpp.rst index 00c87047a..312c2e77c 100644 --- a/DocGen/source/plugins/plugin-cpp.rst +++ b/DocGen/source/plugins/plugin-cpp.rst @@ -38,28 +38,37 @@ main.h struct __attribute__((__packed__)) TSimbaMethods { - void (*RunOnMainThread)(void(*Method)(void*), void* data); + void (*RunOnMainThread)(void(*Method)(void*), void* data); - void* (*GetMem)(NativeUInt size); - void (*FreeMem)(void* ptr); - void* (*AllocMem)(NativeUInt Size); - void* (*ReAllocMem)(void** ptr, NativeUInt size); - NativeUInt (*MemSize)(void* ptr); + void* (*GetMem)(NativeUInt size); + void (*FreeMem)(void* ptr); + void* (*AllocMem)(NativeUInt Size); + void* (*ReAllocMem)(void** ptr, NativeUInt size); + NativeUInt (*MemSize)(void* ptr); - void (*RaiseException)(char* Message); - void* (*GetTypeInfo)(void* Compiler, char* Typ); - NativeUInt (*GetTypeInfoSize)(void* TypeInfo); - NativeInt (*GetTypeInfoFieldOffset)(void* TypeInfo, char* FieldName); + void (*RaiseException)(char* Message); + void* (*GetTypeInfo)(void* Compiler, char* Typ); + NativeUInt (*GetTypeInfoSize)(void* TypeInfo); + NativeInt (*GetTypeInfoFieldOffset)(void* TypeInfo, char* FieldName); - void* (*AllocateRawArray)(NativeInt ElementSize, NativeUInt Len); - void (*ReAllocateRawArray)(void** ptr, NativeInt ElementSize, NativeUInt Len); + void* (*AllocateRawArray)(NativeInt ElementSize, NativeUInt Len); + void (*ReAllocateRawArray)(void** ptr, NativeInt ElementSize, NativeUInt Len); - void* (*AllocateArray)(void* TypeInfo, NativeUInt Len); - void* (*AllocateString)(void* Data); - void* (*AllocateUnicodeString)(void* Data); + void* (*AllocateArray)(void* TypeInfo, NativeUInt Len); + void* (*AllocateString)(void* Data); + void* (*AllocateUnicodeString)(void* Data); - void (*SetArrayLength)(void* TypeInfo, void**ptr, NativeInt NewLen); - NativeInt (*GetArrayLength)(void* AVar); + void (*SetArrayLength)(void* TypeInfo, void**ptr, NativeInt NewLen); + NativeInt (*GetArrayLength)(void* AVar); + + void* (*ExternalImage_Create)(bool FreeOnTerminate); + void (*ExternalImage_SetMemory)(void* img, void* data, int width, int height); + bool (*ExternalImage_TryLock)(void* img); + void (*ExternalImage_Lock)(void* img); + void (*ExternalImage_UnLock)(void* img); + + void (*ExternalImage_AddCallbackOnUnlock)(void* img, void(*callback)(void*)); + void (*ExternalImage_RemoveCallbackOnUnlock)(void* img, void(*callback)(void*)); }; TSimbaInfo* SIMBA_INFO = {0}; diff --git a/DocGen/source/plugins/writing-plugins.rst b/DocGen/source/plugins/writing-plugins.rst index 57d584749..17ff9da0b 100644 --- a/DocGen/source/plugins/writing-plugins.rst +++ b/DocGen/source/plugins/writing-plugins.rst @@ -100,10 +100,24 @@ These pointers are provided to these structures: AllocateArray: function(TypeInfo: Pointer; Len: NativeInt): Pointer; cdecl; AllocateString: function(Data: PChar): Pointer; cdecl; - AllocateUnicodeString: function(Data: PUnicodeChar): Pointer; cdecl; + AllocateUnicodeString: function(Data: PUnicodeChar): Pointer; cdecl; SetArrayLength: procedure(TypeInfo: Pointer; var AVar: Pointer; NewLen: NativeInt); cdecl; GetArrayLength: function(AVar: Pointer): NativeInt; cdecl; + + ExternalImage_Create: function(FreeOnTerminate: Boolean): Pointer; cdecl; + ExternalImage_SetMemory: procedure(Img: Pointer; Data: PColorBGRA; AWidth, AHeight: Integer); cdecl; + ExternalImage_TryLock: function(Img: Pointer): Boolean; cdecl; + ExternalImage_Lock: procedure(Img: Pointer); cdecl; + ExternalImage_UnLock: procedure(Img: Pointer); cdecl; + + ExternalImage_AddCallbackOnUnlock: procedure(Img: Pointer; Callback: TSimbaExternalImageCallback); cdecl; + ExternalImage_RemoveCallbackOnUnlock: procedure(Img: Pointer; Callback: TSimbaExternalImageCallback); cdecl; end; -See the `Example C++ plugin `_ to see how TypeInfo is used to allocate custom records & arrays. \ No newline at end of file +See the `Example C++ plugin `_ to see how TypeInfo is used to allocate custom records & arrays. + +.. note:: + + `RunOnMainThread` is available for creating forms, installing windows hooks and other things that must be done on the main thread. + Simba scripts are not ran on the processes main thread for this reason. diff --git a/DocGen/source/tutorials/Input & Finder Target.rst b/DocGen/source/tutorials/Input & Finder Target.rst new file mode 100644 index 000000000..b2b62bb55 --- /dev/null +++ b/DocGen/source/tutorials/Input & Finder Target.rst @@ -0,0 +1,52 @@ +##################### +Input & Finder Target +##################### + +Both :code:`Input` and :code:`Finder` records have a :code:`Target` field. +If this is not set (is default value) the global :code:`Target` variable is used. + +----- + +These examples will use the global :code:`Target` variable. This by default is set to Simba's target window when the script was started, or the desktop if no window has been selected. + +.. code-block:: + + Input.MouseTeleport([100,100]); + +Of course you can also change the global :code:`Target` variable and the Input/Finder variables will keep updated. + +.. code-block:: + + Target.SetWindow(some_window_handle); + Input.MouseTeleport([100,100]); + +----- + +In these examples since :code:`Input.Target` has a value that target is used. + +.. code-block:: + + Input.Target.SetWindow(some_window_handle); + Input.MouseTeleport([100,100]); + +You can also declare as many Input/Finder variables as you like, all with different targets. + +.. code-block:: + + var + MyOtherInput: TInput; + begin + MyOtherInput.Target.SetWindow(123456); + MyOtherInput.MouseTeleport([100,100]); + end; + +----- + +You can clear the :code:`Input.Target` variable so the global :code:`Target` variable is once again used. + +.. code-block:: + + begin + Input.Target := []; + Input.MouseTeleport([100,100]); + end; diff --git a/DocGen/source/tutorials/index.rst b/DocGen/source/tutorials/index.rst index 5f1769fce..8395b7826 100644 --- a/DocGen/source/tutorials/index.rst +++ b/DocGen/source/tutorials/index.rst @@ -5,4 +5,5 @@ Simba :maxdepth: 2 Color Finding.rst - Sleep Until.rst \ No newline at end of file + Sleep Until.rst + Input & Finder Target.rst \ No newline at end of file diff --git a/Source/Simba.lpi b/Source/Simba.lpi index 14c28d332..2aa8feac6 100644 --- a/Source/Simba.lpi +++ b/Source/Simba.lpi @@ -32,11 +32,10 @@ - - + - + diff --git a/Source/Simba.res b/Source/Simba.res index e57c6ed63738400a564957436b2625ac01984e7c..c282a1f76c44dbd69afe01e6b9987e7a99386072 100644 GIT binary patch delta 62 zcmZp8&)D#uaYG3^HvL8 K%~v?rrV-8n diff --git a/Source/macosbundle/Simba.app/Contents/Info.plist b/Source/macosbundle/Simba.app/Contents/Info.plist index c8c78cb95..05bf859dd 100644 --- a/Source/macosbundle/Simba.app/Contents/Info.plist +++ b/Source/macosbundle/Simba.app/Contents/Info.plist @@ -19,9 +19,9 @@ CFBundleSignature ???? CFBundleShortVersionString - 1.5 + 2.0 CFBundleVersion - 1500 + 2000 CSResourcesFileMapped CFBundleDocumentTypes diff --git a/Source/script/imports/simba/simba.import_matchtemplate.pas b/Source/script/imports/simba/simba.import_matchtemplate.pas index c8453047b..85e95ff2d 100644 --- a/Source/script/imports/simba/simba.import_matchtemplate.pas +++ b/Source/script/imports/simba/simba.import_matchtemplate.pas @@ -24,7 +24,9 @@ implementation (* Match Template ============== -Template matching +Template matching. + +Note:: These functions outputs are equal to OpenCV's matchTemplate. *) (* diff --git a/Source/script/simba.scriptthread.pas b/Source/script/simba.scriptthread.pas index 898479e19..33ac52fc8 100644 --- a/Source/script/simba.scriptthread.pas +++ b/Source/script/simba.scriptthread.pas @@ -7,11 +7,6 @@ {$i simba.inc} -{$IFDEF DARWIN} - {$DEFINE COCOA_TERMINATE_FIX} // https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39496 - {$MODESWITCH OBJECTIVEC1} -{$ENDIF} - interface uses @@ -42,13 +37,9 @@ TSimbaScriptRunner = class(TThread) ); reintroduce; end; - implementation uses - {$IFDEF COCOA_TERMINATE_FIX} - cocoaall, cocoaint, cocoautils, - {$ENDIF} Forms, FileUtil, simba.env, simba.files, simba.datetime, simba.script_communication; @@ -75,15 +66,6 @@ procedure TSimbaScriptRunner.DoTerm(Sender: TObject); Application.Terminate(); while (not Application.Terminated) do Application.ProcessMessages(); - - {$IFDEF COCOA_TERMINATE_FIX} - NSApplication.sharedApplication.postEvent_AtStart( - nsEvent.otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2( - NSApplicationDefined, GetNSPoint(0, 0), 0, NSTimeIntervalSince1970, 0, nil, 0, 0, 0 - ), - True - ); - {$ENDIF} end; procedure TSimbaScriptRunner.DoInputThread; diff --git a/Source/simba.ide_initialization.pas b/Source/simba.ide_initialization.pas index 37a2f155d..5966e0ed7 100644 --- a/Source/simba.ide_initialization.pas +++ b/Source/simba.ide_initialization.pas @@ -98,17 +98,16 @@ procedure SimbaIDEInitialization_CallBeforeCreate; begin for Method in BeforeCreateMethods do begin - Debug('[SimbaIDEInitialization.BeforeCreate]: %s ', [Method.Name]); try T := HighResolutionTime(); if Assigned(Method.Proc) then Method.Proc() else if Assigned(Method.ProcObj) then Method.ProcObj(); - DebugLn('(%f ms)', [HighResolutionTime() - T]); + DebugLn('[SimbaIDEInitialization.BeforeCreate]: %s (%f ms)', [Method.Name, HighResolutionTime() - T]); except on E: Exception do - DebugLn('Exception: (%s)', [E.Message]); + DebugLn('[SimbaIDEInitialization.BeforeCreate]: %s (exception: %s)', [Method.Name, E.Message]); end; end; end; @@ -123,17 +122,16 @@ procedure SimbaIDEInitialization_CallBeforeShow_Background; if not Method.BackgroundTask then Continue; - Debug('[SimbaIDEInitialization.BeforeShow (Background task)]: %s ', [Method.Name]); try T := HighResolutionTime(); if Assigned(Method.Proc) then Method.Proc() else if Assigned(Method.ProcObj) then Method.ProcObj(); - DebugLn('(%f ms)', [HighResolutionTime() - T]); + DebugLn('[SimbaIDEInitialization.BeforeShow_Background]: %s (%f ms)', [Method.Name, HighResolutionTime() - T]); except on E: Exception do - DebugLn('Exception: (%s)', [E.Message]); + DebugLn('[SimbaIDEInitialization.BeforeShow_Background]: %s (exception: %s)', [Method.Name, E.Message]); end; end; end; @@ -148,17 +146,16 @@ procedure SimbaIDEInitialization_CallBeforeShow; if Method.BackgroundTask then Continue; - Debug('[SimbaIDEInitialization.BeforeShow]: %s ', [Method.Name]); try T := HighResolutionTime(); if Assigned(Method.Proc) then Method.Proc() else if Assigned(Method.ProcObj) then Method.ProcObj(); - DebugLn('(%f ms)', [HighResolutionTime() - T]); + DebugLn('[SimbaIDEInitialization.BeforeShow]: %s (%f ms)', [Method.Name, HighResolutionTime() - T]); except on E: Exception do - DebugLn('Exception: (%s)', [E.Message]); + DebugLn('[SimbaIDEInitialization.BeforeShow]: %s (exception: %s)', [Method.Name, E.Message]); end; end; diff --git a/Source/simba.inc b/Source/simba.inc index 017bba644..96b49107b 100644 --- a/Source/simba.inc +++ b/Source/simba.inc @@ -25,8 +25,8 @@ {$MODESWITCH ARRAYOPERATORS} {$MODESWITCH NESTEDPROCVARS} -{$DEFINE SIMBA_MAJOR := 1500} // this should be 980 even if SimbaVersion is 981, etc -{$DEFINE SIMBA_VERSION := 1500} +{$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'}