diff --git a/source/Vcl.ButtonStylesAttributes.pas b/source/Vcl.ButtonStylesAttributes.pas index eb20abf..2a91307 100644 --- a/source/Vcl.ButtonStylesAttributes.pas +++ b/source/Vcl.ButtonStylesAttributes.pas @@ -1607,6 +1607,8 @@ procedure CalcImageAndTextRect(const ASurfaceRect: TRect; IW, IH, IX, IY: Integer; LImageAlignment: TImageAlignment; begin + //Calculate Image and Text Rect for Drawing using ImageAlignment and ImageMargins + //for StyledButton and StyledGraphicButton if ACaption = '' then LImageAlignment := iaCenter else @@ -1722,6 +1724,8 @@ procedure CalcImageAndTextRect(const ACanvas: TCanvas; LLayout: TButtonLayout; LMargin, LSpacing: Integer; begin + //Calculate Image and Text Rect for Drawing using ButtonLayout, Margin and Spacing + //For StyledSpeedButton and StyledBitBtn LLayout := ALayout; if (ABiDiFlags and DT_RIGHT) = DT_RIGHT then begin @@ -1835,7 +1839,8 @@ procedure CalcImageAndTextRect(const ACanvas: TCanvas; Inc(AGlyphPos.X, ASurfaceRect.Left + AOffset.X); Inc(AGlyphPos.Y, ASurfaceRect.Top + AOffset.Y); - OffsetRect(ATextBounds, LTextPos.X + ASurfaceRect.Left + AOffset.X, LTextPos.Y + ASurfaceRect.Top + AOffset.Y); + OffsetRect(ATextBounds, LTextPos.X + ASurfaceRect.Left + AOffset.X, + LTextPos.Y + ASurfaceRect.Top + AOffset.Y); end; procedure DrawIconFromCommandLinkRes(ACanvas: TCanvas; ARect: TRect; @@ -2044,7 +2049,7 @@ procedure DrawButtonText(const ACanvas: TCanvas; const PreserveBorders: Boolean = True); var R: TRect; - OldBKMode: Integer; + LOldBKMode: Integer; begin (* for test ACanvas.Brush.Color := clYellow; @@ -2065,7 +2070,7 @@ procedure DrawButtonText(const ACanvas: TCanvas; else OffsetRect(R, (ARect.Width - R.Width) div 2, (ARect.Height - R.Height) div 2); end; - OldBKMode := SetBkMode(ACanvas.Handle, Winapi.Windows.TRANSPARENT); + LOldBKMode := SetBkMode(ACanvas.Handle, Winapi.Windows.TRANSPARENT); try if PreserveBorders then begin @@ -2075,13 +2080,13 @@ procedure DrawButtonText(const ACanvas: TCanvas; R.Top := ARect.Top + ABorderWidth + ASpacing ; if R.Bottom > ARect.Bottom - ABorderWidth - Aspacing then R.Bottom := ARect.Bottom - ABorderWidth - Aspacing; - (* for test - ACanvas.Brush.Color := clRed; - ACanvas.FillRect(R); - ACanvas.Pen.Color := clBlue; - ACanvas.Pen.Width := 1; - ACanvas.Rectangle(R); - *) + (* for test + ACanvas.Brush.Color := clRed; + ACanvas.FillRect(R); + ACanvas.Pen.Color := clBlue; + ACanvas.Pen.Width := 1; + ACanvas.Rectangle(R); + *) Winapi.Windows.DrawText(ACanvas.Handle, PChar(AText), Length(AText), R, ABidiFlags or DT_END_ELLIPSIS); end @@ -2097,7 +2102,7 @@ procedure DrawButtonText(const ACanvas: TCanvas; Length(AText), R, ABidiFlags); end; finally - SetBkMode(ACanvas.Handle, OldBKMode); + SetBkMode(ACanvas.Handle, LOldBKMode); end; end; diff --git a/source/Vcl.StyledButton.pas b/source/Vcl.StyledButton.pas index 6e69ac6..f420b26 100644 --- a/source/Vcl.StyledButton.pas +++ b/source/Vcl.StyledButton.pas @@ -1506,7 +1506,7 @@ TStyledBitBtn = class(TCustomStyledButton) property ModalResult; property NotificationBadge; property NumGlyphs; - property Style: TButtonStyle read FStyle write FStyle; + property Style: TButtonStyle read FStyle write FStyle default bsAutoDetect; property Spacing default 4; property TabOrder; property TabStop; @@ -2654,6 +2654,7 @@ procedure TStyledButtonRender.DrawCaptionAndImage(const ACanvas: TCanvas; LUseImageList: Boolean; LGlyphPos: TPoint; LCaption: TCaption; + LOldBKMode, LMaxBorderWidth: Integer; begin if FShowCaption then LCaption := GetCaptionToDraw @@ -2785,8 +2786,24 @@ procedure TStyledButtonRender.DrawCaptionAndImage(const ACanvas: TCanvas; end; end else - DrawButtonText(ACanvas, LCaption, FCaptionAlignment, FSpacing, CalcMaxBorderWidth, - LTextRect, LTextFlags); + begin + LMaxBorderWidth := CalcMaxBorderWidth; + if FUseButtonLayout then + begin + LOldBKMode := SetBkMode(ACanvas.Handle, Winapi.Windows.TRANSPARENT); + try + Winapi.Windows.DrawText(ACanvas.Handle, PChar(LCaption), + Length(LCaption), LTextRect, LTextFlags or DT_END_ELLIPSIS); + finally + SetBkMode(ACanvas.Handle, LOldBKMode); + end; + end + else + begin + DrawButtonText(ACanvas, LCaption, FCaptionAlignment, FSpacing, LMaxBorderWidth, + LTextRect, LTextFlags); + end; + end; end; procedure TStyledButtonRender.DrawButton(const ACanvas: TCanvas; @@ -6311,6 +6328,7 @@ procedure TCustomStyledButton.WMPaint(var Message: TMessage); constructor TStyledBitBtn.Create(AOwner: TComponent); begin inherited Create(AOwner); + FStyle := bsAutoDetect; FRender.FUseButtonLayout := True; FRender.Spacing := 4; end;