diff options
Diffstat (limited to 'core/os')
-rw-r--r-- | core/os/input.cpp | 25 | ||||
-rw-r--r-- | core/os/input.h | 2 | ||||
-rw-r--r-- | core/os/keyboard.cpp | 105 | ||||
-rw-r--r-- | core/os/keyboard.h | 1 | ||||
-rw-r--r-- | core/os/os.cpp | 5 | ||||
-rw-r--r-- | core/os/os.h | 13 |
6 files changed, 150 insertions, 1 deletions
diff --git a/core/os/input.cpp b/core/os/input.cpp index 4151c1b5a8..a827e75896 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -29,6 +29,7 @@ #include "input.h" #include "input_map.h" #include "os/os.h" +#include "globals.h" Input *Input::singleton=NULL; Input *Input::get_singleton() { @@ -69,6 +70,30 @@ void Input::_bind_methods() { ADD_SIGNAL( MethodInfo("joy_connection_changed", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::BOOL, "connected")) ); } +void Input::get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const { +#ifdef TOOLS_ENABLED + + String pf=p_function; + if (p_idx==0 && (pf=="is_action_pressed" || pf=="action_press" || pf=="action_release")) { + + List<PropertyInfo> pinfo; + Globals::get_singleton()->get_property_list(&pinfo); + + for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { + const PropertyInfo &pi=E->get(); + + if (!pi.name.begins_with("input/")) + continue; + + String name = pi.name.substr(pi.name.find("/")+1,pi.name.length()); + r_options->push_back("\""+name+"\""); + + } + } +#endif + +} + Input::Input() { singleton=this; diff --git a/core/os/input.h b/core/os/input.h index 1cb0f35d96..387a43a35a 100644 --- a/core/os/input.h +++ b/core/os/input.h @@ -76,6 +76,8 @@ public: virtual void action_press(const StringName& p_action)=0; virtual void action_release(const StringName& p_action)=0; + void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const; + Input(); }; diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp index a4201c34ea..e2a992ecb9 100644 --- a/core/os/keyboard.cpp +++ b/core/os/keyboard.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "keyboard.h" - +#include "os/os.h" struct _KeyCodeText { int code; @@ -353,3 +353,106 @@ int find_keycode(const String& p_code) { return 0; } + + + + +struct _KeyCodeReplace { + int from; + int to; +}; + +static const _KeyCodeReplace _keycode_replace_qwertz[]={ +{KEY_Y,KEY_Z}, +{KEY_Z,KEY_Y}, +{0,0} +}; + +static const _KeyCodeReplace _keycode_replace_azerty[]={ +{KEY_W,KEY_Z}, +{KEY_Z,KEY_W}, +{KEY_A,KEY_Q}, +{KEY_Q,KEY_A}, +{KEY_SEMICOLON,KEY_M}, +{KEY_M,KEY_SEMICOLON}, +{0,0} +}; + +static const _KeyCodeReplace _keycode_replace_qzerty[]={ +{KEY_W,KEY_Z}, +{KEY_Z,KEY_W}, +{KEY_SEMICOLON,KEY_M}, +{KEY_M,KEY_SEMICOLON}, +{0,0} +}; + +static const _KeyCodeReplace _keycode_replace_dvorak[]={ +{KEY_UNDERSCORE,KEY_BRACELEFT}, +{KEY_EQUAL,KEY_BRACERIGHT}, +{KEY_Q,KEY_APOSTROPHE}, +{KEY_W,KEY_COMMA}, +{KEY_E,KEY_PERIOD}, +{KEY_R,KEY_P}, +{KEY_T,KEY_Y}, +{KEY_Y,KEY_F}, +{KEY_U,KEY_G}, +{KEY_I,KEY_C}, +{KEY_O,KEY_R}, +{KEY_P,KEY_L}, +{KEY_BRACELEFT,KEY_SLASH}, +{KEY_BRACERIGHT,KEY_EQUAL}, +{KEY_A,KEY_A}, +{KEY_S,KEY_O}, +{KEY_D,KEY_E}, +{KEY_F,KEY_U}, +{KEY_G,KEY_I}, +{KEY_H,KEY_D}, +{KEY_J,KEY_H}, +{KEY_K,KEY_T}, +{KEY_L,KEY_N}, +{KEY_SEMICOLON,KEY_S}, +{KEY_APOSTROPHE,KEY_UNDERSCORE}, +{KEY_Z,KEY_SEMICOLON}, +{KEY_X,KEY_Q}, +{KEY_C,KEY_J}, +{KEY_V,KEY_K}, +{KEY_B,KEY_X}, +{KEY_N,KEY_B}, +{KEY_M,KEY_M}, +{KEY_COMMA,KEY_W}, +{KEY_PERIOD,KEY_V}, +{KEY_SLASH,KEY_Z}, +{0,0} +}; + +static const _KeyCodeReplace _keycode_replace_neo[]={ +{0,0} +}; + + +int latin_keyboard_keycode_convert(int p_keycode) { + + const _KeyCodeReplace *kcr=NULL; + switch(OS::get_singleton()->get_latin_keyboard_variant()) { + + case OS::LATIN_KEYBOARD_QWERTY: return p_keycode; break; + case OS::LATIN_KEYBOARD_QWERTZ: kcr=_keycode_replace_qwertz; break; + case OS::LATIN_KEYBOARD_AZERTY: kcr=_keycode_replace_azerty; break; + case OS::LATIN_KEYBOARD_QZERTY: kcr=_keycode_replace_qzerty; break; + case OS::LATIN_KEYBOARD_DVORAK: kcr=_keycode_replace_dvorak; break; + case OS::LATIN_KEYBOARD_NEO: kcr=_keycode_replace_neo; break; + default: return p_keycode; + } + + if (!kcr) { + return p_keycode; + } + + while(kcr->from) { + if (kcr->from==p_keycode) + return kcr->to; + kcr++; + } + + return p_keycode; +} diff --git a/core/os/keyboard.h b/core/os/keyboard.h index 18b56b5830..b4ec5da26f 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -328,5 +328,6 @@ enum KeyModifierMask { String keycode_get_string(uint32_t p_code); bool keycode_has_unicode(uint32_t p_unicode); int find_keycode(const String& p_code); +int latin_keyboard_keycode_convert(int p_keycode); #endif diff --git a/core/os/os.cpp b/core/os/os.cpp index 081f7c1c5e..5e0e5eed77 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -485,6 +485,11 @@ void OS::set_time_scale(float p_scale) { _time_scale=p_scale; } +OS::LatinKeyboardVariant OS::get_latin_keyboard_variant() const { + + return LATIN_KEYBOARD_QWERTY; +} + float OS::get_time_scale() const { return _time_scale; diff --git a/core/os/os.h b/core/os/os.h index 805d6ac57d..d4deff2f5e 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -34,6 +34,7 @@ #include "vector.h" #include "os/main_loop.h" #include <stdarg.h> + /** @author Juan Linietsky <reduzio@gmail.com> */ @@ -348,6 +349,18 @@ public: virtual Error dialog_input_text(String p_title, String p_description, String p_partial, Object* p_obj, String p_callback); + enum LatinKeyboardVariant { + LATIN_KEYBOARD_QWERTY, + LATIN_KEYBOARD_QWERTZ, + LATIN_KEYBOARD_AZERTY, + LATIN_KEYBOARD_QZERTY, + LATIN_KEYBOARD_DVORAK, + LATIN_KEYBOARD_NEO, + }; + + + virtual LatinKeyboardVariant get_latin_keyboard_variant() const; + void set_time_scale(float p_scale); float get_time_scale() const; |