home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / YellowBox / Kits / MiscTableScroll-138.1 / Palettes / MiscTableScroll / Framework / MiscGeometry.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-31  |  7.3 KB  |  180 lines

  1. #ifndef __MiscGeometry_h
  2. #define __MiscGeometry_h
  3. #ifdef __GNUC__
  4. # pragma interface
  5. #endif
  6. //=============================================================================
  7. //
  8. //    Copyright (C) 1996,1997,1998 by Paul S. McCarthy and Eric Sunshine.
  9. //        Written by Paul S. McCarthy and Eric Sunshine.
  10. //                All Rights Reserved.
  11. //
  12. //    This notice may not be removed from this source code.
  13. //
  14. //    This object is included in the MiscKit by permission from the authors
  15. //    and its use is governed by the MiscKit license, found in the file
  16. //    "License.rtf" in the MiscKit distribution.  Please refer to that file
  17. //    for a list of all applicable permissions and restrictions.
  18. //    
  19. //=============================================================================
  20. //-----------------------------------------------------------------------------
  21. // MiscGeometry.h
  22. //
  23. //    Geometric types (point, size, rectangle) which understand and can
  24. //    adjust for orientation (horizontal or vertical).  Orientation is
  25. //    specified upon creation and can not be changed thereafter.
  26. //
  27. //    Method names with the "_O" suffix take orientation into consideration,
  28. //    whereas methods lacking this suffix do not.
  29. //
  30. //    Methods dealing with NeXT geometric structures do not apply orientation
  31. //    adjustments.
  32. //
  33. //-----------------------------------------------------------------------------
  34. //-----------------------------------------------------------------------------
  35. // $Id: MiscGeometry.h,v 1.4 98/03/30 09:43:59 sunshine Exp $
  36. // $Log:    MiscGeometry.h,v $
  37. // Revision 1.4  98/03/30  09:43:59  sunshine
  38. // v138.1: Worked around Rhapsody DR1, PPC "internal compiler error" bug.
  39. // 
  40. // Revision 1.3  98/03/29  23:45:48  sunshine
  41. // v138.1: #import was missing "MiscTableScroll/" for public header.
  42. // 
  43. // Revision 1.2  96/05/07  02:06:10  sunshine
  44. // Ported to OpenStep 4.0 for Mach PR2.
  45. //-----------------------------------------------------------------------------
  46. #include <MiscTableScroll/MiscTableTypes.h>
  47. #include "bool.h"
  48. extern "C" {
  49. #import <Foundation/NSGeometry.h>
  50. }
  51.  
  52. class MiscOrientation
  53.     {
  54. private:
  55.     bool horizontal;
  56. public:
  57.     bool isHorz() const { return horizontal; }
  58.     bool isVert() const { return !isHorz(); }
  59.     MiscBorderType border() const
  60.     { return isHorz() ? MISC_COL_BORDER : MISC_ROW_BORDER; }
  61.     MiscOrientation( bool is_horz ) : horizontal(is_horz) {}
  62.     MiscOrientation( MiscBorderType b ) : horizontal( b == MISC_COL_BORDER ) {}
  63.     };
  64.  
  65. class MiscPoint_O : public virtual MiscOrientation
  66.     {
  67. private:
  68.     MiscPixels x;
  69.     MiscPixels y;
  70. public:
  71.     MiscPixels getX() const { return x; }
  72.     MiscPixels getY() const { return y; }
  73.     MiscPixels getX_O() const { return isHorz() ? x : y; }
  74.     MiscPixels getY_O() const { return isHorz() ? y : x; }
  75.     void setX( MiscPixels n ) { x = n; }
  76.     void setY( MiscPixels n ) { y = n; }
  77.     void setX_O( MiscPixels n ) { (isHorz() ? x : y) = n; }
  78.     void setY_O( MiscPixels n ) { (isHorz() ? y : x) = n; }
  79.     MiscPoint_O& operator=( MiscPoint_O const& p )
  80.     { setX_O( p.getX_O() ); setY_O( p.getY_O() ); return *this; }
  81.     bool operator==( MiscPoint_O const& p ) const
  82.     { return isHorz() == p.isHorz() &&
  83.         getX_O() == p.getX_O() && getY_O() == p.getY_O(); }
  84.     bool operator!=( MiscPoint_O const& p ) const { return !operator==(p); }
  85.  
  86.     NSPoint nsPoint() const { return NSMakePoint( x, y ); }
  87.     operator NSPoint() const { return nsPoint(); }
  88.     MiscPoint_O& operator=( NSPoint );
  89.  
  90.     MiscPoint_O( bool is_horz, MiscPixels _x = 0, MiscPixels _y = 0 ) :
  91.     MiscOrientation(is_horz),x(_x),y(_y) {}
  92.     MiscPoint_O( MiscBorderType b, MiscPixels _x = 0, MiscPixels _y = 0 ) :
  93.     MiscOrientation(b),x(_x),y(_y) {}
  94.     MiscPoint_O( MiscPoint_O const& p ) :
  95.     MiscOrientation(p.isHorz()),x(p.getX_O()),y(p.getY_O()) {}
  96.     MiscPoint_O( bool is_horz, NSPoint );
  97.     MiscPoint_O( MiscBorderType b, NSPoint );
  98.     };
  99.  
  100.  
  101. class MiscSize_O : public virtual MiscOrientation
  102.     {
  103. private:
  104.     MiscPixels width;
  105.     MiscPixels height;
  106. public:
  107.     MiscPixels getWidth() const { return width; }
  108.     MiscPixels getHeight() const { return height; }
  109.     MiscPixels getWidth_O() const { return isHorz() ? width : height; }
  110.     MiscPixels getHeight_O() const { return isHorz() ? height : width; }
  111.     void setWidth( MiscPixels w ) { width = w; }
  112.     void setHeight( MiscPixels h ) { height = h; }
  113.     void setWidth_O( MiscPixels w ) { (isHorz() ? width : height) = w; }
  114.     void setHeight_O( MiscPixels h ) { (isHorz() ? height : width) = h; }
  115.     MiscSize_O& operator=( MiscSize_O const& p )
  116.     { setWidth_O( p.getWidth_O() ); setHeight_O( p.getHeight_O() );
  117.         return *this; }
  118.     bool operator==( MiscSize_O const& p ) const
  119.     { return isHorz() == p.isHorz() && getWidth_O() == p.getWidth_O() &&
  120.         getHeight_O() == p.getHeight_O(); }
  121.     bool operator!=( MiscSize_O const& p ) const { return !operator==(p); }
  122.  
  123.     NSSize nsSize() const { return NSMakeSize( width, height ); }
  124.     operator NSSize() const { return nsSize(); }
  125.     MiscSize_O& operator=( NSSize );
  126.  
  127.     MiscSize_O( bool is_horz, MiscPixels w = 0, MiscPixels h = 0 ) :
  128.     MiscOrientation(is_horz),width(w),height(h) {}
  129.     MiscSize_O( MiscBorderType b, MiscPixels w = 0, MiscPixels h = 0 ) :
  130.     MiscOrientation(b),width(w),height(h) {}
  131.     MiscSize_O( MiscSize_O const& p ) : MiscOrientation(p.isHorz()),
  132.     width(p.getWidth_O()),height(p.getHeight_O()) {}
  133.     MiscSize_O( bool is_horz, NSSize );
  134.     MiscSize_O( MiscBorderType b, NSSize );
  135.     };
  136.  
  137.  
  138. class MiscRect_O : public MiscPoint_O, public MiscSize_O
  139.     {
  140. public:
  141.     MiscPixels getMaxX() const { return getX() + getWidth(); }
  142.     MiscPixels getMaxY() const { return getY() + getHeight(); }
  143.     MiscPixels getMaxX_O() const { return getX_O() + getWidth_O(); }
  144.     MiscPixels getMaxY_O() const { return getY_O() + getHeight_O(); }
  145.     MiscRect_O& operator=( MiscPoint_O const& p )
  146.     { MiscPoint_O::operator=( p ); return *this; }
  147.     MiscRect_O& operator=( MiscSize_O const& p )
  148.     { MiscSize_O::operator=( p ); return *this; }
  149.     MiscRect_O& operator=( MiscRect_O const& r )
  150.     { MiscPoint_O::operator=(r); MiscSize_O::operator=(r); return *this; }
  151.     bool operator==( MiscRect_O const& r ) const
  152.     { return MiscPoint_O::operator==(r) && MiscSize_O::operator==(r); }
  153.     bool operator!=( MiscRect_O const& r ) const { return !operator==(r); }
  154.  
  155.     NSRect nsRect() const { NSRect r = { nsPoint(), nsSize() }; return r; }
  156.     operator NSRect() const { return nsRect(); }
  157.     MiscRect_O& operator=( NSPoint p )
  158.     { MiscPoint_O::operator=(p); return *this; }
  159.     MiscRect_O& operator=( NSSize s )
  160.     { MiscSize_O::operator=(s); return *this; }
  161.     MiscRect_O& operator=( NSRect r )
  162.     { MiscPoint_O::operator=( r.origin ); MiscSize_O::operator=( r.size );
  163.         return *this; }
  164.  
  165.     MiscRect_O( bool is_horz, MiscPixels x = 0, MiscPixels y = 0,
  166.     MiscPixels w = 0, MiscPixels h = 0 ) : MiscOrientation(is_horz),
  167.     MiscPoint_O(is_horz,x,y),MiscSize_O(is_horz,w,h) {}
  168.     MiscRect_O( MiscBorderType b, MiscPixels x = 0, MiscPixels y = 0,
  169.     MiscPixels w = 0, MiscPixels h = 0 ) :
  170.     MiscOrientation(b),MiscPoint_O(b,x,y),MiscSize_O(b,w,h) {}
  171.     MiscRect_O( MiscRect_O const& r ) :
  172.     MiscOrientation(r.isHorz()),MiscPoint_O(r),MiscSize_O(r) {}
  173.     MiscRect_O( bool is_horz, NSRect r ) : MiscOrientation(is_horz),
  174.     MiscPoint_O(is_horz,r.origin),MiscSize_O(is_horz,r.size) {}
  175.     MiscRect_O( MiscBorderType b, NSRect r ) : MiscOrientation(b),
  176.     MiscPoint_O(b,r.origin),MiscSize_O(b,r.size) {}
  177.     };
  178.  
  179. #endif // __MiscGeometry_h
  180.