-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish main form theming (SynEdit & MenuBar)
- Loading branch information
Showing
24 changed files
with
1,029 additions
and
549 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
Oops, something went wrong.