/*********************************************************************
*	GFG Global functions
*	SOURCE FILE
*	Autor:	Michal Jirouš
*	Datum: 31.7.2008
*	Soubor: global.cpp
*	Popis: Soubor obsahuje ovladaci funkce GFG rozhrani - nejdulezitejsi je
*			GFG_init, ktera inicializuje nektere promenne
**********************************************************************/

#include "gfg.h"

CMessageBox *GFG_MessageBox_2Buttons( CMainWindow * pMainWindow, GFG_msgBoxTypes type, std::string sQuestion, std::string leftButtonCaption, int leftButtonID,
							 std::string rightButtonCaption, int rightButtonID )
{
	if( pMainWindow == NULL )
		return NULL;

	
	Image *newImage = new Image( 0,0 );
	newImage->setRealSizeDraw( true );

	/*MsgQuestion *newMsgBox = new MsgQuestion( mainWindow->getWidth() * 0.1, mainWindow->getHeight() / 2 - mainWindow->getHeight() * 0.1, mainWindow->getWidth() * 0.8, mainWindow->getHeight() * 0.2, NULL );
	newMsgBox->setQuestionText( sQuestion );
	newMsgBox->setButtons( leftButtonCaption, leftButtonID, rightButtonCaption, rightButtonID );*/
	std::string sFileName;
	switch( type )
	{
		case GFG_MSGBOX_ALERT:
			sFileName = "textures/icons/alert.tga";
			break;
		case GFG_MSGBOX_ERROR:
			sFileName = "textures/icons/error.tga";
			break;
		case GFG_MSGBOX_INFO:
			sFileName = "textures/icons/info.tga";
			break;

		case GFG_MSGBOX_QUESTION:
		default:
			sFileName = "textures/icons/question.tga";
			
	}

	newImage->loadImage( sFileName );

	newImage->setSize( (float)newImage->getImageWidth(), (float)newImage->getImageHeight() );

	const float fMGSPadding = 10.0f;
	const float fBottomPanelHeight = 40;

	float fMSGWidth = pMainWindow->getWidth() * 0.8f;
	float fMSGHeight = newImage->getImageHeight() + fBottomPanelHeight + 2.0f * fMGSPadding;



	CMessageBox *newMessageBox = new CMessageBox( pMainWindow->getWidth() * 0.1f, pMainWindow->getHeight() / 2.0f - pMainWindow->getHeight() * 0.10f, fMSGWidth, fMSGHeight );
	newMessageBox->setPadding( fMGSPadding );
	
	
	ContainerRelativeUpToDown *mainContainer = new ContainerSemiRelativeUpToDown(  );
	newMessageBox->setComponent( mainContainer );
	
	mainContainer->setVerticalPadding( 0.1f );
	
	ContainerSemiRelativeLeftToRight *newSubContainer = new ContainerSemiRelativeLeftToRight(  );
	newSubContainer->setPadding( 5 );
	newSubContainer->setHeight( (float)newImage->getImageHeight() );
	mainContainer->addComponent( newSubContainer );

	

	newSubContainer->addComponent( newImage );
	newSubContainer->setVerticalPadding( 0.1f );
	newSubContainer->setHeight( (float)newImage->getImageHeight() );

	Label *newLabel = new LabelNoOutline( pMainWindow->getWidth() * 0.6f - newImage->getImageWidth() , 100.0f );
	newLabel->setCaption( sQuestion );
	newSubContainer->addComponent( newLabel );
	
	
	ContainerRelativeLeftToRight *newSubContainer2 = new ContainerRelativeLeftToRight(  );
	newSubContainer2->setHeight( fBottomPanelHeight );
	mainContainer->addComponent( newSubContainer2 );
	newSubContainer2->setVerticalPadding( 0.5f );
	newSubContainer2->setPadding( 5 );

	Button *newButton = GFG_newButton( leftButtonCaption, leftButtonID );
	newSubContainer2->addComponent( newButton );

	Button *newButton2 = GFG_newButton( rightButtonCaption, rightButtonID );
	
	newSubContainer2->addComponent( newButton2 );
	newButton->giveMeFocus();
	//pMainWindow->joinMessageBox( newMessageBox );

	return newMessageBox;
}


void GFG_setVisibleWithFocus( CSubWindow *window )
{
	if( window == NULL || window->getMainWindow() == NULL )
		return;
	CMainWindow *pMainWindow = window->getMainWindow();
	if( pMainWindow == NULL )
		return;
	pMainWindow->setVisibleWidthFocus( window );
}

/*CMainWindow *g_pMainWindow = NULL;

CMainWindow *GFG_getMainWindow()
{
	return g_pMainWindow;
}
void GFG_setMainWindow( CMainWindow * w)
{
	g_pMainWindow = w;
}*/



Color4I g_ColorDisabled = GFG_COLOR_DISABLED;
Color4I & GFG_getColorDisabled()
{
	return g_ColorDisabled;
}

void GFG_setColorDisabled( Color4I &color )
{
	g_ColorDisabled = color;
}


Button *GFG_newButton( std::string caption, int object_ID , float width, float height  )
{
	Button *tmpButton = new Button( width, height );
	tmpButton->init();
	tmpButton->setCaption( caption );
	tmpButton->setObjectID( object_ID );
	return tmpButton;
}
Button *GFG_newButton( int object_ID  )
{
	return GFG_newButton( "",object_ID );
}

Button *GFG_newButton( float width, float height, std::string caption )
{
	return GFG_newButton( caption, 0, width, height);
}


GFG_Callback GFG_newCallback( void (*func)( CBaseComponent *, void*), void * data )
{
	GFG_Callback newCallback;
	if( func )
	{
		newCallback.callbackFunc = func;
		newCallback.callbackData = data;
	}
	return newCallback;
}

GFG_Callback g_CallbackDefault;

void GFG_setCallback_default( GFG_Callback &callback )
{
	g_CallbackDefault = callback;
}
GFG_Callback GFG_getCallback_default()
{
	return g_CallbackDefault;
}


ContainerRelativeUpToDown *GFG_newContainerRelativeUD( bool reverse, float vertical_padding, float horizontal_padding )
{
	ContainerRelativeUpToDown *newOne = new ContainerRelativeUpToDown( reverse );
	newOne->setVerticalPadding( vertical_padding );
	newOne->setHorizontalPadding( horizontal_padding );
	return newOne;

}

ContainerRelativeLeftToRight *GFG_newContainerRelativeLR( bool reverse, float vertical_padding, float horizontal_padding )
{
	ContainerRelativeLeftToRight *newOne = new ContainerRelativeLeftToRight( reverse );
	newOne->setVerticalPadding( vertical_padding );
	newOne->setHorizontalPadding( horizontal_padding );
	return newOne;
}

ContainerSemiRelativeUpToDown *GFG_newContainerSemiRelativeUD( bool reverse, float vertical_padding, float horizontal_padding )
{
	ContainerSemiRelativeUpToDown *newOne = new ContainerSemiRelativeUpToDown( reverse );
	newOne->setVerticalPadding( vertical_padding );
	newOne->setHorizontalPadding( horizontal_padding );
	return newOne;
}
ContainerSemiRelativeLeftToRight *GFG_newContainerSemiRelativeLR( bool reverse, float vertical_padding, float horizontal_padding)
{
	ContainerSemiRelativeLeftToRight *newOne = new ContainerSemiRelativeLeftToRight( reverse );
	newOne->setVerticalPadding( vertical_padding );
	newOne->setHorizontalPadding( horizontal_padding );
	return newOne;
}

ContainerFixed *GFG_newContainerFixed()
{
	return new ContainerFixed();
}

void GFG_setContainer_draw( CBaseContainer *pContainer, bool draw, string caption)
{
	if( pContainer )
	{
		pContainer->setAllowDraw( draw );
		if( !caption.empty() )
			pContainer->setCaption( caption );
	}
}

CSubWindow *GFG_newSubWindow(  float x, float y, float w, float h, string caption, float padding, bool resizable)
{
	CSubWindow *newOne = new CSubWindow( x, y, w, h );
	newOne->setCaption( caption );
	newOne->setPadding( padding );
	newOne->setResizable( resizable );
	return newOne;
}

#include "sys_console.h"
using namespace systemConsole;

bool GFG_init()
{
	console << "initialising GFG data...";
	TextureElement *texture = NULL;
	
	texture = textureLibrary.addEntry( "GFG_MASK", "textures/GFG/mask.tga" );
	textureLibrary.setTextureWraps( texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE );
	
	texture = textureLibrary.addEntry( "GFG_PANEL", "textures/GFG/panel.tga" );
	texture = textureLibrary.addEntry( "GFG_BUTTON_UP", "textures/GFG/button_up.tga" );
	texture = textureLibrary.addEntry( "GFG_BUTTON_DOWN", "textures/GFG/button_down.tga" );
	texture = textureLibrary.addEntry( "GFG_ARROW", "textures/GFG/arrow.tga" );
	texture = textureLibrary.addEntry( "GFG_ARROW_PUSHED", "textures/GFG/arrow_pushed.tga" );
	

	texture = textureLibrary.addEntry( "GFG_ARROW_PUSHED", "textures/GFG/arrow_pushed.tga" );
	texture = textureLibrary.addEntry( "GFG_SCROLL_PANEL", "textures/GFG/scroll_panel.tga" );
	//texture = textureLibrary.addEntry( "SCROLL_PANEL_90", "textures/GFG/scroll_panel_90.tga" );
	texture = textureLibrary.addEntry( "GFG_CROSS", "textures/GFG/krizek.tga" );
	texture = textureLibrary.addEntry( "GFG_CROSS_PUSHED", "textures/GFG/krizek_pushed.tga" );
	texture = textureLibrary.addEntry( "GFG_SWITCH_IDLE", "textures/GFG/switch_idle.tga" );
	texture = textureLibrary.addEntry( "GFG_SWITCH_PUSHED", "textures/GFG/switch_pushed.tga" );
	texture = textureLibrary.addEntry( "GFG_OPTION_IDLE", "textures/GFG/option_idle.tga" );
	texture = textureLibrary.addEntry( "GFG_OPTION_PUSHED", "textures/GFG/option_pushed.tga" );
	texture = textureLibrary.addEntry( "GFG_BUTTON_DOWN_PUSHED", "textures/GFG/button_down_pushed.tga" );
	texture = textureLibrary.addEntry( "GFG_SLIDER_BUTTON", "textures/GFG/slider_button.tga" );
	texture = textureLibrary.addEntry( "GFG_PROGRESS_BAR_LEFT", "textures/GFG/progress_left.tga" );
	textureLibrary.setTextureWraps( texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE );
	
	texture = textureLibrary.addEntry( "GFG_PROGRESS_BAR_CENTER", "textures/GFG/progress_center.tga" );
	texture = textureLibrary.addEntry( "GFG_PROGRESS_BAR_RIGHT", "textures/GFG/progress_right.tga" );
	textureLibrary.setTextureWraps( texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE );

	texture = textureLibrary.addEntry( "GFG_PROGRESS_BAR_INDICATOR", "textures/GFG/progress_indicator3.tga" );
	texture = textureLibrary.addEntry( "GFG_TABBED_BUTTON", "textures/GFG/tabbed_button_base5.tga" );
	textureLibrary.setTextureWraps( texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE );

	texture = textureLibrary.addEntry( "GFG_ARROW_DOWN_IDLE", "textures/GFG/arrow_down_idle.tga" );
	texture = textureLibrary.addEntry( "GFG_ARROW_UP_IDLE", "textures/GFG/arrow_up_idle.tga" );
	
	console << "done" << endline;
	return true;
}
