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 7743616
Show file tree
Hide file tree
Showing 24 changed files with 1,029 additions and 549 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
178 changes: 178 additions & 0 deletions Source/components/simba.component_menubar.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
unit simba.component_menubar;

{$i simba.inc}

interface

uses
Classes, SysUtils, Controls, 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 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
// 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;

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('TaylorSwift');
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.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.

13 changes: 7 additions & 6 deletions Source/components/simba.component_statusbar.pas
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ TSimbaStatusBar = class(TCustomControl)
implementation

uses
LCLIntf;
LCLIntf,
simba.theme;

procedure TSimbaStatusBar.CheckIndex(Index: Integer);
begin
Expand Down Expand Up @@ -148,8 +149,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 +176,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
118 changes: 118 additions & 0 deletions Source/components/simba.component_synedit.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
unit simba.component_synedit;

{$i simba.inc}

interface

uses
Classes, SysUtils, Controls, Forms, StdCtrls,
SynEdit, SynEditTypes, SynEditFoldedView, SynEditTextBuffer, SynEditMarkupSelection,
LazSynEditText,
ATScrollBar;

type
TSimbaSynEdit = class(TSynEdit)
protected
FScrollbarVert: TATScrollbar;
FScrollbarHorz: TATScrollbar;

procedure DoVertScrollBarChange(Sender: TObject);
procedure DoHorzScrollBarChange(Sender: TObject);

procedure UpdateBars;
procedure StatusChanged(AChanges: TSynStatusChanges); override;
procedure DoLineChanges(Sender: TSynEditStrings; aIndex, aCount: Integer);
procedure SetParent(NewParent: TWinControl); override;
public
constructor Create(AOwner: TComponent); override;
end;

implementation

uses
simba.mufasatypes, simba.theme;

procedure TSimbaSynEdit.DoVertScrollBarChange(Sender: TObject);
begin
TopLine := FScrollbarVert.Position;
end;

procedure TSimbaSynEdit.DoHorzScrollBarChange(Sender: TObject);
begin
LeftChar := FScrollbarHorz.Position;
end;

procedure TSimbaSynEdit.UpdateBars;
begin
if FScrollbarVert=nil then Exit;
if FScrollbarHorz=nil then Exit;

FScrollbarVert.Min := 1;
FScrollbarVert.Max := TextView.ViewedCount + 1;
if (eoScrollPastEof in Options) then
FScrollbarVert.Max := FScrollbarVert.Max + (LinesInWindow - 1);
FScrollbarVert.PageSize := LinesInWindow;
FScrollbarVert.Position := TopView;

FScrollbarHorz.Min := 1;
FScrollbarHorz.Max := TextView.LengthOfLongestLine + 1;
if (eoScrollPastEol in Options) and (FScrollbarHorz.Max < MaxLeftChar + 1) then
FScrollbarHorz.Max := MaxLeftChar + 1;
FScrollbarHorz.PageSize := CharsInWindow;
FScrollbarHorz.Position := LeftChar;

FScrollbarVert.Update();
FScrollbarHorz.Update();
end;

procedure TSimbaSynEdit.StatusChanged(AChanges: TSynStatusChanges);
begin
inherited StatusChanged(AChanges);

if (AChanges * [scLeftChar, scTopLine, scLinesInWindow, scCharsInWindow] <> []) then
UpdateBars();
end;

procedure TSimbaSynEdit.DoLineChanges(Sender: TSynEditStrings; aIndex, aCount: Integer);
begin
UpdateBars();
end;

procedure TSimbaSynEdit.SetParent(NewParent: TWinControl);
begin
inherited SetParent(NewParent);

FScrollbarHorz.Parent := NewParent;
FScrollbarHorz.Align := alBottom;
FScrollbarHorz.IndentCorner := 100;
FScrollbarVert.Parent := NewParent;
FScrollbarVert.Align := alRight;
end;

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

FScrollbarVert := TATScrollbar.Create(Self);
FScrollbarVert.Kind := sbVertical;
FScrollbarVert.OnChange := @DoVertScrollBarChange;

FScrollbarHorz := TATScrollbar.Create(Self);
FScrollbarHorz.Kind := sbHorizontal;
FScrollbarHorz.OnChange := @DoHorzScrollBarChange;

with FoldedTextBuffer as TSynEditFoldedView do
AddChangeHandler(senrLineMappingChanged, @DoLineChanges);
TextView.AddChangeHandler(senrLineCount, @DoLineChanges);

ScrollBars := ssNone;

TSynEditMarkupSelection(MarkupByClass[TSynEditMarkupSelection]).MarkupInfoSeletion.Background := SimbaTheme.ColorActive;


Color := SimbaTheme.ColorBackground;
Font.Color := SimbaTheme.ColorFont;
end;

end.

0 comments on commit 7743616

Please sign in to comment.