This repository has been archived by the owner on Jun 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zgl_CLineWindowTitle.pas
90 lines (74 loc) · 2.21 KB
/
zgl_CLineWindowTitle.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
unit zgl_CLineWindowTitle;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
zgl_CLineWidget,
zgl_CLineStyle,
zgl_primitives_2d,
zgl_math_2d,
zgl_font,
zgl_text;
type
{ TWindowTitle }
TWindowTitle = class(TWidget)
public
constructor Create(const aOwner: TComponent);
procedure LoadStyle(const aStyle: PWindowStyle);
private
fBackgroundColor: LongWord;
fFontColor: LongWord;
fFont: zglPFont;
fTitle: string;
fRightText: string;
fHorizontalGap: single;
fVerticalGap: single;
const HeightMeasureStr = 'AZ';
public
property BackgroundColor: LongWord read fBackgroundColor write fBackgroundColor;
property FontColor: LongWord read fFontColor write fFontColor;
property Font: zglPFont read fFont write fFont;
property Title: string read fTitle write fTitle;
property RightText: string read fRightText write fRightText;
property HorizontalGap: single read fHorizontalGap write fHorizontalGap;
property VerticalGap: single read fVerticalGap write fVerticalGap;
procedure UpdateArea; override;
procedure Draw; override;
end;
implementation
uses
zgl_CLineWindow;
{ TWindowTitle }
constructor TWindowTitle.Create(const aOwner: TComponent);
begin
inherited Create(aOwner);
end;
procedure TWindowTitle.LoadStyle(const aStyle: PWindowStyle);
begin
BackgroundColor := aStyle^.TitleBackgroundColor;
Font := aStyle^.TitleFont;
HorizontalGap := aStyle^.HTitleGap;
VerticalGap := aStyle^.VTitleGap;
end;
procedure TWindowTitle.UpdateArea;
begin
fArea.H := text_GetHeight(Font, TGraphicalWindow(Parent).Area^.W, HeightMeasureStr);
fArea.H += 2*HorizontalGap;
end;
procedure TWindowTitle.Draw;
var
textRect: zglTRect;
begin
pr2d_Rect(fArea.X, fArea.Y, fArea.W, fArea.H, BackgroundColor, 255, PR2D_FILL);
textRect.X := fArea.X + HorizontalGap;
textRect.Y := fArea.Y + HorizontalGap;
textRect.W := fArea.W - 2*HorizontalGap;
textRect.H := fArea.H - 2*HorizontalGap;
text_DrawInRectEx(Font, textRect, 1, 0, Title, 255, FontColor,
TEXT_HALIGN_LEFT or TEXT_VALIGN_CENTER);
if RightText <> '' then
text_DrawInRectEx(Font, textRect, 1, 0, RightText, 255, FontColor,
TEXT_HALIGN_RIGHT or TEXT_VALIGN_CENTER);
end;
end.