/*                      QBCC Project

This source file is licensed under the GNU Lesser Public Licence which should be 
included with the distribution of this source.

*/
// Console Graphics routines for windows


#include <windows.h>

#include "../../include/graphics.h"

WORD QB_TextColour = 7;			// Default (grey)

///////////////////
// LOCATE
void LOCATE(int *col, int *row)
{	
	COORD curpos;
	HANDLE hstdout;
	hstdout = GetStdHandle(STD_OUTPUT_HANDLE);

	curpos.X = *row;
	curpos.Y = *col;
	SetConsoleCursorPosition(hstdout,curpos);
}


///////////////////
// CLS
void CLS(void)
{
	COORD coordScreen = { 0, 0 };		// Home Coord	
	CONSOLE_SCREEN_BUFFER_INFO csbi;	// Buffer info
	DWORD cCharsWritten;				// Here to keep functions happy	

	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);		

	FillConsoleOutputAttribute(GetStdHandle(STD_OUTPUT_HANDLE)
								, QB_TextColour, (csbi.dwSize.X * (csbi.dwSize.Y + 1)) - csbi.dwSize.X
								,coordScreen, &cCharsWritten);

	FillConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE), 
		                       (TCHAR) ' ',(csbi.dwSize.X * (csbi.dwSize.Y + 1)) - csbi.dwSize.X
							   , coordScreen, &cCharsWritten);
	
}


///////////////////
// COLOR
void COLOR(int *textcol,int *backcol)
{
	HANDLE hstdout;
	QB_TextColour = *textcol + (*backcol * 16);
	
	hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hstdout, QB_TextColour);
}