

#include "Mode_FontDisplay.h"
using namespace iglu;

// Our main window
extern IGLUMultiDisplayWindow::Ptr    myWin;

// Variable containing the current background color
vec4 bgColor = vec4( 0.0f, 0.0f, 0.0f, 0.0f );

// A user variable to determine if we display decimal or hex values
IGLUBool useHex   ( false, "Display character IDs in hex" );
IGLUInt  bgSelect ( 0, IGLURange<int>(0,17), 1, "Select background color" );

void FontDisplay::Display( void )
{
	// Some temp space we'll use when drawing
	char stringBuf[2] = { " " };
	char idString[8];

	// Why isn't there a verctor version of glClearColor()??
	glClearColor( bgColor.X(), bgColor.Y(), bgColor.Z(), bgColor.W() );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	for (int i=0; i<16; i++)
		for (int j=0; j<16; j++)
		{
			// Figure out what character is in this sapace...
			int charID = (15-j)*16 + i;

			// Draw that character
			stringBuf[0] = charID;
			IGLUDraw::DrawText( IGLU_FONT_FIXED, 32*i, 37*j, stringBuf );

			// Print out the numeral identifying that character.
			sprintf( idString, useHex ? "0x%x" : "%d", charID );
			IGLUDraw::DrawColorText( IGLU_FONT_VARIABLE, 32*i, 37*j+25, vec4( 0.6, 0.6, 0.6, 1.0 ), idString, 0.5 );
		}

	// Set our clear color back to normal (in case we switch to a different render mode)
	glClearColor( 0, 0, 0, 1 );
}

// Not part of the FontDisplay class, just a callback for one
//     of our IGLU variables.
void SelectColor( IGLUVariable *uiInt )
{
	switch( ((IGLUInt *)uiInt)->GetValue() )
	{
	default:
	case 0:   bgColor = color::Black;       break;
	case 1:   bgColor = color::Red;         break;
	case 2:   bgColor = color::White;       break;
	case 3:   bgColor = color::Blue;        break;
	case 4:   bgColor = color::Green;       break;
	case 5:   bgColor = color::Orange;      break; 
	case 6:   bgColor = color::Yellow;      break;
	case 7:   bgColor = color::Purple;      break;
	case 8:   bgColor = color::Cyan;        break;
	case 9:   bgColor = color::Aquamarine;  break;
	case 10:  bgColor = color::Sienna;      break;
	case 11:  bgColor = color::Tan;         break;
	case 12:  bgColor = color::NavyBlue;    break;
	case 13:  bgColor = color::Maroon;      break;
	case 14:  bgColor = color::LimeGreen;   break;
	case 15:  bgColor = color::Khaki;       break;
	case 16:  bgColor = color::ForestGreen; break;
	case 17:  bgColor = color::DarkKhaki;   break;
	}
}

// Initialize variables and stuff needed for our font renderer display
void FontDisplay::Initialize( int trackNum )
{
	// Add widgets to the built-in UI window.  Also setup callbacks (if needed)
	myWin->AddWidget( trackNum, &useHex );
	myWin->AddWidgetSpacer( trackNum );
	myWin->AddWidget( trackNum, &bgSelect, new IGLUVariableCallback( SelectColor ) );
}


