Debian Codegraph @

src/ui/castlecontrols_panel.inc

raw
1 {%MainUnit castlecontrols.pas}
2 {
3 Copyright 2010-2018 Michalis Kamburelis.
4
5 This file is part of "Castle Game Engine".
6
7 "Castle Game Engine" is free software; see the file COPYING.txt,
8 included in this distribution, for details about the copyright.
9
10 "Castle Game Engine" is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 ----------------------------------------------------------------------------
15 }
16
17 {$ifdef read_interface}
18
19 { Panel or a toolbar control.
20 Use as a background for other controls like buttons.
21 You can add vertical separators to separate groups of controls on the panel. }
22 TCastlePanel = class(TCastleUserInterface)
23 strict private
24 FVerticalSeparators: TSingleList;
25 public
26 constructor Create(AOwner: TComponent); override;
27 destructor Destroy; override;
28 procedure Render; override;
29
30 { Separator lines drawn on panel. Useful if you want to visually separate
31 groups of contols (like a groups of buttons when you use
32 this panel as a toolbar).
33
34 Values are the horizontal positions of the separators (with respect
35 to this panel @link(Left)). Width of the separator is in SeparatorSize. }
36 property VerticalSeparators: TSingleList read FVerticalSeparators;
37 class function SeparatorSize: Single;
38 end deprecated 'use TCastleHorizontalGroup';
39
40 {$endif read_interface}
41
42 {$ifdef read_implementation}
43
44 { TCastlePanel ------------------------------------------------------------------ }
45
46 constructor TCastlePanel.Create(AOwner: TComponent);
47 begin
48 inherited;
49 FVerticalSeparators := TSingleList.Create;
50 end;
51
52 destructor TCastlePanel.Destroy;
53 begin
54 FreeAndNil(FVerticalSeparators);
55 inherited;
56 end;
57
58 procedure TCastlePanel.Render;
59 const
60 SeparatorMargin = 8;
61 var
62 I: Integer;
63 SeparatorMarginScaled: Single;
64 SR: TFloatRectangle;
65 begin
66 inherited;
67
68 SR := RenderRect;
69 Theme.Draw(SR, tiPanel, UIScale);
70
71 SeparatorMarginScaled := SeparatorMargin * UIScale;
72 if SR.Height <= 2 * SeparatorMarginScaled then
73 Exit; // no space
74 for I := 0 to VerticalSeparators.Count - 1 do
75 Theme.Draw(FloatRectangle(
76 SR.Left + VerticalSeparators[I] * UIScale,
77 SR.Bottom + SeparatorMarginScaled,
78 Theme.ImagesPersistent[tiPanelSeparator].Width, SR.Height - 2 * SeparatorMarginScaled),
79 tiPanelSeparator, UIScale);
80 end;
81
82 class function TCastlePanel.SeparatorSize: Single;
83 begin
84 Result := 2;
85 end;
86
87 {$endif read_implementation}