summaryrefslogtreecommitdiff
path: root/core/input_map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/input_map.cpp')
-rw-r--r--core/input_map.cpp47
1 files changed, 27 insertions, 20 deletions
diff --git a/core/input_map.cpp b/core/input_map.cpp
index 0379131dd3..444c55cac6 100644
--- a/core/input_map.cpp
+++ b/core/input_map.cpp
@@ -27,26 +27,27 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "input_map.h"
-#include "globals.h"
+
+#include "global_config.h"
#include "os/keyboard.h"
InputMap *InputMap::singleton=NULL;
void InputMap::_bind_methods() {
- ClassDB::bind_method(_MD("has_action","action"),&InputMap::has_action);
- ClassDB::bind_method(_MD("get_action_id","action"),&InputMap::get_action_id);
- ClassDB::bind_method(_MD("get_action_from_id","id"),&InputMap::get_action_from_id);
- ClassDB::bind_method(_MD("get_actions"),&InputMap::_get_actions);
- ClassDB::bind_method(_MD("add_action","action"),&InputMap::add_action);
- ClassDB::bind_method(_MD("erase_action","action"),&InputMap::erase_action);
+ ClassDB::bind_method(D_METHOD("has_action","action"),&InputMap::has_action);
+ ClassDB::bind_method(D_METHOD("get_action_id","action"),&InputMap::get_action_id);
+ ClassDB::bind_method(D_METHOD("get_action_from_id","id"),&InputMap::get_action_from_id);
+ ClassDB::bind_method(D_METHOD("get_actions"),&InputMap::_get_actions);
+ ClassDB::bind_method(D_METHOD("add_action","action"),&InputMap::add_action);
+ ClassDB::bind_method(D_METHOD("erase_action","action"),&InputMap::erase_action);
- ClassDB::bind_method(_MD("action_add_event","action","event"),&InputMap::action_add_event);
- ClassDB::bind_method(_MD("action_has_event","action","event"),&InputMap::action_has_event);
- ClassDB::bind_method(_MD("action_erase_event","action","event"),&InputMap::action_erase_event);
- ClassDB::bind_method(_MD("get_action_list","action"),&InputMap::_get_action_list);
- ClassDB::bind_method(_MD("event_is_action","event","action"),&InputMap::event_is_action);
- ClassDB::bind_method(_MD("load_from_globals"),&InputMap::load_from_globals);
+ ClassDB::bind_method(D_METHOD("action_add_event","action","event"),&InputMap::action_add_event);
+ ClassDB::bind_method(D_METHOD("action_has_event","action","event"),&InputMap::action_has_event);
+ ClassDB::bind_method(D_METHOD("action_erase_event","action","event"),&InputMap::action_erase_event);
+ ClassDB::bind_method(D_METHOD("get_action_list","action"),&InputMap::_get_action_list);
+ ClassDB::bind_method(D_METHOD("event_is_action","event","action"),&InputMap::event_is_action);
+ ClassDB::bind_method(D_METHOD("load_from_globals"),&InputMap::load_from_globals);
}
@@ -106,7 +107,7 @@ List<StringName> InputMap::get_actions() const {
return actions;
}
-List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_mod_ignore=false) const {
+List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_action_test) const {
for (List<InputEvent>::Element *E=p_list.front();E;E=E->next()) {
@@ -122,7 +123,13 @@ List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const
case InputEvent::KEY: {
- same=(e.key.scancode==p_event.key.scancode && (p_mod_ignore || e.key.mod == p_event.key.mod));
+ if(p_action_test) {
+ uint32_t code = e.key.get_scancode_with_modifiers();
+ uint32_t event_code = p_event.key.get_scancode_with_modifiers();
+ same=(e.key.scancode==p_event.key.scancode && (!p_event.key.pressed || ((code & event_code) == code)));
+ } else {
+ same=(e.key.scancode==p_event.key.scancode && e.key.mod == p_event.key.mod);
+ }
} break;
case InputEvent::JOYPAD_BUTTON: {
@@ -198,7 +205,7 @@ Array InputMap::_get_action_list(const StringName& p_action) {
if (al) {
for(const List<InputEvent>::Element *E=al->front();E;E=E->next()) {
- ret.push_back(E->get());;
+ ret.push_back(E->get());
}
}
@@ -229,7 +236,7 @@ bool InputMap::event_is_action(const InputEvent& p_event, const StringName& p_ac
return p_event.action.action==E->get().id;
}
- return _find_event(E->get().inputs,p_event,!p_event.is_pressed())!=NULL;
+ return _find_event(E->get().inputs,p_event,true)!=NULL;
}
const Map<StringName, InputMap::Action>& InputMap::get_action_map() const {
@@ -238,7 +245,7 @@ const Map<StringName, InputMap::Action>& InputMap::get_action_map() const {
void InputMap::load_from_globals() {
- input_map.clear();;
+ input_map.clear();
List<PropertyInfo> pinfo;
GlobalConfig::get_singleton()->get_property_list(&pinfo);
@@ -253,7 +260,7 @@ void InputMap::load_from_globals() {
add_action(name);
- Array va = GlobalConfig::get_singleton()->get(pi.name);;
+ Array va = GlobalConfig::get_singleton()->get(pi.name);
for(int i=0;i<va.size();i++) {
@@ -324,7 +331,7 @@ void InputMap::load_default() {
key.key.scancode=KEY_PAGEDOWN;
action_add_event("ui_page_down",key);
-// set("display/handheld/orientation", "landscape");
+ //set("display/handheld/orientation", "landscape");
}