home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / odtlktv4.zip / ODTLKT / TOOLKIT / BETA / SAMPLES / OPENDOC / PUBUTILS / ALTPOINT.H < prev    next >
Text File  |  1995-11-29  |  8KB  |  218 lines

  1. /*****************************************************************************/
  2. /*  Licensed Materials - Property of IBM                                     */
  3. /*                                                                           */
  4. /*                                                                           */
  5. /* Copyright (C) International Business Machines Corp., 1994.                */
  6. /* Copyright (C) Apple Computer, Inc., 1994                                  */
  7. /*                                                                           */
  8. /*  US Government Users Restricted Rights -                                  */
  9. /*  Use, duplication, or disclosure restricted                               */
  10. /*  by GSA ADP Schedule Contract with IBM Corp.                              */
  11. /*                                                                           */
  12. /*  File:    AltPoint.h                                                      */
  13. /*                                                                           */
  14. /*  Contains:  C++ savvy points and rects (alternate ODPoint, ODRect)        */
  15. /*                                                                           */
  16. /*  Notes:                                                                   */
  17. /*                                                                           */
  18. /*  These are alternate definitions of the ODPoint and ODRect structs.       */
  19. /*  These definitions have the same size and data format and can be used     */
  20. /*  interchangeably with the basic definitions; but they're much more C++    */
  21. /*  savvy, with constructors, operators, conversions, and utility methods.   */
  22. /*                                                                           */
  23. /*  To use these classes instead of the defaults, just include "AltPoint.h"  */
  24. /*  as the first thing in your source file. It has to be included first so   */
  25. /*  it can override the default struct definitions in PlfmType.h.            */
  26. /*                                                                           */
  27. /*  This API and implementation are **NOT** an official part of the OpenDoc  */
  28. /*  API, just handy utilities for C++ programmers.                           */
  29. /*                                                                           */
  30. /*****************************************************************************/
  31.  
  32. #ifndef _ALTPOINT_
  33. #define _ALTPOINT_
  34.  
  35. #ifndef __OS2DEF__
  36. #include <os2def.h>
  37. #endif
  38.  
  39. #ifndef INCL_ODDTS // include non-DTS C++ headers
  40.  
  41. // Make sure that built-in structs do not get re-defined
  42. #ifndef SOM_Module_GeoTypes_OpenDoc_GeoTypes_defined
  43.   #define SOM_Module_GeoTypes_OpenDoc_GeoTypes_defined 2
  44. #else
  45.   #error "Must include AltPoint.h *before* os2.h!"
  46. #endif
  47.  
  48. #ifndef SOM_Module_OpenDoc_Global_TypesB_defined
  49. #include "ODTypesB.xh"
  50. #endif
  51.  
  52. #else // include DTS C++ headers
  53.  
  54. // Make sure that built-in structs do not get re-defined
  55. #ifndef _DTS_HH_INCLUDED_GeoTypes
  56.   #define _DTS_HH_INCLUDED_GeoTypes 2
  57. #else
  58.   #error "Must include AltPoint.h *before* os2.h!"
  59. #endif
  60.  
  61. #ifndef SOM_HH_DTS_Included
  62. #include <som.hh>
  63. #endif
  64. #ifndef _DTS_HH_INCLUDED_ODTypesB
  65. #include <ODTypesB.hh>
  66. #endif
  67.  
  68. #endif // ! INCL_ODDTS
  69.  
  70. //==============================================================================
  71. // ODCoordinate
  72. //==============================================================================
  73.  
  74. typedef ODFixed ODCoordinate;
  75.  
  76. //==============================================================================
  77. // ODPoint
  78. //==============================================================================
  79.  
  80. struct ODPoint {
  81.   public:
  82.  
  83.   // CONTENTS:
  84.  
  85.   ODCoordinate x, y;
  86.  
  87.   // CONSTRUCTORS:
  88.  
  89.   ODPoint( ) { }
  90.  
  91.   ODPoint( ODCoordinate xx, ODCoordinate yy )
  92.           {x=xx; y=yy;}
  93.  
  94.   ODPoint( const ODPoint& );        // Copy constructor
  95.  
  96.   // ASSIGNMENT:
  97.  
  98.   ODPoint& operator= ( const ODPoint& );  // Copy from another pt
  99.  
  100.   // MODIFICATION:
  101.  
  102.   inline void  Clear( )
  103.           {x=y=0;}
  104.   inline void  Set( ODCoordinate xx, ODCoordinate yy )
  105.           {x=xx; y=yy;}
  106.   void  Offset( ODCoordinate x, ODCoordinate y );
  107.   void  operator+=( const ODPoint& );
  108.   void  operator-=( const ODPoint& );
  109.  
  110.   // ACCESSORS:
  111.  
  112.   ODSShort  IntX( )    const;    // Returns X-coord as (16bit) integer
  113.   ODSShort  IntY( )    const;    // Returns Y-coord as (16bit) integer
  114.  
  115.   // COMPARISON:
  116.  
  117.   ODBoolean  operator==( const ODPoint& )  const;
  118.   ODBoolean  operator!=( const ODPoint& )  const;
  119.   ODBoolean  ApproxEquals( const ODPoint& )  const;    // to within roundoff error
  120.  
  121.   // CONVENIENCES:
  122.  
  123.   ODPoint( POINTL ptl);                       // Construct from GPI POINTL
  124.   ODPoint& operator= ( const POINTL& ptl);    // Copy from a GPI POINTL
  125.   POINTL  AsPOINTL( )          const;         // Convert to integer POINTL
  126.   void  operator+=( const    POINTL& ptl);    // Add/subtract POINTL
  127.   void  operator-=( const    POINTL& ptl);
  128. };
  129.  
  130.  
  131. //==============================================================================
  132. // ODRect
  133. //==============================================================================
  134.  
  135. struct ODRect {
  136.   public:
  137.  
  138.   // CONTENTS:
  139.  
  140.   ODCoordinate left, top, right, bottom;
  141.  
  142.   // CONSTRUCTORS:
  143.  
  144.   ODRect( )    { }
  145.   ODRect( ODCoordinate l, ODCoordinate t,
  146.           ODCoordinate r, ODCoordinate b )
  147.       {left=l; top=t; right=r; bottom=b; }
  148.   ODRect( const ODPoint&, const ODPoint& );  // Any 2 opposite pts
  149.   ODRect( const ODPoint &topLeft, ODCoordinate width, ODCoordinate height );
  150.   ODRect( const RECTL& r);
  151.  
  152.   // ASSIGNMENT:
  153.  
  154.   ODRect& operator= ( const RECTL& r);
  155.  
  156.   // MODIFICATION:
  157.  
  158.   void  Clear( );
  159.   void  Set( ODCoordinate l, ODCoordinate t, ODCoordinate r, ODCoordinate b );
  160.   void  Set( const ODPoint&, ODCoordinate width, ODCoordinate height );
  161.   void  SetInt( short l, short t, short r, short b );
  162.   void  Offset( ODCoordinate x, ODCoordinate y );
  163.   void  Offset( const ODPoint& );
  164.   void  Inset( ODCoordinate x, ODCoordinate y );
  165.  
  166.   void  operator&= ( const ODRect& );  // Intersect with rectangle
  167.   void  operator|= ( const ODRect& );  // Union with rectangle
  168.   void  operator|= ( const ODPoint& );    // Expand to fit point
  169.  
  170.   // ACCESSORS
  171.  
  172.   ODPoint         BotLeft( )                    const
  173.                 { return ODPoint(left, bottom);}
  174.   ODPoint         TopRight( )                    const
  175.                 {return ODPoint(right, top);}
  176.   ODCoordinate  Width( )                    const
  177.                 {return right-left;}
  178.   ODCoordinate  Height( )                    const
  179.                 {return bottom-top;}
  180.   void          AsRECTL( RECTL& r ) const;
  181.  
  182.   // TESTING
  183.  
  184.   ODBoolean  operator==( const ODRect& )            const;
  185.   ODBoolean  operator!=( const ODRect &r )            const
  186.                 {return !(*this==r);}
  187.   ODBoolean  ApproxEquals( const ODRect &r )            const;
  188.  
  189.   ODBoolean IsEmpty( )                      const;
  190.   ODBoolean Contains( const ODPoint& )              const;
  191.   ODBoolean Contains( const ODRect& )              const;
  192.   ODBoolean  ApproxContains( const ODRect& )            const;
  193.   ODBoolean Intersects( const ODRect& )            const;
  194. };
  195.  
  196. struct ODToolSpaceRect {
  197. public:
  198.        ODCoordinate    left;
  199.        ODCoordinate    top;
  200.        ODCoordinate    right;
  201.        ODCoordinate    bottom;
  202.        ODRect          floatRect;
  203.  
  204.        ODToolSpaceRect( )              { }
  205.  
  206.        ODToolSpaceRect(ODCoordinate l, ODCoordinate t,
  207.                        ODCoordinate r, ODCoordinate b, ODRect* aFloatRect);
  208.  
  209.        ODBoolean IsEmpty() const;
  210.  
  211.        void Set(ODCoordinate l, ODCoordinate t,
  212.                 ODCoordinate r, ODCoordinate b, ODRect* aFloatRect);
  213.  
  214.        void Clear(void);
  215. };
  216.  
  217. #endif //_ALTPOINT_
  218.