/*  GadTools layout toolkit
**
**  Copyright © 1993-1995 by Olaf `Olsen' Barthel
**  Freely distributable.
*/

#include "gtlayout_global.h"

VOID __regargs
LTP_DrawBevelBox(LayoutHandle *handle,ObjectNode *node)
{
	DrawBevelBox(&handle -> RPort,node -> Left,node -> Top,node -> Width,node -> Height,
		GT_VisualInfo,	handle -> VisualInfo,
		GTBB_Recessed,	TRUE,
	TAG_DONE);
}


/*****************************************************************************/


VOID __regargs
LTP_PlaceText(LayoutHandle *handle,STRPTR text,ULONG textLen,LONG x,LONG y)
{
	Move(&handle -> RPort,x,y);
	Text(&handle -> RPort,text,textLen);
}


/*****************************************************************************/


VOID __regargs
LTP_TunnelDraw(struct RastPort *rp,LONG from,LONG to,LONG y,LONG left,LONG right)
{
	Draw(rp,from,y);
	Draw(rp,left - 1,y);
	Move(rp,right + 1,y);
	Draw(rp,to,y);
}


/*****************************************************************************/


VOID __regargs
LTP_DrawGroove(LayoutHandle *handle,LONG left,LONG top,LONG width,LONG height,LONG from,LONG to)
{
	struct RastPort *rp = &handle -> RPort;

	LTP_SetAPen(rp,handle -> ShadowPen);

	Move(rp,left + 1,top + 1);
	Draw(rp,left + 1,top + height - 2);
	Draw(rp,left,top + height - 1);
	LTP_TunnelDraw(rp,left,left + width - 2,top,from,to);
	Draw(rp,left + width - 4,top + 2);
	Draw(rp,left + width - 4,top + height - 3);
	Move(rp,left + width - 3,top + 2);
	Draw(rp,left + width - 3,top + height - 2);
	Draw(rp,left + 3,top + height - 2);

	LTP_SetAPen(rp,handle -> ShinePen);
	Move(rp,left + width - 2,top + height - 2);
	Draw(rp,left + width - 2,top + 1);
	Draw(rp,left + width - 1,top);
	Draw(rp,left + width - 1,top + height - 1);
	Draw(rp,left + 1,top + height - 1);
	Draw(rp,left + 3,top + height - 3);
	Draw(rp,left + 3,top + 2);
	Move(rp,left + 2,top + height - 3);
	LTP_TunnelDraw(rp,left + 2,left + width - 4,top + 1,from,to);
}


/*****************************************************************************/


VOID __regargs
LTP_DrawLabel(LayoutHandle *handle,ObjectNode *label)
{
	struct RastPort *rp;
	LONG		 left;

	left	= label -> Left + (label -> Width - label -> LabelWidth) / 2;
	rp	= &handle -> RPort;

	LockLayerRom(rp -> Layer);

	if(label -> Label)
	{
		WORD y,to;

		LTP_DrawGroove(handle,label -> Left + handle -> GlyphWidth / 2,y = label -> Top + handle -> RPort . TxHeight / 2,label -> Width - handle -> GlyphWidth,label -> Height - (handle -> RPort . TxHeight + handle -> InterHeight) / 2,left,to = left + label -> LabelWidth - 1);

		LTP_SetAPen(rp,handle -> ShinePen);
		Move(rp,left,y);
		Draw(rp,left,y+1);

		LTP_SetAPen(rp,handle -> ShadowPen);
		Move(rp,to,y);
		Draw(rp,to,y+1);

		LTP_SetPens(rp,handle -> DrawInfo -> dri_Pens[HIGHLIGHTTEXTPEN],0,JAM1);
		LTP_PlaceText(handle,label -> Label,strlen(label -> Label),left + handle -> GlyphWidth,label -> Top + handle -> RPort . TxBaseline);
	}
	else
		LTP_DrawGroove(handle,label -> Left + handle -> GlyphWidth / 2,label -> Top,label -> Width - handle -> GlyphWidth,label -> Height - handle -> InterHeight / 2,left,left + label -> LabelWidth - 1);

	UnlockLayerRom(rp -> Layer);
}
