Ok, I am trying to add a username and login box for my menu screen. But the problem is, when you start typing, both boxes fill at the same time. Also, I can not figure out how to do a focus when you click on it. Here is my code, the text buffer was helped by Jason P Sage (with necessary changes of course).
GUI.cpp
char* TextHandler::dbbEntry(int Clean)
{
char* Input = dbEntry();
if (Input && Clean && ( isUser | isPass ) )
{
char *Writer = Input;
for (char* Reader = Input; *Reader; ++Reader)
{
if ( *Reader == VK_BACK )
{
if ( Writer > Input ) {
--Writer;
}
}
else
{
*Writer = *Reader;
++Writer;
}
}
*Writer = 0;
if (Input[0] == 0)
{
dbClearEntryBuffer();
delete[] Input;
Input = 0;
}
}
return Input;
}
char* TextHandler::dbbEntry2(int Clean)
{
char* Input1 = dbEntry();
if (Input1 && Clean && ( isUser | isPass ) )
{
char *Writer1 = Input1;
for (char* Reader1 = Input1; *Reader1; ++Reader1)
{
if ( *Reader1 == VK_BACK )
{
if ( Writer1 > Input1 ) {
--Writer1;
}
}
else
{
*Writer1 = *Reader1;
++Writer1;
}
}
*Writer1 = 0;
if (Input1[0] == 0)
{
dbClearEntryBuffer();
delete[] Input1;
Input1 = 0;
}
}
return Input1;
}
void TextHandler::CreateLogin()
{
dbLoadImage ( "TextBox.png", 886 );
dbSprite ( 886, 347, 295, 886 );
dbLoadImage ( "TextBox.png", 887 );
dbSprite ( 887, 347, 351, 887 );
}
bool TextHandler::SetFocus() {
if( dbMouseX() > 347 && dbMouseX() < 347 + dbSpriteWidth(886) && dbMouseY() > 295 && dbMouseY() < 295 + dbSpriteHeight(886) ) {
isUser = true;
isPass = false;
return true;
}
if( dbMouseX() > 347 && dbMouseX() < 347 + dbSpriteWidth(887) && dbMouseY() > 351 && dbMouseY() < 351 + dbSpriteHeight(887) ) {
isUser = false;
isPass = true;
return true;
}
return false;
}
void TextHandler::FocusText( int x, int y ) {
if( isUser ) {
char* Input = dbbEntry(1);
dbText( x + 3, y + 3, ( Input ? Input : "" ) );
dbInk( dbRGB( 0, 0, 0 ), dbRGB( 0, 0, 0 ) );
delete[] Input;
}
if( isPass ) {
char* Input2 = dbbEntry2(1);
dbText( x + 3, y + 3, ( Input2 ? Input2 : "" ) );
dbInk( dbRGB( 0, 0, 0 ), dbRGB( 0, 0, 0 ) );
delete[] Input2;
}
}
void TextHandler::HandleProc() {
if( isUser )
TextHandler::FocusText( 347, 295 );
if( isPass )
TextHandler::FocusText( 347, 351 );
}
I am working on a 2D Side Scrolling MMORPG, the journey is being blogged and I suggest you check it out. Will include all progress, road blocks even drama! http://exoengine.com/blog/