From 0dca3216743cd5deaffad45ca50fccd7280eb6bd Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 23 Oct 2013 12:46:55 +0300 Subject: Fix inttextfield on SDL2. This allow enter numbers for example in drop or split dialogs. --- src/gui/widgets/inttextfield.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/gui/widgets/inttextfield.cpp') diff --git a/src/gui/widgets/inttextfield.cpp b/src/gui/widgets/inttextfield.cpp index a56023dc5..521d26d59 100644 --- a/src/gui/widgets/inttextfield.cpp +++ b/src/gui/widgets/inttextfield.cpp @@ -22,6 +22,10 @@ #include "gui/widgets/inttextfield.h" +#ifdef USE_SDL2 +#include "gui/sdlinput.h" +#endif + #include "input/keydata.h" #include "input/keyevent.h" @@ -58,8 +62,25 @@ void IntTextField::keyPressed(gcn::KeyEvent &event) event.consume(); } +#ifdef USE_SDL2 + const int val = event.getKey().getValue(); + if (val != Key::TEXTINPUT) + return; + + const std::string str = static_cast(&event)->getText(); + if (str.empty()) + return; + const size_t sz = str.size(); + for (size_t f = 0; f < sz; f ++) + { + const char chr = str[f]; + if (chr < '0' || chr > '9') + return; + } +#else if (!event.getKey().isNumber()) return; +#endif TextField::keyPressed(event); -- cgit v1.2.3-70-g09d2