/*
 * objects.h
 *
 * Turbo Vision - Version 2.0
 *
 * Copyright (c) 1994 by Borland International
 * All Rights Reserved.
 *
 * Modified by Sergio Sigala <ssigala@globalnet.it>
 */

#if defined( Uses_TPoint ) && !defined( __TPoint )
#define __TPoint

/**
 * A screen coordinate.
 *
 * TPoint is a simple object that can be used to record a coordinate on the
 * screen. For this, two public variables are available: `x' and `y'.
 * @see TRect
 * @short A screen coordinate
 */
class TPoint
{
public:
    /**
     * Adds the coordinate of another point to this point.
     */
    TPoint& operator+=( const TPoint& adder );
    /**
     * Subtracts the coordinate of another point from this point.
     */
    TPoint& operator-=( const TPoint& subber );
    /**
     * Calculates the distance between two points.
     * @return a point with the resulting difference.
     */
    friend TPoint operator - ( const TPoint& one, const TPoint& two);
    /**
     * Calculates the sum of two points.
     * @return a point with the resulting sum.
     */
    friend TPoint operator +( const TPoint& one, const TPoint& two );
    /**
     * Checks if two points are equal (have the same coordinate).
     */
    friend int operator == ( const TPoint& one, const TPoint& two);
    /**
     * Checks if two points are not equal (have different coordinate).
     */
    friend int operator != ( const TPoint& one, const TPoint& two);
    int x,y;
};

inline TPoint& TPoint::operator += ( const TPoint& adder )
{
    x += adder.x;
    y += adder.y;
    return *this;
}

inline TPoint& TPoint::operator -= ( const TPoint& subber )
{
    x -= subber.x;
    y -= subber.y;
    return *this;
}

inline ipstream& operator >> ( ipstream& is, TPoint& p )
    { return is >> p.x >> p.y; }
inline ipstream& operator >> ( ipstream& is, TPoint*& p )
    { return is >> p->x >> p->y; }

inline opstream& operator << ( opstream& os, TPoint& p )
    { return os << p.x << p.y; }
inline opstream& operator << ( opstream& os, TPoint* p )
    { return os << p->x << p->y; }

#endif  // Uses_TPoint

#if defined( Uses_TRect ) && !defined( __TRect )
#define __TRect

/**
 * A screen rectangular area.
 *
 * TRect is used to hold two coordinates on the screen, which usually specify
 * the upper left corner and the lower right corner of views. Sometimes the
 * second coordinate speficy the size (extension) of the view. The two
 * coordinates are named `a' and `b'.
 * @see TPoint
 * @short A screen rectangular area
 */
class TRect
{
public:
    /**
     * Constructor.
     *
     * Initializes the rectangle coordinates using the four integer
     * parameters.
     */
    TRect( int ax, int ay, int bx, int by );
    /**
     * Constructor.
     *
     * Initializes the rectangle coordinates using two points.
     * @see TPoint
     */
    TRect( TPoint p1, TPoint p2 );
    /**
     * Constructor.
     *
     * Does nothing. The two coordinates are not initialized, so they contain
     * garbage.
     */
    TRect();
    /**
     * Moves the rectangle to a new position.
     *
     * The two parameters are added to the two old coordinates as delta
     * values. Both parameters can be negative or positive.
     */
    void move( int aDX, int aDY );
    /**
     * Enlarges the rectangle by a specified value.
     *
     * The left side is left-moved by `aDX' units and the right side is
     * right-moved by `aDX' units. In a similar way the upper side is
     * upper-moved by `aDY' units and the bottom side is bottom-moved by `aDY'
     * units.
     */
    void grow( int aDX, int aDY );
    /**
     * Calculates the intersection between this rectangle and the parameter
     * rectangle.
     *
     * The resulting rectangle is the larger rectangle which contains both
     * part of this rectangle and part of the parameter rectangle.
     */
    void intersect( const TRect& r );
    /**
     * Calculates the union between this rectangle and the parameter
     * rectangle.
     *
     * The resulting rectangle is the smaller rectangle which contains both
     * this rectangle and the parameter rectangle.
     */
    void Union( const TRect& r );
    /**
     * Checks if a certain point is contained into the rectangle.
     * @see TPoint
     */
    Boolean contains( const TPoint& p ) const;
    /**
     * Checks if two rectangles are equal (have the same coordinates).
     */
    Boolean operator == ( const TRect& r ) const;
    /**
     * Checks if two rectanges are not equal (have different coordinates).
     */
    Boolean operator != ( const TRect& r ) const;
    /**
     * Checks if the rectangle is empty, i.e. if the first coordinate is
     * greater than the second one.
     */
    Boolean isEmpty();
    TPoint a, b;
};

inline TRect::TRect( int ax, int ay, int bx, int by)
{
    a.x = ax;
    a.y = ay;
    b.x = bx;
    b.y = by;
}

inline TRect::TRect( TPoint p1, TPoint p2 )
{
    a = p1;
    b = p2;
}

inline TRect::TRect()
{
}

inline void TRect::move( int aDX, int aDY )
{
    a.x += aDX;
    a.y += aDY;
    b.x += aDX;
    b.y += aDY;
}

inline void TRect::grow( int aDX, int aDY )
{
    a.x -= aDX;
    a.y -= aDY;
    b.x += aDX;
    b.y += aDY;
}

inline void TRect::intersect( const TRect& r )
{
    a.x = max( a.x, r.a.x );
    a.y = max( a.y, r.a.y );
    b.x = min( b.x, r.b.x );
    b.y = min( b.y, r.b.y );
}

inline void TRect::Union( const TRect& r )
{
    a.x = min( a.x, r.a.x );
    a.y = min( a.y, r.a.y );
    b.x = max( b.x, r.b.x );
    b.y = max( b.y, r.b.y );
}

inline Boolean TRect::contains( const TPoint& p ) const
{
    return Boolean(
        p.x >= a.x && p.x < b.x && p.y >= a.y && p.y < b.y
        );
}

inline Boolean TRect::operator == ( const TRect& r) const
{
    return Boolean( a == r.a && b == r.b );
}

inline Boolean TRect::operator != ( const TRect& r ) const
{
    return Boolean( !(*this == r) );
}

inline Boolean TRect::isEmpty()
{
    return Boolean( a.x >= b.x || a.y >= b.y );
}

inline ipstream& operator >> ( ipstream& is, TRect& r )
    { return is >> r.a >> r.b; }
inline ipstream& operator >> ( ipstream& is, TRect*& r )
    { return is >> r->a >> r->b; }

inline opstream& operator << ( opstream& os, TRect& r )
    { return os << r.a << r.b; }
inline opstream& operator << ( opstream& os, TRect* r )
    { return os << r->a << r->b; }

#endif  // Uses_TRect

#if defined( Uses_TCollection ) && !defined( __TCollection )
#define __TCollection

/**
 * A streamable collection of objects.
 *
 * This class stores an array of pointers to generic objects. This array may
 * grow or shrink at run-time. Note: type `ccIndex' is defined in file
 * `ttypes.h' as `int'.
 * @see TNSCollection
 * @short A streamable collection of objects
 */
class TCollection : public virtual TNSCollection, public TStreamable
{
public:
    /**
     * Constructor.
     *
     * `aLimit' is the initial size of the array of pointers. `aDelta' is used
     * every time the array must be enlarged. In this case a number of
     * `aDelta' pointers will be added to the array.
     */
    TCollection( ccIndex aLimit, ccIndex aDelta )
        { delta = aDelta; setLimit( aLimit ); }
private:
    virtual const char *streamableName() const
        { return name; }
    virtual void *readItem( ipstream& ) = 0;
    virtual void writeItem( void *, opstream& ) = 0;
protected:
    /**
     * Constructor.
     *
     * Used to recover the object from a stream.
     */
    TCollection( StreamableInit );
    /**
     * Used to recover the object from a stream.
     */
    virtual void *read( ipstream& is);
    /**
     * Used to store the object in a stream.
     */
    virtual void write( opstream& os );
public:
    static const char * const name;
};

inline ipstream& operator >> ( ipstream& is, TCollection& cl )
    { return is >> (TStreamable&)cl; }
inline ipstream& operator >> ( ipstream& is, TCollection*& cl )
    { return is >> (void *&)cl; }

inline opstream& operator << ( opstream& os, TCollection& cl )
    { return os << (TStreamable&)cl; }
inline opstream& operator << ( opstream& os, TCollection* cl )
    { return os << (TStreamable *)cl; }

#endif  // Uses_TCollection

#if defined( Uses_TSortedCollection ) && !defined( __TSortedCollection )
#define __TSortedCollection

class TSortedCollection : public TNSSortedCollection, public TCollection
{

public:

    TSortedCollection( ccIndex aLimit, ccIndex aDelta) :
        TCollection( aLimit, aDelta ) {}

private:

    virtual int compare( void *key1, void *key2 ) = 0;

    virtual const char *streamableName() const
        { return name; }
    virtual void *readItem( ipstream& is ) = 0;
    virtual void writeItem( void *, opstream& os ) = 0;

protected:

    TSortedCollection( StreamableInit );
    virtual void *read( ipstream& is );
    virtual void write( opstream& os );

public:

    static const char * const name;

};

inline ipstream& operator >> ( ipstream& is, TSortedCollection& cl )
    { return is >> (TStreamable&)cl; }
inline ipstream& operator >> ( ipstream& is, TSortedCollection*& cl )
    { return is >> (void *&)cl; }

inline opstream& operator << ( opstream& os, TSortedCollection& cl )
    { return os << (TStreamable&)cl; }
inline opstream& operator << ( opstream& os, TSortedCollection* cl )
    { return os << (TStreamable *)cl; }

#endif  // Uses_TSortedCollection

Documentation generated by sergio@athena.milk.it on Wed Feb 10 22:11:47 CET 1999