#include "lib_viewport.h"

//////////////////////////////////////////////////////////////////////////

ViewportHUDLib *lib_viewhud = NULL;
ViewportHighlightLib *lib_viewhlight = NULL;

static ViewportHUDLib *CheckViewportHUDLib(LONG offset) { return (ViewportHUDLib*)CheckLib(LIBRARY_HUD,offset,(C4DLibrary**)&lib_viewhud); }
static ViewportHighlightLib *CheckViewportHighlightLib(LONG offset) { return (ViewportHighlightLib*)CheckLib(LIBRARY_HIGHLIGHT,offset,(C4DLibrary**)&lib_viewhlight); }

#define ViewportHUDLibCall(b) 		ViewportHUDLib *lib = CheckViewportHUDLib(LIBOFFSET(ViewportHUDLib, b)); \
															if (!lib || !lib->b) return; \
															(((iViewportHUD*)this)->*lib->b)

#define ViewportHUDLibCallR(a,b)  ViewportHUDLib *lib = CheckViewportHUDLib(LIBOFFSET(ViewportHUDLib, b)); \
															if (!lib || !lib->b) return a; \
															return (((iViewportHUD*)this)->*lib->b)

#define ViewportHighlightLibCall(b) 		ViewportHighlightLib *lib = CheckViewportHighlightLib(LIBOFFSET(ViewportHighlightLib, b)); \
															if (!lib || !lib->b) return; \
															(((iViewportHighlight*)this)->*lib->b)

#define ViewportHighlightLibCallR(a,b)  ViewportHighlightLib *lib = CheckViewportHighlightLib(LIBOFFSET(ViewportHighlightLib, b)); \
															if (!lib || !lib->b) return a; \
															return (((iViewportHighlight*)this)->*lib->b)

//////////////////////////////////////////////////////////////////////////

ViewportHUD* ViewportHUD::Alloc()
{
	ViewportHUDLib *lib = CheckViewportHUDLib(LIBOFFSET(ViewportHUDLib,Alloc)); if (!lib) return NULL;
	return (ViewportHUD*)lib->Alloc();	
}

void ViewportHUD::Free(ViewportHUD *&p)
{
	if (!p) return;
	ViewportHUDLib *lib = CheckViewportHUDLib(LIBOFFSET(ViewportHUDLib,Free)); if (!lib) return;
	iViewportHUD* i = (iViewportHUD*)p;
	lib->Free(i);
	p = NULL;
}

//////////////////////////////////////////////////////////////////////////

Bool ViewportHUD::AddDescID(BaseDocument *doc, BaseList2D *obj, const DescID &id, const BaseContainer &data)
{
	ViewportHUDLibCallR(FALSE,AddDescID)(doc,obj,id,data);
}

Bool ViewportHUD::BeginGroup()
{
	ViewportHUDLibCallR(FALSE,BeginGroup)();
}

void ViewportHUD::EndGroup()
{
	ViewportHUDLibCall(EndGroup)();
}

Bool ViewportHUD::SetElement(BaseDocument *doc, LONG id, Bool state)
{
	ViewportHUDLibCallR(FALSE,SetElement)(doc,id,state);
}

Bool ViewportHUD::IsValidControl(BaseDocument *doc, BaseList2D *obj, const DescID &id, const BaseContainer &data)
{
	ViewportHUDLibCallR(FALSE,IsValidControl)(doc,obj,id,data);
}

Bool ViewportHUD::DrawHUD(BaseDocument *doc, GeClipMap *clipmap, LONG fps, BaseDraw *bd, LONG flags)
{
	ViewportHUDLibCallR(FALSE,DrawHUD)(doc,clipmap,fps,bd,flags);
}

//////////////////////////////////////////////////////////////////////////

ViewportHighlight* ViewportHighlight::Alloc()
{
	ViewportHighlightLib *lib = CheckViewportHighlightLib(LIBOFFSET(ViewportHighlightLib,Alloc)); if (!lib) return NULL;
	return (ViewportHighlight*)lib->Alloc();	
}

void ViewportHighlight::Free(ViewportHighlight *&p)
{
	if (!p) return;
	ViewportHighlightLib *lib = CheckViewportHighlightLib(LIBOFFSET(ViewportHighlightLib,Free)); if (!lib) return;
	iViewportHighlight* i = (iViewportHighlight*)p;
	lib->Free(i);
	p = NULL;
}

//////////////////////////////////////////////////////////////////////////

Bool ViewportHighlight::Update(BaseDocument *pDoc, BaseDraw *pDraw, LONG x, LONG y)
{
	ViewportHighlightLibCallR(FALSE,Update)(pDoc,pDraw,x,y);
}

Bool ViewportHighlight::Draw(BaseDocument *pDoc, BaseDraw *pDraw)
{
	ViewportHighlightLibCallR(FALSE,Draw)(pDoc,pDraw);
}

Bool ViewportHighlight::Changed(BaseDocument *pDoc)
{
	ViewportHighlightLibCallR(FALSE,Changed)(pDoc);
}

void ViewportHighlight::ResetChanged(BaseDocument *pDoc)
{
	ViewportHighlightLibCall(ResetChanged)(pDoc);
}

Bool ViewportHighlight::HasHit(BaseDocument *pDoc)
{
	ViewportHighlightLibCallR(FALSE,HasHit)(pDoc);
}

void ViewportHighlight::GetHit(BaseDocument *pDoc, HighlightHitData *hitdata)
{
	ViewportHighlightLibCall(GetHit)(pDoc,hitdata);
}

void ViewportHighlight::SetMode(BaseDocument *pDoc, LONG mode)
{
	ViewportHighlightLibCall(SetMode)(pDoc,mode);
}

void ViewportHighlight::SetColor(BaseDocument *pDoc, Vector hcol)
{
	ViewportHighlightLibCall(SetColor)(pDoc,hcol);
}

void ViewportHighlight::SetFlags(BaseDocument *pDoc, LONG flags)
{
	ViewportHighlightLibCall(SetFlags)(pDoc,flags);
}

ViewportSelect *ViewportHighlight::GetViewportSelect(BaseDocument *pDoc, BaseDraw *pDraw)
{
	ViewportHighlightLibCallR(FALSE,GetViewportSelect)(pDoc,pDraw);
}

AtomArray *ViewportHighlight::GetObjects(BaseDocument *pDoc)
{
	ViewportHighlightLibCallR(FALSE,GetObjects)(pDoc);
}

LONG ViewportHighlight::GetFlags(BaseDocument *pDoc)
{
	ViewportHighlightLibCallR(0,GetFlags)(pDoc);
}
