Skip to content

Commit

Permalink
Customizable image sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Aug 20, 2023
1 parent f170da1 commit 4f0ce5c
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 110 deletions.
6 changes: 5 additions & 1 deletion Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
<PackageName Value="LCL"/>
</Item4>
</RequiredPackages>
<Units Count="133">
<Units Count="134">
<Unit0>
<Filename Value="Simba.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -941,6 +941,10 @@
<Filename Value="simba.json.pas"/>
<IsPartOfProject Value="True"/>
</Unit132>
<Unit133>
<Filename Value="simba.ide_utils.pas"/>
<IsPartOfProject Value="True"/>
</Unit133>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
12 changes: 11 additions & 1 deletion Source/components/simba.component_tabcontrol.pas
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ interface

uses
Classes, SysUtils, Forms, Controls, Graphics, ExtCtrls, ImgList, Menus,
attabs;
attabs,
simba.settings;

type
TSimbaTabControl = class;
Expand Down Expand Up @@ -55,6 +56,7 @@ TSimbaTabControl = class(TCustomControl)

procedure CallTabChanged(Data: PtrInt);

procedure DoSettingChanged_ImageSize(Setting: TSimbaSetting);
procedure DoTabMoved(Sender: TObject; AIndexFrom, AIndexTo: Integer);
procedure DoTabChanged(Sender: TObject);
procedure DoTabPlusClick(Sender: TObject);
Expand Down Expand Up @@ -324,6 +326,11 @@ procedure TSimbaTabControl.CallTabChanged(Data: PtrInt);
DoTabChanged(FTabs);
end;

procedure TSimbaTabControl.DoSettingChanged_ImageSize(Setting: TSimbaSetting);
begin
Invalidate();
end;

procedure TSimbaTabControl.DoTabMoved(Sender: TObject; AIndexFrom, AIndexTo: Integer);
begin
if (AIndexFrom = -1) or (AIndexTo = -1) then
Expand Down Expand Up @@ -475,6 +482,9 @@ function TSimbaTabControl.AddTab(Title: String): TSimbaTab;

if NeedChangeEvent and Assigned(FTabChangeEvent) then
FTabChangeEvent(Self, Result);

with SimbaSettings do
RegisterChangeHandler(Self, General.CustomImageSize, @DoSettingChanged_ImageSize);
end;

procedure TSimbaTabControl.MoveTab(AFrom, ATo: Integer);
Expand Down
13 changes: 11 additions & 2 deletions Source/components/simba.component_treeview.pas
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ interface

uses
Classes, SysUtils, Controls, Forms, Graphics, StdCtrls, ComCtrls, LMessages, LCLType, ImgList,
simba.component_edit, simba.component_treeviewhint, simba.component_scrollbar, simba.component_button;
simba.component_edit, simba.component_treeviewhint, simba.component_scrollbar, simba.component_button,
simba.settings;

type
TSimbaTreeView = class;
Expand Down Expand Up @@ -86,6 +87,7 @@ TSimbaTreeView = class(TCustomControl)
procedure DoFilterEditChange(Sender: TObject);
procedure DoMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure DoCreateNodeClass(Sender: TCustomTreeView; var NodeClass: TTreeNodeClass);
procedure DoSettingChanged_ImageSize(Setting: TSimbaSetting);

procedure ScrollHorzChange(Sender: TObject);
procedure ScrollVertChange(Sender: TObject);
Expand Down Expand Up @@ -179,7 +181,6 @@ constructor TSimbaTreeView.Create(AOwner: TComponent; NodeClass: TTreeNodeClass)
FTree.SelectionColor := SimbaTheme.ColorActive;
FTree.Font.Color := SimbaTheme.ColorFont;
FTree.Images := SimbaForm.Images;
//FTree.ImagesWidth := 20;

FScrollbarVert.ForwardScrollControl := FTree;

Expand All @@ -205,6 +206,9 @@ constructor TSimbaTreeView.Create(AOwner: TComponent; NodeClass: TTreeNodeClass)
FFilterClearButton.Hint := 'Clear Filter';
FFilterClearButton.ShowHint := True;
FFilterClearButton.SetClearFilterGlyph();

with SimbaSettings do
RegisterChangeHandler(Self, General.CustomImageSize, @DoSettingChanged_ImageSize);
end;

procedure TSimbaTreeView.FullCollapse;
Expand Down Expand Up @@ -457,6 +461,11 @@ procedure TSimbaTreeView.DoCreateNodeClass(Sender: TCustomTreeView; var NodeClas
NodeClass := TTreeNode;
end;

procedure TSimbaTreeView.DoSettingChanged_ImageSize(Setting: TSimbaSetting);
begin
Invalidate();
end;

procedure TSimbaTreeView.ScrollVertChange(Sender: TObject);
begin
FTree.ScrolledTop := FScrollbarVert.Position;
Expand Down
13 changes: 2 additions & 11 deletions Source/editor/simba.editor_popupmenu.pas
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ implementation
uses
simba.main, simba.editor, simba.editor_docgenerator, simba.nativeinterface,
simba.scripttab, simba.scripttabsform,
simba.ide_events;
simba.ide_events, simba.ide_utils;

var
SimbaEditorPopupMenu: TSimbaEditorPopupMenu;
Expand Down Expand Up @@ -115,16 +115,7 @@ procedure TSimbaEditorPopupMenu.DoScriptTabChange(Sender: TObject);

procedure TSimbaEditorPopupMenu.DoMeasureItem(Sender: TObject; ACanvas: TCanvas; var AWidth, AHeight: Integer);
begin
if TMenuItem(Sender).IsLine then
Exit;

if ACanvas.Font.PixelsPerInch <= 96 then
// no scaling
else
if ACanvas.Font.PixelsPerInch <= 168 then
AHeight := Round(24 * 1.3) // 125%-175% (120-168 DPI): 150% scaling
else
AHeight := Round(32 * 1.3); // 200, 300, 400, ...
MenuItemHeight(Sender as TMenuItem, ACanvas, AHeight);
end;

constructor TSimbaEditorPopupMenu.Create(AOwner: TComponent);
Expand Down
13 changes: 2 additions & 11 deletions Source/forms/simba.filebrowserform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ implementation

uses
FileUtil, LazFileUtils, Clipbrd,
simba.main, simba.scripttabsform, simba.nativeinterface;
simba.main, simba.scripttabsform, simba.nativeinterface, simba.ide_utils;

procedure TSimbaFileBrowserForm.DoFindFiles;

Expand Down Expand Up @@ -214,16 +214,7 @@ procedure TSimbaFileBrowserForm.DoPopupClick(Sender: TObject);

procedure TSimbaFileBrowserForm.PopupMeasureItem(Sender: TObject; ACanvas: TCanvas; var AWidth, AHeight: Integer);
begin
if TMenuItem(Sender).IsLine then
Exit;

if ACanvas.Font.PixelsPerInch <= 96 then
// no scaling
else
if ACanvas.Font.PixelsPerInch <= 168 then
AHeight := Round(24 * 1.3) // 125%-175% (120-168 DPI): 150% scaling
else
AHeight := Round(32 * 1.3); // 200, 300, 400, ...
MenuItemHeight(Sender as TMenuItem, ACanvas, AHeight);
end;

procedure TSimbaFileBrowserForm.PopupPopup(Sender: TObject);
Expand Down
4 changes: 2 additions & 2 deletions Source/forms/simba.main.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ object SimbaForm: TSimbaForm
Top = 550
Width = 1051
Caption = 'Simba'
ClientHeight = 575
ClientWidth = 1051
ClientHeight = 0
ClientWidth = 0
DesignTimePPI = 120
KeyPreview = True
OnClose = FormClose
Expand Down
27 changes: 9 additions & 18 deletions Source/forms/simba.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ TSimbaForm = class(TForm)
procedure TrayIconClick(Sender: TObject);
procedure TrayPopupExitClick(Sender: TObject);
protected
FToolbarImages: TImageList;

FWindowSelection: TWindowHandle;
FProcessSelection: TProcessID;
FRecentFiles: TStringList;
Expand Down Expand Up @@ -292,7 +294,7 @@ implementation
simba.openssl, simba.env,
simba.dockinghelpers, simba.nativeinterface,
simba.scriptformatter, simba.windowhandle, simba.scripttab, simba.theme,
simba.scriptbackup, simba.backupsform;
simba.scriptbackup, simba.backupsform, simba.ide_utils;

procedure TSimbaForm.HandleException(Sender: TObject; E: Exception);

Expand Down Expand Up @@ -700,8 +702,12 @@ procedure TSimbaForm.FormCreate(Sender: TObject);
FRecentFiles := TStringList.Create();
FRecentFiles.Text := SimbaSettings.General.RecentFiles.Value;

FToolbarImages := TImageList.Create(Self); // Create a copy so ImagesGetWidthForPPI is not used for toolbar
FToolbarImages.Assign(Images);

Self.Color := SimbaTheme.ColorFrame;
ToolBar.Color := SimbaTheme.ColorFrame;
ToolBar.Images := FToolbarImages;
end;

procedure TSimbaForm.FormDestroy(Sender: TObject);
Expand Down Expand Up @@ -740,27 +746,12 @@ procedure TSimbaForm.FormShortCut(var Msg: TLMKey; var Handled: Boolean);

procedure TSimbaForm.ImagesGetWidthForPPI(Sender: TCustomImageList; AImageWidth, APPI: Integer; var AResultWidth: Integer);
begin
if APPI <= 96 then
// no scaling
else
if APPI <= 168 then
AResultWidth := 24 // 125%-175% (120-168 DPI): 150% scaling
else
AResultWidth := 32; // 200, 300, 400, ...
AResultWidth := ImageWidthForDPI(APPI);
end;

procedure TSimbaForm.MainMenuMeasureItem(Sender: TObject; ACanvas: TCanvas; var AWidth, AHeight: Integer);
begin
if TMenuItem(Sender).IsLine then
Exit;

if ACanvas.Font.PixelsPerInch <= 96 then
// no scaling
else
if ACanvas.Font.PixelsPerInch <= 168 then
AHeight := Round(24 * 1.3) // 125%-175% (120-168 DPI): 150% scaling
else
AHeight := Round(32 * 1.3); // 200, 300, 400, ...
MenuItemHeight(Sender as TMenuItem, ACanvas, AHeight);
end;

procedure TSimbaForm.MenuItemDocumentationClick(Sender: TObject);
Expand Down
13 changes: 2 additions & 11 deletions Source/forms/simba.outputform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ implementation
SynEditMarkupBracket, SynEditMarkupWordGroup,
simba.dockinghelpers, simba.fonthelpers, simba.scripttabsform,
simba.nativeinterface, simba.settingsform, simba.main, simba.scriptinstance,
simba.scripttab, simba.ide_events;
simba.scripttab, simba.ide_events, simba.ide_utils;

procedure TSimbaOutputTab.DoScriptStateChange(Sender: TObject);
begin
Expand Down Expand Up @@ -585,16 +585,7 @@ procedure TSimbaOutputForm.FormMouseDown(Sender: TObject; Button: TMouseButton;

procedure TSimbaOutputForm.ContextMenuMeasureItem(Sender: TObject; ACanvas: TCanvas; var AWidth, AHeight: Integer);
begin
if TMenuItem(Sender).IsLine then
Exit;

if ACanvas.Font.PixelsPerInch <= 96 then
// no scaling
else
if ACanvas.Font.PixelsPerInch <= 168 then
AHeight := Round(24 * 1.3) // 125%-175% (120-168 DPI): 150% scaling
else
AHeight := Round(32 * 1.3); // 200, 300, 400, ...
MenuItemHeight(Sender as TMenuItem, ACanvas, AHeight);
end;

procedure TSimbaOutputForm.FormMouseLeave(Sender: TObject);
Expand Down
13 changes: 2 additions & 11 deletions Source/forms/simba.scripttabsform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ implementation
LCLType,
simba.mufasatypes, simba.env, simba.editor_docgenerator, simba.main,
simba.dockinghelpers, simba.nativeinterface, simba.outputform,
simba.ide_events, simba.theme, simba.settings;
simba.ide_events, simba.ide_utils, simba.theme, simba.settings;

procedure TSimbaScriptTabsForm.DoOnDropFiles(Sender: TObject; const FileNames: array of String);
var
Expand Down Expand Up @@ -236,16 +236,7 @@ procedure TSimbaScriptTabsForm.FormMouseUp(Sender: TObject; Button: TMouseButton

procedure TSimbaScriptTabsForm.TabPopupMenuMeasureItem(Sender: TObject; ACanvas: TCanvas; var AWidth, AHeight: Integer);
begin
if TMenuItem(Sender).IsLine then
Exit;

if ACanvas.Font.PixelsPerInch <= 96 then
// no scaling
else
if ACanvas.Font.PixelsPerInch <= 168 then
AHeight := Round(24 * 1.3) // 125%-175% (120-168 DPI): 150% scaling
else
AHeight := Round(32 * 1.3); // 200, 300, 400, ...
MenuItemHeight(Sender as TMenuItem, ACanvas, AHeight);
end;

procedure TSimbaScriptTabsForm.FontChanged(Sender: TObject);
Expand Down
Loading

0 comments on commit 4f0ce5c

Please sign in to comment.