This is MiscGeometry.h in view mode; [Download] [Up]
#ifndef __MiscGeometry_h
#define __MiscGeometry_h
#ifdef __GNUC__
# pragma interface
#endif
//=============================================================================
//
// Copyright (C) 1996 by Paul S. McCarthy and Eric Sunshine.
// Written by Paul S. McCarthy and Eric Sunshine.
// All Rights Reserved.
//
// This notice may not be removed from this source code.
//
// This object is included in the MiscKit by permission from the authors
// and its use is governed by the MiscKit license, found in the file
// "License.rtf" in the MiscKit distribution. Please refer to that file
// for a list of all applicable permissions and restrictions.
//
//=============================================================================
//-----------------------------------------------------------------------------
// MiscGeometry.h
//
// Geometric types (point, size, rectangle) which understand and can
// adjust for orientation (horizontal or vertical). Orientation is
// specified upon creation and can not be changed thereafter.
//
// Method names with the "_O" suffix take orientation into consideration,
// whereas methods lacking this suffix do not.
//
// Methods dealing with NeXT geometric structures do not apply orientation
// adjustments.
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// $Id: MiscGeometry.h,v 1.2 96/08/30 14:53:14 sunshine Exp $
// $Log: MiscGeometry.h,v $
// Revision 1.2 96/08/30 14:53:14 sunshine
// Fixed some incorrect casts. Added missing return statements.
//
// Revision 1.1 96/05/05 10:53:51 sunshine
// Geometric type structures which know their border orientation.
//-----------------------------------------------------------------------------
#include <misckit/MiscTableTypes.h>
#include "bool.h"
extern "C" {
#import <appkit/graphics.h>
}
class MiscOrientation
{
private:
bool horizontal;
public:
bool isHorz() const { return horizontal; }
bool isVert() const { return !isHorz(); }
MiscBorderType border() const
{ return isHorz() ? MISC_COL_BORDER : MISC_ROW_BORDER; }
MiscOrientation( bool is_horz ) : horizontal(is_horz) {}
MiscOrientation( MiscBorderType b ) : horizontal( b == MISC_COL_BORDER ) {}
};
class MiscPoint_O : public virtual MiscOrientation
{
private:
MiscPixels x;
MiscPixels y;
public:
MiscPixels getX() const { return x; }
MiscPixels getY() const { return y; }
MiscPixels getX_O() const { return isHorz() ? x : y; }
MiscPixels getY_O() const { return isHorz() ? y : x; }
void setX( MiscPixels n ) { x = n; }
void setY( MiscPixels n ) { y = n; }
void setX_O( MiscPixels n ) { (isHorz() ? x : y) = n; }
void setY_O( MiscPixels n ) { (isHorz() ? y : x) = n; }
MiscPoint_O& operator=( MiscPoint_O const& p )
{ setX_O( p.getX_O() ); setY_O( p.getY_O() ); return *this; }
bool operator==( MiscPoint_O const& p ) const
{ return isHorz() == p.isHorz() &&
getX_O() == p.getX_O() && getY_O() == p.getY_O(); }
bool operator!=( MiscPoint_O const& p ) const { return !operator==(p); }
NXPoint nxPoint() const { NXPoint p = { x, y }; return p; }
operator NXPoint() const { return nxPoint(); }
MiscPoint_O& operator=( NXPoint p )
{ x = MiscPixels( p.x ); y = MiscPixels( p.y ); return *this; }
MiscPoint_O( bool is_horz, MiscPixels _x = 0, MiscPixels _y = 0 ) :
MiscOrientation(is_horz),x(_x),y(_y) {}
MiscPoint_O( MiscBorderType b, MiscPixels _x = 0, MiscPixels _y = 0 ) :
MiscOrientation(b),x(_x),y(_y) {}
MiscPoint_O( MiscPoint_O const& p ) :
MiscOrientation(p.isHorz()),x(p.getX_O()),y(p.getY_O()) {}
MiscPoint_O( bool is_horz, NXPoint p ) :
MiscOrientation(is_horz),x(MiscPixels(p.x)),y(MiscPixels(p.y)) {}
MiscPoint_O( MiscBorderType b, NXPoint p ) :
MiscOrientation(b),x(MiscPixels(p.x)),y(MiscPixels(p.y)) {}
};
class MiscSize_O : public virtual MiscOrientation
{
private:
MiscPixels width;
MiscPixels height;
public:
MiscPixels getWidth() const { return width; }
MiscPixels getHeight() const { return height; }
MiscPixels getWidth_O() const { return isHorz() ? width : height; }
MiscPixels getHeight_O() const { return isHorz() ? height : width; }
void setWidth( MiscPixels w ) { width = w; }
void setHeight( MiscPixels h ) { height = h; }
void setWidth_O( MiscPixels w ) { (isHorz() ? width : height) = w; }
void setHeight_O( MiscPixels h ) { (isHorz() ? height : width) = h; }
MiscSize_O& operator=( MiscSize_O const& p )
{ setWidth_O( p.getWidth_O() ); setHeight_O( p.getHeight_O() );
return *this; }
bool operator==( MiscSize_O const& p ) const
{ return isHorz() == p.isHorz() && getWidth_O() == p.getWidth_O() &&
getHeight_O() == p.getHeight_O(); }
bool operator!=( MiscSize_O const& p ) const { return !operator==(p); }
NXSize nxSize() const { NXSize s = { width, height }; return s; }
operator NXSize() const { return nxSize(); }
MiscSize_O& operator=( NXSize s )
{ width = MiscPixels( s.width ); height = MiscPixels( s.height );
return *this; }
MiscSize_O( bool is_horz, MiscPixels w = 0, MiscPixels h = 0 ) :
MiscOrientation(is_horz),width(w),height(h) {}
MiscSize_O( MiscBorderType b, MiscPixels w = 0, MiscPixels h = 0 ) :
MiscOrientation(b),width(w),height(h) {}
MiscSize_O( MiscSize_O const& p ) : MiscOrientation(p.isHorz()),
width(p.getWidth_O()),height(p.getHeight_O()) {}
MiscSize_O( bool is_horz, NXSize p ) :
MiscOrientation(is_horz),
width(MiscPixels(p.width)),height(MiscPixels(p.height)) {}
MiscSize_O( MiscBorderType b, NXSize p ) :
MiscOrientation(b),
width(MiscPixels(p.width)),height(MiscPixels(p.height)) {}
};
class MiscRect_O : public MiscPoint_O, public MiscSize_O
{
public:
MiscPixels getMaxX() const { return getX() + getWidth(); }
MiscPixels getMaxY() const { return getY() + getHeight(); }
MiscPixels getMaxX_O() const { return getX_O() + getWidth_O(); }
MiscPixels getMaxY_O() const { return getY_O() + getHeight_O(); }
MiscRect_O& operator=( MiscPoint_O const& p )
{ MiscPoint_O::operator=( p ); return *this; }
MiscRect_O& operator=( MiscSize_O const& p )
{ MiscSize_O::operator=( p ); return *this; }
MiscRect_O& operator=( MiscRect_O const& r )
{ MiscPoint_O::operator=(r); MiscSize_O::operator=(r); return *this; }
bool operator==( MiscRect_O const& r ) const
{ return MiscPoint_O::operator==(r) && MiscSize_O::operator==(r); }
bool operator!=( MiscRect_O const& r ) const { return !operator==(r); }
NXRect nxRect() const { NXRect r = { nxPoint(), nxSize() }; return r; }
operator NXRect() const { return nxRect(); }
MiscRect_O& operator=( NXPoint p )
{ MiscPoint_O::operator=(p); return *this; }
MiscRect_O& operator=( NXSize s )
{ MiscSize_O::operator=(s); return *this; }
MiscRect_O& operator=( NXRect r )
{ MiscPoint_O::operator=( r.origin ); MiscSize_O::operator=( r.size );
return *this; }
MiscRect_O( bool is_horz, MiscPixels x = 0, MiscPixels y = 0,
MiscPixels w = 0, MiscPixels h = 0 ) : MiscOrientation(is_horz),
MiscPoint_O(is_horz,x,y),MiscSize_O(is_horz,w,h) {}
MiscRect_O( MiscBorderType b, MiscPixels x = 0, MiscPixels y = 0,
MiscPixels w = 0, MiscPixels h = 0 ) :
MiscOrientation(b),MiscPoint_O(b,x,y),MiscSize_O(b,w,h) {}
MiscRect_O( MiscRect_O const& r ) :
MiscOrientation(r.isHorz()),MiscPoint_O(r),MiscSize_O(r) {}
MiscRect_O( bool is_horz, NXRect r ) : MiscOrientation(is_horz),
MiscPoint_O(is_horz,r.origin),MiscSize_O(is_horz,r.size) {}
MiscRect_O( MiscBorderType b, NXRect r ) : MiscOrientation(b),
MiscPoint_O(b,r.origin),MiscSize_O(b,r.size) {}
};
#endif // __MiscGeometry_h
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.