Allow to change cursor position in text box when screen keyboard is active

This commit is contained in:
Deve 2019-02-13 21:34:31 +01:00
parent 71c5c3988c
commit 415bfb491e
2 changed files with 47 additions and 39 deletions

View File

@ -362,27 +362,35 @@ bool ScreenKeyboard::onEvent(const SEvent &event)
if (event.EventType == EET_MOUSE_INPUT_EVENT) if (event.EventType == EET_MOUSE_INPUT_EVENT)
{ {
core::position2d<s32> point(event.MouseInput.X, event.MouseInput.Y); core::position2d<s32> point(event.MouseInput.X, event.MouseInput.Y);
bool is_point_inside = m_irrlicht_window->isPointInside(point);
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) if (m_edit_box->isPointInside(point))
{ {
if (!is_point_inside) m_edit_box->OnEvent(event);
{
m_schedule_close = true;
return true;
}
} }
else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) else
{ {
if (!is_point_inside && m_schedule_close) bool is_point_inside = m_irrlicht_window->isPointInside(point);
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{ {
dismiss(); if (!is_point_inside)
return true; {
m_schedule_close = true;
return true;
}
} }
else else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
{ {
m_schedule_close = false; if (!is_point_inside && m_schedule_close)
return false; {
dismiss();
return true;
}
else
{
m_schedule_close = false;
return false;
}
} }
} }
} }

View File

@ -1259,6 +1259,10 @@ bool CGUIEditBox::processMouse(const SEvent& event)
calculateScrollPos(); calculateScrollPos();
return true; return true;
} }
else
{
MouseMarking = false;
}
break; break;
case irr::EMIE_MOUSE_MOVED: case irr::EMIE_MOUSE_MOVED:
{ {
@ -1303,10 +1307,10 @@ bool CGUIEditBox::processMouse(const SEvent& event)
{ {
return false; return false;
} }
else if (GUIEngine::ScreenKeyboard::shouldUseScreenKeyboard())
if (GUIEngine::ScreenKeyboard::shouldUseScreenKeyboard())
{ {
openScreenKeyboard(); openScreenKeyboard();
return true;
} }
#ifdef ANDROID #ifdef ANDROID
else if (UserConfigParams::m_screen_keyboard == 3) else if (UserConfigParams::m_screen_keyboard == 3)
@ -1319,28 +1323,25 @@ bool CGUIEditBox::processMouse(const SEvent& event)
} }
} }
#endif #endif
else // move cursor
{ CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y);
// move cursor
CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y);
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) #if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
if (UTF16_IS_SURROGATE_LO(Text[CursorPos])) if (UTF16_IS_SURROGATE_LO(Text[CursorPos]))
{ {
if (CursorPos > 0) if (CursorPos > 0)
--CursorPos; --CursorPos;
}
#endif
s32 newMarkBegin = MarkBegin;
if (!MouseMarking)
newMarkBegin = CursorPos;
MouseMarking = true;
setTextMarkers( newMarkBegin, CursorPos);
calculateScrollPos();
return true;
} }
#endif
s32 newMarkBegin = MarkBegin;
if (!MouseMarking)
newMarkBegin = CursorPos;
MouseMarking = true;
setTextMarkers( newMarkBegin, CursorPos);
calculateScrollPos();
return true;
} }
default: default:
break; break;
@ -1707,6 +1708,9 @@ void CGUIEditBox::calculateScrollPos()
//! set text markers //! set text markers
void CGUIEditBox::setTextMarkers(s32 begin, s32 end) void CGUIEditBox::setTextMarkers(s32 begin, s32 end)
{ {
if (GUIEngine::ScreenKeyboard::isActive())
return;
if ( begin != MarkBegin || end != MarkEnd ) if ( begin != MarkBegin || end != MarkEnd )
{ {
MarkBegin = begin; MarkBegin = begin;
@ -1785,10 +1789,6 @@ void CGUIEditBox::openScreenKeyboard()
if (GUIEngine::ScreenKeyboard::getCurrent() != NULL) if (GUIEngine::ScreenKeyboard::getCurrent() != NULL)
return; return;
CursorPos = Text.size();
setTextMarkers(CursorPos, CursorPos);
calculateScrollPos();
new GUIEngine::ScreenKeyboard(1.0f, 0.40f, this); new GUIEngine::ScreenKeyboard(1.0f, 0.40f, this);
} }