diff --git a/src/guiengine/engine.cpp b/src/guiengine/engine.cpp index f59d86f35..4601ee3aa 100644 --- a/src/guiengine/engine.cpp +++ b/src/guiengine/engine.cpp @@ -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 diff --git a/src/guiengine/event_handler.cpp b/src/guiengine/event_handler.cpp index e3b616c73..678480e03 100644 --- a/src/guiengine/event_handler.cpp +++ b/src/guiengine/event_handler.cpp @@ -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; diff --git a/src/guiengine/widget.cpp b/src/guiengine/widget.cpp index d2106ad13..130654223 100644 --- a/src/guiengine/widget.cpp +++ b/src/guiengine/widget.cpp @@ -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) { diff --git a/src/guiengine/widget.hpp b/src/guiengine/widget.hpp index ccfcc0924..c042a1f70 100644 --- a/src/guiengine/widget.hpp +++ b/src/guiengine/widget.hpp @@ -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) { } diff --git a/src/guiengine/widgets/text_box_widget.cpp b/src/guiengine/widgets/text_box_widget.cpp index 4c6cfd6ee..3a5875aee 100644 --- a/src/guiengine/widgets/text_box_widget.cpp +++ b/src/guiengine/widgets/text_box_widget.cpp @@ -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) diff --git a/src/guiengine/widgets/text_box_widget.hpp b/src/guiengine/widgets/text_box_widget.hpp index 0555d9b78..b73b6e9f3 100644 --- a/src/guiengine/widgets/text_box_widget.hpp +++ b/src/guiengine/widgets/text_box_widget.hpp @@ -34,7 +34,7 @@ namespace GUIEngine TextBoxWidget(); ~TextBoxWidget() { - isWithinATextBox = false; + setWithinATextBox(false); } void add(); diff --git a/src/input/input_manager.cpp b/src/input/input_manager.cpp index 553ff1d17..c50601316 100644 --- a/src/input/input_manager.cpp +++ b/src/input/input_manager.cpp @@ -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;