#ifdef __APPLE_CC__
#include <Carbon/Carbon.h>
#else
#ifndef __LOWMEM__
#include <LowMem.h>
#endif

#ifndef __QUICKDRAW__
#include <QuickDraw.h>
#endif
#endif

#include "Frame3DHiliteProc.h"


static const RGBColor	_00Col = {0,0,0};
//===============================
pascal void Frame3DHiliteProc( const Rect* inRect, BlugsRef inList )
{
	#pragma unused (inList)
	RGBColor	hiliteRGB, darkHilite, liteHilite;
	Rect		tempRect;
	
	LMGetHiliteRGB( &hiliteRGB );
	darkHilite.red = (hiliteRGB.red >= 0x2000) ? hiliteRGB.red - 0x2000 : 0x0000;
	darkHilite.green = (hiliteRGB.green >= 0x2000) ? hiliteRGB.green - 0x2000 : 0x0000;
	darkHilite.blue = (hiliteRGB.blue >= 0x2000) ? hiliteRGB.blue - 0x2000 : 0x0000;
	liteHilite.red = (hiliteRGB.red <= 0xDFFF) ? hiliteRGB.red + 0x2000 : 0xFFFF;
	liteHilite.green = (hiliteRGB.green <= 0xDFFF) ? hiliteRGB.green + 0x2000 : 0xFFFF;
	liteHilite.blue = (hiliteRGB.blue <= 0xDFFF) ? hiliteRGB.blue + 0x2000 : 0xFFFF;
	
	tempRect = *inRect;
	RGBForeColor( &_00Col );
	FrameRect( &tempRect );
	RGBForeColor( &liteHilite );
	MoveTo( tempRect.left + 1, tempRect.bottom - 3 );
	LineTo( tempRect.left + 1, tempRect.top + 1 );
	LineTo( tempRect.right - 3, tempRect.top + 1 );
	Move( -1, 3 );
	LineTo( tempRect.right - 4, tempRect.bottom - 4 );
	LineTo( tempRect.left + 4, tempRect.bottom - 4 );
	RGBForeColor( &hiliteRGB );
	MoveTo( tempRect.left + 1, tempRect.bottom - 2 );
	Line( 0, 0 );
	Move( 2, -2 );
	Line( 0, 0 );
	MoveTo( tempRect.right - 2, tempRect.top + 1 );
	Line( 0, 0 );
	RGBForeColor( &darkHilite );
	MoveTo( tempRect.left + 2, tempRect.bottom - 2 );
	LineTo( tempRect.right - 2, tempRect.bottom - 2 );
	LineTo( tempRect.right - 2, tempRect.top + 2 );
	MoveTo( tempRect.left + 3, tempRect.bottom - 4 );
	LineTo( tempRect.left + 3, tempRect.top + 3 );
	LineTo( tempRect.right - 4, tempRect.top + 3 );
	RGBForeColor( &hiliteRGB );
	InsetRect( &tempRect, 2, 2 );
	FrameRect( &tempRect );
	RGBForeColor( &_00Col );
	InsetRect( &tempRect, 2, 2 );
	FrameRect( &tempRect );
}

//===============================
pascal void WowItsITunesHiliteProc( const Rect* inRect, BlugsRef inList )
{
	#pragma unused (inList)
	//RGBColor	col = {0xBBBB,0xBBBB,0xBBBB};
	RGBColor	col = {0xDDDD,0xDDDD,0xDDDD};
	float		height, rIncr, gIncr, bIncr, i;
	
	height = inRect->bottom - inRect->top;
	if (BLIsActive( inList )) LMGetHiliteRGB( &col );
	rIncr = (65536.0 - col.red) / height;
	gIncr = (65536.0 - col.green) / height;
	bIncr = (65536.0 - col.blue) / height;
	for (i = 0; i < height; i++)
	{
		MoveTo( inRect->left, inRect->top + i + 1 );
		RGBForeColor( &col );
		LineTo( inRect->right - 1, inRect->top + i + 1 );
		col.red += rIncr;
		col.green += gIncr;
		col.blue += bIncr;
	}
}

//===============================
pascal void WowItsAnotherITunesHiliteProc( const Rect* inRect, BlugsRef inList )
{
	#pragma unused (inList)
	RGBColor	col = {0xFFFF,0xFFFF,0xFFFF}, target = {0xDDDD,0xDDDD,0xDDDD};
	float		halfHeight, rIncr, gIncr, bIncr, i;
	
	halfHeight = (inRect->bottom - inRect->top) / 2;
	if (BLIsActive( inList )) LMGetHiliteRGB( &target );
	rIncr = (col.red - target.red) / halfHeight;
	gIncr = (col.green - target.green) / halfHeight;
	bIncr = (col.blue - target.blue) / halfHeight;
	for (i = 0; i < halfHeight; i++)
	{
		MoveTo( inRect->left, inRect->top + i + 1 );
		RGBForeColor( &col );
		LineTo( inRect->right - 1, inRect->top + i + 1 );
		col.red -= rIncr;
		col.green -= gIncr;
		col.blue -= bIncr;
	}
	for (i = 0; i < halfHeight; i++)
	{
		MoveTo( inRect->left, inRect->top + halfHeight + i + 1 );
		RGBForeColor( &col );
		LineTo( inRect->right - 1, inRect->top +  halfHeight + i + 1 );
		col.red += rIncr;
		col.green += gIncr;
		col.blue += bIncr;
	}
}