/* ======================================================================== *
         GetDClip -- gets the size of the screen, including DisplayClip
							       By Talin.
				  Compiled under Manx 5.0 with small code/data
 * ======================================================================== */

#include <std_headers.h>
#include <graphics/videocontrol.h>

struct TagItem vpe_tags[2] = { { VTAG_VIEWPORTEXTRA_GET, NULL }, { TAG_DONE, } };

extern struct Library	*GfxBase;

void GetDClip(struct Screen *s, struct IBox *result)
{	struct ViewPortExtra *vpe;

	result->Left = 0;
	result->Top = 0;
	result->Width = s->Width;
	result->Height = s->Height;

	if (GfxBase->lib_Version >= 36)
	{	vpe_tags[0].ti_Data = NULL;
		vpe_tags[0].ti_Tag = VTAG_VIEWPORTEXTRA_GET;
		VideoControl(s->ViewPort.ColorMap,vpe_tags);

		if (vpe = (struct ViewPortExtra *)vpe_tags[0].ti_Data)
		{	result->Left = vpe->DisplayClip.MinX;
			result->Top = vpe->DisplayClip.MinY;
			result->Width =  clamp(0,vpe->DisplayClip.MaxX + 1 - vpe->DisplayClip.MinX,s->Width);
			result->Height = clamp(0,vpe->DisplayClip.MaxY + 1 - vpe->DisplayClip.MinY,s->Height);
		}
	}
}
