LCL: TBitBtn: implemented NumGlyphs from Giuliano Colla

git-svn-id: trunk@12467 -
This commit is contained in:
mattias 2007-10-14 22:23:19 +00:00
parent 8ff0a64f6e
commit 18fa72e639
2 changed files with 48 additions and 6 deletions

View File

@ -103,7 +103,8 @@ type
FLayout: TButtonLayout;
FMargin: integer;
FSpacing: Integer;
Function GetGlyph: TBitmap;
FMultiGlyph: TBitmap;
function GetGlyph: TBitmap;
function GetNumGlyphs: Integer;
Function IsGlyphStored: Boolean;
Procedure SetGlyph(AValue: TBitmap);
@ -113,7 +114,7 @@ type
procedure SetNumGlyphs(AValue: Integer);
Procedure SetSpacing(AValue: Integer);
procedure RealizeKind;
procedure DrawGlyph;
//Return the caption associated with the aKind value.
function GetCaptionOfKind(aKind: TBitBtnKind): String;
protected

View File

@ -39,6 +39,7 @@ end;
destructor TCustomBitBtn.Destroy;
Begin
FreeThenNil(FButtonGlyph);
FreeThenNil(FMultiGlyph);
inherited Destroy;
end;
@ -83,7 +84,14 @@ end;
procedure TCustomBitBtn.GlyphChanged(Sender: TObject);
begin
if HandleAllocated
then TWSBitBtnClass(WidgetSetClass).SetGlyph(Self, Glyph);
then begin
if NumGlyphs > 1 then begin
DrawGlyph;
TWSBitBtnClass(WidgetSetClass).SetGlyph(Self, FMultiGlyph);
end
else
TWSBitBtnClass(WidgetSetClass).SetGlyph(Self, Glyph);
end;
InvalidatePreferredSize;
AdjustSize;
end;
@ -220,6 +228,34 @@ begin
end;
end;
procedure TCustomBitBtn.DrawGlyph;
var
AGlyphRect: TRect;
AOffset: TPoint;
AState :TButtonState;
begin
if FButtonGlyph.FOriginal = nil then exit;
AOffset.X:= 0;
AOffset.Y:= 0;
AGlyphRect.Left :=0;
AGlyphRect.Top := 0;
AGlyphRect.Bottom:= FButtonGlyph.Glyph.Height;
if NumGlyphs > 1 then
AGlyphRect.Right:= FButtonGlyph.Glyph.Width div NumGlyphs
else
AGlyphRect.Right:= FButtonGlyph.Glyph.Width;
if FMultiGlyph =nil then FMultiGlyph := TBitmap.Create;
FMultiGlyph.Height:=AGlyphRect.Bottom;
FMultiGlyph.Width:=AGlyphRect.Right;
FMultiGlyph.Canvas.Brush.Color:=Color;
FMultiGlyph.Canvas.FillRect(AGlyphRect);
if Enabled then AState := bsUp
else AState := bsDisabled;
FButtonGlyph.Draw(FMultiGlyph.Canvas,AGlyphRect,AOffset,AState,True,0);
end;
{ Return the caption associated with the akind value.
This function replaces BitBtnCaption const because the localizing
dont work with an const array }
@ -244,9 +280,14 @@ end;
procedure TCustomBitBtn.InitializeWnd;
begin
inherited;
TWSBitBtnClass(WidgetSetClass).SetGlyph(Self, Glyph);
TWSBitBtnClass(WidgetSetClass).SetLayout(Self, FLayout);
inherited InitializeWnd;
if NumGlyphs > 1 then begin
DrawGlyph;
TWSBitBtnClass(WidgetSetClass).SetGlyph(Self, FMultiGlyph);
end
else
TWSBitBtnClass(WidgetSetClass).SetGlyph(Self, Glyph);
TWSBitBtnClass(WidgetSetClass).SetLayout(Self, FLayout);
TWSBitBtnClass(WidgetSetClass).SetMargin(Self, FMargin);
TWSBitBtnClass(WidgetSetClass).SetSpacing(Self, FSpacing);
end;