mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 16:49:07 +02:00
* Patch from Eric Grange to correct TRectF.FitInto
This commit is contained in:
parent
4b04608a44
commit
cbbba25198
@ -1690,20 +1690,37 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TRectF.FitInto(const Dest: TRectF; out Ratio: Single): TRectF;
|
function TRectF.FitInto(const Dest: TRectF; out Ratio: Single): TRectF;
|
||||||
|
var
|
||||||
|
dw, dh, w, h : Single;
|
||||||
begin
|
begin
|
||||||
if (Dest.Width<=0) or (Dest.Height<=0) then
|
dw := Dest.Width;
|
||||||
|
dh := Dest.Height;
|
||||||
|
if (dw <= 0) or (dh <= 0) then
|
||||||
begin
|
begin
|
||||||
Ratio:=1.0;
|
Ratio := 1.0;
|
||||||
exit(Self);
|
exit(Self);
|
||||||
end;
|
end;
|
||||||
Ratio:=Max(Self.Width / Dest.Width, Self.Height / Dest.Height);
|
|
||||||
if Ratio=0 then
|
w := Self.Width;
|
||||||
|
h := Self.Height;
|
||||||
|
|
||||||
|
if w * dh > h * dw then
|
||||||
|
Ratio := w / dw
|
||||||
|
else
|
||||||
|
Ratio := h / dh;
|
||||||
|
|
||||||
|
if Ratio = 0 then
|
||||||
exit(Self);
|
exit(Self);
|
||||||
Result.Width:=Self.Width / Ratio;
|
|
||||||
Result.Height:=Self.Height / Ratio;
|
w := w / Ratio;
|
||||||
|
h := h / Ratio;
|
||||||
|
|
||||||
// Center the result within the Dest rectangle
|
// Center the result within the Dest rectangle
|
||||||
Result.Left:=Dest.Left + (Dest.Width - Result.Width) / 2;
|
Result.Left := (Dest.Left + Dest.Right - w) * 0.5;
|
||||||
Result.Top:=Dest.Top + (Dest.Height - Result.Height) / 2;
|
Result.Right := Result.Left + w;
|
||||||
|
|
||||||
|
Result.Top := (Dest.Top + Dest.Bottom - h) * 0.5;
|
||||||
|
Result.Bottom := Result.Top + h;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TRectF.FitInto(const Dest: TRectF): TRectF;
|
function TRectF.FitInto(const Dest: TRectF): TRectF;
|
||||||
|
Loading…
Reference in New Issue
Block a user