mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
Move touchscreen input handling to base GUIModalMenu class
This commit is contained in:
parent
0d54399be2
commit
323c860045
14 changed files with 425 additions and 272 deletions
|
@ -97,9 +97,6 @@ GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick,
|
|||
m_text_dst(tdst),
|
||||
m_joystick(joystick),
|
||||
m_remap_dbl_click(remap_dbl_click)
|
||||
#ifdef __ANDROID__
|
||||
, m_JavaDialogFieldName("")
|
||||
#endif
|
||||
{
|
||||
current_keys_pending.key_down = false;
|
||||
current_keys_pending.key_up = false;
|
||||
|
@ -2265,23 +2262,11 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
|||
#ifdef __ANDROID__
|
||||
bool GUIFormSpecMenu::getAndroidUIInput()
|
||||
{
|
||||
/* no dialog shown */
|
||||
if (m_JavaDialogFieldName == "") {
|
||||
if (!hasAndroidUIInput())
|
||||
return false;
|
||||
}
|
||||
|
||||
/* still waiting */
|
||||
if (porting::getInputDialogState() == -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string fieldname = m_JavaDialogFieldName;
|
||||
m_JavaDialogFieldName = "";
|
||||
|
||||
/* no value abort dialog processing */
|
||||
if (porting::getInputDialogState() != 0) {
|
||||
return false;
|
||||
}
|
||||
std::string fieldname = m_jni_field_name;
|
||||
m_jni_field_name.clear();
|
||||
|
||||
for(std::vector<FieldSpec>::iterator iter = m_fields.begin();
|
||||
iter != m_fields.end(); ++iter) {
|
||||
|
@ -2301,8 +2286,7 @@ bool GUIFormSpecMenu::getAndroidUIInput()
|
|||
|
||||
std::string text = porting::getInputDialogValue();
|
||||
|
||||
((gui::IGUIEditBox*) tochange)->
|
||||
setText(utf8_to_wide(text).c_str());
|
||||
((gui::IGUIEditBox *)tochange)->setText(utf8_to_wide(text).c_str());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -3043,158 +3027,6 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
// display software keyboard when clicking edit boxes
|
||||
if (event.EventType == EET_MOUSE_INPUT_EVENT
|
||||
&& event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
|
||||
gui::IGUIElement *hovered =
|
||||
Environment->getRootGUIElement()->getElementFromPoint(
|
||||
core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y));
|
||||
if ((hovered) && (hovered->getType() == irr::gui::EGUIET_EDIT_BOX)) {
|
||||
bool retval = hovered->OnEvent(event);
|
||||
if (retval)
|
||||
Environment->setFocus(hovered);
|
||||
|
||||
std::string field_name = getNameByID(hovered->getID());
|
||||
/* read-only field */
|
||||
if (field_name.empty())
|
||||
return retval;
|
||||
|
||||
m_JavaDialogFieldName = field_name;
|
||||
std::string message = gettext("Enter ");
|
||||
std::string label = wide_to_utf8(getLabelByID(hovered->getID()));
|
||||
if (label.empty())
|
||||
label = "text";
|
||||
message += gettext(label) + ":";
|
||||
|
||||
/* single line text input */
|
||||
int type = 2;
|
||||
|
||||
/* multi line text input */
|
||||
if (((gui::IGUIEditBox*) hovered)->isMultiLineEnabled())
|
||||
type = 1;
|
||||
|
||||
/* passwords are always single line */
|
||||
if (((gui::IGUIEditBox*) hovered)->isPasswordBox())
|
||||
type = 3;
|
||||
|
||||
porting::showInputDialog(gettext("ok"), "",
|
||||
wide_to_utf8(((gui::IGUIEditBox*) hovered)->getText()),
|
||||
type);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.EventType == EET_TOUCH_INPUT_EVENT)
|
||||
{
|
||||
SEvent translated;
|
||||
memset(&translated, 0, sizeof(SEvent));
|
||||
translated.EventType = EET_MOUSE_INPUT_EVENT;
|
||||
gui::IGUIElement* root = Environment->getRootGUIElement();
|
||||
|
||||
if (!root) {
|
||||
errorstream
|
||||
<< "GUIFormSpecMenu::preprocessEvent unable to get root element"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
gui::IGUIElement* hovered = root->getElementFromPoint(
|
||||
core::position2d<s32>(
|
||||
event.TouchInput.X,
|
||||
event.TouchInput.Y));
|
||||
|
||||
translated.MouseInput.X = event.TouchInput.X;
|
||||
translated.MouseInput.Y = event.TouchInput.Y;
|
||||
translated.MouseInput.Control = false;
|
||||
|
||||
bool dont_send_event = false;
|
||||
|
||||
if (event.TouchInput.touchedCount == 1) {
|
||||
switch (event.TouchInput.Event) {
|
||||
case ETIE_PRESSED_DOWN:
|
||||
m_pointer = v2s32(event.TouchInput.X,event.TouchInput.Y);
|
||||
translated.MouseInput.Event = EMIE_LMOUSE_PRESSED_DOWN;
|
||||
translated.MouseInput.ButtonStates = EMBSM_LEFT;
|
||||
m_down_pos = m_pointer;
|
||||
break;
|
||||
case ETIE_MOVED:
|
||||
m_pointer = v2s32(event.TouchInput.X,event.TouchInput.Y);
|
||||
translated.MouseInput.Event = EMIE_MOUSE_MOVED;
|
||||
translated.MouseInput.ButtonStates = EMBSM_LEFT;
|
||||
break;
|
||||
case ETIE_LEFT_UP:
|
||||
translated.MouseInput.Event = EMIE_LMOUSE_LEFT_UP;
|
||||
translated.MouseInput.ButtonStates = 0;
|
||||
hovered = root->getElementFromPoint(m_down_pos);
|
||||
/* we don't have a valid pointer element use last
|
||||
* known pointer pos */
|
||||
translated.MouseInput.X = m_pointer.X;
|
||||
translated.MouseInput.Y = m_pointer.Y;
|
||||
|
||||
/* reset down pos */
|
||||
m_down_pos = v2s32(0,0);
|
||||
break;
|
||||
default:
|
||||
dont_send_event = true;
|
||||
//this is not supposed to happen
|
||||
errorstream
|
||||
<< "GUIFormSpecMenu::preprocessEvent unexpected usecase Event="
|
||||
<< event.TouchInput.Event << std::endl;
|
||||
}
|
||||
} else if ( (event.TouchInput.touchedCount == 2) &&
|
||||
(event.TouchInput.Event == ETIE_PRESSED_DOWN) ) {
|
||||
hovered = root->getElementFromPoint(m_down_pos);
|
||||
|
||||
translated.MouseInput.Event = EMIE_RMOUSE_PRESSED_DOWN;
|
||||
translated.MouseInput.ButtonStates = EMBSM_LEFT | EMBSM_RIGHT;
|
||||
translated.MouseInput.X = m_pointer.X;
|
||||
translated.MouseInput.Y = m_pointer.Y;
|
||||
|
||||
if (hovered) {
|
||||
hovered->OnEvent(translated);
|
||||
}
|
||||
|
||||
translated.MouseInput.Event = EMIE_RMOUSE_LEFT_UP;
|
||||
translated.MouseInput.ButtonStates = EMBSM_LEFT;
|
||||
|
||||
|
||||
if (hovered) {
|
||||
hovered->OnEvent(translated);
|
||||
}
|
||||
dont_send_event = true;
|
||||
}
|
||||
/* ignore unhandled 2 touch events ... accidental moving for example */
|
||||
else if (event.TouchInput.touchedCount == 2) {
|
||||
dont_send_event = true;
|
||||
}
|
||||
else if (event.TouchInput.touchedCount > 2) {
|
||||
errorstream
|
||||
<< "GUIFormSpecMenu::preprocessEvent to many multitouch events "
|
||||
<< event.TouchInput.touchedCount << " ignoring them" << std::endl;
|
||||
}
|
||||
|
||||
if (dont_send_event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* check if translated event needs to be preprocessed again */
|
||||
if (preprocessEvent(translated)) {
|
||||
return true;
|
||||
}
|
||||
if (hovered) {
|
||||
grab();
|
||||
bool retval = hovered->OnEvent(translated);
|
||||
|
||||
if (event.TouchInput.Event == ETIE_LEFT_UP) {
|
||||
/* reset pointer */
|
||||
m_pointer = v2s32(0,0);
|
||||
}
|
||||
drop();
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) {
|
||||
/* TODO add a check like:
|
||||
if (event.JoystickEvent != joystick_we_listen_for)
|
||||
|
@ -3214,7 +3046,7 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
|
|||
return handled;
|
||||
}
|
||||
|
||||
return false;
|
||||
return GUIModalMenu::preprocessEvent(event);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue