home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
deans.zip
/
BASE.HPP
< prev
next >
Wrap
Text File
|
1994-09-14
|
22KB
|
690 lines
//
// NAME: CIDGui_Base.Hpp
//
// DESCRIPTION:
//
// This is the header for the CIDGui_Base.Cpp module. This module provides the
// most basic classes needed by this facility. These are classes such as AREA
// and POINT which define a rectangular area or a 2 dimensional point
// respectively. Since these are used so often for a number of operations, they
// are made classes.
//
// An area with a width or height of 0 is empty. When 1 the area includes 1
// pixel.
//
// The class hierarchy here is:
//
// CIDOBJECT
// |
// CIDSTORABLE
// |
// |-----|-------|
// AREA POINT
//
//
// AUTHOR: Dean Roddey
//
// CREATE DATE: 05/23/93
//
// COPYRIGHT: 1992..1994, 'CIDCorp
//
// CAVEATS/GOTCHAS:
//
// 1) Note that the methods i4XRight() and i4YTop() methods will return the
// same thing for an empty area as for an area of 1x1. There is no way to
// avoid this. Client apps must be aware of watching for empty areas.
//
// 2) If you convert a non-inclusive rect to an area, but that rectangle's
// horizontal or vertical left or right are equal, that is really an
// error because no such creature exists. However, the result will just
// be an empty area.
//
// MODIFICATION LOG:
//
// Avoid multiple inclusions
#if !defined(CIDGUI_BASE_HPP)
#define CIDGUI_BASE_HPP
typedef struct _POINTL POINTL;
class AREA;
// -----------------------------------------------------------------------------
// CLASS: POINT
// PREFIX: pnt
//
// This class defines a 2 dimensional point. The coordinates are 32 bit signed
// values
// -----------------------------------------------------------------------------
class POINT : public CIDSTORABLE
{
public :
// ---------------------------------------------------------------------
// Constructors and Destructors
//
// POINT
// We have 4 constructors, one that provides default 0 values,
// one that accepts the x and y, one that accepts a PM POINTL,
// and the the copy constructor.
// ---------------------------------------------------------------------
POINT();
POINT
(
const POINTL& ptlSrc
);
POINT
(
tCIDLib::INT4 x
, tCIDLib::INT4 y
);
POINT
(
const POINT& pntSrc
);
// ---------------------------------------------------------------------
// Public, inherited methods
//
// FormatAt
// This method is called from the public pFormatToBuf() to handle
// formatting this object into the passed buffer.
//
// FormatToStr
// Formats the object's data members into the string buffer
//
// ParseAt
// This method is called from the public bParseFromBuf() to handle
// parsing this object's data from the passed buffer.
// ---------------------------------------------------------------------
STDVPUBMETHODS(POINT,CIDSTORABLE,tCIDLib::eFALSE);
virtual tCIDLib::VOID FormatAt
(
tCIDLib::CH* pszBuf
, tCIDLib::CARD4& c4CurInd
) const;
virtual tCIDLib::VOID FormatToStr
(
STRGBUF& strbDest
) const;
virtual tCIDLib::VOID ParseAt
(
const tCIDLib::CH* pszBuf
, tCIDLib::CARD4& c4CurInd
);
// ---------------------------------------------------------------------
// Pubic, non-virtual methods
//
// operator POINTL*
// This guy allows us to pass POINTL objects straight to PM
// POINTL* parameters.
//
// bInArea
// Returns eTRUE if the point lies in the passed area
//
// Exchange
// This method will exchange the x and y components
//
// FromPtl
// Parses a PM POINTL into this point object
//
// Offset
// This method will add the passed offset values to the current x
// and y values.
//
// ToPtl
// Puts the point info into a PM POINTL
//
// x, y
// These get/set the x and y data members.
// ---------------------------------------------------------------------
operator POINTL*() const;
tCIDLib::eBOOL bInArea
(
const AREA& areaTarget
) const;
tCIDLib::VOID Exchange
(
) {tCIDLib::INT4 i4Tmp=__i4X; __i4X=__i4Y;__i4Y=i4Tmp;}
tCIDLib::VOID FromPtl
(
const POINTL& ptlSrc
);
tCIDLib::VOID Offset
(
tCIDLib::INT4 ofsX
, tCIDLib::INT4 ofsY
) {__i4X += ofsX; __i4Y += ofsY;}
tCIDLib::VOID ToPtl
(
POINTL& ptlTarget
) const;
tCIDLib::INT4 i4X
(
) const {return __i4X;}
tCIDLib::INT4 i4X
(
tCIDLib::INT4 x
) {__i4X=x;return __i4X;}
tCIDLib::INT4 i4Y
(
) const {return __i4Y;}
tCIDLib::INT4 i4Y
(
tCIDLib::INT4 y
) {__i4Y=y;return __i4Y;}
protected :
// ---------------------------------------------------------------------
// Protected, inherited methods
//
// _bIsEqual
// This method is called from the public bIsEqual, which has
// determined that the objects are of comparable classes and
// are not the same object. It does the comparison down the
// class hierarchy.
//
// _StorageBytes
// This method will add, to c4CurCount, the number of storage
// bytes needed to store an object of this type.
// ---------------------------------------------------------------------
virtual tCIDLib::eBOOL _bIsEqual
(
const CIDOBJECT& objTarget
) const;
virtual tCIDLib::VOID _StorageBytes
(
tCIDLib::CARD4& c4CurCount
) const {CIDSTORABLE::_StorageBytes(c4CurCount); c4CurCount += 8;}
private :
// ---------------------------------------------------------------------
// Private data members
//
// __i4X
// __i4Y
// Storage for the x,y coordinates.
// ---------------------------------------------------------------------
tCIDLib::INT4 __i4X, __i4Y;
};
#define NUL_POINT (*(POINT*)0)
// -----------------------------------------------------------------------------
// CLASS: AREA
// PREFIX: area
//
// This class defines a rectangular area with an integral x,y origin and a
// cardinal cx,cy length and width.
// -----------------------------------------------------------------------------
class AREA : public CIDSTORABLE
{
public :
// ---------------------------------------------------------------------
// Constuctors and Destructors
//
// AREA
// There are a number of possible constructors here since great
// flexibility is greatly paid back. This is a heavily used class.
// The compiler's default constructor is ok.
// ---------------------------------------------------------------------
AREA();
AREA
(
const RECTL& rectlSrc
, tCIDGui::eRECTLTYPE eInclusive
);
AREA
(
const SWP& swpSrc
);
AREA
(
const POINTL& ptlLLeft
, const POINTL& ptlURight
);
AREA
(
const POINT& pntLLeft
, const POINT& pntURight
);
AREA
(
tCIDLib::INT4 x
, tCIDLib::INT4 y
, tCIDLib::CARD4 cx
, tCIDLib::CARD4 cy
);
AREA
(
const AREA& areaSrc
);
// ---------------------------------------------------------------------
// Public, inherited, virtual methods
//
// FormatAt
// This method is called from the public pFormatToBuf() to handle
// formatting this object into the passed buffer.
//
// FormatToStr
// Formats the object's data members into the string buffer
//
// ParseAt
// This method is called from the public bParseFromBuf() to handle
// parsing this object's data from the passed buffer.
// ---------------------------------------------------------------------
STDVPUBMETHODS(AREA,CIDSTORABLE,tCIDLib::eFALSE);
virtual tCIDLib::VOID FormatAt
(
tCIDLib::CH* pszBuf
, tCIDLib::CARD4& c4CurInd
) const;
virtual tCIDLib::VOID FormatToStr
(
STRGBUF& strbDest
) const;
virtual tCIDLib::VOID ParseAt
(
const tCIDLib::CH* pszBuf
, tCIDLib::CARD4& c4CurInd
);
// ---------------------------------------------------------------------
// Public, non-virtual methods
//
// operator+
// operator+=
// These operators will add areas. Adding creates a union of the
// two areas, which is an area that contains both of the original
// areas.
//
// operator-
// operator-=
// These operators will create an area that is the common portion
// of both areas. If they don't overlap at all, then the area will
// be empty. Note that, if they just touch on a common side, that
// does not count as overlap.
//
// AdjustOrg
// This method will adjust the area origin by the indicated
// offsets.
//
// AdjustSides
// This method will adjust the area by the passed x and y values.
// The left and right sides will be adjusted by i4XOfs units. The
// top and bottom sides will be adjusted by i4YOfs. Negative makes
// the area smaller and positive makes it larger.
//
// AdjustSize
// This method will just adjust the cx and cy values by the passed
// values.
//
// areaHorzPercent
// areaVertPercent
// These methods will return an area that represents a percent of
// the area, either horizontally or vertically.
//
// bEmpty
// If either the cx or cy is 0, then the area is empty.
//
// bIntersects
// Returns eTRUE if this object intersects the passed object.
//
// c4CX, c4CY
// These set or return the cx and cy members
//
// FromPnts
// FromPtls
// FromRectl
// FromSwp
// For internal use to convert PM structures into area objects.
// These are not exported to the outside world since they are for
// internal use only. The one for rectangles has an optional buffer
// that indicates that the passed rectangle is inclusive or
// non-inclusive.
//
// i4X, i4Y
// These set or return the x and y members
//
// i4XRight
// This will return the value (__i4X+__c4CX)-1 if c4CX is larger
// than 0 or just (__i4X+__c4CX) otherwise. This means that there
// is no way to distinguish and empty or 1 sized area by calling
// this method. The other version allows the right side to be set.
// This will cause the horizontal size to be recalced.
//
// i4YTop
// This will return the value (__i4Y+__c4CY)-1 if c4CY is larger
// than 0 or just (__i4Y+__c4CY) otherwise. This means that there
// is no way to distinguish and empty or 1 sized area by calling
// this method. The other version allows the top to be set. This
// will cause the vertical size to be recalced.
//
// pntCenter
// This method will return the center of the area. If the cx or cy
// is an odd number the odd 1 bit is shifted out, which means its
// rounds toward the origin of the area.
//
// pntOrg
// This method will get/set x,y origin of the area as a POINT
// object or as individual x and y values.
//
// SetSizes
// This method will just set the cx and cy values to the passed
// values.
//
// ToPtlArray
// Converts the area into an array of 5 POINTL structures that
// start and end at the lower left corner and goes clockwise.
//
// ToCornerPtls
// ToCornerPnts
// Converts the area into either POINTL structures or POINT objects
// that represent the corners of the area.
//
// ToPnts
// ToPtls
// ToRectl
// ToSwp
// The opposite of the FromXXX methods above. Converts from areas
// to the PM types or to 2 POINT objects.
// For ToRectl, the second parm indicates whether the resulting
// rectangle should be inclusive or not.
// ---------------------------------------------------------------------
AREA operator+
(
const AREA& areaSrc
);
tCIDLib::VOID operator+=
(
const AREA& areaSrc
);
AREA operator-
(
const AREA& areaSrc
);
tCIDLib::VOID operator-=
(
const AREA& areaSrc
);
tCIDLib::VOID AdjustOrg
(
tCIDLib::INT4 i4XOfs
, tCIDLib::INT4 i4YOfs
);
tCIDLib::VOID AdjustOrg
(
const POINT& pntOfs
);
tCIDLib::VOID AdjustSides
(
tCIDLib::INT4 i4XOfs
, tCIDLib::INT4 i4YOfs
);
tCIDLib::VOID AdjustSize
(
tCIDLib::INT4 i4CXOfs
, tCIDLib::INT4 i4CYOfs
);
AREA areaHorzPercent
(
tCIDLib::CARD4 c4Percent
) const;
AREA areaVertPercent
(
tCIDLib::CARD4 c4Percent
) const;
tCIDLib::eBOOL bEmpty
(
) const;
tCIDLib::eBOOL bIntersects
(
const AREA& areaTest
) const;
tCIDLib::CARD4 c4CX
(
) const {return __c4CX;}
tCIDLib::CARD4 c4CX
(
tCIDLib::CARD4 iNewCX
) {__c4CX=iNewCX;return __c4CX;}
tCIDLib::CARD4 c4CY
(
) const {return __c4CY;}
tCIDLib::CARD4 c4CY
(
tCIDLib::CARD4 iNewCY
) {__c4CY=iNewCY;return __c4CY;}
tCIDLib::VOID FromPnts
(
const POINT& pntLLeft
, const POINT& pntURight
);
tCIDLib::VOID FromPtls
(
const POINTL& ptlLLeft
, const POINTL& ptlURight
);
tCIDLib::VOID FromRectl
(
const RECTL& rectlSrc
, tCIDGui::eRECTLTYPE eInclusive
);
tCIDLib::VOID FromSwp
(
const SWP& swpSrc
);
tCIDLib::VOID JustifyIn
(
const AREA& areaTarget
, tCIDLib::eHJUSTIFY eHJustify
, tCIDLib::eVJUSTIFY eVJustify
);
POINT pntCenter
(
) const {return POINT(__i4X+(__c4CX>>1), __i4Y+(__c4CY>>1));}
POINT pntOrg
(
) const {return POINT(__i4X, __i4Y);}
POINT pntOrg
(
const POINT& pntNew
) {__i4X=pntNew.i4X();__i4Y=pntNew.i4Y();return pntNew;}
POINT pntOrg
(
tCIDLib::INT4 i4X
, tCIDLib::INT4 i4Y
) {__i4X=i4X;__i4Y=i4Y; return POINT(i4X,i4Y);}
tCIDLib::VOID SetSizes
(
tCIDLib::CARD4 c4CX
, tCIDLib::CARD4 c4CY
) {__c4CX=c4CX;__c4CY=c4CY;}
tCIDLib::VOID ToPtlArray
(
POINTL* aptlTarget
);
tCIDLib::VOID ToCornerPtls
(
POINTL& ptlLLeft
, POINTL& ptlULeft
, POINTL& ptlURight
, POINTL& ptlLRight
) const;
tCIDLib::VOID ToCornerPnts
(
POINT& pntLLeft
, POINT& pntULeft
, POINT& pntURight
, POINT& pntLRight
) const;
tCIDLib::VOID ToPnts
(
POINT& pntLLeft
, POINT& pntURight
) const;
tCIDLib::VOID ToPtls
(
POINTL& ptlLLeft
, POINTL& ptlURight
) const;
tCIDLib::VOID ToRectl
(
RECTL& rectlSrc
, tCIDGui::eRECTLTYPE eInclusive
) const;
tCIDLib::VOID ToSwp
(
SWP& swpSrc
) const;
tCIDLib::INT4 i4X
(
) const {return __i4X;}
tCIDLib::INT4 i4X
(
tCIDLib::INT4 iNewX
) {__i4X=iNewX;return __i4X;}
tCIDLib::INT4 i4Y
(
) const {return __i4Y;}
tCIDLib::INT4 i4Y
(
tCIDLib::INT4 iNewY
) {__i4Y=iNewY;return __i4Y;}
tCIDLib:: INT4 i4XRight
(
) const;
tCIDLib:: INT4 i4XRight
(
tCIDLib::INT4 i4XRight
);
tCIDLib::INT4 i4YTop
(
) const;
tCIDLib::INT4 i4YTop
(
tCIDLib::INT4 i4YTop
);
protected :
// ---------------------------------------------------------------------
// Protected, inherited methods
//
// _bIsEqual
// This method is called from the public bIsEqual, which has
// determined that the objects are of comparable classes and are
// not the same object. It does the comparison down the class
// hierarchy.
//
// _StorageBytes
// This method will add, to c4CurCount, the number of storage
// bytes needed to store an object of this type.
// ---------------------------------------------------------------------
virtual tCIDLib::eBOOL _bIsEqual
(
const CIDOBJECT& objTarget
) const;
virtual tCIDLib::VOID _StorageBytes
(
tCIDLib::CARD4& c4CurCount
) const {CIDSTORABLE::_StorageBytes(c4CurCount); c4CurCount += 16;}
private :
// ---------------------------------------------------------------------
// Private data members
//
// __i4X, __i4Y
// The origin of the area. It is signed because it could start
// below the origin of the window it is within.
//
// __c4CX, __c4CY
// The length and width of the area which always must be
// positive.
// ---------------------------------------------------------------------
tCIDLib::CARD4 __c4CX, __c4CY;
tCIDLib::INT4 __i4X, __i4Y;
};
#define NUL_AREA (*(AREA*)0)
#endif