Original Post
🔒 Locked
Textbox
Advertisement
Hi.
I've done this thing recently.
Actually, my textbox uses my own cursor and direct input class.
'Textbox' class is inherited from 'Window' class which supports
functions like 'MouseDown', 'Click' etc...
Main thing is done by an Update function. I think you'll understand it well,
if something is not clear then PM me or ICQ.
Here it goes:
if( gpf_PointInRect( m_pCursor->GetPosX(), m_pCursor->GetPosY(), GetRect( true ) ) == true )
{
if( m_pCursor->ButtonDownPrev(0) == true )
{
m_bDoInput = true;
}
}
else
{
m_bDoInput = false;
}
if( m_bDoInput == true )
{
for( int i = 0; i < 256; ++i )
{
// If a key has just been pressed
if( m_pDI->IsPrevKeyDown(i) == true )
{
bool bSkip = false;
// Erase
if( i == DIK_BACKSPACE )
{
if( m_iTextLength > 0 )
{
m_sText.erase( --m_iTextLength, 1 );
}
bool bSkip = true;
}
if( ( bSkip == false ) &&
( ( m_iTextLength < m_iMaxTextLength ) ||
( m_iTextLength == 0 ) ) )
{
// Get ascii code from a scancode
USHORT c;
gpf_Scan2Ascii( m_pDI->DI_Keys, (UINT)i, &c );
char cc = (char)c;
// If symbol is allowed then add it to the box
if( ( isalpha( cc ) && m_bAllowSymbols_ABC ) ||
( isdigit( cc ) && m_bAllowSymbols_Digits ) ||
( ispunct( cc ) && m_bAllowSymbols_Special ) ||
( isspace( cc ) && m_bAllowSymbols_Space ) )
{
m_sText += cc;
++m_iTextLength;
// Dont't check other input keys
bSkip = true;
if( m_bHasKeyPressFunc == true )
m_pFuncKeyPress( i, cc );
}
}
}
}
}
I've done this thing recently.
Actually, my textbox uses my own cursor and direct input class.
'Textbox' class is inherited from 'Window' class which supports
functions like 'MouseDown', 'Click' etc...
Main thing is done by an Update function. I think you'll understand it well,
if something is not clear then PM me or ICQ.
Here it goes:
if( gpf_PointInRect( m_pCursor->GetPosX(), m_pCursor->GetPosY(), GetRect( true ) ) == true )
{
if( m_pCursor->ButtonDownPrev(0) == true )
{
m_bDoInput = true;
}
}
else
{
m_bDoInput = false;
}
if( m_bDoInput == true )
{
for( int i = 0; i < 256; ++i )
{
// If a key has just been pressed
if( m_pDI->IsPrevKeyDown(i) == true )
{
bool bSkip = false;
// Erase
if( i == DIK_BACKSPACE )
{
if( m_iTextLength > 0 )
{
m_sText.erase( --m_iTextLength, 1 );
}
bool bSkip = true;
}
if( ( bSkip == false ) &&
( ( m_iTextLength < m_iMaxTextLength ) ||
( m_iTextLength == 0 ) ) )
{
// Get ascii code from a scancode
USHORT c;
gpf_Scan2Ascii( m_pDI->DI_Keys, (UINT)i, &c );
char cc = (char)c;
// If symbol is allowed then add it to the box
if( ( isalpha( cc ) && m_bAllowSymbols_ABC ) ||
( isdigit( cc ) && m_bAllowSymbols_Digits ) ||
( ispunct( cc ) && m_bAllowSymbols_Special ) ||
( isspace( cc ) && m_bAllowSymbols_Space ) )
{
m_sText += cc;
++m_iTextLength;
// Dont't check other input keys
bSkip = true;
if( m_bHasKeyPressFunc == true )
m_pFuncKeyPress( i, cc );
}
}
}
}
}
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement