mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-09 13:08:12 +02:00
- remove obsoleted code from TButtonGlyph.Draw
- dont shift speedbutton glyph in down state if it intersects border git-svn-id: trunk@13164 -
This commit is contained in:
parent
86b4a94077
commit
4db33cbc97
@ -81,6 +81,8 @@ type
|
||||
FNumGlyphs: TNumGlyphs;
|
||||
FOnChange: TNotifyEvent;
|
||||
FImagesCache: TImageListCache;
|
||||
function GetHeight: Integer;
|
||||
function GetWidth: Integer;
|
||||
procedure SetGlyph(Value: TBitmap);
|
||||
procedure SetNumGlyphs(Value: TNumGlyphs);
|
||||
protected
|
||||
@ -104,6 +106,8 @@ type
|
||||
property Glyph: TBitmap read FOriginal write SetGlyph;
|
||||
property NumGlyphs: TNumGlyphs read FNumGlyphs write SetNumGlyphs;
|
||||
property Images: TCustomImageList read FImages;
|
||||
property Width: Integer read GetWidth;
|
||||
property Height: Integer read GetHeight;
|
||||
public
|
||||
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
||||
end;
|
||||
|
@ -99,6 +99,22 @@ begin
|
||||
GlyphChanged(FOriginal);
|
||||
end;
|
||||
|
||||
function TButtonGlyph.GetHeight: Integer;
|
||||
begin
|
||||
if FImages <> nil then
|
||||
Result := FImages.Height
|
||||
else
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function TButtonGlyph.GetWidth: Integer;
|
||||
begin
|
||||
if FImages <> nil then
|
||||
Result := FImages.Width
|
||||
else
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
procedure TButtonGlyph.GlyphChanged(Sender: TObject);
|
||||
begin
|
||||
if FImagesCache <> nil then
|
||||
@ -126,56 +142,23 @@ function TButtonGlyph.Draw(Canvas: TCanvas; const Client: TRect;
|
||||
const Offset: TPoint; State: TButtonState; Transparent: Boolean;
|
||||
BiDiFlags: Longint): TRect;
|
||||
var
|
||||
gWidth: integer;
|
||||
gHeight: integer;
|
||||
DestRect, SrcRect: TRect;
|
||||
ImgID: integer;
|
||||
src_wh, dst_wh: Integer;
|
||||
AEffect: TGraphicsDrawEffect;
|
||||
begin
|
||||
Result := Client;
|
||||
if (FOriginal = nil) then
|
||||
exit;
|
||||
|
||||
gWidth := FOriginal.Width;
|
||||
gHeight := FOriginal.Height;
|
||||
|
||||
if (gWidth = 0) or (gHeight = 0) or
|
||||
if (Width = 0) or (Height = 0) or
|
||||
(Client.Left >= Client.Right) or (Client.Top >= Client.Bottom) then
|
||||
Exit;
|
||||
|
||||
if NumGlyphs > 1 then
|
||||
gWidth := gWidth div NumGlyphs;
|
||||
|
||||
GetImageIndexAndEffect(State, ImgID, AEffect);
|
||||
|
||||
SrcRect := Rect((ImgID * gWidth), 0, ((ImgID+1) * gWidth), gHeight);
|
||||
DestRect := Client;
|
||||
|
||||
Inc(DestRect.Left, Offset.X);
|
||||
src_wh := SrcRect.Right - SrcRect.Left;
|
||||
dst_wh := DestRect.Right - DestRect.Left;
|
||||
|
||||
if (dst_wh > src_wh) then
|
||||
DestRect.Right := DestRect.Left+src_wh // if window for image is wider
|
||||
else
|
||||
if (dst_wh < src_wh) then
|
||||
SrcRect.Right := SrcRect.Left + dst_wh; // if image not fits in their window width
|
||||
|
||||
Inc(DestRect.Top, Offset.Y);
|
||||
src_wh := SrcRect.Bottom - SrcRect.Top;
|
||||
dst_wh := DestRect.Bottom - DestRect.Top;
|
||||
|
||||
if (dst_wh > src_wh) then
|
||||
DestRect.Bottom := DestRect.Top + src_wh // if window for image is higher
|
||||
else
|
||||
if (dst_wh < src_wh) then
|
||||
SrcRect.Bottom := SrcRect.Top + dst_wh; // if image not fits in their window height
|
||||
|
||||
FImages.Draw(Canvas, DestRect.Left, DestRect.Top, ImgID, AEffect);
|
||||
FImages.Draw(Canvas, Client.Left + Offset.X, Client.Top + Offset.y, ImgID,
|
||||
AEffect);
|
||||
|
||||
// ToDo: VCL returns the text rectangle
|
||||
Result := SrcRect;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -587,7 +587,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
// todo: for Themed painting we need imagelist here. Wait for it implementation
|
||||
DrawGlyph(Canvas, PaintRect, Offset, FState, Transparent, 0);
|
||||
if FShowCaption and (Caption <> '') then
|
||||
begin
|
||||
@ -889,13 +888,22 @@ end;
|
||||
function TCustomSpeedButton.DrawGlyph(ACanvas: TCanvas; const AClient: TRect;
|
||||
const AOffset: TPoint; AState: TButtonState; ATransparent: Boolean;
|
||||
BiDiFlags: Longint): TRect;
|
||||
var
|
||||
NewOffset: TPoint;
|
||||
begin
|
||||
if Assigned(FGlyph) then
|
||||
begin
|
||||
if (AState = bsUp) and FMouseInControl then
|
||||
AState := bsExclusive;
|
||||
if (AState = bsDown) or (Down = true) then
|
||||
Result := FGlyph.Draw(ACanvas, AClient, point(AOffset.x + 1, AOffset.y + 1), AState, ATransparent, BiDiFlags)
|
||||
begin
|
||||
NewOffset := Point(AOffset.x + 1, AOffset.y + 1);
|
||||
if NewOffset.x + FGlyph.Width >= AClient.Right then
|
||||
NewOffset.x := AOffset.x;
|
||||
if NewOffset.y + FGlyph.Height >= AClient.Bottom then
|
||||
NewOffset.y := AOffset.y;
|
||||
Result := FGlyph.Draw(ACanvas, AClient, NewOffset, AState, ATransparent, BiDiFlags);
|
||||
end
|
||||
else
|
||||
Result := FGlyph.Draw(ACanvas, AClient, AOffset, AState, ATransparent, BiDiFlags);
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user