Skip to content

Commit

Permalink
Remove the need for a running script to need to reference a SimbaScri…
Browse files Browse the repository at this point in the history
…ptThread global variable
  • Loading branch information
ollydev committed Aug 2, 2023
1 parent 625f24a commit 4433952
Show file tree
Hide file tree
Showing 18 changed files with 286 additions and 174 deletions.
4 changes: 2 additions & 2 deletions Source/Simba.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
else
SimbaProcessType := ESimbaProcessType.SCRIPT;

SimbaScriptThread := TSimbaScriptRunner.Create(
TSimbaScriptRunner.Create(
Application.Params[Application.ParamCount],
Application.GetOptionValue('simbacommunication'),
Application.GetOptionValue('target'),
Expand All @@ -110,7 +110,7 @@
Application.CreateForm(TSimbaFileBrowserForm, SimbaFileBrowserForm);
Application.CreateForm(TSimbaAboutForm, SimbaAboutForm);
Application.CreateForm(TSimbaSettingsForm, SimbaSettingsForm);
Application.CreateForm(TSimbaImageToStringForm, SimbaImageToStringForm);
Application.CreateForm(TSimbaImageToStringForm, SimbaImageToStringForm);
Application.CreateForm(TSimbaOpenExampleForm, SimbaOpenExampleForm);
Application.CreateForm(TSimbaColorPickerHistoryForm, SimbaColorPickerHistoryForm);
Application.CreateForm(TSimbaPackageForm, SimbaPackageForm);
Expand Down
8 changes: 4 additions & 4 deletions Source/forms/simba.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls, ExtCtrls,
Menus, ImgList, LMessages, AnchorDockPanel,
simba.settings, simba.mufasatypes, simba.mouselogger, simba.areaselector,
simba.scriptinstance, simba.component_menubar;
simba.scriptinstance, simba.component_menubar, simba.process;

const
IMAGE_NONE = -1;
Expand Down Expand Up @@ -218,7 +218,7 @@ TSimbaForm = class(TForm)
procedure TrayPopupExitClick(Sender: TObject);
protected
FWindowSelection: TWindowHandle;
FProcessSelection: Integer;
FProcessSelection: TProcessID;
FRecentFiles: TStringList;

FMenuBar: TSimbaMainMenuBar;
Expand Down Expand Up @@ -256,7 +256,7 @@ TSimbaForm = class(TForm)
procedure SetTrayIconVisible(Value: Boolean);
public
property WindowSelection: TWindowHandle read FWindowSelection;
property ProcessSelection: Integer read FProcessSelection;
property ProcessSelection: TProcessID read FProcessSelection;
property MenuBar: TSimbaMainMenuBar read FMenuBar;

procedure Setup(Data: PtrInt);
Expand Down Expand Up @@ -284,7 +284,7 @@ implementation

simba.windowselector, simba.colorpicker,

simba.openssl, simba.env, simba.process,
simba.openssl, simba.env,
simba.dockinghelpers, simba.nativeinterface,
simba.scriptformatter, simba.windowhandle, simba.scripttab, simba.theme,
simba.backupsform;
Expand Down
94 changes: 43 additions & 51 deletions Source/script/imports/simba/simba.import_debugimage.pas
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ procedure ImportDebugImage(Compiler: TSimbaScript_Compiler);
implementation

uses
lptypes,
simba.scriptthread, simba.bitmap;
lptypes;

(*
Debug Image
Expand Down Expand Up @@ -112,91 +111,84 @@ implementation
~~~~
> procedure Show(Bitmap: TSimbaImage; EnsureVisible: Boolean = True);
*)
procedure _LapeShowBitmap(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
if (SimbaScriptThread.Script.SimbaCommunication = nil) then
raise Exception.Create('ShowBitmap requires Simba communication');

SimbaScriptThread.Script.SimbaCommunication.DebugImage_Show(PSimbaImage(Params^[0])^, PBoolean(Params^[1])^);
end;

(*
UpdateDebugImage
~~~~~~~~~~~~~~~~
> procedure UpdateDebugImage(Bitmap: TSimbaImage);
*)
procedure _LapeUpdateDebugImage(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
if (SimbaScriptThread.Script.SimbaCommunication = nil) then
raise Exception.Create('DrawBitmapDebugImg requires Simba communication');

SimbaScriptThread.Script.SimbaCommunication.DebugImage_Update(PSimbaImage(Params^[0])^);
end;

(*
ShowDebugImage
~~~~~~~~~~~~~~
> procedure ShowDebugImage(Width, Height: Integer);
*)
procedure _LapeShowDebugImage1(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
if (SimbaScriptThread.Script.SimbaCommunication = nil) then
raise Exception.Create('ShowDebugImage requires Simba communication');

SimbaScriptThread.Script.SimbaCommunication.DebugImage_Display(PInteger(Params^[0])^, PInteger(Params^[1])^);
end;

(*
ShowDebugImage
~~~~~~~~~~~~~~
> procedure ShowDebugImage(X, Y,Width, Height: Integer);
*)
procedure _LapeShowDebugImage2(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
if (SimbaScriptThread.Script.SimbaCommunication = nil) then
raise Exception.Create('ShowDebugImage requires Simba communication');

SimbaScriptThread.Script.SimbaCommunication.DebugImage_Display(PInteger(Params^[0])^, PInteger(Params^[1])^, PInteger(Params^[2])^, PInteger(Params^[3])^);
end;

(*
SetDebugImageMaxSize
~~~~~~~~~~~~~~~~~~~~
> procedure SetDebugImageMaxSize(MaxWidth, MaxHeight: Integer);
*)
procedure _LapeSetDebugImageMaxSize(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
if (SimbaScriptThread.Script.SimbaCommunication = nil) then
raise Exception.Create('SetDebugImgMaxSize requires Simba communication');

SimbaScriptThread.Script.SimbaCommunication.DebugImage_SetMaxSize(PInteger(Params^[0])^, PInteger(Params^[1])^);
end;

(*
HideDebugImage
~~~~~~~~~~~~~~
> procedure HideDebugImage;
*)
procedure _LapeHideDebugImage(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
if (SimbaScriptThread.Script.SimbaCommunication = nil) then
raise Exception.Create('HideDebugImage requires Simba communication');

SimbaScriptThread.Script.SimbaCommunication.DebugImage_Hide();
end;

procedure ImportDebugImage(Compiler: TSimbaScript_Compiler);
begin
with Compiler do
begin
ImportingSection := 'Debug Image';

addGlobalFunc('procedure SetDebugImageMaxSize(MaxWidth, MaxHeight: Integer)', @_LapeSetDebugImageMaxSize);
addGlobalFunc('procedure ShowDebugImage(Width, Height: Integer); overload;', @_LapeShowDebugImage1);
addGlobalFunc('procedure ShowDebugImage(X, Y, Width, Height: Integer); overload;', @_LapeShowDebugImage2);
addGlobalFunc('procedure HideDebugImage;', @_LapeHideDebugImage);
addGlobalFunc('procedure UpdateDebugImage(Bitmap: TImage);', @_LapeUpdateDebugImage);
addGlobalFunc('procedure Show(Bitmap: TImage; EnsureVisible: Boolean = True);', @_LapeShowBitmap);
addGlobalFunc(
'procedure SetDebugImageMaxSize(MaxWidth, MaxHeight: Integer);', [
'begin',
' _SimbaScript.DebugImage_SetMaxSize(MaxWidth, MaxHeight);',
'end;'
]);

addGlobalFunc(
'procedure ShowDebugImage(Width, Height: Integer); overload;', [
'begin',
' _SimbaScript.DebugImage_Display(Width, Height);',
'end;'
]);

addGlobalFunc(
'procedure ShowDebugImage(X, Y, Width, Height: Integer); overload;', [
'begin',
' _SimbaScript.DebugImage_Display(X, Y, Width, Height);',
'end;'
]);

addGlobalFunc(
'procedure HideDebugImage;', [
'begin',
' _SimbaScript.DebugImage_Hide();',
'end;'
]);

addGlobalFunc(
'procedure UpdateDebugImage(Image: TImage);', [
'begin',
' _SimbaScript.DebugImage_Update(Image);',
'end;'
]);

addGlobalFunc(
'procedure Show(Image: TImage; EnsureVisible: Boolean = True);', [
'begin',
' _SimbaScript.DebugImage_Show(Image, EnsureVisible);',
'end;'
]);

ImportingSection := 'TImage';

Expand Down Expand Up @@ -381,4 +373,4 @@ procedure ImportDebugImage(Compiler: TSimbaScript_Compiler);
end;
end;

end.
end.
19 changes: 8 additions & 11 deletions Source/script/imports/simba/simba.import_dialogs.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ implementation

uses
dialogs, controls, lptypes,
simba.scriptthread, simba.aca, simba.dtmeditor,
simba.dialog, simba.threading, simba.target, simba.finder;
simba.aca, simba.dtmeditor, simba.dialog, simba.threading, simba.target, simba.finder;

procedure _LapeInputCombo(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV

Expand Down Expand Up @@ -122,14 +121,6 @@ procedure _LapeShowQuestionDialog(const Params: PParamArray; const Result: Point
ExecuteOnMainThread(@Execute);
end;

procedure _LapeShowTrayNotification(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
if (SimbaScriptThread.Script.SimbaCommunication = nil) then
raise Exception.Create('ShowTrayNotification requires Simba communication');

SimbaScriptThread.Script.SimbaCommunication.ShowTrayNotification(PString(Params^[0])^, PString(Params^[1])^, PInteger(Params^[2])^);
end;

procedure ImportDialogs(Compiler: TSimbaScript_Compiler);
begin
with Compiler do
Expand All @@ -142,11 +133,17 @@ procedure ImportDialogs(Compiler: TSimbaScript_Compiler);
addGlobalFunc('function ShowQueryDialog(Caption, Prompt: String; var Value: String): Boolean', @_LapeInputQuery);
addGlobalFunc('function ShowComboDialog(Caption, Prompt: string; List: TStringArray): Integer', @_LapeInputCombo);
addGlobalFunc('procedure ShowMessage(Message: String)', @_LapeShowMessage);
addGlobalFunc('procedure ShowTrayNotification(Title, Message: String; Timeout: Integer = 3000)', @_LapeShowTrayNotification);
addGlobalFunc('function ShowQuestionDialog(Title, Question: String): ESimbaDialogResult', @_LapeShowQuestionDialog);
addGlobalFunc('function ShowDTMEditor(Target: TSimbaTarget; Title: String): String', @_LapeShowDTMEditor);
addGlobalFunc('function ShowACA(Target: TSimbaTarget; Title: String): TColorTolerance', @_LapeShowACA);

addGlobalFunc(
'procedure ShowTrayNotification(Title, Message: String; Timeout: Integer = 3000);', [
'begin',
' _SimbaScript.ShowTrayNotification(Title, Message, Timeout);',
'end;'
]);

ImportingSection := '';
end;
end;
Expand Down
Loading

0 comments on commit 4433952

Please sign in to comment.