rect.h
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:12k
- /*
- * rect.h
- *
- * Rectangle class.
- *
- * Portable Windows Library
- *
- * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Portable Windows Library.
- *
- * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
- *
- * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- * $Log: rect.h,v $
- * Revision 1.20 1999/03/10 03:49:53 robertj
- * More documentation adjustments.
- *
- * Revision 1.19 1999/03/09 08:01:49 robertj
- * Changed comments for doc++ support (more to come).
- *
- * Revision 1.18 1999/02/16 08:08:46 robertj
- * MSVC 6.0 compatibility changes.
- *
- * Revision 1.17 1998/09/23 06:28:47 robertj
- * Added open source copyright license.
- *
- * Revision 1.16 1995/06/17 11:13:14 robertj
- * Documentation update.
- *
- * Revision 1.15 1995/03/14 12:42:24 robertj
- * Updated documentation to use HTML codes.
- *
- * Revision 1.14 1995/02/22 10:50:35 robertj
- * Changes required for compiling release (optimised) version.
- *
- * Revision 1.13 1995/01/14 06:19:28 robertj
- * Documentation
- *
- * Revision 1.12 1994/12/05 11:20:31 robertj
- * Removed Normalise() function from PRect as all rectangles should be inherently normal.
- *
- * Revision 1.11 1994/08/23 11:32:52 robertj
- * Oops
- *
- * Revision 1.10 1994/08/22 00:46:48 robertj
- * Added pragma fro GNU C++ compiler.
- *
- * Revision 1.9 1994/06/25 11:55:15 robertj
- * Unix version synchronisation.
- *
- * Revision 1.8 1994/03/07 07:38:19 robertj
- * Major enhancementsacross the board.
- *
- * Revision 1.7 1994/01/03 04:42:23 robertj
- * Mass changes to common container classes and interactors etc etc etc.
- *
- * Revision 1.6 1993/12/31 06:45:38 robertj
- * Made inlines optional for debugging purposes.
- *
- * Revision 1.5 1993/12/29 04:40:47 robertj
- * Mac port.
- *
- * Revision 1.4 1993/11/20 17:26:28 robertj
- * Made real point structure private and added operators to get at pointers.
- *
- * Revision 1.3 1993/07/14 12:49:16 robertj
- * Fixed RCS keywords.
- *
- */
- #define _PRECT
- #ifdef __GNUC__
- #pragma interface
- #endif
- /**This class defines a rectangle in the drawing plane. A rectangle is defined
- by two points on the plane. A rectangle is always "normalised". That is
- the left is always less then the right and the top is always less than the
- bottom.
- */
- class PRect : public PObject
- {
- PCLASSINFO(PRect, PObject);
- public:
- /** Create a rectangle given the top left corner and width and height. */
- PRect(
- PORDINATE x = 0, /// Horizontal position of the rectangle.
- PORDINATE y = 0, /// Vertical position of the rectangle.
- PDIMENSION dx = 0, /// Width of the rectangle.
- PDIMENSION dy = 0 /// Height of the rectangle.
- );
- /** Create a rectangle at 0,0 and the dimensions specified. */
- PRect(
- const PDim & dim /// Dimensions of the rectangle.
- );
- /**Create a rectangle given the 2 points as opposite corners. Note that
- the top left corner of the rectangle may not be either of these points
- as it is normalised so that left is less than right and top is less
- than bottom.
- */
- PRect(
- const PPoint & p1, /// First corner of rectangle.
- const PPoint & p2 /// Second, opposite, corner of rectangle.
- );
- /** Create a rectangle given the top left corner and dimensions. */
- PRect(
- const PPoint & topLeft, /// Top left corner ofthe rectangle.
- const PDim & dim /// Dimensions of the rectangle.
- );
- /**@name Overrides from class PObject */
- /**Create a new copy of the rectangle. Note that it is the responsibility
- of the caller to delete the object.
-
- @return
- a new rectangle on the heap.
- */
- virtual PObject * Clone() const;
- /**Determine if the two rectangles are identical. A rectangle is identical
- if the origin and dimensions are the same.
- @return
- #EqualTo# if the rectangles are the same, otherwise returns
- #GreaterThan#.
- */
- virtual Comparison Compare(
- const PObject & obj /// Another rectangle object to comapre against.
- ) const;
- /**@name New functions for class */
- /**Get the top side of the rectangle.
- @return
- Y value of the top of the rectagle.
- */
- PORDINATE Top() const;
- /**Get the left side of the rectangle.
- @return
- X value of the left of the rectagle.
- */
- PORDINATE Left() const;
-
- /**Get the bottom side of the rectangle.
- @return
- Y value of the bottom of the rectagle.
- */
- PORDINATE Bottom() const;
-
- /**Get the right side of the rectangle.
- @return
- X value of the right of the rectagle.
- */
- PORDINATE Right() const;
-
- /**Get the horizontal position of the origin of the rectangle.
- @return
- X value of the left of the rectagle.
- */
- PORDINATE X() const;
-
- /**Get the vertical position of the origin of the rectangle.
- @return
- Y value of the top of the rectagle.
- */
- PORDINATE Y() const;
-
- /**Get the horizontal dimension of the rectagle.
- @return
- width of the rectagle.
- */
- PDIMENSION Width() const;
-
- /**Get the vertical dimension of the rectagle.
- @return
- height of the rectagle.
- */
- PDIMENSION Height() const;
-
- /**Set the Y value of the top of the rectagle. Note that this does not
- change the bottom of the rectangle so the height will change.
- */
- void SetTop(
- PORDINATE top /// New top for rectangle.
- );
- /**Set the X value of the left of the rectagle. Note that this does not
- change the right of the rectangle so the width will change.
- */
- void SetLeft(
- PORDINATE left /// New left for rectangle.
- );
-
- /**Set the Y value of the bottom of the rectagle. Note that this does not
- change the top of the rectangle so the height will change.
- */
- void SetBottom(
- PORDINATE bottom /// New bottom of rectangle.
- );
-
- /**Set the X value of the right of the rectagle. Note that this does not
- change the left of the rectangle so the width will change.
- */
- void SetRight(
- PORDINATE right /// New right of rectangle.
- );
- /**Set the X value of the left of the rectagle. Note that this does not
- change the width of the rectangle so the right position will change.
- */
- void SetX(
- PORDINATE x /// New x position for rectangle.
- );
-
- /**Set the Y value of the top of the rectagle. Note that this does not
- change the height of the rectangle so the bottom position will change.
- */
- void SetY(
- PORDINATE ny /// new y position for rectangle.
- );
- /**Set the width of the rectagle. Note that this does not change the x
- position of the rectangle so the right position will change.
- */
- void SetWidth(
- PDIMENSION dx /// New width for rectangle.
- );
-
- /**Set the height of the rectagle. Note that this does not change the y
- position of the rectangle so the bottom position will change.
- */
- void SetHeight(
- PDIMENSION dy /// New height for the rectangle.
- );
- /**Get the origin or top left corner of the rectangle.
- @return
- point for top left corner of rectangle.
- */
- PPoint Origin() const;
- /**Get the bottom right corner of the rectangle.
- @return
- point for bottom right corner of rectangle.
- */
- PPoint Corner() const;
- /**Get the coordinates of the centre of the rectangle.
- @return
- point for the centre of the rectangle.
- */
- PPoint Centre() const;
- /**Get the width and height of the rectangle.
- @return
- dimensions of the rectangle.
- */
- PDim Dimensions() const;
- /**Set the top left corner of the rectangle. This is eqivalent to doing
- a Ref{SetX()} and a Ref{SetY()}, ie does not change the width and
- height of the rectangle.
- */
- void SetOrigin(
- PORDINATE nx, /// New x position for the rectangle.
- PORDINATE ny /// New y position for the rectangle.
- );
- void SetOrigin(
- const PPoint & org /// New x and y position for the rectangle.
- );
- /**Set the top left corner of the rectangle. This is eqivalent to doing
- a Ref{SetBottom()} and a Ref{SetTop()}, ie does not change the
- width and height of the rectangle.
- */
- void SetCorner(
- PORDINATE nx, /// New x position for bottom right corner of the rectangle.
- PORDINATE ny /// New y position for bottom right corner of the rectangle.
- );
- void SetCorner(
- const PPoint & cnr /// New bottom right corner of the rectangle.
- );
- /**Set the width and height of the rectangle. This is equivalent to doing
- a Ref{SetWidth()} and Ref{SetHeight}.
- */
- void SetDimensions(
- PDIMENSION dx, /// New width for rectangle.
- PDIMENSION dy /// New height for rectangle.
- );
- void SetDimensions(
- const PDim & dim /// New dimensions for the rectangle.
- );
- /**Determine if the width and height of the rectangle are zero.
-
- @return
- TRUE if the rectangle is empty.
- */
- BOOL IsEmpty() const;
- /**Increase the size of the rectangle by expanding in all four directions
- by the amount specified. That is the left has #dx# subtracted
- from it and the right has it added while the top has #dy#
- subtracted from it and the bottom has it added.
- */
- void Inflate(
- PORDINATE dx, /// Amount to increase the horizontal.
- PORDINATE dy /// Amount to increase the vertical.
- );
- /**Move the rectangle the specified delta amount. This is eqivalent to
- doing a Ref{SetX()} and a Ref{SetY()}, ie does not change the width
- and height of the rectangle.
- */
- void Offset(
- PORDINATE dx, /// Amount to move the rectangle horizontally.
- PORDINATE dy /// Amount to move the rectangle vertically.
- );
- /**Determine if the point is contained within the bounds of the rectangle.
- @return
- TRUE if point is within the rectangle.
- */
- BOOL ContainsPoint(const PPoint & pt) const;
- /**Calculate the rectangle that is the intersection of the object and the
- specified rectangle. That is the part of the two rectangle contained by
- both rectangles. This can easily be an empty rectangle.
- @return
- intersection rectangle.
- */
- PRect Intersection(const PRect & rect) const;
- /**Calculate the rectangle that is the union of the object and the
- specified rectangle. That is the amllest rectangle that will contain
- both the other rectangles.
- @return
- union rectangle.
- */
- PRect Union(const PRect & rect) const;
- #ifdef DOC_PLUS_PLUS
- };
- #endif
- // Class declaration continued in platform specific header file ///////////////