Skip to content

Commit

Permalink
Finish main form theming (SynEdit & MenuBar)
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed May 9, 2023
1 parent 649982c commit e888d67
Show file tree
Hide file tree
Showing 24 changed files with 1,033 additions and 570 deletions.
18 changes: 17 additions & 1 deletion Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
<PackageName Value="LCL"/>
</Item4>
</RequiredPackages>
<Units Count="169">
<Units Count="173">
<Unit0>
<Filename Value="Simba.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -1061,6 +1061,22 @@
<Filename Value="components/simba.component_edit.pas"/>
<IsPartOfProject Value="True"/>
</Unit168>
<Unit169>
<Filename Value="components/simba.component_synedit.pas"/>
<IsPartOfProject Value="True"/>
</Unit169>
<Unit170>
<Filename Value="simba.theme.pas"/>
<IsPartOfProject Value="True"/>
</Unit170>
<Unit171>
<Filename Value="../Third-Party/win32menustyler.pas"/>
<IsPartOfProject Value="True"/>
</Unit171>
<Unit172>
<Filename Value="components/simba.component_menubar.pas"/>
<IsPartOfProject Value="True"/>
</Unit172>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
2 changes: 1 addition & 1 deletion Source/Simba.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
simba.outputform, simba.colorpickerhistoryform, simba.filebrowserform,
simba.notesform, simba.settingsform, simba.associate, simba.openexampleform,
simba.scriptthread, simba.package_form, simba.mufasatypes, simba.shapeboxform,
simba.windowsdarktheme, simba.compiler_dump, simba.plugin_dump,
simba.compiler_dump, simba.plugin_dump,
simba.ide_analytics, simba.ide_codetools_setup, simba.ide_codetools_insight;

type
Expand Down
4 changes: 2 additions & 2 deletions Source/components/simba.component_edit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ function TSimbaEdit.CalculateHeight: Integer;
with TBitmap.Create() do
try
Canvas.Font := Self.Font;
Canvas.Font.Size := Round(-GetFontData(Canvas.Font.Reference.Handle).Height * 72 / Canvas.Font.PixelsPerInch) + 2;
Canvas.Font.Size := Round(Abs(GetFontData(Canvas.Font.Handle).Height) * 72 / Canvas.Font.PixelsPerInch) + 2; // Measure on larger font size - Font size can be 0

Result := Canvas.TextHeight('Olly') + (BorderWidth * 2);
Result := Canvas.TextHeight('Tay') + (BorderWidth * 2);
finally
Free();
end;
Expand Down
184 changes: 184 additions & 0 deletions Source/components/simba.component_menubar.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
unit simba.component_menubar;

{$i simba.inc}

interface

uses
Classes, SysUtils, Controls, Forms, Menus, Graphics;

type
TSimbaMainMenuBar = class(TCustomControl)
protected
FItems: array of record
Text: String;
Rect: TRect;
Menu: TPopupMenu;
ClosedAt: UInt64;
end;
FHotIndex: Integer;

function IndexAtXY(X, Y: Integer): Integer;

procedure CalculateSizes;
procedure Paint; override;
procedure FontChanged(Sender: TObject); override;

procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseLeave; override;

procedure DoMenuClose(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;

procedure AddMenu(Title: String; APopupMenu: TPopupMenu);
end;

implementation

uses
simba.theme;

function TSimbaMainMenuBar.IndexAtXY(X, Y: Integer): Integer;
var
I: Integer;
begin
Result := -1;
for I := 0 to High(FItems) do
if (X >= FItems[I].Rect.Left) and (X <= FItems[I].Rect.Right) then
Exit(I);
end;

procedure TSimbaMainMenuBar.CalculateSizes;
var
I: Integer;
begin
with TBitmap.Create() do
try
Canvas.Font := Self.Font;
Canvas.Font.Size := Round(Abs(GetFontData(Canvas.Font.Handle).Height) * 72 / Canvas.Font.PixelsPerInch) + 3; // Measure on larger font size - Font size can be 0

if (Length(FItems) > 0) then
begin
FItems[0].Rect.Left := 5;
FItems[0].Rect.Right := FItems[0].Rect.Left + Canvas.TextWidth(FItems[0].Text);
for I := 1 to High(FItems) do
begin
FItems[I].Rect.Left := FItems[I-1].Rect.Right + 5;
FItems[I].Rect.Right := FItems[I].Rect.Left + Canvas.TextWidth(FItems[I].Text);
end;
end;

Self.Height := Canvas.TextHeight('Tay');
finally
Free();
end;
end;

procedure TSimbaMainMenuBar.Paint;
var
I: Integer;
R: TRect;
Style: TTextStyle;
begin
Style := Canvas.TextStyle;
Style.Alignment := taCenter;
Style.Layout := tlCenter;

Canvas.Brush.Color := SimbaTheme.ColorFrame;
Canvas.FillRect(ClientRect);

for I := 0 to High(FItems) do
begin
R := FItems[I].Rect;
R.Top := 0;
R.Height := Height;

if (I = FHotIndex) then
begin
Canvas.Brush.Color := SimbaTheme.ColorActive;
Canvas.FillRect(R.Left, R.Top + 2, R.Right, R.Height - 2);
end;

Canvas.TextRect(R, R.Left, R.Top, FItems[I].Text, Style);
end;
Canvas.Pen.Color := SimbaTheme.ColorLine;
Canvas.Line(0, Height - 1, Width, Height - 1);
end;

procedure TSimbaMainMenuBar.FontChanged(Sender: TObject);
begin
inherited FontChanged(Sender);

CalculateSizes();
end;

procedure TSimbaMainMenuBar.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
I: Integer;
begin
inherited MouseDown(Button, Shift, X, Y);

I := IndexAtXY(X, Y);
if (I > -1) and (GetTickCount64() - FItems[I].ClosedAt > 100) then
with ClientToScreen(TPoint.Create(FItems[I].Rect.Left, Height)) do
FItems[I].Menu.PopUp(X, Y);
end;

procedure TSimbaMainMenuBar.MouseMove(Shift: TShiftState; X, Y: Integer);
var
n: Integer;
begin
inherited MouseMove(Shift, X, Y);

n := IndexAtXY(X,Y);
if (n <> FHotIndex) then
begin
FHotIndex := n;
Invalidate();
end;
end;

procedure TSimbaMainMenuBar.MouseLeave;
begin
inherited MouseLeave();

if (FHotIndex > -1) then
begin
FHotIndex := -1;
Invalidate();
end;
end;

procedure TSimbaMainMenuBar.DoMenuClose(Sender: TObject);
var
I: Integer;
begin
for I := 0 to High(FItems) do
if (FItems[I].Menu = Sender) then
FItems[I].ClosedAt := GetTickCount64();
end;

constructor TSimbaMainMenuBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);

ControlStyle := ControlStyle + [csOpaque];
Font.Color := SimbaTheme.ColorFont;

CalculateSizes();
end;

procedure TSimbaMainMenuBar.AddMenu(Title: String; APopupMenu: TPopupMenu);
begin
SetLength(FItems, Length(FItems) + 1);
FItems[High(FItems)].Text := Title;
FItems[High(FItems)].Menu := APopupMenu;
APopupMenu.OnClose := @DoMenuClose;

CalculateSizes();
end;

end.

29 changes: 18 additions & 11 deletions Source/components/simba.component_statusbar.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
interface

uses
Classes, SysUtils, Controls, Graphics, LCLType, LMessages,
Classes, SysUtils, Controls, Forms, Graphics, LCLType, LMessages,
simba.mufasatypes;

type
Expand All @@ -28,6 +28,7 @@ TSimbaStatusBar = class(TCustomControl)
procedure WMPaint(var Message: TLMPaint); message LM_PAINT;

procedure CalculateSizes;
procedure FontChanged(Sender: TObject); override;
procedure Paint; override;
procedure PaintPanel(Index: Integer);

Expand All @@ -54,7 +55,8 @@ TSimbaStatusBar = class(TCustomControl)
implementation

uses
LCLIntf;
LCLIntf,
simba.theme;

procedure TSimbaStatusBar.CheckIndex(Index: Integer);
begin
Expand Down Expand Up @@ -123,20 +125,25 @@ procedure TSimbaStatusBar.CalculateSizes;
begin
with TBitmap.Create() do
try
// Measure on larger font size
// Font size can be 0 so use GetFontData
Canvas.Font := Self.Font;
Canvas.Font.Size := Round(-GetFontData(Canvas.Font.Reference.Handle).Height * 72 / Canvas.Font.PixelsPerInch) + 3;
Canvas.Font.Size := Round(Abs(GetFontData(Canvas.Font.Handle).Height) * 72 / Canvas.Font.PixelsPerInch) + 3; // Measure on larger font size - Font size can be 0

for I := 0 to FPanelCount - 1 do
FPanelWidths[I] := Canvas.TextWidth(FPanelTextMeasure[I]);

Self.Height := Canvas.TextHeight('TaylorSwift');
Self.Height := Canvas.TextHeight('Tay');
finally
Free();
end;
end;

procedure TSimbaStatusBar.FontChanged(Sender: TObject);
begin
inherited FontChanged(Sender);

CalculateSizes();
end;

procedure TSimbaStatusBar.EraseBackground(DC: HDC);
begin
{ nothing }
Expand All @@ -148,8 +155,8 @@ procedure TSimbaStatusBar.Paint;
begin
if (FPanelCount = 0) then
begin
Canvas.Pen.Color := clWhite;
Canvas.Brush.Color := $4A4136;
Canvas.Pen.Color := SimbaTheme.ColorLine;
Canvas.Brush.Color := SimbaTheme.ColorFrame;
Canvas.Line(0, 0, Width, 0);
Canvas.FillRect(0, 1, Width, Height);
end else
Expand All @@ -175,9 +182,9 @@ procedure TSimbaStatusBar.PaintPanel(Index: Integer);
Style := Canvas.TextStyle;
Style.Layout := tlCenter;

Canvas.Font.Color := clWhite;
Canvas.Pen.Color := clWhite;
Canvas.Brush.Color := $322F2D;
Canvas.Font.Color := SimbaTheme.ColorFont;
Canvas.Pen.Color := SimbaTheme.ColorLine;
Canvas.Brush.Color := SimbaTheme.ColorFrame;

R := PanelRect(Index);

Expand Down
Loading

0 comments on commit e888d67

Please sign in to comment.