cxgeometry.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,071 行 · 第 1/3 页
PAS
1,071 行
function cxRectRotate(const R: TRect): TRect;
begin
Result := Rect(R.Top, R.Left, R.Bottom, R.Right);
end;
function cxRectPtInEx(const R: TRect; X, Y, Delta: Integer): TcxPtInRectType;
begin
Result := cxRectPtInEx(R, X, Y, Delta, Delta, Delta, Delta);
end;
function cxRectPtInEx(const R: TRect;
X, Y, DeltaX, DeltaY: Integer): TcxPtInRectType;
begin
Result := cxRectPtInEx(R, X, Y, DeltaX, DeltaY, DeltaX, DeltaY);
end;
function cxRect(const Left, Top, Right, Bottom: Integer): TRect;
begin
Result.Left := Left;
Result.Top := Top;
Result.Right := Right;
Result.Bottom := Bottom;
end;
function cxRect(const TopLeft, BottomRight: TPoint): TRect;
begin
Result.TopLeft := TopLeft;
Result.BottomRight := BottomRight;
end;
function cxRectAdjust(const R: TRect): TRect;
begin
with R do
Result := Rect(Min(Left, Right), Min(Top, Bottom), Max(Left, Right), Max(Top, Bottom));
end;
function cxRectBounds(Left, Top, Width, Height: Integer): TRect;
begin
Result.Left := Left;
Result.Top := Top;
Result.Right := Left + Width;
Result.Bottom := Top + Height;
end;
function cxRectRightTop(const R: TRect): TPoint;
begin
Result := cxPoint(R.Right, R.Top);
end;
function cxRectScaleHeight(const R: TRect; Y1, Y2, H1, H2: Integer): TRect;
var
H: Integer;
begin
Result := R;
with Result do
begin
H := MulDiv(Bottom - Top, H2, H1);
Top := MulDiv(Y1 - Top, H2, H1) + Y2;
Bottom := Top + H;
end;
end;
function cxRectScaleWidth(const R: TRect; X1, X2, W1,
W2: Integer): TRect;
var
L: Integer;
begin
Result := R;
with Result do
begin
L := MulDiv(Right - Left, W2, W1);
Left := MulDiv(X1 - Left, W2, W1) + X2;
Right := Left + L;
end;
end;
function cxRectSetBottom(const R: TRect; Y: Integer): TRect;
begin
Result := cxRectSetBottom(R, Y, R.Bottom - R.Top);
end;
function cxRectSetBottom(const R: TRect; Y, H: Integer): TRect;
begin
Result := R;
Result.Bottom := Y;
Result.Top := Y - H;
end;
function cxRectSetHeight(const R: TRect; H: Integer): TRect;
begin
Result := R;
Result.Bottom := Result.Top + H;
end;
function cxRectSetLeft(const R: TRect; X: Integer): TRect;
begin
Result := cxRectSetLeft(R, X, R.Right - R.Left);
end;
function cxRectSetLeft(const R: TRect; X, W: Integer): TRect;
begin
Result := R;
Result.Left := X;
Result.Right := X + W;
end;
function cxRectSetTop(const R: TRect; Y: Integer): TRect;
begin
Result := cxRectSetTop(R, Y, R.Bottom - R.Top);
end;
function cxRectSetTop(const R: TRect; Y, H: Integer): TRect;
begin
Result := R;
Result.Top := Y;
Result.Bottom := Y + H;
end;
function cxRectSetRight(const R: TRect; X: Integer): TRect;
begin
Result := cxRectSetRight(R, X, R.Right - R.Left);
end;
function cxRectSetRight(const R: TRect; X, W: Integer): TRect;
begin
Result := R;
Result.Right := X;
Result.Left := X - W;
end;
function cxRectSetSize(const R: TRect; W, H: Integer): TRect;
begin
Result := R;
with R do
begin
Result.Right := Left + W;
Result.Bottom := Top + H;
end;
end;
function cxRectSetWidth(const R: TRect; W: Integer): TRect;
begin
Result := R;
Result.Right := R.Left + W;
end;
function cxRectSetWidth(const R: TRect; X, W: Integer): TRect;
begin
Result := R;
Result.Left := X;
Result.Right := X + W;
end;
function cxRectSetXPos(const R: TRect; X1, X2: Integer): TRect;
begin
with R do
Result := cxRect(X1, Top, X2, Bottom);
end;
function cxRectSetYPos(const R: TRect; Y1, Y2: Integer): TRect;
begin
with R do
Result := cxRect(Left, Y1, Right, Y2);
end;
function cxRectSize(const R: TRect): TSize;
begin
with R do
begin
Result.cx := Right - Left;
Result.cy := Bottom - Top;
end;
end;
procedure cxRectSplitHorz(const ABounds: TRect; var ARect1, ARect2: TRect);
begin
ARect1 := ABounds;
ARect2 := ABounds;
ARect1.Right := (ABounds.Right + ABounds.Left) div 2;
ARect2.Left := ARect1.Right;
end;
procedure cxRectSplitVert(const ABounds: TRect; var ARect1, ARect2: TRect);
begin
ARect1 := ABounds;
ARect2 := ABounds;
ARect1.Bottom := (ABounds.Bottom + ABounds.Top) div 2;
ARect2.Top := ARect1.Bottom;
end;
function cxRectUnion(const R1, R2: TRect): TRect;
begin
Result := R1;
if (R2.Right - R2.Left <= 0) or (R2.Bottom - R2.Top <= 0) then Exit;
if R2.Left < R1.Left then
Result.Left := R2.Left;
if R2.Top < R1.Top then
Result.Top := R2.Top;
if R2.Right > R1.Right then
Result.Right := R2.Right;
if R2.Bottom > R1.Bottom then
Result.Bottom := R2.Bottom;
end;
function cxRectWidth(const R: TRect): Integer;
begin
Result := R.Right - R.Left;
end;
function cxRectCompare(const R1, R2: TRect): Boolean;
begin
Result := cxRectIsEqual(R1, R2);
end;
function cxRectCenter(const R: TRect): TPoint;
begin
with R do
Result := cxPoint((Right + Left) div 2, (Bottom + Top) div 2);
end;
function cxRectCenter(const Bounds: TRect; const ASize: TSize): TRect;
begin
Result := cxRectCenter(Bounds, ASize.cx, ASize.cy)
end;
function cxRectCenter(const Bounds: TRect; Width, Height: Integer): TRect;
begin
with Bounds do
begin
Result.Left := (Left + Right - Width) div 2;
Result.Top := (Top + Bottom - Height) div 2;
Result.Right := Result.Left + Width;
Result.Bottom := Result.Top + Height;
end;
end;
function cxRectContain(const ABounds, AInner: TRect): Boolean;
begin
with ABounds do
Result := (Left <= AInner.Left) and (Right >= AInner.Right) and
(Top <= AInner.Top) and (Bottom >= AInner.Bottom);
end;
function cxRectContent(const R, Margins: TRect): TRect;
begin
with Result do
begin
Left := R.Left + Margins.Left;
Top := R.Top + Margins.Top;
Right := R.Right - Margins.Right;
Bottom := R.Bottom - Margins.Bottom;
end;
end;
function cxPointInvert(const P: TPoint): TPoint;
begin
Result.X := -P.X;
Result.Y := -P.Y;
end;
function cxPointIsEqual(const P1, P2: TPoint): Boolean;
begin
Result := (P1.X = P2.X) and (P1.Y = P2.Y);
end;
function cxPointIsNull(const P: TPoint): Boolean;
begin
Result := (P.X = cxNullPoint.X) and (P.Y = cxNullPoint.Y);
end;
function cxPointGetItem(const P: TPoint; AIndex: Integer): Integer;
begin
if AIndex = 0 then
Result := P.X
else
Result := P.Y;
end;
function cxPointOffset(const P: TPoint; const Ps: array of TPoint): TPoint;
begin
with cxPointSum(Ps) do
Result := cxPointOffset(P, X, Y);
end;
function cxPointOffset(const P: TPoint; X, Y: Integer): TPoint;
begin
Result.X := P.X + X;
Result.Y := P.Y + Y;
end;
function cxPointReplaceItem(const P: TPoint; const AIndex, AValue: Integer): TPoint;
begin
if AIndex = 0 then
Result.X := AValue
else
Result.Y := AValue;
end;
function cxPoint(X, Y: Integer): TPoint;
begin
Result.X := X;
Result.Y := Y;
end;
function cxPoint(const ASize: TSize): TPoint;
begin
with Result do
begin
X := ASize.cx;
Y := ASize.cy;
end;
end;
function cxPointOffset(const P, DP: TPoint): TPoint;
begin
Result := cxPointOffset(P, DP.X, DP.Y);
end;
function cxPointSum(const Ps: array of TPoint): TPoint;
var
I: Integer;
begin
if Length(Ps) >= 1 then
begin
Result := Ps[Low(Ps)];
for I := Low(Ps) + 1 to High(Ps) do
with Ps[I] do
begin
Inc(Result.X, X);
Inc(Result.Y, Y);
end;
end
else
Result := cxNullPoint;
end;
function cxSize(DX, DY: Integer): TSize;
begin
Result.cx := DX;
Result.cy := DY;
end;
function cxSizeIsEqual(const S1, S2: TSize): Boolean;
begin
Result := (S1.cx = S2.cx) and (S1.cy = S2.cy);
end;
initialization
RegisterClasses([TcxRect]);
finalization
UnregisterClasses([TcxRect]);
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?