//	Zinc Application Framework - Z_REGION.HPP
//	COPYRIGHT (C) 1990-1999.  All Rights Reserved.
//	Zinc Software Incorporated.  Pleasant Grove, Utah  USA

#if !defined(Z_REGION_HPP)
#define Z_REGION_HPP
#include <z_pos.hpp>

// --------------------------------------------------------------------------
// ----- ZafRegionStruct ----------------------------------------------------
// --------------------------------------------------------------------------

class ZAF_EXPORT ZafDisplay;
struct ZAF_EXPORT ZafRegionStruct
{
	int left, top, right, bottom;
	ZafCoordinateType coordinateType;

	void Assign(int left, int top, int width, int height, ZafCoordinateType type = ZAF_COORD_DEFAULT);
	bool Encompassed(const ZafRegionStruct &region) const;
	int Height(void) const;
	void HzShift(int shift);
	bool Overlap(const ZafRegionStruct &region) const;
	bool Overlap(const ZafPositionStruct &position) const;
	bool Overlap(const ZafPositionStruct &position, int columnShift, int lineShift) const;
	bool Overlap(const ZafRegionStruct &region, ZafRegionStruct &result) const;
	bool Touching(const ZafPositionStruct &position) const;
	void VtShift(int shift);
	int Width(void) const;

	// --- Conversion ---
	void ConvertCoordinates(ZafCoordinateType newType, ZafDisplay *display = ZAF_NULLP(ZafDisplay));
	ZafRegionStruct Region(ZafCoordinateType type) const;

	// --- Operators ---
	bool operator==(const ZafRegionStruct &region) const;
	bool operator!=(const ZafRegionStruct &region) const;
	ZafRegionStruct operator++(void);
	ZafRegionStruct operator++(int);
	ZafRegionStruct operator--(void);
	ZafRegionStruct operator--(int);
	ZafRegionStruct &operator+=(int offset);
	ZafRegionStruct &operator-=(int offset);

	// --- OS specific functions ---
#	if defined(ZAF_MSWINDOWS)
	void ExportPixel(OSRegion &rect) const { rect.left = left, rect.top = top, rect.right = right, rect.bottom = bottom; }
	void ExportPoint(OSRegion &rect) const { rect.left = left, rect.top = top, rect.right = right + 1, rect.bottom = bottom + 1; }
	void ImportPixel(const OSRegion &rect) { left = rect.left, top = rect.top, right = rect.right, bottom = rect.bottom, coordinateType = ZAF_PIXEL; }
	void ImportPoint(const OSRegion &rect) { left = rect.left, top = rect.top, right = rect.right - 1, bottom = rect.bottom - 1, coordinateType = ZAF_PIXEL; }
#	elif defined(ZAF_MACINTOSH)
	// Add or subtract one on the bottom and right to convert between pixels and points.
	// Zinc regions are always in pixel coordinates.
	void ExportPixel(OSRegion &rect) const { rect.left = (short)left, rect.top = (short)top, rect.right = (short)right, rect.bottom = (short)bottom; }
	void ExportPoint(OSRegion &rect) const { rect.left = (short)left, rect.top = (short)top, rect.right = (short)(right + 1), rect.bottom = (short)(bottom + 1); }
	void ImportPixel(const OSRegion &rect) { left = rect.left, top = rect.top, right = rect.right, bottom = rect.bottom, coordinateType = ZAF_PIXEL; }
	void ImportPoint(const OSRegion &rect) { left = rect.left, top = rect.top, right = rect.right - 1, bottom = rect.bottom - 1, coordinateType = ZAF_PIXEL; }
#	endif
};

// --- inline functions ---
inline void ZafRegionStruct::Assign(int tLeft, int tTop, int tWidth, int tHeight, ZafCoordinateType tCoordinateType)
	{ left = tLeft, right = tLeft + tWidth - 1, top = tTop, bottom = tTop + tHeight - 1;
	  coordinateType = (tCoordinateType != ZAF_COORD_DEFAULT) ? tCoordinateType : coordinateType; }
inline int ZafRegionStruct::Height(void) const { return (bottom - top + 1); }
inline void ZafRegionStruct::HzShift(int shift)
	{ right += shift, left += shift; }
inline void ZafRegionStruct::VtShift(int shift)
	{ bottom += shift, top += shift; }
inline int ZafRegionStruct::Width(void) const { return (right - left + 1); }

inline ZafRegionStruct &ZafRegionStruct::operator+=(int offset)
	{ left -= offset, top -= offset, right += offset, bottom += offset; return (*this); }
inline ZafRegionStruct &ZafRegionStruct::operator-=(int offset)
	{ left += offset, top += offset, right -= offset, bottom -= offset; return (*this); }

#endif // Z_REGION_HPP

