mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 04:29:28 +02:00
LCL: TImage: TImageList support (properties Images, ImageIndex and ImageWidth)
This commit is contained in:
parent
6a416779cd
commit
a7d0453a6e
@ -503,6 +503,9 @@ type
|
|||||||
TCustomImage = class(TGraphicControl)
|
TCustomImage = class(TGraphicControl)
|
||||||
private
|
private
|
||||||
FAntialiasingMode: TAntialiasingMode;
|
FAntialiasingMode: TAntialiasingMode;
|
||||||
|
FImageIndex: Integer;
|
||||||
|
FImages: TCustomImageList;
|
||||||
|
FImageWidth: Integer;
|
||||||
FOnPictureChanged: TNotifyEvent;
|
FOnPictureChanged: TNotifyEvent;
|
||||||
FOnPaintBackground: TImagePaintBackgroundEvent;
|
FOnPaintBackground: TImagePaintBackgroundEvent;
|
||||||
FPicture: TPicture;
|
FPicture: TPicture;
|
||||||
@ -517,7 +520,11 @@ type
|
|||||||
FUseAncestorCanvas: boolean;
|
FUseAncestorCanvas: boolean;
|
||||||
FPainting: boolean;
|
FPainting: boolean;
|
||||||
function GetCanvas: TCanvas;
|
function GetCanvas: TCanvas;
|
||||||
|
function GetHasGraphic: Boolean;
|
||||||
procedure SetAntialiasingMode(AValue: TAntialiasingMode);
|
procedure SetAntialiasingMode(AValue: TAntialiasingMode);
|
||||||
|
procedure SetImageIndex(const AImageIndex: Integer);
|
||||||
|
procedure SetImages(const AImages: TCustomImageList);
|
||||||
|
procedure SetImageWidth(const AImageWidth: Integer);
|
||||||
procedure SetPicture(const AValue: TPicture);
|
procedure SetPicture(const AValue: TPicture);
|
||||||
procedure SetCenter(const AValue : Boolean);
|
procedure SetCenter(const AValue : Boolean);
|
||||||
procedure SetKeepOriginX(AValue: Boolean);
|
procedure SetKeepOriginX(AValue: Boolean);
|
||||||
@ -541,6 +548,7 @@ type
|
|||||||
property Canvas: TCanvas read GetCanvas;
|
property Canvas: TCanvas read GetCanvas;
|
||||||
function DestRect: TRect; virtual;
|
function DestRect: TRect; virtual;
|
||||||
procedure Invalidate; override;
|
procedure Invalidate; override;
|
||||||
|
property HasGraphic: Boolean read GetHasGraphic; // has either a picture or valid image from imagelist
|
||||||
public
|
public
|
||||||
property AntialiasingMode: TAntialiasingMode read FAntialiasingMode write SetAntialiasingMode default amDontCare;
|
property AntialiasingMode: TAntialiasingMode read FAntialiasingMode write SetAntialiasingMode default amDontCare;
|
||||||
property Align;
|
property Align;
|
||||||
@ -549,6 +557,9 @@ type
|
|||||||
property KeepOriginXWhenClipped: Boolean read FKeepOriginXWhenClipped write SetKeepOriginX default False;
|
property KeepOriginXWhenClipped: Boolean read FKeepOriginXWhenClipped write SetKeepOriginX default False;
|
||||||
property KeepOriginYWhenClipped: Boolean read FKeepOriginYWhenClipped write SetKeepOriginY default False;
|
property KeepOriginYWhenClipped: Boolean read FKeepOriginYWhenClipped write SetKeepOriginY default False;
|
||||||
property Constraints;
|
property Constraints;
|
||||||
|
property ImageIndex: Integer read FImageIndex write SetImageIndex default 0;
|
||||||
|
property ImageWidth: Integer read FImageWidth write SetImageWidth default 0; // a specific width for the image from Images
|
||||||
|
property Images: TCustomImageList read FImages write SetImages;
|
||||||
property Picture: TPicture read FPicture write SetPicture;
|
property Picture: TPicture read FPicture write SetPicture;
|
||||||
property Visible;
|
property Visible;
|
||||||
property OnClick;
|
property OnClick;
|
||||||
@ -586,6 +597,9 @@ type
|
|||||||
property DragCursor;
|
property DragCursor;
|
||||||
property DragMode;
|
property DragMode;
|
||||||
property Enabled;
|
property Enabled;
|
||||||
|
property ImageIndex;
|
||||||
|
property ImageWidth;
|
||||||
|
property Images;
|
||||||
property OnChangeBounds;
|
property OnChangeBounds;
|
||||||
property OnClick;
|
property OnClick;
|
||||||
property OnContextPopup;
|
property OnContextPopup;
|
||||||
|
@ -135,6 +135,27 @@ begin
|
|||||||
PictureChanged(Self);
|
PictureChanged(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomImage.SetImageIndex(const AImageIndex: Integer);
|
||||||
|
begin
|
||||||
|
if FImageIndex = AImageIndex then Exit;
|
||||||
|
FImageIndex := AImageIndex;
|
||||||
|
PictureChanged(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomImage.SetImages(const AImages: TCustomImageList);
|
||||||
|
begin
|
||||||
|
if FImages = AImages then Exit;
|
||||||
|
FImages := AImages;
|
||||||
|
PictureChanged(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomImage.SetImageWidth(const AImageWidth: Integer);
|
||||||
|
begin
|
||||||
|
if FImageWidth = AImageWidth then Exit;
|
||||||
|
FImageWidth := AImageWidth;
|
||||||
|
PictureChanged(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomImage.SetProportional(const AValue: Boolean);
|
procedure TCustomImage.SetProportional(const AValue: Boolean);
|
||||||
begin
|
begin
|
||||||
if FProportional = AValue then exit;
|
if FProportional = AValue then exit;
|
||||||
@ -144,24 +165,26 @@ end;
|
|||||||
|
|
||||||
procedure TCustomImage.PictureChanged(Sender : TObject);
|
procedure TCustomImage.PictureChanged(Sender : TObject);
|
||||||
begin
|
begin
|
||||||
if Picture.Graphic <> nil
|
if HasGraphic then
|
||||||
then begin
|
begin
|
||||||
if AutoSize
|
if AutoSize then
|
||||||
then begin
|
begin
|
||||||
InvalidatePreferredSize;
|
InvalidatePreferredSize;
|
||||||
AdjustSize;
|
AdjustSize;
|
||||||
end;
|
end;
|
||||||
Picture.Graphic.Transparent := FTransparent;
|
if Assigned(Picture.Graphic) then
|
||||||
|
Picture.Graphic.Transparent := FTransparent;
|
||||||
end;
|
end;
|
||||||
invalidate;
|
Invalidate;
|
||||||
if Assigned(OnPictureChanged) then
|
if Assigned(OnPictureChanged) then
|
||||||
OnPictureChanged(Self);
|
OnPictureChanged(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomImage.DestRect: TRect;
|
function TCustomImage.DestRect: TRect;
|
||||||
var
|
var
|
||||||
PicWidth: Integer;
|
PicSize: TSize;
|
||||||
PicHeight: Integer;
|
PicWidth: Integer absolute PicSize.Width;
|
||||||
|
PicHeight: Integer absolute PicSize.Height;
|
||||||
ImgWidth: Integer;
|
ImgWidth: Integer;
|
||||||
ImgHeight: Integer;
|
ImgHeight: Integer;
|
||||||
w: Integer;
|
w: Integer;
|
||||||
@ -169,8 +192,13 @@ var
|
|||||||
ChangeX, ChangeY: Integer;
|
ChangeX, ChangeY: Integer;
|
||||||
PicInside, PicOutside, PicOutsidePartial: boolean;
|
PicInside, PicOutside, PicOutsidePartial: boolean;
|
||||||
begin
|
begin
|
||||||
PicWidth := Picture.Width;
|
if Assigned(Picture.Graphic) then
|
||||||
PicHeight := Picture.Height;
|
PicSize := TSize.Create(Picture.Width, Picture.Height)
|
||||||
|
else
|
||||||
|
if Assigned(Images) then
|
||||||
|
PicSize := Images.SizeForPPI[ImageWidth, Font.PixelsPerInch]
|
||||||
|
else
|
||||||
|
Exit(TRect.Create(0, 0, 0, 0));
|
||||||
ImgWidth := ClientWidth;
|
ImgWidth := ClientWidth;
|
||||||
ImgHeight := ClientHeight;
|
ImgHeight := ClientHeight;
|
||||||
if (PicWidth=0) or (PicHeight=0) then Exit(Rect(0, 0, 0, 0));
|
if (PicWidth=0) or (PicHeight=0) then Exit(Rect(0, 0, 0, 0));
|
||||||
@ -217,9 +245,20 @@ end;
|
|||||||
|
|
||||||
procedure TCustomImage.CalculatePreferredSize(var PreferredWidth,
|
procedure TCustomImage.CalculatePreferredSize(var PreferredWidth,
|
||||||
PreferredHeight: integer; WithThemeSpace: Boolean);
|
PreferredHeight: integer; WithThemeSpace: Boolean);
|
||||||
|
var
|
||||||
|
S: TSize;
|
||||||
begin
|
begin
|
||||||
PreferredWidth := Picture.Width;
|
if Assigned(Picture.Graphic) then
|
||||||
PreferredHeight := Picture.Height;
|
begin
|
||||||
|
PreferredWidth := Picture.Width;
|
||||||
|
PreferredHeight := Picture.Height;
|
||||||
|
end else
|
||||||
|
if Assigned(Images) then
|
||||||
|
begin
|
||||||
|
S := Images.SizeForPPI[ImageWidth, Font.PixelsPerInch];
|
||||||
|
PreferredWidth := S.Width;
|
||||||
|
PreferredHeight := S.Height;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCustomImage.GetControlClassDefaultSize: TSize;
|
class function TCustomImage.GetControlClassDefaultSize: TSize;
|
||||||
@ -228,6 +267,11 @@ begin
|
|||||||
Result.CY := 90;
|
Result.CY := 90;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCustomImage.GetHasGraphic: Boolean;
|
||||||
|
begin
|
||||||
|
Result := Assigned(Picture.Graphic) or (Assigned(Images) and (ImageIndex>=0));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomImage.Paint;
|
procedure TCustomImage.Paint;
|
||||||
|
|
||||||
procedure DrawFrame;
|
procedure DrawFrame;
|
||||||
@ -254,8 +298,8 @@ begin
|
|||||||
if csDesigning in ComponentState
|
if csDesigning in ComponentState
|
||||||
then DrawFrame;
|
then DrawFrame;
|
||||||
|
|
||||||
if Picture.Graphic = nil
|
if not HasGraphic then
|
||||||
then Exit;
|
Exit;
|
||||||
|
|
||||||
C := inherited Canvas;
|
C := inherited Canvas;
|
||||||
R := DestRect;
|
R := DestRect;
|
||||||
@ -264,7 +308,12 @@ begin
|
|||||||
try
|
try
|
||||||
if Assigned(FOnPaintBackground) then
|
if Assigned(FOnPaintBackground) then
|
||||||
FOnPaintBackground(Self, C, R);
|
FOnPaintBackground(Self, C, R);
|
||||||
C.StretchDraw(R, Picture.Graphic);
|
|
||||||
|
if Assigned(Picture.Graphic) then
|
||||||
|
C.StretchDraw(R, Picture.Graphic)
|
||||||
|
else
|
||||||
|
if Assigned(Images) and (ImageIndex>=0) then
|
||||||
|
Images.StretchDraw(C, ImageIndex, R);
|
||||||
finally
|
finally
|
||||||
FPainting:=false;
|
FPainting:=false;
|
||||||
end;
|
end;
|
||||||
|
@ -683,7 +683,7 @@ var
|
|||||||
Par: TWinControl;
|
Par: TWinControl;
|
||||||
Panel: TPanel;
|
Panel: TPanel;
|
||||||
CurrTabOrder: TTabOrder;
|
CurrTabOrder: TTabOrder;
|
||||||
Image: TImageListImage;
|
Image: TImage;
|
||||||
List: TStrings;
|
List: TStrings;
|
||||||
B: TCommonButton;
|
B: TCommonButton;
|
||||||
CommandLink: TBitBtn;
|
CommandLink: TBitBtn;
|
||||||
@ -878,7 +878,7 @@ begin
|
|||||||
|
|
||||||
if (LCL_IMAGES[aDialogIcon]<>0) then
|
if (LCL_IMAGES[aDialogIcon]<>0) then
|
||||||
begin
|
begin
|
||||||
Image := TImageListImage.Create(Dialog.Form);
|
Image := TImage.Create(Dialog.Form);
|
||||||
Image.Parent := Par;
|
Image.Parent := Par;
|
||||||
Image.Images := GetDialogImages;
|
Image.Images := GetDialogImages;
|
||||||
Image.ImageIndex := GetDialogImages.DialogIndexes[LCL_IMAGES[aDialogIcon]];
|
Image.ImageIndex := GetDialogImages.DialogIndexes[LCL_IMAGES[aDialogIcon]];
|
||||||
@ -1076,7 +1076,7 @@ begin
|
|||||||
inc(Y,16);
|
inc(Y,16);
|
||||||
if (LCL_FOOTERIMAGES[aFooterIcon]<>0) then
|
if (LCL_FOOTERIMAGES[aFooterIcon]<>0) then
|
||||||
begin
|
begin
|
||||||
Image := TImageListImage.Create(Dialog.Form);
|
Image := TImage.Create(Dialog.Form);
|
||||||
Image.Parent := Par;
|
Image.Parent := Par;
|
||||||
Image.Images := GetDialogImages;
|
Image.Images := GetDialogImages;
|
||||||
Image.ImageWidth := 16;
|
Image.ImageWidth := 16;
|
||||||
|
Loading…
Reference in New Issue
Block a user