diff --git a/lcl/extctrls.pp b/lcl/extctrls.pp index 4491a7c1ab..713bc54148 100644 --- a/lcl/extctrls.pp +++ b/lcl/extctrls.pp @@ -494,6 +494,8 @@ type FProportional: Boolean; FTransparent: Boolean; FStretch: Boolean; + FStretchOutEnabled: Boolean; + FStretchInEnabled: Boolean; FUseAncestorCanvas: boolean; FPainting: boolean; function GetCanvas: TCanvas; @@ -504,6 +506,8 @@ type procedure SetKeepOriginY(AValue: Boolean); procedure SetProportional(const AValue: Boolean); procedure SetStretch(const AValue : Boolean); + procedure SetStretchInEnabled(AValue: Boolean); + procedure SetStretchOutEnabled(AValue: Boolean); procedure SetTransparent(const AValue : Boolean); protected class procedure WSRegisterClass; override; @@ -539,6 +543,8 @@ type property OnMouseWheelDown; property OnMouseWheelUp; property Stretch: Boolean read FStretch write SetStretch default False; + property StretchOutEnabled: Boolean read FStretchOutEnabled write SetStretchOutEnabled default True; + property StretchInEnabled: Boolean read FStretchInEnabled write SetStretchInEnabled default True; property Transparent: Boolean read FTransparent write SetTransparent default False; property Proportional: Boolean read FProportional write SetProportional default False; property OnPictureChanged: TNotifyEvent read FOnPictureChanged write FOnPictureChanged; @@ -587,6 +593,8 @@ type property Proportional; property ShowHint; property Stretch; + property StretchOutEnabled; + property StretchInEnabled; property Transparent; property Visible; end; diff --git a/lcl/include/customimage.inc b/lcl/include/customimage.inc index ea17513e62..2f9113afbb 100644 --- a/lcl/include/customimage.inc +++ b/lcl/include/customimage.inc @@ -20,6 +20,8 @@ begin FKeepOriginYWhenClipped := False; FProportional := False; FStretch := False; + FStretchOutEnabled := True; + FStretchInEnabled := True; FTransparent := False; FPicture := TPicture.Create; FPicture.OnChange := @PictureChanged; @@ -97,6 +99,20 @@ begin PictureChanged(Self); end; +procedure TCustomImage.SetStretchInEnabled(AValue: Boolean); +begin + if FStretchInEnabled = AValue then Exit; + FStretchInEnabled := AValue; + PictureChanged(Self); +end; + +procedure TCustomImage.SetStretchOutEnabled(AValue: Boolean); +begin + if FStretchOutEnabled = AValue then Exit; + FStretchOutEnabled := AValue; + PictureChanged(Self); +end; + procedure TCustomImage.SetTransparent(const AValue : Boolean); begin if FTransparent = AValue then exit; @@ -151,30 +167,37 @@ var w: Integer; h: Integer; ChangeX, ChangeY: Integer; + PicInside, PicOutside, PicOutsidePartial: boolean; begin PicWidth := Picture.Width; PicHeight := Picture.Height; ImgWidth := ClientWidth; ImgHeight := ClientHeight; - if Stretch or (Proportional - and ((PicWidth > ImgWidth) or (PicHeight > ImgHeight))) then begin - if Proportional and (PicWidth > 0) and (PicHeight > 0) then begin - w:=ImgWidth; - h:=(PicHeight*w) div PicWidth; - if h>ImgHeight then begin - h:=ImgHeight; - w:=(PicWidth*h) div PicHeight; - end; - PicWidth:=w; - PicHeight:=h; - end - else begin - PicWidth := ImgWidth; - PicHeight := ImgHeight; - end; - end; + if (PicWidth=0) or (PicHeight=0) then Exit(Rect(0, 0, 0, 0)); - Result:=Rect(0,0,PicWidth,PicHeight); + PicInside := (PicWidthImgWidth) and (PicHeight>ImgHeight); + PicOutsidePartial := (PicWidth>ImgWidth) or (PicHeight>ImgHeight); + + if Stretch or (Proportional and PicOutsidePartial) then + if (FStretchOutEnabled or PicOutside) and + (FStretchInEnabled or PicInside) then + if Proportional then begin + w:=ImgWidth; + h:=(PicHeight*w) div PicWidth; + if h>ImgHeight then begin + h:=ImgHeight; + w:=(PicWidth*h) div PicHeight; + end; + PicWidth:=w; + PicHeight:=h; + end + else begin + PicWidth := ImgWidth; + PicHeight := ImgHeight; + end; + + Result := Rect(0, 0, PicWidth, PicHeight); if Center then begin