bsnes/hiro/core/hotkey.cpp

58 lines
1.1 KiB
C++

#if defined(Hiro_Hotkey)
auto mHotkey::allocate() -> pObject* {
return new pHotkey(*this);
}
//
auto mHotkey::doPress() const -> void {
if(state.onPress) return state.onPress();
}
auto mHotkey::doRelease() const -> void {
if(state.onRelease) return state.onRelease();
}
auto mHotkey::onPress(const function<void ()>& callback) -> type& {
state.onPress = callback;
return *this;
}
auto mHotkey::onRelease(const function<void ()>& callback) -> type& {
state.onRelease = callback;
return *this;
}
auto mHotkey::owner() const -> wObject {
return state.owner;
}
auto mHotkey::remove() -> type& {
//todo: remove from Keyboard::hotkeys
return *this;
}
auto mHotkey::sequence() const -> string {
return state.sequence;
}
auto mHotkey::setOwner(sObject owner) -> type& {
state.owner = owner;
return *this;
}
auto mHotkey::setSequence(const string& sequence) -> type& {
state.active = false;
state.sequence = sequence;
state.keys.reset();
for(auto& key : sequence.split("+")) {
if(auto position = Keyboard::keys.find(key)) {
state.keys.append(*position);
}
}
return *this;
}
#endif