implement auto repeat configuration for key press events, to give more flexibility

This commit is contained in:
Eduardo Bart 2012-02-06 10:53:28 -02:00
parent f97104f12e
commit add8505a5b
18 changed files with 68 additions and 198 deletions

View File

@ -6,14 +6,13 @@ local loadBox
local characterList local characterList
-- private functions -- private functions
local function onCharactersWindowKeyPress(self, keyCode, keyboardModifiers, wouldFilter) local function onCharactersWindowKeyPress(self, keyCode, keyboardModifiers)
if wouldFilter then return end
if keyboardModifiers == KeyboardNoModifier then if keyboardModifiers == KeyboardNoModifier then
if keyCode == KeyUp then if keyCode == KeyUp then
characterList:focusPreviousChild(ActiveFocusReason) characterList:focusPreviousChild(KeyboardFocusReason)
return true return true
elseif keyCode == KeyDown or keyCode == KeyTab then elseif keyCode == KeyDown or keyCode == KeyTab then
characterList:focusNextChild(ActiveFocusReason) characterList:focusNextChild(KeyboardFocusReason)
return true return true
end end
end end

View File

@ -13,6 +13,9 @@ function ModuleManager.init()
ModuleManager.updateModuleInfo(focusedChild:getText()) ModuleManager.updateModuleInfo(focusedChild:getText())
end }) end })
Keyboard.bindKeyPress('Up', function() moduleList:focusPreviousChild(KeyboardFocusReason) end, moduleManagerWindow)
Keyboard.bindKeyPress('Down', function() moduleList:focusNextChild(KeyboardFocusReason) end, moduleManagerWindow)
moduleManagerButton = TopMenu.addButton('moduleManagerButton', 'Module manager', 'modulemanager.png', ModuleManager.toggle) moduleManagerButton = TopMenu.addButton('moduleManagerButton', 'Module manager', 'modulemanager.png', ModuleManager.toggle)
addEvent(ModuleManager.listModules) addEvent(ModuleManager.listModules)

View File

@ -1,134 +0,0 @@
Hotkeys = {}
-- private functions
local function translateKeyCombo(keyCombo)
if not keyCombo or #keyCombo == 0 then return nil end
table.sort(keyCombo)
local keyComboDesc = ''
for k,v in pairs(keyCombo) do
local keyDesc = KeyCodeDescs[v]
if keyDesc == nil then return nil end
keyComboDesc = keyComboDesc .. '+' .. keyDesc
end
keyComboDesc = keyComboDesc:sub(2)
return keyComboDesc
end
local function retranslateKeyComboDesc(keyComboDesc)
if keyComboDesc == nil then return nil end
local keyCombo = {}
for i,currentKeyDesc in ipairs(keyComboDesc:split('+')) do
for keyCode, keyDesc in pairs(KeyCodeDescs) do
if keyDesc:lower() == currentKeyDesc:trim():lower() then
table.insert(keyCombo, keyCode)
end
end
end
return translateKeyCombo(keyCombo)
end
local function determineKeyComboDesc(keyCode, keyboardModifiers)
local keyCombo = {}
if keyCode == KeyCtrl or keyCode == KeyShift or keyCode == KeyAlt then
table.insert(keyCombo, keyCode)
elseif KeyCodeDescs[keyCode] ~= nil then
if keyboardModifiers == KeyboardCtrlModifier then
table.insert(keyCombo, KeyCtrl)
elseif keyboardModifiers == KeyboardAltModifier then
table.insert(keyCombo, KeyAlt)
elseif keyboardModifiers == KeyboardCtrlAltModifier then
table.insert(keyCombo, KeyCtrl)
table.insert(keyCombo, KeyAlt)
elseif keyboardModifiers == KeyboardShiftModifier then
table.insert(keyCombo, KeyShift)
elseif keyboardModifiers == KeyboardCtrlShiftModifier then
table.insert(keyCombo, KeyCtrl)
table.insert(keyCombo, KeyShift)
elseif keyboardModifiers == KeyboardAltShiftModifier then
table.insert(keyCombo, KeyAlt)
table.insert(keyCombo, KeyShift)
elseif keyboardModifiers == KeyboardCtrlAltShiftModifier then
table.insert(keyCombo, KeyCtrl)
table.insert(keyCombo, KeyAlt)
table.insert(keyCombo, KeyShift)
end
table.insert(keyCombo, keyCode)
end
table.sort(keyCombo)
return translateKeyCombo(keyCombo)
end
local function onWidgetKeyDown(widget, keyCode, keyboardModifiers)
if keyCode == KeyUnknown then return end
local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
local callback = widget.boundKeyDownCombos[keyComboDesc]
if callback then
callback()
return true
end
return false
end
local function onWidgetKeyPress(widget, keyCode, keyboardModifiers, wouldFilter)
local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
if keyCode == KeyUnknown then return end
local callback = widget.boundKeyPressCombos[keyComboDesc]
if callback then
callback()
return true
end
return false
end
local function connectKeyDownEvent(widget)
if widget.boundKeyDownCombos then return end
connect(widget, { onKeyDown = onWidgetKeyDown })
widget.boundKeyDownCombos = {}
end
local function connectKeyPressEvent(widget)
if widget.boundKeyPressCombos then return end
connect(widget, { onKeyPress = onWidgetKeyPress })
widget.boundKeyPressCombos = {}
end
-- public functions
function Hotkeys.bindKeyDown(keyComboDesc, callback, widget)
widget = widget or rootWidget
connectKeyDownEvent(widget)
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
if keyComboDesc then
widget.boundKeyDownCombos[keyComboDesc] = callback
else
error('key combo \'' .. keyComboDesc .. '\' is failed')
end
end
function Hotkeys.bindKeyPress(keyComboDesc, callback, widget)
widget = widget or rootWidget
connectKeyPressEvent(widget)
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
if keyComboDesc then
widget.boundKeyPressCombos[keyComboDesc] = callback
else
error('key combo \'' .. keyComboDesc .. '\' is failed')
end
end
function Hotkeys.unbindKeyDown(keyComboDesc, widget)
widget = widget or rootWidget
if widget.boundKeyDownCombos == nil then return end
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
if keyComboDesc then
widget.boundKeyDownCombos[keyComboDesc] = nil
end
end
function Hotkeys.unbindKeyPress(keyComboDesc, widget)
widget = widget or rootWidget
if widget.boundKeyPressCombos == nil then return end
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
if keyComboDesc then
widget.boundKeyPressCombos[keyComboDesc] = nil
end
end

View File

@ -59,7 +59,7 @@ local function determineKeyComboDesc(keyCode, keyboardModifiers)
end end
local function onWidgetKeyDown(widget, keyCode, keyboardModifiers) local function onWidgetKeyDown(widget, keyCode, keyboardModifiers)
if keyCode == KeyUnknown then return end if keyCode == KeyUnknown then return false end
local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers) local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
local callback = widget.boundKeyDownCombos[keyComboDesc] local callback = widget.boundKeyDownCombos[keyComboDesc]
if callback then if callback then
@ -69,12 +69,12 @@ local function onWidgetKeyDown(widget, keyCode, keyboardModifiers)
return false return false
end end
local function onWidgetKeyPress(widget, keyCode, keyboardModifiers, wouldFilter) local function onWidgetKeyPress(widget, keyCode, keyboardModifiers, autoRepeatTicks)
local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers) local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
if keyCode == KeyUnknown then return end if keyCode == KeyUnknown then return false end
local callback = widget.boundKeyPressCombos[keyComboDesc] local comboConf = widget.boundKeyPressCombos[keyComboDesc]
if callback then if comboConf and (autoRepeatTicks >= comboConf.autoRepeatDelay or autoRepeatTicks == 0) and comboConf.callback then
callback() comboConf.callback()
return true return true
end end
return false return false
@ -104,12 +104,14 @@ function Keyboard.bindKeyDown(keyComboDesc, callback, widget)
end end
end end
function Keyboard.bindKeyPress(keyComboDesc, callback, widget) function Keyboard.bindKeyPress(keyComboDesc, callback, widget, autoRepeatDelay)
autoRepeatDelay = autoRepeatDelay or 500
widget = widget or rootWidget widget = widget or rootWidget
connectKeyPressEvent(widget) connectKeyPressEvent(widget)
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc) local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
if keyComboDesc then if keyComboDesc then
widget.boundKeyPressCombos[keyComboDesc] = callback widget.boundKeyPressCombos[keyComboDesc] = { callback = callback, autoRepeatDelay = autoRepeatDelay }
widget:setAutoRepeatDelay(math.min(autoRepeatDelay, widget:getAutoRepeatDelay()))
else else
error('key combo \'' .. keyComboDesc .. '\' is failed') error('key combo \'' .. keyComboDesc .. '\' is failed')
end end

View File

@ -56,8 +56,7 @@ function UIPopupMenu:onMousePress(mousePos, mouseButton)
return false return false
end end
function UIPopupMenu:onKeyPress(keyCode, keyboardModifiers, wouldFilter) function UIPopupMenu:onKeyPress(keyCode, keyboardModifiers)
if wouldFilter then return end
if keyCode == KeyEscape then if keyCode == KeyEscape then
self:destroy() self:destroy()
return true return true

View File

@ -6,8 +6,7 @@ function UIWindow.create()
return window return window
end end
function UIWindow:onKeyPress(keyCode, keyboardModifiers, wouldFilter) function UIWindow:onKeyPress(keyCode, keyboardModifiers)
if wouldFilter then return end
if keyboardModifiers == KeyboardNoModifier then if keyboardModifiers == KeyboardNoModifier then
if keyCode == KeyEnter then if keyCode == KeyEnter then
signalcall(self.onEnter, self) signalcall(self.onEnter, self)

View File

@ -2,8 +2,7 @@
local m_mouseGrabberWidget local m_mouseGrabberWidget
-- private functions -- private functions
local function onGameKeyPress(self, keyCode, keyboardModifiers, wouldFilter) local function onGameKeyPress(self, keyCode, keyboardModifiers)
if wouldFilter then return end
if keyboardModifiers == KeyboardCtrlModifier then if keyboardModifiers == KeyboardCtrlModifier then
if keyCode == KeyG then if keyCode == KeyG then
CharacterList.show() CharacterList.show()

View File

@ -37,8 +37,8 @@ struct InputEvent {
mouseButton = Fw::MouseNoButton; mouseButton = Fw::MouseNoButton;
keyCode = Fw::KeyUnknown; keyCode = Fw::KeyUnknown;
keyText = ""; keyText = "";
autoRepeatTicks = 0;
mouseMoved = Point(); mouseMoved = Point();
wouldFilter = false;
}; };
Fw::InputEventType type; Fw::InputEventType type;
@ -49,7 +49,7 @@ struct InputEvent {
int keyboardModifiers; int keyboardModifiers;
Point mousePos; Point mousePos;
Point mouseMoved; Point mouseMoved;
bool wouldFilter; int autoRepeatTicks;
}; };
#endif #endif

View File

@ -101,6 +101,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("setPhantom", &UIWidget::setPhantom); g_lua.bindClassMemberFunction<UIWidget>("setPhantom", &UIWidget::setPhantom);
g_lua.bindClassMemberFunction<UIWidget>("setFixedSize", &UIWidget::setFixedSize); g_lua.bindClassMemberFunction<UIWidget>("setFixedSize", &UIWidget::setFixedSize);
g_lua.bindClassMemberFunction<UIWidget>("setLastFocusReason", &UIWidget::setLastFocusReason); g_lua.bindClassMemberFunction<UIWidget>("setLastFocusReason", &UIWidget::setLastFocusReason);
g_lua.bindClassMemberFunction<UIWidget>("setAutoRepeatDelay", &UIWidget::setAutoRepeatDelay);
g_lua.bindClassMemberFunction<UIWidget>("isVisible", &UIWidget::isVisible); g_lua.bindClassMemberFunction<UIWidget>("isVisible", &UIWidget::isVisible);
g_lua.bindClassMemberFunction<UIWidget>("isChildLocked", &UIWidget::isChildLocked); g_lua.bindClassMemberFunction<UIWidget>("isChildLocked", &UIWidget::isChildLocked);
g_lua.bindClassMemberFunction<UIWidget>("hasChild", &UIWidget::hasChild); g_lua.bindClassMemberFunction<UIWidget>("hasChild", &UIWidget::hasChild);
@ -154,6 +155,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("getStyle", &UIWidget::getStyle); g_lua.bindClassMemberFunction<UIWidget>("getStyle", &UIWidget::getStyle);
g_lua.bindClassMemberFunction<UIWidget>("getChildCount", &UIWidget::getChildCount); g_lua.bindClassMemberFunction<UIWidget>("getChildCount", &UIWidget::getChildCount);
g_lua.bindClassMemberFunction<UIWidget>("getLastFocusReason", &UIWidget::getLastFocusReason); g_lua.bindClassMemberFunction<UIWidget>("getLastFocusReason", &UIWidget::getLastFocusReason);
g_lua.bindClassMemberFunction<UIWidget>("getAutoRepeatDelay", &UIWidget::getAutoRepeatDelay);
g_lua.bindClassMemberFunction<UIWidget>("getStyleName", &UIWidget::getStyleName); g_lua.bindClassMemberFunction<UIWidget>("getStyleName", &UIWidget::getStyleName);
g_lua.bindClassMemberFunction<UIWidget>("setX", &UIWidget::setX); g_lua.bindClassMemberFunction<UIWidget>("setX", &UIWidget::setX);
g_lua.bindClassMemberFunction<UIWidget>("setY", &UIWidget::setY); g_lua.bindClassMemberFunction<UIWidget>("setY", &UIWidget::setY);

View File

@ -58,7 +58,7 @@ void PlatformWindow::processKeyDown(Fw::Key keyCode)
else if(keyCode == Fw::KeyShift) else if(keyCode == Fw::KeyShift)
m_inputEvent.keyboardModifiers |= Fw::KeyboardShiftModifier; m_inputEvent.keyboardModifiers |= Fw::KeyboardShiftModifier;
m_inputEvent.reset(); m_inputEvent.reset(Fw::KeyDownInputEvent);
m_inputEvent.type = Fw::KeyDownInputEvent; m_inputEvent.type = Fw::KeyDownInputEvent;
m_inputEvent.keyCode = keyCode; m_inputEvent.keyCode = keyCode;
@ -126,7 +126,7 @@ void PlatformWindow::fireKeysPress()
if(m_onInputEvent) { if(m_onInputEvent) {
m_inputEvent.reset(Fw::KeyPressInputEvent); m_inputEvent.reset(Fw::KeyPressInputEvent);
m_inputEvent.keyCode = keyCode; m_inputEvent.keyCode = keyCode;
m_inputEvent.wouldFilter = g_clock.ticksElapsed(firstKeyPress) < KEY_PRESS_REPEAT_DELAY; m_inputEvent.autoRepeatTicks = g_clock.ticksElapsed(firstKeyPress);
m_onInputEvent(m_inputEvent); m_onInputEvent(m_inputEvent);
} }
m_lastKeysPress[keyCode] = g_clock.ticks(); m_lastKeysPress[keyCode] = g_clock.ticks();

View File

@ -31,7 +31,6 @@ class PlatformWindow
{ {
enum { enum {
KEY_PRESS_REPEAT_INTERVAL = 30, KEY_PRESS_REPEAT_INTERVAL = 30,
KEY_PRESS_REPEAT_DELAY = 500
}; };
typedef std::function<void(const Size&)> OnResizeCallback; typedef std::function<void(const Size&)> OnResizeCallback;

View File

@ -429,12 +429,11 @@ void UILineEdit::onFocusChange(bool focused, Fw::FocusReason reason)
UIWidget::onFocusChange(focused, reason); UIWidget::onFocusChange(focused, reason);
} }
bool UILineEdit::onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter) bool UILineEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks)
{ {
if(UIWidget::onKeyPress(keyCode, keyboardModifiers, wouldFilter)) if(UIWidget::onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks))
return true; return true;
if(!wouldFilter) {
if(keyCode == Fw::KeyDelete) // erase right character if(keyCode == Fw::KeyDelete) // erase right character
removeCharacter(true); removeCharacter(true);
else if(keyCode == Fw::KeyBackspace) // erase left character { else if(keyCode == Fw::KeyBackspace) // erase left character {
@ -458,8 +457,6 @@ bool UILineEdit::onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilt
return false; return false;
return true; return true;
} }
return false;
}
bool UILineEdit::onKeyText(const std::string& keyText) bool UILineEdit::onKeyText(const std::string& keyText)
{ {

View File

@ -63,7 +63,7 @@ protected:
virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect); virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
virtual void onFocusChange(bool focused, Fw::FocusReason reason); virtual void onFocusChange(bool focused, Fw::FocusReason reason);
virtual bool onKeyText(const std::string& keyText); virtual bool onKeyText(const std::string& keyText);
virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter); virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks);
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button); virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
private: private:

View File

@ -69,7 +69,7 @@ void UIManager::inputEvent(const InputEvent& event)
m_keyboardReceiver->propagateOnKeyDown(event.keyCode, event.keyboardModifiers); m_keyboardReceiver->propagateOnKeyDown(event.keyCode, event.keyboardModifiers);
break; break;
case Fw::KeyPressInputEvent: case Fw::KeyPressInputEvent:
m_keyboardReceiver->propagateOnKeyPress(event.keyCode, event.keyboardModifiers, event.wouldFilter); m_keyboardReceiver->propagateOnKeyPress(event.keyCode, event.keyboardModifiers, event.autoRepeatTicks);
break; break;
case Fw::KeyUpInputEvent: case Fw::KeyUpInputEvent:
m_keyboardReceiver->propagateOnKeyUp(event.keyCode, event.keyboardModifiers); m_keyboardReceiver->propagateOnKeyUp(event.keyCode, event.keyboardModifiers);

View File

@ -36,6 +36,7 @@ UIWidget::UIWidget()
m_lastFocusReason = Fw::ActiveFocusReason; m_lastFocusReason = Fw::ActiveFocusReason;
m_states = Fw::DefaultState; m_states = Fw::DefaultState;
m_clickTimer.stop(); m_clickTimer.stop();
m_autoRepeatDelay = 500;
initBaseStyle(); initBaseStyle();
initText(); initText();
@ -1152,9 +1153,9 @@ bool UIWidget::onKeyDown(uchar keyCode, int keyboardModifiers)
return callLuaField<bool>("onKeyDown", keyCode, keyboardModifiers); return callLuaField<bool>("onKeyDown", keyCode, keyboardModifiers);
} }
bool UIWidget::onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter) bool UIWidget::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks)
{ {
return callLuaField<bool>("onKeyPress", keyCode, keyboardModifiers, wouldFilter); return callLuaField<bool>("onKeyPress", keyCode, keyboardModifiers, autoRepeatTicks);
} }
bool UIWidget::onKeyUp(uchar keyCode, int keyboardModifiers) bool UIWidget::onKeyUp(uchar keyCode, int keyboardModifiers)
@ -1260,7 +1261,7 @@ bool UIWidget::propagateOnKeyDown(uchar keyCode, int keyboardModifiers)
return onKeyDown(keyCode, keyboardModifiers); return onKeyDown(keyCode, keyboardModifiers);
} }
bool UIWidget::propagateOnKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter) bool UIWidget::propagateOnKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks)
{ {
// do a backup of children list, because it may change while looping it // do a backup of children list, because it may change while looping it
UIWidgetList children; UIWidgetList children;
@ -1275,11 +1276,14 @@ bool UIWidget::propagateOnKeyPress(uchar keyCode, int keyboardModifiers, bool wo
} }
for(const UIWidgetPtr& child : children) { for(const UIWidgetPtr& child : children) {
if(child->propagateOnKeyPress(keyCode, keyboardModifiers, wouldFilter)) if(child->propagateOnKeyPress(keyCode, keyboardModifiers, autoRepeatTicks))
return true; return true;
} }
return onKeyPress(keyCode, keyboardModifiers, wouldFilter); if(autoRepeatTicks == 0 || autoRepeatTicks >= m_autoRepeatDelay) {
return onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks);
} else
return false;
} }
bool UIWidget::propagateOnKeyUp(uchar keyCode, int keyboardModifiers) bool UIWidget::propagateOnKeyUp(uchar keyCode, int keyboardModifiers)

View File

@ -124,6 +124,7 @@ public:
void setDragable(bool dragable); void setDragable(bool dragable);
void setFixedSize(bool fixed); void setFixedSize(bool fixed);
void setLastFocusReason(Fw::FocusReason reason); void setLastFocusReason(Fw::FocusReason reason);
void setAutoRepeatDelay(int delay) { m_autoRepeatDelay = delay; }
bool isVisible(); bool isVisible();
bool isChildLocked(const UIWidgetPtr& child); bool isChildLocked(const UIWidgetPtr& child);
@ -177,7 +178,7 @@ protected:
virtual void onDrop(UIWidgetPtr draggedWidget, const Point& mousePos); virtual void onDrop(UIWidgetPtr draggedWidget, const Point& mousePos);
virtual bool onKeyText(const std::string& keyText); virtual bool onKeyText(const std::string& keyText);
virtual bool onKeyDown(uchar keyCode, int keyboardModifiers); virtual bool onKeyDown(uchar keyCode, int keyboardModifiers);
virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter); virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks);
virtual bool onKeyUp(uchar keyCode, int keyboardModifiers); virtual bool onKeyUp(uchar keyCode, int keyboardModifiers);
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button); virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button); virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
@ -188,7 +189,7 @@ protected:
bool propagateOnKeyText(const std::string& keyText); bool propagateOnKeyText(const std::string& keyText);
bool propagateOnKeyDown(uchar keyCode, int keyboardModifiers); bool propagateOnKeyDown(uchar keyCode, int keyboardModifiers);
bool propagateOnKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter); bool propagateOnKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks);
bool propagateOnKeyUp(uchar keyCode, int keyboardModifiers); bool propagateOnKeyUp(uchar keyCode, int keyboardModifiers);
bool propagateOnMousePress(const Point& mousePos, Fw::MouseButton button); bool propagateOnMousePress(const Point& mousePos, Fw::MouseButton button);
bool propagateOnMouseRelease(const Point& mousePos, Fw::MouseButton button); bool propagateOnMouseRelease(const Point& mousePos, Fw::MouseButton button);
@ -240,6 +241,7 @@ public:
OTMLNodePtr getStyle() { return m_style; } OTMLNodePtr getStyle() { return m_style; }
int getChildCount() { return m_children.size(); } int getChildCount() { return m_children.size(); }
Fw::FocusReason getLastFocusReason() { return m_lastFocusReason; } Fw::FocusReason getLastFocusReason() { return m_lastFocusReason; }
int getAutoRepeatDelay() { return m_autoRepeatDelay; }
std::string getStyleName() { return m_style->tag(); } std::string getStyleName() { return m_style->tag(); }
@ -264,6 +266,7 @@ protected:
EdgeGroup<int> m_margin; EdgeGroup<int> m_margin;
EdgeGroup<int> m_padding; EdgeGroup<int> m_padding;
float m_opacity; float m_opacity;
int m_autoRepeatDelay;
public: public:
void setX(int x) { move(x, getY()); } void setX(int x) { move(x, getY()); }

View File

@ -25,9 +25,9 @@
#include <framework/ui/uilineedit.h> #include <framework/ui/uilineedit.h>
#include <framework/platform/platformwindow.h> #include <framework/platform/platformwindow.h>
bool UIGame::onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter) bool UIGame::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks)
{ {
if(UIWidget::onKeyPress(keyCode, keyboardModifiers, wouldFilter)) if(UIWidget::onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks))
return true; return true;
UILineEditPtr chatLineEdit = std::dynamic_pointer_cast<UILineEdit>(getParent()->recursiveGetChildById("consoleLineEdit")); UILineEditPtr chatLineEdit = std::dynamic_pointer_cast<UILineEdit>(getParent()->recursiveGetChildById("consoleLineEdit"));
@ -58,8 +58,6 @@ bool UIGame::onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter)
} else if(keyCode == Fw::KeyNumpad7) { } else if(keyCode == Fw::KeyNumpad7) {
g_game.walk(Otc::NorthWest); g_game.walk(Otc::NorthWest);
return true; return true;
} else if(wouldFilter) {
return false;
} else if(keyCode == Fw::KeyDelete) { } else if(keyCode == Fw::KeyDelete) {
chatLineEdit->removeCharacter(true); chatLineEdit->removeCharacter(true);
return true; return true;

View File

@ -29,7 +29,7 @@
class UIGame : public UIWidget class UIGame : public UIWidget
{ {
protected: protected:
bool onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter); bool onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks);
bool onKeyText(const std::string& keyText); bool onKeyText(const std::string& keyText);
}; };