summaryrefslogtreecommitdiff
path: root/src/corelib
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graemeg@gmail.com>2013-07-12 11:42:31 +0100
committerGraeme Geldenhuys <graemeg@gmail.com>2013-07-12 11:42:31 +0100
commit7a41980dd5764124dbf1443615e67e54dfe0e4de (patch)
treecf2b51208cbfc1df2f2d5d61f525a6a2149622f4 /src/corelib
parent7984379dec66f66ea67ee4db4c3cdf692f56bbf1 (diff)
downloadfpGUI-7a41980dd5764124dbf1443615e67e54dfe0e4de.tar.xz
New Rectangle and Point methods introduced in fpg_main
* Moved PtInRect() to fpg_main, from fpg_base * New Rect and Point utility functions introduced in fpg_main
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/fpg_base.pas11
-rw-r--r--src/corelib/fpg_main.pas124
2 files changed, 109 insertions, 26 deletions
diff --git a/src/corelib/fpg_base.pas b/src/corelib/fpg_base.pas
index 4f99d11e..11f3a78c 100644
--- a/src/corelib/fpg_base.pas
+++ b/src/corelib/fpg_base.pas
@@ -1,7 +1,7 @@
{
fpGUI - Free Pascal GUI Toolkit
- Copyright (C) 2006 - 2010 See the file AUTHORS.txt, included in this
+ Copyright (C) 2006 - 2013 See the file AUTHORS.txt, included in this
distribution, for details of the copyright.
See the file COPYING.modifiedLGPL, included in this distribution,
@@ -777,7 +777,6 @@ function fpgLighter(const AColor: TfpgColor; APercent: Byte = 50): TfpgColor;
{ Points }
-function PtInRect(const ARect: TfpgRect; const APoint: TPoint): Boolean;
procedure SortRect(var ARect: TRect);
procedure SortRect(var ARect: TfpgRect);
procedure SortRect(var left, top, right, bottom: integer);
@@ -1102,14 +1101,6 @@ begin
Result := RGBTripleTofpgColor(lColor);
end;
-function PtInRect(const ARect: TfpgRect; const APoint: TPoint): Boolean;
-begin
- Result := (APoint.x >= ARect.Left) and
- (APoint.y >= ARect.Top) and
- (APoint.x <= ARect.Right) and
- (APoint.y <= ARect.Bottom);
-end;
-
procedure SortRect(var ARect: TRect);
begin
with ARect do
diff --git a/src/corelib/fpg_main.pas b/src/corelib/fpg_main.pas
index 8aa5f95a..c037617c 100644
--- a/src/corelib/fpg_main.pas
+++ b/src/corelib/fpg_main.pas
@@ -1,7 +1,7 @@
{
fpGUI - Free Pascal GUI Toolkit
- Copyright (C) 2006 - 2012 See the file AUTHORS.txt, included in this
+ Copyright (C) 2006 - 2013 See the file AUTHORS.txt, included in this
distribution, for details of the copyright.
See the file COPYING.modifiedLGPL, included in this distribution,
@@ -392,10 +392,15 @@ function fpgGetTickCount: DWord;
procedure fpgPause(MilliSeconds: Cardinal);
// Rectangle, Point & Size routines
+function CopyRect(out Dest: TfpgRect; const Src: TfpgRect): Boolean;
function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
function InflateRect(var Rect: TfpgRect; dx: Integer; dy: Integer): Boolean;
+function IntersectRect(out ARect: TfpgRect; const r1, r2: TfpgRect): Boolean;
+function IsRectEmpty(const ARect: TfpgRect): Boolean;
function OffsetRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
function OffsetRect(var Rect: TfpgRect; dx: Integer; dy: Integer): Boolean;
+function PtInRect(const ARect: TfpgRect; const APoint: TPoint): Boolean;
+function UniongRect(out ARect: TfpgRect; const R1, R2: TfpgRect): Boolean;
function CenterPoint(const Rect: TRect): TPoint;
function CenterPoint(const Rect: TfpgRect): TPoint;
function fpgRect(ALeft, ATop, AWidth, AHeight: integer): TfpgRect;
@@ -419,11 +424,12 @@ procedure DebugLn(const s1, s2: TfpgString);
procedure DebugLn(const s1, s2, s3: TfpgString);
procedure DebugLn(const s1, s2, s3, s4: TfpgString);
procedure DebugLn(const s1, s2, s3, s4, s5: TfpgString);
-function DebugMethodEnter(const s1: TfpgString): IInterface;
+function DebugMethodEnter(const s1: TfpgString): IInterface;
procedure DebugSeparator;
// operator overloading of some useful structures
-operator = (a: TRect; b: TRect): boolean;
+operator = (const a, b: TRect): boolean;
+operator = (const a, b: TfpgRect): boolean;
operator = (const ASize1, ASize2: TfpgSize) b: Boolean;
operator = (const APoint1, APoint2: TPoint) b: Boolean;
operator + (const APoint1, APoint2: TPoint) p: TPoint;
@@ -443,7 +449,8 @@ operator - (const APoint: TfpgPoint; i: Integer) p: TfpgPoint;
operator - (const ASize: TfpgSize; const APoint: TPoint) s: TfpgSize;
operator - (const ASize: TfpgSize; const APoint: TfpgPoint) s: TfpgSize;
operator - (const ASize: TfpgSize; i: Integer) s: TfpgSize;
-operator = (const AColor1, AColor2: TFPColor) b: Boolean;
+operator = (const AColor1, AColor2: TFPColor) b: Boolean; deprecated;
+operator = (const AColor1, AColor2: TRGBTriple) b: Boolean;
implementation
@@ -618,6 +625,17 @@ begin
until ((Now*MSecsPerDay)-lStart) > MilliSeconds;
end;
+function CopyRect(out Dest: TfpgRect; const Src: TfpgRect): Boolean;
+begin
+ Dest := Src;
+ if IsRectEmpty(Dest) then
+ begin
+ FillChar(Dest, SizeOf(Dest), 0);
+ Result := false;
+ end
+ else
+ Result := true;
+end;
function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
begin
@@ -650,6 +668,35 @@ begin
Result := False;
end;
+function IntersectRect(out ARect: TfpgRect; const r1, r2: TfpgRect): Boolean;
+begin
+ ARect := r1;
+ with r2 do
+ begin
+ if Left > r1.Left then
+ ARect.Left := Left;
+ if Top > r1.Top then
+ ARect.Top := Top;
+ if Right < r1.Right then
+ ARect.Width := ARect.Left + Right;
+ if Bottom < r1.Bottom then
+ ARect.Height := ARect.Top + Bottom;
+ end;
+
+ if IsRectEmpty(ARect) then
+ begin
+ FillChar(ARect, SizeOf(ARect), 0);
+ Result := false;
+ end
+ else
+ Result := true;
+end;
+
+function IsRectEmpty(const ARect: TfpgRect): Boolean;
+begin
+ Result := (ARect.Width <= 0) or (ARect.Height <= 0);
+end;
+
function OffsetRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
begin
if Assigned(@Rect) then
@@ -661,10 +708,10 @@ begin
inc(Right, dx);
inc(Bottom, dy);
end;
- OffsetRect := True;
+ Result := True;
end
else
- OffsetRect := False;
+ Result := False;
end;
function OffsetRect(var Rect: TfpgRect; dx: Integer; dy: Integer): Boolean;
@@ -676,10 +723,42 @@ begin
inc(Left, dx);
inc(Top, dy);
end;
- OffsetRect := True;
+ Result := True;
+ end
+ else
+ Result := False;
+end;
+
+function PtInRect(const ARect: TfpgRect; const APoint: TPoint): Boolean;
+begin
+ Result := (APoint.x >= ARect.Left) and
+ (APoint.y >= ARect.Top) and
+ (APoint.x <= ARect.Right) and
+ (APoint.y <= ARect.Bottom);
+end;
+
+function UniongRect(out ARect: TfpgRect; const R1, R2: TfpgRect): Boolean;
+begin
+ ARect := R1;
+ with R2 do
+ begin
+ if Left < R1.Left then
+ ARect.Left := Left;
+ if Top < R1.Top then
+ ARect.Top := Top;
+ if Right > R1.Right then
+ ARect.Width := ARect.Left + Right;
+ if Bottom > R1.Bottom then
+ ARect.Height := ARect.Top + Bottom;
+ end;
+
+ if IsRectEmpty(ARect) then
+ begin
+ FillChar(ARect, SizeOf(ARect), 0);
+ Result := false;
end
else
- OffsetRect := False;
+ Result := true;
end;
function CenterPoint(const Rect: TRect): TPoint;
@@ -954,15 +1033,20 @@ begin
DebugLn('>--------------------------<');
end;
-operator = (a: TRect; b: TRect): boolean;
+operator = (const a, b: TRect): boolean;
begin
- if (a.Top = b.Top)
- and (a.Left = b.Left)
- and (a.Bottom = b.Bottom)
- and (a.Right = b.Right) then
- Result := True
- else
- Result := False;
+ Result := (a.Top = b.Top) and
+ (a.Left = b.Left) and
+ (a.Bottom = b.Bottom) and
+ (a.Right = b.Right);
+end;
+
+operator = (const a, b: TfpgRect): boolean;
+begin
+ Result := (a.Left = b.Left) and
+ (a.Top = b.Top) and
+ (a.Width = b.Width) and
+ (a.Height = b.Height);
end;
operator = (const ASize1, ASize2: TfpgSize) b: Boolean;
@@ -1085,6 +1169,14 @@ begin
and (AColor1.Alpha = AColor2.Alpha);
end;
+operator = (const AColor1, AColor2: TRGBTriple) b: Boolean;
+begin
+ b := (AColor1.Red = AColor2.Red)
+ and (AColor1.Green = AColor2.Green)
+ and (AColor1.Blue = AColor2.Blue)
+ and (AColor1.Alpha = AColor2.Alpha);
+end;
+
{ TfpgTimer }
constructor TfpgTimer.Create(AInterval: integer);