[fpc-devel] InflateRect() not cross-platform
Tiziano_mk
tizzziano at tiscali.it
Wed Jul 26 09:47:32 CEST 2006
Graeme Geldenhuys ha scritto:
> Hi,
>
> Any reason why there isn't a cross-platfrom InflateRect() function in
> the RTL? It only appears in the Windows API translations and is a
> very handly funtion to have.
>
> For those that don't know InflateRect():
> Usage:
> InflateRect(Rect, 1, 1);
> InflateRect(Rect, -2, -2);
>
> You can enlarge/shrink the X and Y co-ordinates of a TRect using this
> function.
>
> Regards,
> Graeme.
>
>
Maybe because it is trivial?
There are a lot of ways to implement and use such a function.
This was from JvUtils.PAS in the Project JEDI's JVCL:
function TrueInflateRect(const R: TRect; const I: Integer): TRect;
begin
with R do
SetRect(Result, Left - I, Top - I, Right + I, Bottom + I);
end;
but I prefer this one (tested on Delphi and Lazarus):
procedure inflateR(var r: trect; xy: array of integer);
begin
with r do
if high(xy)=0
then SetRect(R, Left - xy[0], Top - xy[0],
Right + xy[0], Bottom + xy[0])
else SetRect(R, Left - xy[0], Top - xy[0],
Right + xy[1], Bottom + xy[1]);
end;
Note that if you don't use the LCL also implement SetRect.
you can find another implementation in the LCL (winapi.inc) were you can
find other platofrm independent functions of this kind .
what do you prefer?
tiziano
More information about the fpc-devel
mailing list