/////////////////////////////////////////////////////////////
// CINEMA 4D SDK                                           //
/////////////////////////////////////////////////////////////
// (c) MAXON Computer GmbH, all rights reserved            //
/////////////////////////////////////////////////////////////

#ifndef _LIB_CLIPMAP_H_
#define _LIB_CLIPMAP_H_

#include "c4d_library.h"

#ifdef __API_INTERN__

#include "ge_file.h"
#include	"ge_cp2d.h"

#define iGeClipMap	GeClipMap

#else

#include "c4d_file.h"

enum GE_CM_CLIPREGION
{
	GE_CM_CLIPREGION_EVENODD		= 1,
	GE_CM_CLIPREGION_WINDING		= 2
} ENUM_END_LIST(GE_CM_CLIPREGION);

enum GE_CM_DRAWMODE
{
	GE_CM_DRAWMODE_COPY			= 0,
	GE_CM_DRAWMODE_BLEND		= 1,
	GE_CM_DRAWMODE_MASK			= 2
} ENUM_END_LIST(GE_CM_DRAWMODE);

#ifndef GE_CM_SRC_MAX_OPACITY
#define	GE_CM_SRC_MAX_OPACITY	256														// this is the maximum source opacity for GE_CM_DRAWMODE_BLEND and equals 1.0 which means opaque, 128 equals 0.5 and so on ...
#endif

enum GE_CM_BLIT
{
	GE_CM_BLIT_COPY			= 0,																	// source overwrites destination
	GE_CM_BLIT_COL			= 1,																	// source overwrites destination wherever source doesn't equal the background color
	GE_CM_BLIT_FG				= 2																		// sets pixels to the foreground color if the color is not the background color
} ENUM_END_LIST(GE_CM_BLIT);

enum GE_CM_ARCSEGMENT
{
	GE_CM_ARCSEGMENT_RIGHTTOP    = 0, // (x1,y1) -> (x2,y1) -> (x2,y2)
	GE_CM_ARCSEGMENT_RIGHTBOTTOM = 1, // (x2,y1) -> (x2,y2) -> (x1,y2)
	GE_CM_ARCSEGMENT_LEFTBOTTOM  = 2, // (x2,y2) -> (x1,y2) -> (x1,y1)
	GE_CM_ARCSEGMENT_LEFTTOP     = 3  // (x1,y2) -> (x1,y1) -> (x2,y1)
} ENUM_END_LIST(GE_CM_ARCSEGMENT);

enum GE_CM_FONTSORT
{
	GE_CM_FONTSORT_FLAT					= 0,
	GE_CM_FONTSORT_HIERARCHICAL	= 1
} ENUM_END_LIST(GE_CM_FONTSORT);

class BaseBitmap;

typedef struct _NGV_DRAW_PORT*		NGVH_DP;
typedef struct _NGV_RGN*					NGVH_RGN;

struct GE_POINT2D
{
	LONG x;
	LONG y;
};

enum GeFontNameType
{
	GE_FONT_NAME_DISPLAY = 0,																	// human readable font name (e.g. "Helvetica Bold")
	GE_FONT_NAME_FAMILY = 1,																	// font family name (e.g. "Helvetica")
	GE_FONT_NAME_STYLE = 2,																		// font style name (e.g. "Bold")
	GE_FONT_NAME_POSTSCRIPT = 3																// font postscript name (e.g. "Helvetica-Bold")
};

enum GeFontDefaultType
{
	GE_FONT_DEFAULT_SYSTEM = 0,																// the c4d system font
	GE_FONT_DEFAULT_MONOSPACED = 1														// the c4d monospaced font
};

enum GeFontSizeType
{
	GE_FONT_SIZE_INTERNAL = 0																	// the unit of the font size is not specified (OS or context dependent) it is NOT guaranteed to be pixels or points or whatever, you can only use it to compare the size of two font descriptions
};

class GeClipMap
{
	public:
		static GeClipMap* Alloc();
		static void Free       (GeClipMap *&data);

	private:
		GeClipMap();
		~GeClipMap();

	public:
		IMAGERESULT	Init			(LONG w, LONG h, LONG bits);
		IMAGERESULT	Init   		(BaseBitmap *bm);
		IMAGERESULT	Init   		(BaseBitmap *bm, BaseBitmap *alpha_channel);
		IMAGERESULT	Init      (const Filename &name, LONG frame, Bool *ismovie);
		void	Destroy					();

		void	GetDim					(LONG *w, LONG *h) const;
		LONG	GetBw						() const;
		LONG	GetBh						() const;

		BaseBitmap* GetBitmap	();

		void	BeginDraw				();
		void	EndDraw					();

		void	SetOffset				(LONG off_x, LONG off_y);

		void	SetDrawMode			(GE_CM_DRAWMODE mode, ULONG par);

		void	SetColor				(LONG r, LONG g, LONG b, LONG a = 255);

		void	SetPixel				(LONG x, LONG y);
		void	Line						(LONG x1, LONG y1, LONG x2, LONG y2);
		void	PolyLine				(LONG cnt, GE_POINT2D *points);
		void	FillPolygon			(LONG cnt, GE_POINT2D *points);
		void	Rect						(LONG x1, LONG y1, LONG x2, LONG y2);
		void	FillRect				(LONG x1, LONG y1, LONG x2, LONG y2);
		void	Arc							(LONG x1, LONG y1, LONG x2, LONG y2, GE_CM_ARCSEGMENT seg);
		void	FillArc					(LONG x1, LONG y1, LONG x2, LONG y2, GE_CM_ARCSEGMENT seg);
		void	Ellipse					(LONG x1, LONG y1, LONG x2, LONG y2);
		void	FillEllipse			(LONG x1, LONG y1, LONG x2, LONG y2);

		void	SetPixelRGBA		(LONG x, LONG y, LONG r, LONG g, LONG b, LONG a = 255);
		void	GetPixelRGBA		(LONG x, LONG y, LONG *r, LONG *g, LONG *b, LONG *a);

		void	TextAt					(LONG x, LONG y, const String &txt);
		LONG	GetTextWidth		(const String &txt);
		LONG	GetTextHeight		();
		LONG	GetTextAscent		();

		void	Blit						(LONG dx, LONG dy, const GeClipMap &s_dp, LONG sx1, LONG sy1, LONG sx2, LONG sy2, GE_CM_BLIT rop);

		void	SetClipRgn			(LONG left, LONG top, LONG right, LONG bottom);
		void	SetClipRgn			(GE_POINT2D *points, LONG count, GE_CM_CLIPREGION mode);

		Bool	ClipPoint				(LONG x, LONG y);
		LONG	ClipArea				(LONG x1, LONG y1, LONG x2, LONG y2);

		Bool	SetFont( BaseContainer const *font_description, Real font_size = 0.0 );
		Real	GetFont( BaseContainer *font_description );
		static Bool	GetFontName( BaseContainer const *font_description, GeFontNameType type, String *dst );
		static Bool	GetFontDescription( String const &name, GeFontNameType type, BaseContainer *dst );
		static void	EnumerateFonts( BaseContainer *dst, GE_CM_FONTSORT sort_mode );
		static Bool	GetDefaultFont( GeFontDefaultType type, BaseContainer *font_description );
		static Bool	GetFontSize( BaseContainer const *font_description, GeFontSizeType type, Real *size );
		static Bool	SetFontSize( BaseContainer *font_description, GeFontSizeType type, Real size );
};

class iGeClipMap;

#endif

// INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF
// INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF
// INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF

#define LIB_CLIPMAP 		1000494

struct GeClipMapLib : public C4DLibrary
{
		GeClipMap*	(*Alloc)											();
		void				(*Free)												(GeClipMap *&data);

		IMAGERESULT	(*Init)(iGeClipMap *this_ptr, LONG w, LONG h, LONG bits);
		IMAGERESULT	(*InitWith)(iGeClipMap *this_ptr, BaseBitmap *bm);
		IMAGERESULT	(*InitFrom)(iGeClipMap *this_ptr, BaseBitmap *bm, BaseBitmap *alpha_channel);
		IMAGERESULT	(*InitFromFile)(iGeClipMap *this_ptr, const Filename &name, LONG frame, Bool *ismovie);
		void				(*Destroy)(iGeClipMap *this_ptr);
		void				(*GetDim)(const iGeClipMap *this_ptr, LONG *w, LONG *h) ;
		BaseBitmap*	(*GetBitmap)(iGeClipMap *this_ptr);
		void				(*BeginDraw)(iGeClipMap *this_ptr);
		void				(*EndDraw)(iGeClipMap *this_ptr);
		void				(*SetOffset)(iGeClipMap *this_ptr, LONG off_x, LONG off_y);
		void				(*SetDrawMode)(iGeClipMap *this_ptr, GE_CM_DRAWMODE mode, ULONG par);
		void				(*SetColor)(iGeClipMap *this_ptr, LONG r, LONG g, LONG b, LONG a);
		void				(*SetPixel)(iGeClipMap *this_ptr, LONG x, LONG y);
		void				(*CMLine)(iGeClipMap *this_ptr, LONG x1, LONG y1, LONG x2, LONG y2);
		void				(*PolyLine)(iGeClipMap *this_ptr, LONG cnt, GE_POINT2D *points);
		void				(*FillPolygon)(iGeClipMap *this_ptr, LONG cnt, GE_POINT2D *points);
		void				(*Rect)(iGeClipMap *this_ptr, LONG x1, LONG y1, LONG x2, LONG y2);
		void				(*FillRect)(iGeClipMap *this_ptr, LONG x1, LONG y1, LONG x2, LONG y2);
		void				(*Arc)(iGeClipMap *this_ptr, LONG x1, LONG y1, LONG x2, LONG y2, GE_CM_ARCSEGMENT seg);
		void				(*FillArc)(iGeClipMap *this_ptr, LONG x1, LONG y1, LONG x2, LONG y2, GE_CM_ARCSEGMENT seg);
		void				(*Ellipse)(iGeClipMap *this_ptr, LONG x1, LONG y1, LONG x2, LONG y2);
		void				(*FillEllipse)(iGeClipMap *this_ptr, LONG x1, LONG y1, LONG x2, LONG y2);
		void				(*SetPixelRGBA)(iGeClipMap *this_ptr, LONG x, LONG y, LONG r, LONG g, LONG b, LONG a);
		void				(*GetPixelRGBA)(iGeClipMap *this_ptr, LONG x, LONG y, LONG *r, LONG *g, LONG *b, LONG *a);
		void				(*TextAt)(iGeClipMap *this_ptr, LONG x, LONG y, const String &txt);
		LONG				(*GetTextWidth)(iGeClipMap *this_ptr, const String &txt);
		LONG				(*GetTextHeight)(iGeClipMap *this_ptr);
		LONG				(*GetTextAscent)(iGeClipMap *this_ptr);
		void				(*Blit)(iGeClipMap *this_ptr, LONG dx, LONG dy, const iGeClipMap &s_dp, LONG sx1, LONG sy1, LONG sx2, LONG sy2, GE_CM_BLIT rop);
		void				(*SetClipRgn)(iGeClipMap *this_ptr, LONG left, LONG top, LONG right, LONG bottom);
		void				(*SetClipRgn2)(iGeClipMap *this_ptr, GE_POINT2D *points, LONG count, GE_CM_CLIPREGION mode);
		Bool				(*ClipPoint)(iGeClipMap *this_ptr, LONG x, LONG y);
		LONG				(*ClipArea)(iGeClipMap *this_ptr, LONG x1, LONG y1, LONG x2, LONG y2);
		LONG				(*GetBw)(const iGeClipMap *this_ptr);
		LONG				(*GetBh)(const iGeClipMap *this_ptr);
		Bool				(*SetFont				  )(iGeClipMap *this_ptr,  BaseContainer const *font_description, Real font_size );
		Real				(*GetFont				  )(iGeClipMap *this_ptr,  BaseContainer *font_description );
		Bool				(*GetFontName									)( BaseContainer const *font_description, GeFontNameType type, String *dst );
		Bool				(*GetFontDescription					)( String const &name, GeFontNameType type, BaseContainer *dst );
		void				(*EnumerateFonts							)( BaseContainer *dst, GE_CM_FONTSORT sort_mode );
		Bool				(*GetDefaultFont							)( GeFontDefaultType type, BaseContainer *font_description );
		Bool				(*GetFontSize									)( BaseContainer const *font_description, GeFontSizeType type, Real *size );
		Bool				(*SetFontSize									)( BaseContainer *font_description, GeFontSizeType type, Real size );

};

// INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF
// INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF
// INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF -- INTERNAL STUFF

#endif
