Allow to activate screen keyboard using gamepad

This commit is contained in:
Deve 2018-10-23 23:54:22 +02:00
parent 91074705fd
commit e585c26833
5 changed files with 52 additions and 25 deletions

View File

@ -352,7 +352,7 @@ void EventHandler::processGUIAction(const PlayerAction action,
case PA_FIRE: case PA_FIRE:
case PA_MENU_SELECT: case PA_MENU_SELECT:
if (pressedDown && !isWithinATextBox()) if (pressedDown)
{ {
Widget* w = GUIEngine::getFocusForPlayer(playerID); Widget* w = GUIEngine::getFocusForPlayer(playerID);
if (w == NULL) break; if (w == NULL) break;

View File

@ -1286,34 +1286,14 @@ bool CGUIEditBox::processMouse(const SEvent& event)
} }
else if (!m_rtl) else if (!m_rtl)
{ {
bool use_screen_keyboard = UserConfigParams::m_screen_keyboard > 1;
#ifdef ANDROID
if (UserConfigParams::m_screen_keyboard == 1)
{
int32_t keyboard = AConfiguration_getKeyboard(
global_android_app->config);
use_screen_keyboard = (keyboard != ACONFIGURATION_KEYBOARD_QWERTY);
}
#endif
if (!AbsoluteClippingRect.isPointInside( if (!AbsoluteClippingRect.isPointInside(
core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y))) core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y)))
{ {
return false; return false;
} }
else if (use_screen_keyboard) else if (shouldUseScreenKeyboard())
{ {
CursorPos = Text.size(); openScreenKeyboard();
setTextMarkers(CursorPos, CursorPos);
calculateScrollPos();
if (GUIEngine::ScreenKeyboard::getCurrent() == NULL)
{
new GUIEngine::ScreenKeyboard(0.98f, 0.30f, this);
}
return true; return true;
} }
else else
@ -1774,3 +1754,33 @@ void CGUIEditBox::deserializeAttributes(io::IAttributes* in, io::SAttributeReadW
// setOverrideFont(in->getAttributeAsFont("OverrideFont")); // setOverrideFont(in->getAttributeAsFont("OverrideFont"));
} }
bool CGUIEditBox::shouldUseScreenKeyboard()
{
bool use_screen_keyboard = UserConfigParams::m_screen_keyboard > 1;
#ifdef ANDROID
if (UserConfigParams::m_screen_keyboard == 1)
{
int32_t keyboard = AConfiguration_getKeyboard(
global_android_app->config);
use_screen_keyboard = (keyboard != ACONFIGURATION_KEYBOARD_QWERTY);
}
#endif
return use_screen_keyboard;
}
void CGUIEditBox::openScreenKeyboard()
{
if (GUIEngine::ScreenKeyboard::getCurrent() != NULL)
return;
CursorPos = Text.size();
setTextMarkers(CursorPos, CursorPos);
calculateScrollPos();
new GUIEngine::ScreenKeyboard(0.98f, 0.30f, this);
}

View File

@ -118,7 +118,10 @@ using namespace gui;
virtual irr::gui::IGUIFont* getOverrideFont() const { return NULL; } virtual irr::gui::IGUIFont* getOverrideFont() const { return NULL; }
virtual irr::gui::IGUIFont* getActiveFont() const { return NULL; } virtual irr::gui::IGUIFont* getActiveFont() const { return NULL; }
virtual void setDrawBackground(bool) { } virtual void setDrawBackground(bool) { }
bool shouldUseScreenKeyboard();
void openScreenKeyboard();
protected: protected:
//! Breaks the single text line. //! Breaks the single text line.
void breakText(); void breakText();

View File

@ -17,8 +17,8 @@
#include "guiengine/engine.hpp" #include "guiengine/engine.hpp"
#include "guiengine/modaldialog.hpp" #include "guiengine/modaldialog.hpp"
#include "guiengine/screen_keyboard.hpp"
#include "guiengine/widgets/text_box_widget.hpp" #include "guiengine/widgets/text_box_widget.hpp"
#include "guiengine/widgets/CGUIEditBox.hpp" #include "guiengine/widgets/CGUIEditBox.hpp"
#include "utils/ptr_vector.hpp" #include "utils/ptr_vector.hpp"
#include "utils/translation.hpp" #include "utils/translation.hpp"
@ -197,3 +197,15 @@ void TextBoxWidget::setActive(bool active)
} // setActive } // setActive
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
EventPropagation TextBoxWidget::onActivationInput(const int playerID)
{
if (((MyCGUIEditBox*)m_element)->shouldUseScreenKeyboard())
{
((MyCGUIEditBox*)m_element)->openScreenKeyboard();
}
// The onWidgetActivated() wasn't used at all before, so always block
// event to avoid breaking something
return EVENT_BLOCK;
}

View File

@ -75,6 +75,8 @@ namespace GUIEngine
/** Override method from base class Widget */ /** Override method from base class Widget */
virtual void setActive(bool active=true); virtual void setActive(bool active=true);
virtual EventPropagation onActivationInput(const int playerID);
}; };
} }