SDL ChatPanel

This commit is contained in:
Bacsu 2016-10-05 20:19:07 +02:00
parent ac85878fa9
commit 32506d863b
4 changed files with 82 additions and 10 deletions

Binary file not shown.

View file

@ -2384,11 +2384,11 @@ bool TeamFortressViewport::SlotInput( int iSlot )
// Direct Key Input
int TeamFortressViewport::KeyInput( int down, int keynum, const char *pszCurrentBinding )
{
/*@linux remove chat
if (m_chatPanel->isVisible())
{
// Don't let the game handle the input while the user is typing in the
// chat window.
// Don't let the game handle the input while the user is typing in the chat window.
m_chatPanel->KeyEvent();
return 0;
}
@ -2405,7 +2405,7 @@ int TeamFortressViewport::KeyInput( int down, int keynum, const char *pszCurrent
m_chatPanel->requestFocus();
m_chatPanel->SetChatMode(ChatPanel::chatModeTeam);
return 0;
}*/
}
// Open Text Window?
if (m_pCurrentMenu && gEngfuncs.Con_IsVisible() == false)

View file

@ -193,3 +193,75 @@ bool ChatPanel::WasKeyPushed(int virtualKey) const
return true;
}
}
std::string ChatPanel::UTF8toASCII(unsigned char* multibyte)
{
string ASCIIValue;
if (multibyte[0] <= 127)// let ascii pass
ASCIIValue = multibyte[0];
if (multibyte[0] == 0xC3)// is it a UTF8 multibyte?
{
ASCIIValue = multibyte[1] + 64;
}
return ASCIIValue;
}
void ChatPanel::KeyEvent()
{
const Uint8 *state = SDL_GetKeyboardState(NULL);
if (SDL_PollEvent(&event)) {
if (event.type == SDL_TEXTINPUT)
{
unsigned char* buffer;
buffer = (unsigned char*)event.text.text;
mText += UTF8toASCII(buffer);
}
}
if (state[SDL_SCANCODE_ESCAPE])
{
CancelChat();
}
if (state[SDL_SCANCODE_BACKSPACE])
{
if (mText.length() > 0)
{
mText.erase(mText.length() - 1, mText.length());
}
}
if (state[SDL_SCANCODE_RETURN])
{
std::string theCommand;
theCommand += mChatMode;
theCommand += " \"";
// Replace all ';' characters with ':' characters since we can't have
// ';' characters on a console message.
for (unsigned int i = 0; i < mText.length(); ++i)
{
if (mText[i] == ';')
{
mText[i] = ':';
}
}
theCommand += mText;
theCommand += "\"";
//say_x "the message here" instead of
//say_x the message here (ever word was treated as another argument)
gEngfuncs.pfnClientCmd((char*)theCommand.c_str());
CancelChat();
}
}

View file

@ -11,9 +11,9 @@
#include <string>
//@2014
//#define VK_ESCAPE 0x1B
//#define VK_RETURN 0x0D
//#define VK_CAPITAL 0x14
#include <SDL2\SDL_events.h> //#define VK_ESCAPE 0x1B
#include <SDL2\SDL_keyboard.h> //#define VK_RETURN 0x0D
#include <SDL2\SDL_keycode.h> //#define VK_CAPITAL 0x14
//#define VK_LCONTROL 0xA2
//#define VK_RCONTROL 0xA3
@ -25,7 +25,7 @@ public:
void CancelChat();
void SetChatMode(std::string sChatMode);
void KeyEvent();
void KeyDown(int virtualKey, int scanCode);
// Checks if a key was pushed since the chat window was opened.
@ -40,9 +40,9 @@ public:
private:
std::string mText;
std::string mChatMode;
std::string UTF8toASCII(unsigned char* multibyte);
bool mKeyPushed[256];
SDL_Event event;
};
#endif