Fixed pressing space in text areas (/me should beware about static variables in header files...)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@4186 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-10-31 23:35:54 +00:00
parent c3419d8ddb
commit 129c93f4bf
7 changed files with 23 additions and 9 deletions

View File

@ -203,7 +203,7 @@ void transmitEvent(Widget* widget, std::string& name, const int playerID)
// -----------------------------------------------------------------------------
void render(float elapsed_time)
{
{
GUIEngine::dt = elapsed_time;
// ---- menu drawing

View File

@ -282,7 +282,7 @@ void EventHandler::processAction(const int action, const unsigned int value, Inp
break;
case PA_FIRE:
if (pressedDown && !isWithinATextBox)
if (pressedDown && !isWithinATextBox())
{
Widget* w = GUIEngine::getFocusForPlayer(playerID);
if (w == NULL) break;

View File

@ -42,6 +42,17 @@ using namespace gui;
namespace GUIEngine
{
static bool g_is_within_a_text_box = false;
bool isWithinATextBox()
{
return g_is_within_a_text_box;
}
void setWithinATextBox(bool in)
{
g_is_within_a_text_box = in;
}
// -----------------------------------------------------------------------------
Widget::Widget(bool reserve_id)
{

View File

@ -74,7 +74,8 @@ namespace GUIEngine
PROP_SQUARE
};
static bool isWithinATextBox = false;
bool isWithinATextBox();
void setWithinATextBox(bool in);
/**
* The nearly-abstract base of all widgets (not fully abstract since a bare Widget
@ -121,7 +122,7 @@ namespace GUIEngine
virtual EventPropagation mouseHovered(Widget* child) { return EVENT_BLOCK; }
/** override in children if you need to know when the widget is focused. return whether to block event */
virtual EventPropagation focused(const int playerID) { isWithinATextBox = false; return EVENT_LET; }
virtual EventPropagation focused(const int playerID) { setWithinATextBox(false); return EVENT_LET; }
/** override in children if you need to know when the widget is unfocused. */
virtual void unfocused(const int playerID) { }

View File

@ -55,7 +55,7 @@ EventPropagation TextBoxWidget::focused(const int playerID)
// special case : to work, the text box must receive "irrLicht focus", STK focus is not enough
GUIEngine::getGUIEnv()->setFocus(m_element);
isWithinATextBox = true;
setWithinATextBox(true);
return EVENT_LET;
}
// -----------------------------------------------------------------------------
@ -63,6 +63,8 @@ void TextBoxWidget::unfocused(const int playerID)
{
assert(playerID == 0); // No support for multiple players in text areas!
setWithinATextBox(false);
// special case : to work, the text box must receive "irrLicht focus", STK focus is not enough
// below is a cheap way to unset the irrLicht focus from the widget (nope, 'removeFocus' from
// IGUIEnv doesn't work reliably, not sure why)

View File

@ -34,7 +34,7 @@ namespace GUIEngine
TextBoxWidget();
~TextBoxWidget()
{
isWithinATextBox = false;
setWithinATextBox(false);
}
void add();

View File

@ -461,11 +461,11 @@ EventPropagation InputManager::input(const SEvent& event)
// 'backspace' in a text control must never be mapped, since user can be in a text
// area trying to erase text (and if it's mapped to rescue that would dismiss the
// dialog instead of erasing a single letter). Same for spacebar.
if (key == KEY_BACK && GUIEngine::isWithinATextBox)
if (key == KEY_BACK && GUIEngine::isWithinATextBox())
{
return EVENT_LET;
}
if (key == KEY_SPACE && GUIEngine::isWithinATextBox)
if (key == KEY_SPACE && GUIEngine::isWithinATextBox())
{
return EVENT_LET;
}
@ -515,7 +515,7 @@ EventPropagation InputManager::input(const SEvent& event)
#endif
// block events in all modes but initial menus (except in text boxes to allow typing, and exceptm in modal dialogs in-game)
if (getDeviceList()->playerAssignMode() != NO_ASSIGN && !GUIEngine::isWithinATextBox &&
if (getDeviceList()->playerAssignMode() != NO_ASSIGN && !GUIEngine::isWithinATextBox() &&
(!GUIEngine::ModalDialog::isADialogActive() && StateManager::get()->getGameState() == GUIEngine::GAME))
{
return EVENT_BLOCK;