Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Dec 26, 2023
1 parent 6ce8c84 commit 85aa1ff
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 106 deletions.
57 changes: 21 additions & 36 deletions Source/box.inc
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ type
function Box(const Mid: TPoint; const XRad, YRad: Integer): TBox; inline;

operator = (const Left, Right: TBox): Boolean;

const
NullBox: TBox = (X1: -1; Y1: -1; X2: -1; Y2: -1);

{$ENDIF}

{$IFDEF BODY}
Expand Down Expand Up @@ -203,41 +199,30 @@ begin
Result.Y2 := Max(Max(Self.Y1, Other.Y2), Max(Other.Y1, Self.Y2));
end;

function TBoxHelper.Invert(Box: TBox): TBoxArray;
function TBoxHelper.Invert(Area: TBox): TBoxArray;
var
Box: TBox;
Boxes: TBoxArray;
I, Count: Integer;
begin
Result := [];

Box.X1 := Max(Area.X1, Self.X1-1);
Box.X2 := Min(Area.X2, Self.X2+1);
Box.Y1 := Max(Area.Y1, Self.Y1-1);
Box.Y2 := Min(Area.Y2, Self.Y2+1);

Boxes := [
TBox.Create(Area.X1, Area.Y1, Box.X1, Box.Y1),
TBox.Create(Area.X1, Box.Y1, Box.X1, Box.Y2),
TBox.Create(Area.X1, Box.Y1, Box.X1, Area.Y2),
TBox.Create(Box.X1, Area.Y1, Box.X2, Box.Y1),
TBox.Create(Box.X1, Box.Y2, Box.X2, Area.Y2),
TBox.Create(Box.X2, Area.Y1, Area.X2, Box.Y1),
TBox.Create(Box.X2, Box.Y1, Area.X2, Box.Y2),
TBox.Create(Box.X2, Box.Y1, Area.X2, Area.Y2)
lowX, maxX, lowY, maxY: Integer;
I: Integer;
begin
lowX := Max(Area.X1, Self.X1-1);
maxX := Min(Area.X2, Self.X2+1);
lowY := Max(Area.Y1, Self.Y1-1);
maxY := Min(Area.Y2, Self.Y2+1);

Result := [
TBox.Create(Area.X1, Area.Y1, lowX, lowY),
TBox.Create(Area.X1, lowY, lowX, maxY),
TBox.Create(Area.X1, lowY, lowX, Area.Y2),
TBox.Create(lowX, Area.Y1, maxX, lowY),
TBox.Create(lowX, maxY, maxX, Area.Y2),
TBox.Create(maxX, Area.Y1, Area.X2, lowY),
TBox.Create(maxX, lowY, Area.X2, maxY),
TBox.Create(maxX, lowY, Area.X2, Area.Y2)
];

Count := 0;
SetLength(Result, Length(Boxes));
for I := 0 to High(Boxes) do
with Boxes[I] do
if (X2 > X1) and (Y2 > Y1) then
begin
Result[Count] := Boxes[I];
Inc(Count);
end;

SetLength(Result, Count);
for I := High(Result) downto 0 do
if (Result[I].X2 <= Result[I].X1) or (Result[I].Y2 <= Result[I].Y1) then
Delete(Result, I, 1);
end;

function TBoxHelper.Partition(Rows, Cols: Integer): TBoxArray;
Expand Down
5 changes: 3 additions & 2 deletions Source/components/simba.component_toolbar.pas
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,10 @@ constructor TSimbaToolbar.Create(AOwner: TComponent);
FFlowPanel.Align := alClient;
FFlowPanel.BevelOuter := bvNone;

Spacing := 3;

ControlStyle := ControlStyle + [csOpaque];
AutoSize := True;
Spacing := 3;
Color := SimbaTheme.ColorFrame;
end;

end.
Expand Down
160 changes: 97 additions & 63 deletions Source/forms/simba.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ TSimbaForm = class(TForm)
procedure DoResetDocking;
procedure DoDefaultDocking;

procedure SetupDocking;
procedure SetupCompleted;

procedure DoSettingChanged_CustomFontSize(Setting: TSimbaSetting);
Expand All @@ -247,6 +246,10 @@ TSimbaForm = class(TForm)
procedure SetConsoleVisible(Value: Boolean);
procedure SetLayoutLocked(Value: Boolean);
procedure SetTrayIconVisible(Value: Boolean);

procedure DoApplicationParameters;
procedure DoFocusEditor;
procedure UpdateTitle;
public
procedure Setup;
end;
Expand Down Expand Up @@ -372,6 +375,37 @@ procedure TSimbaForm.SetTrayIconVisible(Value: Boolean);
TrayIcon.Visible := Value;
end;

procedure TSimbaForm.DoApplicationParameters;
begin
if (Application.ParamCount > 0) then
begin
if (Application.ParamCount = 1) and FileExists(Application.Params[1]) then
SimbaScriptTabsForm.Open(Application.Params[1])
else
if Application.HasOption('open') and FileExists(Application.Params[Application.ParamCount]) then
begin
SimbaScriptTabsForm.Open(Application.Params[Application.ParamCount]);

if Application.HasOption('compile') then
SimbaMainToolBar.ButtonCompile.Click();
if Application.HasOption('run') then
SimbaMainToolBar.ButtonRun.Click();
end;
end;
end;

procedure TSimbaForm.DoFocusEditor;
begin
if Assigned(SimbaScriptTabsForm.CurrentEditor) then
if SimbaScriptTabsForm.CurrentEditor.CanSetFocus() then
SimbaScriptTabsForm.CurrentEditor.SetFocus();
end;

procedure TSimbaForm.UpdateTitle;
begin
Caption := Format('Simba %.1f', [SIMBA_VERSION / 1000]);
end;

procedure TSimbaForm.HandleFormCreated(Sender: TObject; Form: TCustomForm);
begin
if (SimbaSettings.General.CustomFontSize.Value > 0) then
Expand All @@ -385,11 +419,12 @@ procedure TSimbaForm.HandleRecentFileClick(Sender: TObject);

procedure TSimbaForm.MenuItemAssociateScriptsClick(Sender: TObject);
const
Message = 'Would you like to associate scripts with this Simba?' + LineEnding +
'This means when opening a script, the script will be opened using this Simba executable.';
Message = 'Would you like to associate Simba files with this Simba?' + LineEnding +
'This means when opening a .simba file the file will be opened using this Simba executable.' + LineEnding +
'It also adds right click actions to run the script.';
begin
{$IFDEF WINDOWS}
if MessageDlg(Message, mtConfirmation, mbYesNo, 0) = mrYes then
if (MessageDlg(Message, mtConfirmation, mbYesNo, 0) = mrYes) then
Associate();
{$ENDIF}
end;
Expand Down Expand Up @@ -515,7 +550,7 @@ procedure TSimbaForm.DoDefaultDocking;
DockMaster.MakeVisible(SimbaOutputForm, False);
DockMaster.MakeVisible(SimbaFunctionListForm, False);
DockMaster.MakeVisible(SimbaFileBrowserForm, False);
DockMaster.ScaleOnResize:=False;
DockMaster.ScaleOnResize := False;

Width := 1200;
Height := 850;
Expand All @@ -538,6 +573,13 @@ procedure TSimbaForm.DoDefaultDocking;

procedure TSimbaForm.Setup;
begin
// Register events etc
Application.CaptureExceptions := True;
Application.OnException := @Self.HandleException;
Application.AddOnKeyDownBeforeHandler(@DoApplicationKeyDown);

Screen.AddHandlerFormAdded(@Self.HandleFormCreated, True);

SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_LOADED, @DoTabLoaded);

with SimbaSettings do
Expand All @@ -548,29 +590,65 @@ procedure TSimbaForm.Setup;
RegisterChangeHandler(Self, General.ConsoleVisible, @DoSettingChanged_ConsoleVisible, True);
end;

Application.CaptureExceptions := True;
Application.OnException := @Self.HandleException;
Application.AddOnKeyDownBeforeHandler(@DoApplicationKeyDown);

Screen.AddHandlerFormAdded(@Self.HandleFormCreated, True);

// Create things
FRecentFiles := TStringList.Create();
FRecentFiles.Text := SimbaSettings.General.RecentFiles.Value;

FMouseLogger := TSimbaMouseLogger.Create();

Color := SimbaTheme.ColorFrame;
// Docking
BeginFormUpdate();
try
DockMaster.BeginUpdate();
DockMaster.SplitterWidth := Scale96ToScreen(8);
DockMaster.HeaderClass := TSimbaAnchorDockHeader;
DockMaster.SplitterClass := TSimbaAnchorDockSplitter;
DockMaster.SiteClass := TSimbaAnchorDockHostSite;
DockMaster.HideHeaderCaptionFloatingControl := False;
DockMaster.HeaderAlignTop := $FFFFFF;
DockMaster.PageAreaInPercent := 0;
DockMaster.HeaderHint := 'Use the mouse to drag and dock this window';
DockMaster.MakeDockPanel(DockPanel, admrpChild);
DockMaster.DragTreshold := 40;

DockMaster.MakeDockable(SimbaScriptTabsForm, MenuItemEditor);
DockMaster.MakeDockable(SimbaOutputForm, MenuItemOutput);
DockMaster.MakeDockable(SimbaFileBrowserForm, MenuItemFileBrowser);
DockMaster.MakeDockable(SimbaFunctionListForm, MenuItemFunctionList);
DockMaster.MakeDockable(SimbaNotesForm, MenuItemNotes);
DockMaster.MakeDockable(SimbaDebugImageForm, MenuItemDebugImage);
DockMaster.MakeDockable(SimbaColorPickerHistoryForm, MenuItemColourHistory);

SimbaScriptTabsForm.AddTab();
if (SimbaSettings.General.Layout.Value <> '') then
begin
DockMaster.LoadLayout(SimbaSettings.General.Layout.Value);

SetupDocking();
if (DockMaster.GetAnchorSite(SimbaScriptTabsForm) <> nil) then
DockMaster.GetAnchorSite(SimbaScriptTabsForm).Header.Visible := False;
if (DockMaster.GetAnchorSite(SimbaOutputForm) <> nil) then
DockMaster.GetAnchorSite(SimbaOutputForm).Header.Visible := False;

// Finally, give the editor focus as default.
if Assigned(SimbaScriptTabsForm.CurrentEditor) then
if SimbaScriptTabsForm.CurrentEditor.CanSetFocus() then
SimbaScriptTabsForm.CurrentEditor.SetFocus();
EnsureVisible();
end else
QueueOnMainThread(@DoDefaultDocking);
finally
DockMaster.EndUpdate();

EndFormUpdate();
end;

SetupCompleted();
// Main title
UpdateTitle();

// Add a tab
SimbaScriptTabsForm.AddTab();

// If first simba launch, associate
if SimbaSettings.FirstLaunch then
QueueOnMainThread(@MenuItemAssociateScripts.Click);

QueueOnMainThread(@DoApplicationParameters); // open/compile/run parameters
QueueOnMainThread(@DoFocusEditor); // finally focus the tab
end;

procedure TSimbaForm.FormDestroy(Sender: TObject);
Expand Down Expand Up @@ -966,50 +1044,6 @@ procedure TSimbaForm.TrayIconClick(Sender: TObject);
SetFocus();
end;

procedure TSimbaForm.SetupDocking;
begin
BeginFormUpdate();

try
DockMaster.BeginUpdate();
DockMaster.SplitterWidth := Scale96ToScreen(8);
DockMaster.HeaderClass := TSimbaAnchorDockHeader;
DockMaster.SplitterClass := TSimbaAnchorDockSplitter;
DockMaster.SiteClass := TSimbaAnchorDockHostSite;
DockMaster.HideHeaderCaptionFloatingControl := False;
DockMaster.HeaderAlignTop := $FFFFFF;
DockMaster.PageAreaInPercent := 0;
DockMaster.HeaderHint := 'Use the mouse to drag and dock this window';
DockMaster.MakeDockPanel(DockPanel, admrpChild);
DockMaster.DragTreshold := 40;

DockMaster.MakeDockable(SimbaScriptTabsForm, MenuItemEditor);
DockMaster.MakeDockable(SimbaOutputForm, MenuItemOutput);
DockMaster.MakeDockable(SimbaFileBrowserForm, MenuItemFileBrowser);
DockMaster.MakeDockable(SimbaFunctionListForm, MenuItemFunctionList);
DockMaster.MakeDockable(SimbaNotesForm, MenuItemNotes);
DockMaster.MakeDockable(SimbaDebugImageForm, MenuItemDebugImage);
DockMaster.MakeDockable(SimbaColorPickerHistoryForm, MenuItemColourHistory);

if (SimbaSettings.General.Layout.Value <> '') then
begin
DockMaster.LoadLayout(SimbaSettings.General.Layout.Value);

if (DockMaster.GetAnchorSite(SimbaScriptTabsForm) <> nil) then
DockMaster.GetAnchorSite(SimbaScriptTabsForm).Header.Visible := False;
if (DockMaster.GetAnchorSite(SimbaOutputForm) <> nil) then
DockMaster.GetAnchorSite(SimbaOutputForm).Header.Visible := False;

EnsureVisible();
end else
QueueOnMainThread(@DoDefaultDocking);
finally
DockMaster.EndUpdate();

EndFormUpdate();
end;
end;

procedure TSimbaForm.SetupCompleted;
begin
if SimbaSettings.FirstLaunch then
Expand Down
2 changes: 1 addition & 1 deletion Source/forms/simba.outputform.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object SimbaOutputForm: TSimbaOutputForm
OnMouseDown = FormMouseDown
OnMouseLeave = FormMouseLeave
OnMouseMove = FormMouseMove
LCLVersion = '3.0.0.1'
LCLVersion = '3.0.0.2'
object ContextMenu: TPopupMenu
OnMeasureItem = ContextMenuMeasureItem
Left = 40
Expand Down
4 changes: 2 additions & 2 deletions Source/script/simba.script_runner.pas
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ procedure TSimbaScriptRunner.DoError(E: Exception);
begin
ExitCode := 1;

DoDebugLn([EDebugLn.RED], E.Message);
DoDebugLn([EDebugLn.RED, EDebugLn.FOCUS], E.Message);

if (E is lpException) then
with lpException(E) do
begin
for Line in StackTrace.Split(LineEnding) do
if (Line <> '') then
DoDebugLn([EDebugLn.RED], Line);
DoDebugLn([EDebugLn.RED, EDebugLn.FOCUS], Line);

if (FScript.SimbaCommunication <> nil) then
FScript.SimbaCommunication.ScriptError(Message, DocPos.Line, DocPos.Col, DocPos.FileName);
Expand Down
4 changes: 2 additions & 2 deletions Source/simba.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
{$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'}
Expand Down

0 comments on commit 85aa1ff

Please sign in to comment.