Skip to content

Commit

Permalink
Examples refractor
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Jul 15, 2023
1 parent b88345e commit 1d08ca9
Show file tree
Hide file tree
Showing 20 changed files with 541 additions and 462 deletions.
6 changes: 0 additions & 6 deletions Examples/examples.rc

This file was deleted.

Binary file removed Examples/examples.res
Binary file not shown.
6 changes: 0 additions & 6 deletions Examples/makeresource.sh

This file was deleted.

18 changes: 17 additions & 1 deletion Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
<DpiAware Value="True/PM"/>
</XPManifest>
<Icon Value="0"/>
<Resources Count="6">
<Resource_0 FileName="..\Examples\array.simba" Type="RCDATA" ResourceName="EXAMPLE_ARRAY"/>
<Resource_1 FileName="..\Examples\bitmap.simba" Type="RCDATA" ResourceName="EXAMPLE_BITMAP"/>
<Resource_2 FileName="..\Examples\function.simba" Type="RCDATA" ResourceName="EXAMPLE_FUNCTION"/>
<Resource_3 FileName="..\Examples\loop.simba" Type="RCDATA" ResourceName="EXAMPLE_LOOP"/>
<Resource_4 FileName="..\Examples\procedure.simba" Type="RCDATA" ResourceName="EXAMPLE_PROCEDURE"/>
<Resource_5 FileName="..\Examples\timing.simba" Type="RCDATA" ResourceName="EXAMPLE_TIMING"/>
</Resources>
</General>
<VersionInfo>
<UseVersionInfo Value="True"/>
Expand Down Expand Up @@ -312,7 +320,7 @@
<PackageName Value="LCL"/>
</Item4>
</RequiredPackages>
<Units Count="131">
<Units Count="133">
<Unit0>
<Filename Value="Simba.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -912,6 +920,14 @@
<Filename Value="../Third-Party/fphashutils_simba.pas"/>
<IsPartOfProject Value="True"/>
</Unit130>
<Unit131>
<Filename Value="package/simba.package_menubuilder.pas"/>
<IsPartOfProject Value="True"/>
</Unit131>
<Unit132>
<Filename Value="components/simba.component_buttonpanel.pas"/>
<IsPartOfProject Value="True"/>
</Unit132>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
Binary file modified Source/Simba.res
Binary file not shown.
8 changes: 7 additions & 1 deletion Source/components/simba.component_button.pas
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ TSimbaButton = class(TSpeedButton)

constructor Create(AOwner: TComponent); override;

procedure SetOkGlpyh;
procedure SetCloseGlyph;
procedure SetClearFilterGlyph;
end;
Expand Down Expand Up @@ -86,10 +87,15 @@ constructor TSimbaButton.Create(AOwner: TComponent);
inherited Create(AOwner);

AutoSize := True;

Font.Color := SimbaTheme.ColorFont;
VertPadding := 5;
end;

procedure TSimbaButton.SetOkGlpyh;
begin
ButtonGlyph.LCLGlyphName := 'btn_ok';
end;

procedure TSimbaButton.SetCloseGlyph;
begin
ButtonGlyph.LCLGlyphName := 'btn_cancel';
Expand Down
103 changes: 103 additions & 0 deletions Source/components/simba.component_buttonpanel.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
Author: Raymond van Venetië and Merlijn Wajer
Project: Simba (https://github.com/MerlijnWajer/Simba)
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0)
}
unit simba.component_buttonpanel;

{$i simba.inc}

interface

uses
Classes, SysUtils, Controls, Forms,
simba.component_button;

type
TSimbaButtonPanel = class(TCustomControl)
protected
FButtonOk: TSimbaButton;
FButtonCancel: TSimbaButton;

procedure DoButtonCancelResize(Sender: TObject);

procedure SetParent(NewParent: TWinControl); override;
public
constructor Create(AOwner: TComponent); override;

property ButtonOk: TSimbaButton read FButtonOk;
property ButtonCancel: TSimbaButton read FButtonCancel;
end;

implementation

uses
simba.theme;

type
TButtonPanelButton = class(TSimbaButton)
public
procedure Click; override;
end;

procedure TButtonPanelButton.Click;
var
Form: TCustomForm;
begin
Form := GetTopFormSkipNonDocked(Self);

if Assigned(Form) and (Parent is TSimbaButtonPanel) then
begin
if Self.Equals(TSimbaButtonPanel(Parent).FButtonOk) then
Form.ModalResult := mrOK;
if Self.Equals(TSimbaButtonPanel(Parent).FButtonCancel) then
Form.ModalResult := mrCancel;

Form.Close();
end;

inherited Click();
end;

procedure TSimbaButtonPanel.DoButtonCancelResize(Sender: TObject);
begin
FButtonOk.Width := FButtonCancel.Width;
FButtonOk.Height := FButtonCancel.Height;
end;

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

Align := alBottom;
end;

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

FButtonOk := TButtonPanelButton.Create(Self);
FButtonOk.Parent := Self;
FButtonOk.Align := alRight;
FButtonOk.Caption := 'Ok';
FButtonOk.BorderSpacing.Around := 8;
FButtonOk.VertPadding := 10;
FButtonOk.AutoSize := False;
FButtonOk.SetOkGlpyh();

FButtonCancel := TButtonPanelButton.Create(Self);
FButtonCancel.Parent := Self;
FButtonCancel.Align := alRight;
FButtonCancel.Caption := 'Cancel';
FButtonCancel.BorderSpacing.Around := 8;
FButtonCancel.VertPadding := 10;
FButtonCancel.SetCloseGlyph();
FButtonCancel.OnResize := @DoButtonCancelResize;

Color := SimbaTheme.ColorFrame;

AutoSize := True;
end;

end.

31 changes: 27 additions & 4 deletions Source/components/simba.component_menubar.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ interface
simba.settings;

type
TPopupMenuArray = array of TPopupMenu;

TSimbaMainMenuBar = class(TCustomControl)
protected
FItems: array of record
Expand Down Expand Up @@ -45,17 +47,29 @@ TSimbaMainMenuBar = class(TCustomControl)
procedure DoMenuClose(Sender: TObject);

procedure MaybeReplaceModifiers(Menu: TPopupMenu);

function GetMenus: TPopupMenuArray;
public
constructor Create(AOwner: TComponent); override;

property Menus: TPopupMenuArray read GetMenus;
procedure AddMenu(Title: String; APopupMenu: TPopupMenu);
end;

implementation

uses
LMessages, LCLIntf,
simba.theme;
simba.theme, simba.fonthelpers;

function TSimbaMainMenuBar.GetMenus: TPopupMenuArray;
var
I: Integer;
begin
SetLength(Result, Length(FItems));
for I := 0 to High(Result) do
Result[I] := FItems[I].Menu;
end;

procedure TSimbaMainMenuBar.SetHotIndex(Index: Integer);
begin
Expand Down Expand Up @@ -132,23 +146,25 @@ procedure TSimbaMainMenuBar.CalculateSizes;
with TBitmap.Create() do
try
Canvas.Font := Self.Font;
Canvas.Font.Size := Round(Abs(GetFontData(Canvas.Font.Handle).Height) * 72 / Canvas.Font.PixelsPerInch) + 4; // Measure on larger font size - Font size can be 0
Canvas.Font.Size := GetFontSize(Self);

if (Length(FItems) > 0) then
begin
FItems[0].Rect.Top := 0;
FItems[0].Rect.Bottom := Self.Height;
FItems[0].Rect.Left := 5;
FItems[0].Rect.Right := FItems[0].Rect.Left + Canvas.TextWidth(FItems[0].Text);
FItems[0].Rect.Right := FItems[0].Rect.Left + Canvas.TextWidth(FItems[0].Text) + 10;

for I := 1 to High(FItems) do
begin
FItems[I].Rect.Top := 0;
FItems[I].Rect.Bottom := Self.Height;
FItems[I].Rect.Left := FItems[I-1].Rect.Right + 5;
FItems[I].Rect.Right := FItems[I].Rect.Left + Canvas.TextWidth(FItems[I].Text);
FItems[I].Rect.Right := FItems[I].Rect.Left + Canvas.TextWidth(FItems[I].Text) + 10;
end;
end;

Canvas.Font.Size := GetFontSize(Self, 3);
Self.Height := Canvas.TextHeight('Tay');
finally
Free();
Expand Down Expand Up @@ -271,7 +287,13 @@ constructor TSimbaMainMenuBar.Create(AOwner: TComponent);
end;

procedure TSimbaMainMenuBar.AddMenu(Title: String; APopupMenu: TPopupMenu);
var
I: Integer;
begin
for I := 0 to High(FItems) do
if (FItems[I].Menu = APopupMenu) then
Exit;

SetLength(FItems, Length(FItems) + 1);
FItems[High(FItems)].Text := Title;
FItems[High(FItems)].Menu := APopupMenu;
Expand All @@ -282,6 +304,7 @@ procedure TSimbaMainMenuBar.AddMenu(Title: String; APopupMenu: TPopupMenu);
{$ENDIF}

CalculateSizes();
Invalidate();
end;

end.
Expand Down
11 changes: 10 additions & 1 deletion Source/components/simba.component_synedit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ TSimbaSynEdit = class(TSynEdit)
procedure StatusChanged(AChanges: TSynStatusChanges); override;
procedure DoLineChanges(Sender: TSynEditStrings; aIndex, aCount: Integer);
procedure SetParent(NewParent: TWinControl); override;
procedure SetVisible(Value: Boolean); override;

function GetFontAntialising: Boolean;
procedure SetFontAntialising(Value: Boolean);
public
constructor Create(AOwner: TComponent); override;

// Hide gutters etc so the synedit acts more like the "memo" component.
// Hide gutters and such so the synedit acts more like the "memo" component.
procedure HideSynEditThings;
procedure ReplaceKeyStrokeModifiers(const Find, Replace: TShiftStateEnum);

Expand Down Expand Up @@ -116,6 +117,14 @@ procedure TSimbaSynEdit.SetParent(NewParent: TWinControl);
FScrollbarVert.Align := alRight;
end;

procedure TSimbaSynEdit.SetVisible(Value: Boolean);
begin
inherited SetVisible(Value);

FScrollbarHorz.Visible := Value;
FScrollbarVert.Visible := Value;
end;

constructor TSimbaSynEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Expand Down
10 changes: 9 additions & 1 deletion Source/components/simba.component_treeview.pas
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ TSimbaTreeView = class(TCustomControl)
procedure BeginUpdate;
procedure EndUpdate;
procedure Clear;
procedure ClearSelection;

procedure Invalidate; override;

Expand All @@ -122,7 +123,8 @@ TSimbaTreeView = class(TCustomControl)
implementation

uses
Math, simba.theme;
Math,
simba.theme, simba.main;

constructor TSimbaTreeView.Create(AOwner: TComponent; NodeClass: TTreeNodeClass);
var
Expand Down Expand Up @@ -171,6 +173,7 @@ constructor TSimbaTreeView.Create(AOwner: TComponent; NodeClass: TTreeNodeClass)
FTree.BackgroundColor := SimbaTheme.ColorBackground;
FTree.SelectionColor := SimbaTheme.ColorActive;
FTree.Font.Color := SimbaTheme.ColorFont;
FTree.Images := SimbaForm.Images;

FScrollbarVert.ForwardScrollControl := FTree;

Expand Down Expand Up @@ -238,6 +241,11 @@ procedure TSimbaTreeView.Clear;
FFilterEdit.Clear();
end;

procedure TSimbaTreeView.ClearSelection;
begin
FTree.ClearSelection();
end;

procedure TSimbaTreeView.Invalidate;
begin
inherited;
Expand Down
1 change: 1 addition & 0 deletions Source/forms/simba.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ TSimbaForm = class(TForm)
public
property WindowSelection: TWindowHandle read FWindowSelection;
property ProcessSelection: Integer read FProcessSelection;
property MenuBar: TSimbaMainMenuBar read FMenuBar;

procedure Setup(Data: PtrInt);
end;
Expand Down
Loading

0 comments on commit 1d08ca9

Please sign in to comment.