// ----------------------------------------------------------------------------
// Blitz-Irrlicht 1.8.3 Wrapper by Ed Musolino 2015
// Based off of Frank Dodd's Irrlicht 1.7 Freebasic Wrapper (2006-2010)
// ----------------------------------------------------------------------------

//  This software is provided 'as-is', without any express Or implied
//  warranty.  In no event will the authors be held liable For any damages
//  arising from the use of this software.

//  Permission is granted To anyone To use this software For any purpose,
//  including commercial applications, And To alter it And redistribute it
//  freely, subject To the following restrictions:

//  1. The Origin of this software must Not be misrepresented; you must not
//     claim that you wrote the original software. If you use this software
//     in a product, an acknowledgement in the product documentation would be
//     appreciated but is Not required.
//  2. Altered source versions must be clearly marked as such, And must Not be
//     misrepresented as being the original software.
//  3. This notice may Not be removed Or altered from any source distribution.
//
// /////////////////////////////////////////////////////////////////////////////

#include "bIrrlicht.h"


extern IrrlichtDevice*		device;
extern IVideoDriver*		driver;
extern ISceneManager*		smgr;
extern IGUIEnvironment*		guienv;

extern int g_TextColorAlpha;
extern int g_TextColorRed;
extern int g_TextColorGrn;
extern int g_TextColorBlu;



extern "C"
{

/* ----------------------------------------------------------------------------
load a bitmap based font
*/
DLL_EXPORT int * BBCALL iLoadFont( char * font )
{
	IGUIFont * dfont;
	dfont = device->getGUIEnvironment()->getFont( font );
	if(dfont)
		return (int *)dfont;
	else
		return (int *)device->getGUIEnvironment()->getBuiltInFont();
}

/* ----------------------------------------------------------------------------
draw text to the display using a bitmap font
*/
DLL_EXPORT void BBCALL iText( IGUIFont* font, const char * wcptrText, int tx, int ty, int bx, int by )
{
	//CHECK IF VALID FONT EXISTS
	if (!font && guienv)
		font = guienv->getBuiltInFont();
	font->draw(ConvertCharToWChar(wcptrText), core::rect<s32>(tx, ty, bx, by), video::SColor(g_TextColorAlpha, g_TextColorRed, g_TextColorGrn, g_TextColorBlu));
}

DLL_EXPORT void BBCALL iColor( unsigned int alpha, unsigned int red, unsigned int green, unsigned int blue )
{
	if(alpha<0){alpha=0;}
	if(alpha>255){alpha=255;}
	if(red<0){red=0;}
	if(red>255){red=255;}
	if(green<0){green=0;}
	if(green>255){green=255;}
	if(blue<0){blue=0;}
	if(blue>255){blue=255;}

	g_TextColorAlpha = alpha;
	g_TextColorRed = red;
	g_TextColorGrn = green;
	g_TextColorBlu = blue;
}









}