forked from Memnarch/Delphinus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDN.Controls.Button.pas
121 lines (108 loc) · 3.4 KB
/
DN.Controls.Button.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
{
#########################################################
# Copyright by Alexander Benikowski #
# This unit is part of the Delphinus project hosted on #
# https://github.com/Memnarch/Delphinus #
#########################################################
}
unit DN.Controls.Button;
interface
uses
Types,
Delphinus.UITypes,
Windows,
Graphics,
Math,
DN.Controls;
type
TDNButton = class(TDNControl)
private
FColor: TColor;
FEndColor: TColor;
FBorderColor: TColor;
FHoverColor: TColor;
FEndHoverColor: TColor;
FBorderHoverColor: TColor;
FHoverDownColor: TColor;
FEndHoverDownColor: TColor;
FBorderHoverDownColor: TColor;
FCaption: string;
procedure SetColor(const Value: TColor);
procedure SetHoverColor(const Value: TColor);
procedure SetCaption(const Value: string);
public
procedure PaintTo(ACanvas: TCanvas); override;
property Color: TColor read FColor write SetColor;
property HoverColor: TColor read FHoverColor write SetHoverColor;
property Caption: string read FCaption write SetCaption;
end;
implementation
uses
DN.Graphics;
const
CAlterForEnd = -10;
CAlterForBorder = -25;
CAlterDown = +10;
CAlterEndDown = -20;
CAlterEndForBorderDown = 0;
{ TDNButton }
procedure TDNButton.PaintTo(ACanvas: TCanvas);
var
LSize: TSize;
begin
inherited;
if dnsMouseIn in State then
begin
if dnsMouseLeft in State then
begin
GradientFillRectVertical(ACanvas, FHoverDownColor, FEndHoverDownColor, Rect(Left, Top, Left + Width, Top + Height));
ACanvas.Pen.Color := FBorderHoverDownColor;
ACanvas.Brush.Style := bsClear;
ACanvas.Rectangle(Left, Top, Left+Width, Top + Height);
end
else
begin
GradientFillRectVertical(ACanvas, FHoverColor, FEndHoverColor, Rect(Left, Top, Left + Width, Top + Height));
ACanvas.Pen.Color := FBorderHoverColor;
ACanvas.Brush.Style := bsClear;
ACanvas.Rectangle(Left, Top, Left+Width, Top + Height);
end;
end
else
begin
GradientFillRectVertical(ACanvas, FColor, FEndColor, Rect(Left, Top, Left + Width, Top + Height));
ACanvas.Pen.Color := FBorderColor;
ACanvas.Brush.Style := bsClear;
ACanvas.Rectangle(Left, Top, Left+Width, Top + Height);
end;
if Caption <> '' then
begin
LSize := ACanvas.TextExtent(Caption);
ACanvas.TextOut(Left + (Width - LSize.cx) div 2,
Top + (Height - LSize.cy) div 2, Caption);
end;
end;
procedure TDNButton.SetCaption(const Value: string);
begin
FCaption := Value;
Changed();
end;
procedure TDNButton.SetColor(const Value: TColor);
begin
FColor := Value;
FEndColor := AlterColor(FColor, CAlterForEnd);
FBorderColor := AlterColor(FColor, CAlterForBorder);
end;
procedure TDNButton.SetHoverColor(const Value: TColor);
begin
FHoverColor := Value;
FEndHoverColor := AlterColor(FHoverColor, CAlterForEnd);
FBorderHoverColor := AlterColor(FHoverColor, CAlterForBorder);
// FHoverDownColor := ALterColor(Value, CAlterDown);
// FEndHoverDownColor := AlterColor(FHoverDownColor, CAlterEndDown);
// FBorderHoverDownColor := AlterColor(FEndHoverDownColor, CAlterEndForBorderDown);
FHoverDownColor := FEndHoverColor;
FEndHoverDownColor := AlterColor(FHoverColor, CAlterDown);
FBorderHoverDownColor := FBorderHoverColor;
end;
end.