// BlinkGame - Hunt for the Lost Pixels
// an SDL game in honor of the BlinkenArea crew
//
// (C) 2005-06 Rene Schickbauer
//
// See License.txt for licensing information
//
#ifdef NOP_CODE
/*--------------------------------------------------------------------
					CVS AUTO-GENERATED INFO
$Author: cavac $
$Date: 2006/03/02 13:03:41 $
$Name: rel-0-3-patches $
$Revision: 1.5 $
$State: Exp $

$Log: drawprimitives.cpp,v $
Revision 1.5  2006/03/02 13:03:41  cavac
Re-formatted all .cpp and .h files a bit to get rid of the TAB/SPACE mess
that makes troubles with XCode's "re-format" feature

Revision 1.4  2006/02/24 22:25:53  cavac
(Probably) fixed warning Tracker #1430266

Revision 1.3  2006/02/10 18:56:17  cavac
Code Audit: Fixed many 64Bit based problems (mostly untested)

Revision 1.2  2006/01/09 00:50:34  cavac
Bugfixed CVS autogenerated entries in background.cpp
Added CVS autogenerated entries to remaining .cpp and .h files
Updated copyright from "2005 Rene Schickbauer" to "2005-06 Rene Schickbauer"


--------------------------------------------------------------------*/
#endif //NOP_CODE

#include "globals.h"
#include "drawprimitives.h"
#include <math.h>

void drawcircle(Sint32 x, Sint32 y, Sint32 r, Uint32 c)
{
	Uint32 pitch = gScreen->pitch / 4;
	
	Sint32 i, j;
	for (i = 0; i < 2 * r; i++)
	{
		// vertical clipping: (top and bottom)
		if ((y - r + i) >= 0 && (y - r + i) < SCR_HEIGHT)
		{
			Sint32 len = (int)sqrt((float)(r * r - (r - i) * (r - i))) * 2;
			Sint32 xofs = x - len / 2;
			
			// left border
			if (xofs < 0)
			{
				len += xofs;
				xofs = 0;
			}
			
			// right border
			if (xofs + len >= SCR_WIDTH)
			{
				len -= (xofs + len) - SCR_WIDTH;
			}
			Sint32 ofs = (y - r + i) * pitch + xofs;
			
			// note that len may be 0 at this point, 
			// and no pixels get drawn!
			for (j = 0; j < len; j++)
				((Uint32*)gScreen->pixels)[ofs + j] = c;
		}
	}
}


void drawrect(Sint32 x, Sint32 y, Sint32 width, Sint32 height, Sint32 c)
{
	Sint32 i, j;
	Sint32 pitch = gScreen->pitch / 4;
	
	for (i = 0; i < height; i++)
	{
		// vertical clipping: (top and bottom)
		if ((y + i) >= 0 && (y + i) < SCR_HEIGHT)
		{
			Sint32 len = width;
			Sint32 xofs = x;
			
			// left border
			if (xofs < 0)
			{
				len += xofs;
				xofs = 0;
			}
			
			// right border
			if (xofs + len >= SCR_WIDTH)
			{
				len -= (xofs + len) - SCR_WIDTH;
			}
			Sint32 ofs = (i + y) * pitch + xofs;
			
			// note that len may be 0 at this point, 
			// and no pixels get drawn!
			for (j = 0; j < len; j++)
				((Uint32*)gScreen->pixels)[ofs + j] = c;
		}
	}
}
