Allow to repeat backspace key on screen keyboard
This commit is contained in:
parent
900beae4b2
commit
f559627951
@ -1162,14 +1162,26 @@ namespace GUIEngine
|
||||
// ---- some menus may need updating
|
||||
if (gamestate != GAME)
|
||||
{
|
||||
if (ModalDialog::isADialogActive())
|
||||
if (ScreenKeyboard::isActive())
|
||||
{
|
||||
ScreenKeyboard::getCurrent()->onUpdate(dt);
|
||||
}
|
||||
else if (ModalDialog::isADialogActive())
|
||||
{
|
||||
ModalDialog::getCurrent()->onUpdate(dt);
|
||||
}
|
||||
else
|
||||
{
|
||||
getCurrentScreen()->onUpdate(elapsed_time);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ModalDialog::isADialogActive())
|
||||
if (ScreenKeyboard::isActive())
|
||||
{
|
||||
ScreenKeyboard::getCurrent()->onUpdate(dt);
|
||||
}
|
||||
else if (ModalDialog::isADialogActive())
|
||||
{
|
||||
ModalDialog::getCurrent()->onUpdate(dt);
|
||||
}
|
||||
|
@ -81,6 +81,8 @@ ScreenKeyboard::ScreenKeyboard(float percent_width, float percent_height,
|
||||
m_percent_height = std::min(std::max(percent_height, 0.0f), 1.0f);
|
||||
m_irrlicht_window = NULL;
|
||||
m_edit_box = edit_box;
|
||||
m_back_button = NULL;
|
||||
m_repeat_time = 0;
|
||||
|
||||
init();
|
||||
} // ScreenKeyboard
|
||||
@ -135,6 +137,10 @@ void ScreenKeyboard::init()
|
||||
|
||||
createButtons();
|
||||
assignButtons(BUTTONS_LOWER);
|
||||
|
||||
Widget* button_widget = getWidget<ButtonWidget>("Back");
|
||||
assert(button_widget != NULL);
|
||||
m_back_button = button_widget->getIrrlichtElement<IGUIButton>();
|
||||
} // init
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -221,6 +227,42 @@ void ScreenKeyboard::assignButtons(ButtonsType buttons_type)
|
||||
}
|
||||
} // assignButtons
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ScreenKeyboard::onUpdate(float dt)
|
||||
{
|
||||
if (m_back_button->isPressed())
|
||||
{
|
||||
const unsigned int repeat_rate = 40;
|
||||
const unsigned int repeat_delay = 400;
|
||||
|
||||
SEvent event;
|
||||
event.KeyInput.Key = IRR_KEY_BACK;
|
||||
event.KeyInput.Char = 0;
|
||||
event.EventType = EET_KEY_INPUT_EVENT;
|
||||
event.KeyInput.PressedDown = true;
|
||||
event.KeyInput.Control = false;
|
||||
event.KeyInput.Shift = false;
|
||||
|
||||
if (m_repeat_time == 0)
|
||||
{
|
||||
m_edit_box->OnEvent(event);
|
||||
}
|
||||
|
||||
while (m_repeat_time > repeat_delay + repeat_rate)
|
||||
{
|
||||
m_edit_box->OnEvent(event);
|
||||
m_repeat_time -= repeat_rate;
|
||||
}
|
||||
|
||||
m_repeat_time += (unsigned int)(dt * 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_repeat_time = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** A function that handles buttons events
|
||||
* \param eventSource Button ID
|
||||
@ -272,9 +314,7 @@ EventPropagation ScreenKeyboard::processEvent(const std::string& eventSource)
|
||||
}
|
||||
else if (eventSource == "Back")
|
||||
{
|
||||
event.KeyInput.Key = IRR_KEY_BACK;
|
||||
event.KeyInput.Char = 0;
|
||||
send_event = true;
|
||||
send_event = false;
|
||||
}
|
||||
else if (eventSource == "Space")
|
||||
{
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef HEADER_SCREEN_KEYBOARD_HPP
|
||||
#define HEADER_SCREEN_KEYBOARD_HPP
|
||||
|
||||
#include <IGUIButton.h>
|
||||
#include <IGUIWindow.h>
|
||||
|
||||
#include "guiengine/abstract_top_level_container.hpp"
|
||||
@ -67,9 +68,15 @@ namespace GUIEngine
|
||||
* that is used by the keyboard */
|
||||
float m_percent_height;
|
||||
|
||||
/** A time for repeat key feature */
|
||||
unsigned int m_repeat_time;
|
||||
|
||||
/** The edit box that is assigned to the keyboard */
|
||||
CGUIEditBox* m_edit_box;
|
||||
|
||||
/** A button that is used as backspace key */
|
||||
irr::gui::IGUIButton* m_back_button;
|
||||
|
||||
/** Remembers currently selected button type */
|
||||
ButtonsType m_buttons_type;
|
||||
|
||||
@ -100,7 +107,6 @@ namespace GUIEngine
|
||||
|
||||
static void dismiss();
|
||||
static bool onEscapePressed();
|
||||
|
||||
/** Returns pointer to the created keyboard or NULL if keyboard was
|
||||
* not created */
|
||||
static ScreenKeyboard* getCurrent() {return m_screen_keyboard;}
|
||||
@ -108,6 +114,9 @@ namespace GUIEngine
|
||||
/** Returns true if keyboard is created */
|
||||
static bool isActive() {return m_screen_keyboard != NULL;}
|
||||
|
||||
/** Override to be notified of updates */
|
||||
virtual void onUpdate(float dt);
|
||||
|
||||
/** Get irrlicht window used by the keyboard widget */
|
||||
irr::gui::IGUIWindow* getIrrlichtElement() {return m_irrlicht_window;}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user