ButtonGlyph:

- allow setting bigger glyphcount than 4 (limited by High(TGlyphCount)). current limit is 5
- clear imagelist and imageindexes after glyph change to prevent possible garbage drawing

git-svn-id: trunk@13295 -
This commit is contained in:
paul 2007-12-12 14:19:25 +00:00
parent 2665090c3d
commit d27b65a627
4 changed files with 19 additions and 8 deletions

View File

@ -87,6 +87,7 @@ type
function GetWidth: Integer; function GetWidth: Integer;
procedure SetGlyph(Value: TBitmap); procedure SetGlyph(Value: TBitmap);
procedure SetNumGlyphs(Value: TNumGlyphs); procedure SetNumGlyphs(Value: TNumGlyphs);
procedure ClearImages;
protected protected
// IUnknown // IUnknown
function QueryInterface(const iid: tguid; out obj): longint; stdcall; function QueryInterface(const iid: tguid; out obj): longint; stdcall;

View File

@ -148,11 +148,11 @@ end;
procedure TCustomBitBtn.SetNumGlyphs(AValue: Integer); procedure TCustomBitBtn.SetNumGlyphs(AValue: Integer);
begin begin
if AValue < 0 then AValue := 1; if AValue < 0 then AValue := 1;
if AValue > 4 then AValue := 4; if AValue > High(TNumGlyphs) then AValue := High(TNumGlyphs);
if AValue <> FButtonGlyph.NumGlyphs then if AValue <> FButtonGlyph.NumGlyphs then
Begin Begin
FButtonGlyph.NumGlyphs := TNumGlyphs(AValue); FButtonGlyph.NumGlyphs := TNumGlyphs(AValue);
Invalidate; Invalidate;
end; end;
end; end;

View File

@ -95,10 +95,10 @@ begin
begin begin
if FOriginal.Width mod FOriginal.Height = 0 then if FOriginal.Width mod FOriginal.Height = 0 then
begin begin
GlyphCount:= FOriginal.Width div FOriginal.Height; GlyphCount := FOriginal.Width div FOriginal.Height;
if GlyphCount > 4 then if GlyphCount > High(TNumGlyphs) then
GlyphCount:= 1; GlyphCount := Low(TNumGlyphs);
FNumGlyphs:= TNumGlyphs(GlyphCount); FNumGlyphs := TNumGlyphs(GlyphCount);
end; end;
end; end;
GlyphChanged(FOriginal); GlyphChanged(FOriginal);
@ -126,6 +126,7 @@ begin
begin begin
FImagesCache.UnregisterListener(Self); FImagesCache.UnregisterListener(Self);
FImagesCache := nil; // cache can free on unregister FImagesCache := nil; // cache can free on unregister
ClearImages;
end; end;
if (FOriginal.Width > 0) and (FOriginal.Height > 0) then if (FOriginal.Width > 0) and (FOriginal.Height > 0) then
@ -179,6 +180,15 @@ begin
end; end;
end; end;
procedure TButtonGlyph.ClearImages;
var
i: TButtonState;
begin
FImages := nil;
for i := Low(TButtonState) to High(TButtonState) do
FImageIndexes[i] := -1;
end;
function TButtonGlyph.QueryInterface(const iid: tguid; out obj): longint; stdcall; function TButtonGlyph.QueryInterface(const iid: tguid; out obj): longint; stdcall;
begin begin
if GetInterface(iid, obj) then if GetInterface(iid, obj) then

View File

@ -238,11 +238,11 @@ end;
procedure TCustomSpeedButton.SetNumGlyphs(Value : integer); procedure TCustomSpeedButton.SetNumGlyphs(Value : integer);
Begin Begin
if Value < 0 then Value := 1; if Value < 0 then Value := 1;
if Value > 4 then Value := 4; if Value > High(TNumGlyphs) then Value := High(TNumGlyphs);
if Value <> TButtonGlyph(fGlyph).NumGlyphs then if Value <> TButtonGlyph(fGlyph).NumGlyphs then
Begin Begin
TButtonGlyph(fGlyph).NumGlyphs := TNumGlyphs(Value); TButtonGlyph(fGlyph).NumGlyphs := TNumGlyphs(Value);
Invalidate; Invalidate;
end; end;
end; end;