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

#ifndef __LIB_VIEWPORT_H__
#define __LIB_VIEWPORT_H__

#include "c4d_library.h"
#include "ge_matrix.h"

class BaseDocument;
class BaseDraw;
class C4DAtom;
class iViewportHUD;
class iViewportHighlight;
class ViewHUD;
class HUDGroupList;
class AtomArray;
class ViewportSelect;
class GeClipMap;

#define HIGHLIGHT_FLAG_REALTIME		(1<<0)
#define HIGHLIGHT_FLAG_FREESELECT	(1<<1)
#define HIGHLIGHT_FLAG_NOEDITSTATE	(1<<2)
#define HIGHLIGHT_FLAG_FULLMESH		(1<<3)
#define HIGHLIGHT_FLAG_CALLCURSOR	(1<<4)
#define HIGHLIGHT_FLAG_HIDE			(1<<5)
#define HIGHLIGHT_FLAG_SELECTIONS	(1<<6)
#define HIGHLIGHT_FLAG_SNAPPING		(1<<7)
#define HIGHLIGHT_FLAG_ACTIVEONLY	(1<<8)
#define HIGHLIGHT_FLAG_ADDFLAGS		(1<<31)

class ViewportHUD
{
private:

	ViewportHUD();
	~ViewportHUD();

	ViewHUD *m_pHUD;
	HUDGroupList *m_pGroup;
	
public:

	static ViewportHUD *Alloc();
	static void Free(ViewportHUD *&p);

	Bool AddDescID(BaseDocument *doc, BaseList2D *obj, const DescID &id, const BaseContainer &data);
	Bool BeginGroup();
	void EndGroup();
	Bool SetElement(BaseDocument *doc, LONG id, Bool state);
	Bool IsValidControl(BaseDocument *doc, BaseList2D *obj, const DescID &id, const BaseContainer &data);
	Bool DrawHUD(BaseDocument *doc, GeClipMap *clipmap, LONG fps, BaseDraw *bd, LONG flags);
};

struct HighlightHitData
{
	LONG m_HitEdge;
	LONG m_HitPoint;
	LONG m_HitPolygon;
	Real m_HitX;
	Real m_HitY;
	Vector m_HitPos;
	BaseObject *m_pHitObject;
	Matrix	m_HitMg;
	Matrix	m_HitInvMg;
	Real	m_EdgePos;
};

class ViewportHighlight
{
private:

	ViewportHighlight();
	~ViewportHighlight();
	
public:

	static ViewportHighlight *Alloc();
	static void Free(ViewportHighlight *&p);

	Bool Update(BaseDocument *pDoc, BaseDraw *pDraw, LONG x, LONG y);
	Bool Draw(BaseDocument *pDoc, BaseDraw *pDraw);

	Bool Changed(BaseDocument *pDoc);
	void ResetChanged(BaseDocument *pDoc);

	Bool HasHit(BaseDocument *pDoc);
	void GetHit(BaseDocument *pDoc, HighlightHitData *hitdata);

	void SetMode(BaseDocument *pDoc, LONG mode);
	void SetColor(BaseDocument *pDoc, Vector hcol);
	void SetFlags(BaseDocument *pDoc, LONG flags);
	ViewportSelect *GetViewportSelect(BaseDocument *pDoc, BaseDraw *pDraw);
	AtomArray *GetObjects(BaseDocument *pDoc);
	LONG GetFlags(BaseDocument *pDoc);
};

// 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 LIBRARY_HUD	1016073
#define LIBRARY_HIGHLIGHT 1016132
//////////////////////////////////////////////////////////////////////////

struct ViewportHUDLib : public C4DLibrary
{
	iViewportHUD *(*Alloc)();
	void (*Free)(iViewportHUD *&p);

	Bool (iViewportHUD::*AddDescID)(BaseDocument *doc, BaseList2D *obj, const DescID &id, const BaseContainer &data);
	Bool (iViewportHUD::*BeginGroup)();
	void (iViewportHUD::*EndGroup)();
	Bool (iViewportHUD::*SetElement)(BaseDocument *doc, LONG id, Bool state);
	Bool (iViewportHUD::*IsValidControl)(BaseDocument *doc, BaseList2D *obj, const DescID &id, const BaseContainer &data);
	Bool (iViewportHUD::*DrawHUD)(BaseDocument *doc, GeClipMap *clipmap, LONG fps, BaseDraw *bd, LONG flags);
};

struct ViewportHighlightLib : public C4DLibrary
{
	iViewportHighlight *(*Alloc)();
	void (*Free)(iViewportHighlight *&p);

	Bool (iViewportHighlight::*Update)(BaseDocument *pDoc, BaseDraw *pDraw, LONG x, LONG y);
	Bool (iViewportHighlight::*Draw)(BaseDocument *pDoc, BaseDraw *pDraw);
	Bool (iViewportHighlight::*Changed)(BaseDocument *pDoc);
	void (iViewportHighlight::*ResetChanged)(BaseDocument *pDoc);
	Bool (iViewportHighlight::*HasHit)(BaseDocument *pDoc);
	void (iViewportHighlight::*GetHit)(BaseDocument *pDoc, HighlightHitData *hitdata);
	void (iViewportHighlight::*SetMode)(BaseDocument *pDoc, LONG mode);
	void (iViewportHighlight::*SetColor)(BaseDocument *pDoc, Vector hcol);
	void (iViewportHighlight::*SetFlags)(BaseDocument *pDoc, LONG flags);
	ViewportSelect *(iViewportHighlight::*GetViewportSelect)(BaseDocument *pDoc, BaseDraw *pDraw);
	AtomArray *(iViewportHighlight::*GetObjects)(BaseDocument *pDoc);
	LONG (iViewportHighlight::*GetFlags)(BaseDocument *pDoc);
};

// 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	// __LIB_VIEWPORT_H__
