Close screen keyboard when clicked outside of it
This commit is contained in:
@@ -75,6 +75,12 @@ bool EventHandler::OnEvent (const SEvent &event)
|
||||
|
||||
if(!Debug::onEvent(event))
|
||||
return false;
|
||||
|
||||
if (ScreenKeyboard::isActive())
|
||||
{
|
||||
if (ScreenKeyboard::getCurrent()->onEvent(event))
|
||||
return true; // EVENT_BLOCK
|
||||
}
|
||||
|
||||
// TO DEBUG HATS (when you don't actually have a hat)
|
||||
/*
|
||||
|
||||
@@ -89,6 +89,7 @@ ScreenKeyboard::ScreenKeyboard(float percent_width, float percent_height,
|
||||
m_back_button = NULL;
|
||||
m_repeat_time = 0;
|
||||
m_back_button_pressed = false;
|
||||
m_schedule_close = false;
|
||||
|
||||
init();
|
||||
} // ScreenKeyboard
|
||||
@@ -307,6 +308,44 @@ void ScreenKeyboard::onUpdate(float dt)
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** A function that handles irrlicht events
|
||||
* \param event Irrlicht event
|
||||
* \return Block event if true
|
||||
*/
|
||||
bool ScreenKeyboard::onEvent(const SEvent &event)
|
||||
{
|
||||
if (event.EventType == EET_MOUSE_INPUT_EVENT)
|
||||
{
|
||||
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 (!is_point_inside)
|
||||
{
|
||||
m_schedule_close = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
|
||||
{
|
||||
if (!is_point_inside && m_schedule_close)
|
||||
{
|
||||
dismiss();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_schedule_close = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** A function that handles buttons events
|
||||
* \param eventSource Button ID
|
||||
@@ -428,4 +467,4 @@ bool ScreenKeyboard::shouldUseScreenKeyboard()
|
||||
#endif
|
||||
|
||||
return use_screen_keyboard;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,9 @@ namespace GUIEngine
|
||||
/** True if backspace button was pressed */
|
||||
bool m_back_button_pressed;
|
||||
|
||||
/** True if screen keyboard is going to be closed */
|
||||
bool m_schedule_close;
|
||||
|
||||
/** The edit box that is assigned to the keyboard */
|
||||
CGUIEditBox* m_edit_box;
|
||||
|
||||
@@ -123,6 +126,8 @@ namespace GUIEngine
|
||||
/** Override to be notified of updates */
|
||||
virtual void onUpdate(float dt);
|
||||
|
||||
bool onEvent(const SEvent &event);
|
||||
|
||||
/** Get irrlicht window used by the keyboard widget */
|
||||
irr::gui::IGUIWindow* getIrrlichtElement() {return m_irrlicht_window;}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user