home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Utilities / Interfaces / AltPoint.h next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  5.1 KB  |  193 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        AltPoint.h
  3.  
  4.     Contains:    C++ savvy points and rects (alternate ODPoint, ODRect)
  5.  
  6.     Owned by:    Jens Alfke
  7.  
  8.     Copyright:    © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  9.     
  10.     Notes:
  11.     
  12.     These are alternate definitions of the ODPoint and ODRect structs.
  13.     These definitions have the same size and data format and can be used
  14.     interchangeably with the basic definitions; but they're much more C++
  15.     savvy, with constructors, operators, conversions, and utility methods.
  16.     
  17.     To use these classes instead of the defaults, just include "AltPoint.h"
  18.     as the first thing in your source file. It has to be included first so
  19.     it can override the default struct definitions in PlfmType.h.
  20.     
  21.     This API and implementation are **NOT** an official part of the OpenDoc
  22.     API, just handy utilities for C++ programmers.
  23.     
  24. */
  25.  
  26.  
  27. #ifndef _ALTPOINT_
  28. #define _ALTPOINT_
  29.  
  30. // Make sure that built-in structs do not get defined by PlfmType.h.
  31. #if !defined(SOM_Module_OpenDoc_GeoTypes_defined)
  32.     #define SOM_Module_OpenDoc_GeoTypes_defined
  33. #else
  34.     #error "Must include AltPoint.h *before* ODTypes.h!"
  35. #endif
  36.  
  37.  
  38. #ifndef _ODTYPESF_
  39. #include "ODTypesF.h"        // Must include before ODTypesM.xh
  40. #endif
  41.  
  42. #ifndef SOM_Module_OpenDoc_Global_TypesB_defined
  43. #include "ODTypesB.xh"        
  44. #endif
  45.  
  46. #ifdef _PLATFORM_MACINTOSH_
  47. #ifndef __TYPES__
  48. #include <Types.h>
  49. #endif
  50. #endif
  51.  
  52. //==============================================================================
  53. // ODCoordinate
  54. //==============================================================================
  55.  
  56. typedef ODFixed ODCoordinate;
  57.  
  58. //==============================================================================
  59. // ODPoint
  60. //==============================================================================
  61.  
  62. struct ODPoint {
  63.     public:
  64.     
  65.     // CONTENTS:
  66.     
  67.     ODCoordinate x, y;
  68.     
  69.     // CONSTRUCTORS:
  70.     
  71.     ODPoint( ) { }
  72.     
  73.     ODPoint( ODCoordinate xx, ODCoordinate yy )
  74.                     {x=xx; y=yy;}
  75.     
  76.     ODPoint( const ODPoint& );                // Copy constructor
  77.     
  78.     // ASSIGNMENT:
  79.     
  80.     ODPoint& operator= ( const ODPoint& );    // Copy from another pt
  81.     
  82.     // MODIFICATION:
  83.     
  84.     inline void    Clear( )
  85.                     {x=y=0;}
  86.     inline void    Set( ODCoordinate xx, ODCoordinate yy )
  87.                     {x=xx; y=yy;}
  88.     void    Offset( ODCoordinate x, ODCoordinate y );
  89.     void    operator+=( const ODPoint& );
  90.     void    operator-=( const ODPoint& );
  91.     
  92.     // ACCESSORS:
  93.  
  94.     ODSShort    IntX( )        const;        // Returns X-coord as (16bit) integer
  95.     ODSShort    IntY( )        const;        // Returns Y-coord as (16bit) integer
  96.     
  97.     // COMPARISON:
  98.     
  99.     ODBoolean    operator==( const ODPoint& )    const;
  100.     ODBoolean    operator!=( const ODPoint& )    const;
  101.     ODBoolean    ApproxEquals( const ODPoint& )    const;        // to within roundoff error
  102.     
  103.     // MAC TOOLBOX CONVENIENCES:
  104.     
  105. #ifdef _PLATFORM_MACINTOSH_
  106.     ODPoint( Point );                            // Construct from QD point
  107.     ODPoint& operator= ( const Point& );        // Copy from a QD Point
  108.     Point    AsQDPoint( )                    const;    // Convert to integer (QD) point
  109.     void    operator+=( const    Point& );            // Add/subtract QD point
  110.     void    operator-=( const    Point& );
  111. #endif
  112. };
  113.  
  114.  
  115. //==============================================================================
  116. // ODRect
  117. //==============================================================================
  118.  
  119. struct ODRect {
  120.     public:
  121.     
  122.     // CONTENTS:
  123.     
  124.     ODCoordinate left, top, right, bottom;
  125.         
  126.     // CONSTRUCTORS:
  127.     
  128.     ODRect( )        { }
  129.     ODRect( ODCoordinate l, ODCoordinate t,
  130.                   ODCoordinate r, ODCoordinate b )
  131.             {left=l; top=t; right=r; bottom=b; }
  132.     ODRect( const ODPoint&, const ODPoint& );    // Any 2 opposite pts
  133.     ODRect( const ODPoint &topLeft, ODCoordinate width, ODCoordinate height );
  134. #ifdef _PLATFORM_MACINTOSH_
  135.     ODRect( const Rect& );
  136. #endif
  137.     
  138.     // ASSIGNMENT:
  139.     
  140. #ifdef _PLATFORM_MACINTOSH_
  141.     ODRect& operator= ( const Rect& );
  142. #endif
  143.     
  144.     // MODIFICATION:
  145.     
  146.     void    Clear( );
  147.     void    Set( ODCoordinate l, ODCoordinate t, ODCoordinate r, ODCoordinate b );
  148.     void    Set( const ODPoint&, ODCoordinate width, ODCoordinate height );
  149.     void    Set( const ODPoint&, const ODPoint& );    // Any 2 opposite pts
  150.     void    SetInt( short l, short t, short r, short b );
  151.     void    Offset( ODCoordinate x, ODCoordinate y );
  152.     void    Offset( const ODPoint& );
  153.     void    Inset( ODCoordinate x, ODCoordinate y );
  154.     
  155.     void    operator&= ( const ODRect& );    // Intersect with rectangle
  156.     void    operator|= ( const ODRect& );    // Union with rectangle
  157.     void    operator|= ( const ODPoint& );        // Expand to fit point
  158.         
  159.     // ACCESSORS
  160.     
  161.     const ODPoint& TopLeft( )                                        const
  162.                                 {return *(ODPoint*)&left;}
  163.     ODPoint&        TopLeft( )
  164.                                 {return *(ODPoint*)&left;}
  165.     const ODPoint& BotRight( )                                        const
  166.                                 {return *(ODPoint*)&right;}
  167.     ODPoint&        BotRight( )
  168.                                 {return *(ODPoint*)&right;}
  169.     ODCoordinate    Width( )                                        const
  170.                                 {return right-left;}
  171.     ODCoordinate    Height( )                                        const
  172.                                 {return bottom-top;}
  173. #ifdef _PLATFORM_MACINTOSH_
  174.     void            AsQDRect( Rect& )                                const;
  175. #endif
  176.     
  177.     // TESTING
  178.  
  179.     ODBoolean    operator==( const ODRect& )                            const;
  180.     ODBoolean    operator!=( const ODRect &r )                        const
  181.                                 {return !(*this==r);}
  182.     ODBoolean    ApproxEquals( const ODRect &r )                        const;
  183.     
  184.     ODBoolean    IsEmpty( )                                            const;
  185.     ODBoolean    Contains( const ODPoint& )                            const;
  186.     ODBoolean    Contains( const ODRect& )                            const;
  187.     ODBoolean    ApproxContains( const ODRect& )                        const;
  188.     ODBoolean    Intersects( const ODRect& )                            const;
  189. };
  190.  
  191.  
  192. #endif //_ALTPOINT_
  193.