www.pudn.com > Gimcrack-v0.0051-Source.zip > console.cpp
#include "console.h"
GcConsole::GcConsole()
{
m_sliding = false;
m_slide_speed = 5;
tile_repeat = 1.0f;
}
void GcConsole::Load()
{
if( !bg_tex.Create("data/industrial.tga") )
{
MessageBox(NULL, "Unable to load sprite.", "ERROR", MB_OK);
}
if(!font.Build("data/font.tga", 16, 16, 32, 32, 32))
{
MessageBox(NULL, "Unable to build the font.", "ERROR", MB_OK);
}
/*m_width = settings.ScreenWidth();
m_height = settings.ScreenHeight() / 2;
m_x = 0.0f;
m_y = settings.ScreenHeight();*/
strcpy(CmdLine, "]");
CurrentPos = 1;
// settings.ScreenHeight() - m_height
}
void GcConsole::SetSize( int width, int height )
{
m_width = (float)width;
m_height = (float)height;
m_x = 0.0f;
m_y = (float)height;
}
void GcConsole::Draw()
{
if( m_state == Raised && !m_sliding )
return;
if( m_sliding )
Slide();
glTranslatef(m_x, m_y , 0.0f);
RenderBackground();
RenderBuffers();
RenderCmdLine();
//glBegin(GL_QUADS);
/*
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
*/
}
void GcConsole::RenderBackground()
{
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
bg_tex.Bind();
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex2f(m_width, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex2f(m_width, m_height);
glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, m_height);
glEnd();
font.Print(GIMCRACK, (int)m_width - strlen(GIMCRACK) * 12, (int)m_height - 40);
}
void GcConsole::RenderBuffers()
{
int i;
for( i = 0; i < 10; i++ )
{
font.Print(Buffer[i], 0, (i * 15) + 25);
}
}
void GcConsole::RenderCmdLine()
{
font.Print(CmdLine, 0, 10);
}
void GcConsole::SendKey( uint key )
{
// Add character
// Make sure we are not at the end of line and the key a character
if( CurrentPos < CMDLINE && (key >= 32) && (key <= 125) )
{
//if( (key >= 32) && (key <= 125) )
//{
CmdLine[CurrentPos] = key;
CurrentPos++;
CmdLine[CurrentPos] = '_';
//}
}
// Delete character
if( (CurrentPos > 1) && (key == VK_BACK ))
{
CmdLine[CurrentPos - 1] = '_';
CmdLine[CurrentPos] = '\0';
CurrentPos--;
}
// Parse command
if( key == VK_RETURN )
{
AddBuffer(CmdLine);
for( int i = 1; i < CMDLINE; i++ )
CmdLine[i] = '\0';
CurrentPos = 1;
CmdLine[CurrentPos] = '_';
}
}
void GcConsole::AddBuffer( char * text )
{
int i;
for( i = CONSOLEBUFFER - 1; i > 0; i-- )
strcpy(Buffer[i + 1], Buffer[i]);
strcpy(Buffer[0], text);
}
void GcConsole::Slide()
{
if( m_state == Lowered )
{
if( m_y > m_height / 2 ) // FIX ME: screen height / 2
m_y -= m_slide_speed;
else
m_sliding = false;
}
if( m_state == Raised )
{
if( m_y < m_height ) // FIX ME: screen height
m_y += m_slide_speed;
else
m_sliding = false;
}
}
void GcConsole::TurnOn()
{
//m_active = true;
m_state = Lowered;
m_sliding = true;
}
void GcConsole::TurnOff()
{
//m_active = false;
m_state = Raised;
m_sliding = true;
}
void GcConsole::Toggle()
{
if( m_state == Lowered )
TurnOff();
else
TurnOn();
}