mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-05 18:15:57 +02:00
lcl: TCustomImage.StretchOutEnabled/StrechInEnabled, issue #29605, from Alexey Torgashin
git-svn-id: trunk@52955 -
This commit is contained in:
parent
8f3ff56888
commit
2a7d1a624a
@ -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;
|
||||
|
@ -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 := (PicWidth<ImgWidth) and (PicHeight<ImgHeight);
|
||||
PicOutside := (PicWidth>ImgWidth) 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
|
||||
|
Loading…
Reference in New Issue
Block a user