You've already forked lazarus-ccr
ExCtrls: PaintButton method.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7483 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -102,6 +102,7 @@ type
|
|||||||
function GetDrawTextFlags: Cardinal;
|
function GetDrawTextFlags: Cardinal;
|
||||||
procedure MouseEnter; override;
|
procedure MouseEnter; override;
|
||||||
procedure MouseLeave; override;
|
procedure MouseLeave; override;
|
||||||
|
procedure PaintButton;
|
||||||
procedure PaintCustomButton;
|
procedure PaintCustomButton;
|
||||||
procedure PaintThemedButton;
|
procedure PaintThemedButton;
|
||||||
procedure WMKillFocus(var Message: TLMKillFocus); message LM_KILLFOCUS;
|
procedure WMKillFocus(var Message: TLMKillFocus); message LM_KILLFOCUS;
|
||||||
@@ -394,67 +395,12 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TButtonEx.PaintThemedButton;
|
procedure TButtonEx.PaintButton;
|
||||||
var
|
|
||||||
btn: TThemedButton;
|
|
||||||
details: TThemedElementDetails;
|
|
||||||
lRect: TRect;
|
|
||||||
flags: Cardinal;
|
|
||||||
txtSize: TSize;
|
|
||||||
txtPt: TPoint;
|
|
||||||
begin
|
begin
|
||||||
if (csDestroying in ComponentState) or not HandleAllocated then
|
if FDefaultDrawing then
|
||||||
exit;
|
PaintThemedButton
|
||||||
|
|
||||||
lRect.Left := 0;
|
|
||||||
lRect.Right := Width;
|
|
||||||
lRect.Top := 0;
|
|
||||||
lRect.Bottom := Height;
|
|
||||||
|
|
||||||
if FState = bxsDisabled then
|
|
||||||
btn := tbPushButtonDisabled
|
|
||||||
else if FState = bxsDown then
|
|
||||||
btn := tbPushButtonPressed
|
|
||||||
else if FState = bxsHot then
|
|
||||||
btn := tbPushButtonHot
|
|
||||||
else
|
else
|
||||||
if Focused or Default then
|
PaintCustomButton;
|
||||||
btn := tbPushButtonDefaulted
|
|
||||||
else
|
|
||||||
btn := tbPushButtonNormal;
|
|
||||||
|
|
||||||
// Background
|
|
||||||
details := ThemeServices.GetElementDetails(btn);
|
|
||||||
InflateRect(lRect, 1, 1);
|
|
||||||
ThemeServices.DrawElement(FCanvas.Handle, details, lRect);
|
|
||||||
InflateRect(lRect, -1, -1);
|
|
||||||
|
|
||||||
// Text
|
|
||||||
FCanvas.Font.Assign(Font);
|
|
||||||
flags := GetDrawTextFlags;
|
|
||||||
|
|
||||||
with ThemeServices.GetTextExtent(FCanvas.Handle, details, Caption, flags, @lRect) do begin
|
|
||||||
txtSize.CX := Right;
|
|
||||||
txtSize.CY := Bottom;
|
|
||||||
end;
|
|
||||||
|
|
||||||
case FAlignment of
|
|
||||||
taLeftJustify:
|
|
||||||
if IsRightToLeft then
|
|
||||||
txtPt.X := Width - txtSize.CX - FMargin
|
|
||||||
else
|
|
||||||
txtPt.X := FMargin;
|
|
||||||
taRightJustify:
|
|
||||||
if IsRightToLeft then
|
|
||||||
txtPt.X := FMargin
|
|
||||||
else
|
|
||||||
txtPt.X := Width - txtSize.CX - FMargin;
|
|
||||||
taCenter:
|
|
||||||
txtPt.X := (Width - txtSize.CX) div 2;
|
|
||||||
end;
|
|
||||||
txtPt.Y := (Height + 1 - txtSize.CY) div 2;
|
|
||||||
lRect := Rect(txtPt.X, txtPt.Y, txtPt.X + txtSize.CX, txtPt.Y + txtSize.CY);
|
|
||||||
ThemeServices.DrawText(FCanvas, details, Caption, lRect, flags, 0);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TButtonEx.PaintCustomButton;
|
procedure TButtonEx.PaintCustomButton;
|
||||||
@@ -528,10 +474,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
lRect.Left := 0;
|
lRect := Rect(0, 0, Width, Height);
|
||||||
lRect.Right := Width;
|
|
||||||
lRect.Top := 0;
|
|
||||||
lRect.Bottom := Height;
|
|
||||||
|
|
||||||
if FGradient then
|
if FGradient then
|
||||||
lCanvas.GradientFill(lRect, lColorFrom, lColorTo, gdVertical)
|
lCanvas.GradientFill(lRect, lColorFrom, lColorTo, gdVertical)
|
||||||
@@ -598,6 +541,66 @@ begin
|
|||||||
lBitmap.Free;
|
lBitmap.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TButtonEx.PaintThemedButton;
|
||||||
|
var
|
||||||
|
btn: TThemedButton;
|
||||||
|
details: TThemedElementDetails;
|
||||||
|
lRect: TRect;
|
||||||
|
flags: Cardinal;
|
||||||
|
txtSize: TSize;
|
||||||
|
txtPt: TPoint;
|
||||||
|
begin
|
||||||
|
if (csDestroying in ComponentState) or not HandleAllocated then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
lRect := Rect(0, 0, Width, Height);
|
||||||
|
|
||||||
|
if FState = bxsDisabled then
|
||||||
|
btn := tbPushButtonDisabled
|
||||||
|
else if FState = bxsDown then
|
||||||
|
btn := tbPushButtonPressed
|
||||||
|
else if FState = bxsHot then
|
||||||
|
btn := tbPushButtonHot
|
||||||
|
else
|
||||||
|
if Focused or Default then
|
||||||
|
btn := tbPushButtonDefaulted
|
||||||
|
else
|
||||||
|
btn := tbPushButtonNormal;
|
||||||
|
|
||||||
|
// Background
|
||||||
|
details := ThemeServices.GetElementDetails(btn);
|
||||||
|
InflateRect(lRect, 1, 1);
|
||||||
|
ThemeServices.DrawElement(FCanvas.Handle, details, lRect);
|
||||||
|
InflateRect(lRect, -1, -1);
|
||||||
|
|
||||||
|
// Text
|
||||||
|
FCanvas.Font.Assign(Font);
|
||||||
|
flags := GetDrawTextFlags;
|
||||||
|
|
||||||
|
with ThemeServices.GetTextExtent(FCanvas.Handle, details, Caption, flags, @lRect) do begin
|
||||||
|
txtSize.CX := Right;
|
||||||
|
txtSize.CY := Bottom;
|
||||||
|
end;
|
||||||
|
|
||||||
|
case FAlignment of
|
||||||
|
taLeftJustify:
|
||||||
|
if IsRightToLeft then
|
||||||
|
txtPt.X := Width - txtSize.CX - FMargin
|
||||||
|
else
|
||||||
|
txtPt.X := FMargin;
|
||||||
|
taRightJustify:
|
||||||
|
if IsRightToLeft then
|
||||||
|
txtPt.X := FMargin
|
||||||
|
else
|
||||||
|
txtPt.X := Width - txtSize.CX - FMargin;
|
||||||
|
taCenter:
|
||||||
|
txtPt.X := (Width - txtSize.CX) div 2;
|
||||||
|
end;
|
||||||
|
txtPt.Y := (Height + 1 - txtSize.CY) div 2;
|
||||||
|
lRect := Rect(txtPt.X, txtPt.Y, txtPt.X + txtSize.CX, txtPt.Y + txtSize.CY);
|
||||||
|
ThemeServices.DrawText(FCanvas, details, Caption, lRect, flags, 0);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TButtonEx.SetAlignment(const Value: TAlignment);
|
procedure TButtonEx.SetAlignment(const Value: TAlignment);
|
||||||
begin
|
begin
|
||||||
if FAlignment = Value then
|
if FAlignment = Value then
|
||||||
@@ -669,10 +672,7 @@ end;
|
|||||||
procedure TButtonEx.WMPaint(var Msg: TLMPaint);
|
procedure TButtonEx.WMPaint(var Msg: TLMPaint);
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
if FDefaultDrawing then
|
PaintButton;
|
||||||
PaintThemedButton
|
|
||||||
else
|
|
||||||
PaintCustomButton;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TButtonEx.WndProc(var Message: TLMessage);
|
procedure TButtonEx.WndProc(var Message: TLMessage);
|
||||||
|
Reference in New Issue
Block a user