/*	XTypes.h
 *
 *		This declares a number of universal types for the YAAF library,
 *	such as for unsigned integers.
 */

/**********************************************************************

  YAAF is Copyright 1997-1999 by William Woody.

  Redistribution and use in source and binary forms, with or without 
  modification, are permitted provided that the following conditions 
  are met:

  Redistributions of source code must retain the above copyright notice, 
  this list of conditions and the following disclaimer.

  Neither the name of the copyright holder or other contributors may
  be used to promote products derived from this software without
  specific written prior permission.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
  SOFTWARE.
  
  Contact:   woody@alumni.caltech.edu
  Web page:  http://www.pandawave.com/yaaf/

**********************************************************************/

#ifndef YAAF_XTYPES
#define YAAF_XTYPES

#include <XConfig.h>

/************************************************************************/
/*																		*/
/*	Now define various universal types									*/
/*																		*/
/************************************************************************/

/**@name Support--Portable Types
 *
 *	These are the portable integer types. The reason for defining these
 *	types is to explicitly call out places in the YAAF code and
 *	interfaces where particular data types are used. 
 */
//@{

/// Unsigned byte type. This is an 8-bit wide unsigned integer value
typedef unsigned char				uint8;
/// Signed byte. This is an 8-bit wide signed integer value
typedef signed char					sint8;
/// Unsigned word. This is a 16-bit wide unsigned integer value
typedef unsigned short				uint16;
/// Signed word. This is a 16-bit wide signed integer value
typedef signed short				sint16;
/// Unsigned long word. This is a 32-bit wide unsigned integer
typedef unsigned long				uint32;
/// Signed long word. This is a 32-bit wide signed integer
typedef signed long					sint32;

#if !OPT_WINOS

struct XRect {
	sint32	left;
	sint32	top;
	sint32	right;
	sint32	bottom;

#ifdef __cplusplus
	#if OPT_MACOS
	inline XRect() {}
	inline XRect( const Rect &in )
		{ left = in.left; top = in.top; right = in.right; bottom = in.bottom; }
	inline XRect &operator=( const Rect &in )
		{ left = in.left; top = in.top; right = in.right; bottom = in.bottom; return *this; }
	inline Rect MacRect()
		{ Rect r = { top, left, bottom, right }; return r; }
	#endif
#endif
};

#ifndef __cplusplus
typedef struct XRect XRect;
#endif

#else

// redeclare RECT as XRect under windows.
typedef RECT XRect;

#endif



struct XPoint {
	/// 'vertical' or Y value
	sint32	v;
	/// 'horizontal' or X value
	sint32	h;
#ifdef __cplusplus
	#if OPT_MACOS
	inline XPoint() {}
	inline XPoint( const Point &in )
		{ v = in.v; h = in.h; }
	inline XPoint &operator=( const Point &in )
		{ v = in.v; h = in.h; return *this; }
	inline Point MacPoint()
		{ Point p = { v, h }; return p; }
	#endif
#endif
};

#ifndef __cplusplus
typedef struct XPoint XPoint;
#endif



/** Boolean type. This is defined for handling C routines in the
 *  YAAF libraries which return a boolean type to the C++ code.
 */

#if !OPT_WINOS						// already defined by Windows headers
typedef unsigned char				boolean;
#endif

#ifndef __cplusplus
	#ifndef true
	    /// Defined to be 1 if we are using C. This allows us to use bool types.
		#define	true				1
	#endif
	#ifndef false
		/// Defined to be 0 if we are using C. This allows us to use bool types
		#define false				0
	#endif
#endif

/*
 *	Portable string types
 */

typedef unsigned char				pchar;

//@}

/************************************************************************/
/*																		*/
/*	Portable Graphics Types												*/
/*																		*/
/************************************************************************/

#if OPT_WINOS == 1

/*$	Color
 *
 *		This is how I store color in a structure. This uses the
 *	Microsoft Windows color model: 0x00bbggaa
 *
 *		(On Microsoft Windows, this *is* a COLORREF.)
 *
 *		Reserved colors are marked by storing a '01' in the top
 *	8-bits of the word, and the palette entry in the lower 24
 *	bits. These are all defined with the various palette color
 *	macros, and are interpreted internally by YAAF to expand to
 *	certain predefined colors.
 */

	typedef COLORREF Color;
#else
	typedef uint32 Color;
#endif

#endif // YAAF_XTYPES
