Skip to content

Commit

Permalink
Update scripts runtime on MainStatusBar
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Jul 6, 2023
1 parent 88d2b9f commit 7e1189e
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 91 deletions.
4 changes: 2 additions & 2 deletions Source/forms/simba.main.lfm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object SimbaForm: TSimbaForm
Left = 4022
Left = 4202
Height = 578
Top = 670
Top = 175
Width = 910
Caption = 'Simba'
ClientHeight = 578
Expand Down
8 changes: 8 additions & 0 deletions Source/forms/simba.outputform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ TSimbaOutputBox = class(TSimbaSynEdit)
procedure GetWordBoundsAtRowCol(const XY: TPoint; out StartX, EndX: integer); override;

function Add(const S: String): String;
procedure AddLine(Flags: EDebugLnFlags; const S: String);
procedure Empty;
procedure Flush;

Expand Down Expand Up @@ -396,6 +397,13 @@ function TSimbaOutputBox.Add(const S: String): String;
end;
end;

procedure TSimbaOutputBox.AddLine(Flags: EDebugLnFlags; const S: String);
begin
FLock.Enter();
FBuffer.AddObject(S, TObject(PtrUInt(Integer(Flags))));
FLock.Leave();
end;

procedure TSimbaOutputBox.Empty;
begin
Add(FlagsToString([EDebugLn.CLEAR]) + LineEnding);
Expand Down
16 changes: 0 additions & 16 deletions Source/forms/simba.scripttabsform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ TSimbaScriptTabsForm = class(TForm)
procedure FindNext;
procedure FindPrevious;

function FindTab(ScriptInstance: TObject): TSimbaScriptTab;

function AddTab: TSimbaScriptTab;

function CloseTab(Tab: TSimbaScriptTab; KeepOne: Boolean): Boolean;
Expand Down Expand Up @@ -466,20 +464,6 @@ procedure TSimbaScriptTabsForm.FindPrevious;
FEditorFind.FindPrev(CurrentEditor);
end;

function TSimbaScriptTabsForm.FindTab(ScriptInstance: TObject): TSimbaScriptTab;
var
I: Integer;
begin
for I := 0 to TabCount - 1 do
if (Tabs[I].ScriptInstance = ScriptInstance) then
begin
Result := Tabs[I];
Exit;
end;

Result := nil;
end;

function TSimbaScriptTabsForm.AddTab: TSimbaScriptTab;
begin
Result := FTabControl.AddTab() as TSimbaScriptTab;
Expand Down
26 changes: 25 additions & 1 deletion Source/simba.ide_events.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SimbaIDEEvents = class
CODETOOLS_SETUP,
TAB_CARETMOVED, TAB_MODIFIED, TAB_LOADED, TAB_SEARCH, TAB_BEFORECHANGE, TAB_CHANGE, TAB_CLOSED,
MOUSELOGGER_CHANGE,
SCRIPTSTATE_CHANGE
SCRIPTSTATE_CHANGE, SCRIPT_RUNNING
);
class var
FMethodLists: array[EMethodType] of TMethodList;
Expand All @@ -32,6 +32,7 @@ SimbaIDEEvents = class
class procedure RegisterOnTabClosed(Proc: TNotifyEvent);
class procedure CallOnScriptTabClose(Sender: TObject);


class procedure CallOnScriptStateChange(Sender: TObject); // Sender = TSimbaScriptInstance
class procedure CallOnBeforeTabChange(Sender: TObject);
class procedure CallOnScriptTabChange(Sender: TObject); // Sender = TSimbaScriptTab
Expand All @@ -41,6 +42,14 @@ SimbaIDEEvents = class
class procedure CallOnEditorModified(Sender: TObject);
class procedure CallOnMouseLoggerChange(Sender: TObject);


// Called every 500ms from a script instance while a script is running.
// Sender = TSimbaScriptInstance
class procedure CallOnScriptRunning(Sender: TObject);
class procedure RegisterMethodOnScriptRunning(Proc: TNotifyEvent);
class procedure UnRegisterMethodOnScriptRunning(Proc: TNotifyEvent);


class procedure RegisterMethodOnScriptStateChange(Proc: TNotifyEvent);
class procedure RegisterMethodOnScriptTabChange(Proc: TNotifyEvent);
class procedure RegisterOnBeforeTabChange(Proc: TNotifyEvent);
Expand Down Expand Up @@ -106,6 +115,11 @@ class procedure SimbaIDEEvents.CallOnScriptTabClose(Sender: TObject);
Call(TAB_CLOSED, Sender);
end;

class procedure SimbaIDEEvents.CallOnScriptRunning(Sender: TObject);
begin
Call(SCRIPT_RUNNING, Sender);
end;

class procedure SimbaIDEEvents.CallOnScriptStateChange(Sender: TObject);
begin
Call(SCRIPTSTATE_CHANGE, Sender);
Expand Down Expand Up @@ -146,6 +160,16 @@ class procedure SimbaIDEEvents.CallOnMouseLoggerChange(Sender: TObject);
Call(MOUSELOGGER_CHANGE, Sender);
end;

class procedure SimbaIDEEvents.RegisterMethodOnScriptRunning(Proc: TNotifyEvent);
begin
RegisterMethod(SCRIPT_RUNNING, Proc);
end;

class procedure SimbaIDEEvents.UnRegisterMethodOnScriptRunning(Proc: TNotifyEvent);
begin
UnRegisterMethod(SCRIPT_RUNNING, Proc);
end;

class procedure SimbaIDEEvents.RegisterMethodOnScriptStateChange(Proc: TNotifyEvent);
begin
RegisterMethod(SCRIPTSTATE_CHANGE, Proc);
Expand Down
15 changes: 15 additions & 0 deletions Source/simba.ide_mainstatusbar.pas
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
Author: Raymond van Venetië and Merlijn Wajer
Project: Simba (https://github.com/MerlijnWajer/Simba)
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0)
}
unit simba.ide_mainstatusbar;

{$i simba.inc}
Expand All @@ -21,6 +26,7 @@ TSimbaMainStatusBar = class
procedure DoTabSearch(Sender: TObject);
procedure DoTabChange(Sender: TObject);
procedure DoScriptStateChange(Sender: TObject);
procedure DoScriptRunning(Sender: TObject);
public
constructor Create;

Expand Down Expand Up @@ -89,6 +95,14 @@ procedure TSimbaMainStatusBar.DoScriptStateChange(Sender: TObject);
SetScriptStatePanel(TSimbaScriptInstance(Sender));
end;

procedure TSimbaMainStatusBar.DoScriptRunning(Sender: TObject);
var
ScriptInstance: TSimbaScriptInstance absolute Sender;
begin
if (Sender is TSimbaScriptInstance) and ScriptInstance.IsActiveTab() and (ScriptInstance.State <> ESimbaScriptState.STATE_PAUSED) then
FStatusBar.PanelText[1] := FormatMilliseconds(ScriptInstance.TimeRunning, 'hh:mm:ss');
end;

constructor TSimbaMainStatusBar.Create;
begin
FStatusBar := TSimbaStatusBar.Create(Application.MainForm);
Expand All @@ -106,6 +120,7 @@ constructor TSimbaMainStatusBar.Create;
SimbaIDEEvents.RegisterMethodOnScriptTabChange(@DoTabLoaded);
SimbaIDEEvents.RegisterMethodOnScriptStateChange(@DoScriptStateChange);
SimbaIDEEvents.RegisterMethodOnScriptTabChange(@DoTabChange);
SimbaIDEEvents.RegisterMethodOnScriptRunning(@DoScriptRunning);
end;

procedure TSimbaMainStatusBar.SetMainPanelText(Str: String);
Expand Down
22 changes: 21 additions & 1 deletion Source/simba.mufasatypes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ procedure Swap(var A, B: TPoint); overload;
procedure Swap(var A, B: Pointer); overload;
procedure Swap(var A, B: TColorBGRA); overload;

function IfThen(const Val: Boolean; const IfTrue, IfFalse: String): String; inline; overload;
function IsDefault(const Item; const Size: SizeInt): Boolean;
function IfThen(const Val: Boolean; const IfTrue, IfFalse: String): String; overload;

type
ESimbaException = class(Exception);
Expand Down Expand Up @@ -644,6 +645,25 @@ procedure Swap(var A, B: TColorBGRA);
specialize Swap<TColorBGRA>(A, B);
end;

function IsDefault(const Item; const Size: SizeInt): Boolean;
var
Ptr: PByte;
Upper: PtrUInt;
begin
Result := False;

Ptr := PByte(@Item);
Upper := PtrUInt(Ptr) + Size;
while (PtrUInt(Ptr) <= Upper) do
begin
if (Ptr^ <> 0) then
Exit;
Inc(Ptr);
end;

Result := True;
end;

function IfThen(const Val: Boolean; const IfTrue, IfFalse: String): String;
begin
if Val then
Expand Down
Loading

0 comments on commit 7e1189e

Please sign in to comment.