diff --git a/.travis.yml b/.travis.yml index eeeedef063..8b58e12563 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ matrix: - name: Linux editor (debug, GCC 9, with Mono) stage: build - env: PLATFORM=x11 TOOLS=yes TARGET=debug CACHE_NAME=${PLATFORM}-tools-mono-gcc-9 MATRIX_EVAL="CC=gcc-9 && CXX=g++-9" EXTRA_ARGS="module_mono_enabled=yes mono_glue=no warnings=extra werror=yes" + env: PLATFORM=linuxbsd TOOLS=yes TARGET=debug CACHE_NAME=${PLATFORM}-tools-mono-gcc-9 MATRIX_EVAL="CC=gcc-9 && CXX=g++-9" EXTRA_ARGS="module_mono_enabled=yes mono_glue=no warnings=extra werror=yes" os: linux compiler: gcc-9 addons: @@ -47,7 +47,7 @@ matrix: - name: Linux export template (release, Clang 7) stage: build - env: PLATFORM=x11 TOOLS=no TARGET=release CACHE_NAME=${PLATFORM}-clang EXTRA_ARGS="warnings=extra werror=yes" + env: PLATFORM=linuxbsd TOOLS=no TARGET=release CACHE_NAME=${PLATFORM}-clang EXTRA_ARGS="warnings=extra werror=yes" os: linux compiler: clang addons: @@ -67,17 +67,17 @@ matrix: # packages: # - openjdk-8-jdk -# - name: macOS editor (debug, Clang) -# stage: build -# env: PLATFORM=osx TOOLS=yes TARGET=debug CACHE_NAME=${PLATFORM}-tools-clang EXTRA_ARGS="warnings=extra werror=yes" -# os: osx -# osx_image: xcode11.3 -# compiler: clang -# addons: -# homebrew: -# packages: -# - scons -# update: true + - name: macOS editor (debug, Clang) + stage: build + env: PLATFORM=osx TOOLS=yes TARGET=debug CACHE_NAME=${PLATFORM}-tools-clang EXTRA_ARGS="warnings=extra werror=yes" + os: osx + osx_image: xcode11.3 + compiler: clang + addons: + homebrew: + packages: + - scons + update: true # TODO: iOS MoltenVK support @@ -109,7 +109,7 @@ matrix: - name: Linux export template (release_debug, GCC 7, without 3D support) stage: build - env: PLATFORM=x11 TOOLS=no TARGET=release_debug CACHE_NAME=${PLATFORM}-gcc-7 EXTRA_ARGS="disable_3d=yes" + env: PLATFORM=linuxbsd TOOLS=no TARGET=release_debug CACHE_NAME=${PLATFORM}-gcc-7 EXTRA_ARGS="disable_3d=yes" os: linux compiler: gcc addons: @@ -117,15 +117,15 @@ matrix: packages: - *linux_deps - - name: Javascript export template (release, emscripten latest) - stage: build - env: PLATFORM=javascript TOOLS=no TARGET=release CACHE_NAME=${PLATFORM}-emcc-latest EXTRA_ARGS="use_closure_compiler=yes" - os: linux - compiler: clang - addons: - apt: - packages: - - *linux_deps +# - name: Javascript export template (release, emscripten latest) +# stage: build +# env: PLATFORM=javascript TOOLS=no TARGET=release CACHE_NAME=${PLATFORM}-emcc-latest EXTRA_ARGS="use_closure_compiler=yes" +# os: linux +# compiler: clang +# addons: +# apt: +# packages: +# - *linux_deps before_install: - eval "${MATRIX_EVAL}" @@ -165,7 +165,7 @@ script: scons -j2 CC=$CC CXX=$CXX platform=$PLATFORM tools=$TOOLS target=$TARGET $OPTIONS $EXTRA_ARGS && if [ "$TEST_PROJECT" = "yes" ]; then git clone --depth 1 "https://github.com/godotengine/godot-tests.git"; - sed -i "s:custom_template/release=\"\":custom_template/release=\"$(readlink -e bin/godot_server.x11.opt.tools.64)\":" godot-tests/tests/project_export/export_presets.cfg; - godot-tests/tests/project_export/test_project.sh "bin/godot_server.x11.opt.tools.64"; + sed -i "s:custom_template/release=\"\":custom_template/release=\"$(readlink -e bin/godot_server.linuxbsd.opt.tools.64)\":" godot-tests/tests/project_export/export_presets.cfg; + godot-tests/tests/project_export/test_project.sh "bin/godot_server.linuxbsd.opt.tools.64"; fi fi diff --git a/SConstruct b/SConstruct index 84400e800d..ed4b3c6242 100644 --- a/SConstruct +++ b/SConstruct @@ -236,7 +236,7 @@ elif env_base['p'] != "": else: # Missing `platform` argument, try to detect platform automatically if sys.platform.startswith('linux'): - selected_platform = 'x11' + selected_platform = 'linuxbsd' elif sys.platform == 'darwin': selected_platform = 'osx' elif sys.platform == 'win32': diff --git a/core/SCsub b/core/SCsub index b4974196bd..ca003ce931 100644 --- a/core/SCsub +++ b/core/SCsub @@ -166,6 +166,7 @@ SConscript('math/SCsub') SConscript('crypto/SCsub') SConscript('io/SCsub') SConscript('debugger/SCsub') +SConscript('input/SCsub') SConscript('bind/SCsub') diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 62d83b2e04..0236523200 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -194,82 +194,6 @@ _ResourceSaver::_ResourceSaver() { singleton = this; } -/////////////////OS - -void _OS::global_menu_add_item(const String &p_menu, const String &p_label, const Variant &p_signal, const Variant &p_meta) { - - OS::get_singleton()->global_menu_add_item(p_menu, p_label, p_signal, p_meta); -} - -void _OS::global_menu_add_separator(const String &p_menu) { - - OS::get_singleton()->global_menu_add_separator(p_menu); -} - -void _OS::global_menu_remove_item(const String &p_menu, int p_idx) { - - OS::get_singleton()->global_menu_remove_item(p_menu, p_idx); -} - -void _OS::global_menu_clear(const String &p_menu) { - - OS::get_singleton()->global_menu_clear(p_menu); -} - -Point2 _OS::get_mouse_position() const { - - return OS::get_singleton()->get_mouse_position(); -} - -void _OS::set_window_title(const String &p_title) { - - OS::get_singleton()->set_window_title(p_title); -} - -int _OS::get_mouse_button_state() const { - - return OS::get_singleton()->get_mouse_button_state(); -} - -String _OS::get_unique_id() const { - return OS::get_singleton()->get_unique_id(); -} - -bool _OS::has_touchscreen_ui_hint() const { - - return OS::get_singleton()->has_touchscreen_ui_hint(); -} - -void _OS::set_clipboard(const String &p_text) { - - OS::get_singleton()->set_clipboard(p_text); -} - -String _OS::get_clipboard() const { - - return OS::get_singleton()->get_clipboard(); -} - -int _OS::get_video_driver_count() const { - return OS::get_singleton()->get_video_driver_count(); -} - -String _OS::get_video_driver_name(VideoDriver p_driver) const { - return OS::get_singleton()->get_video_driver_name((int)p_driver); -} - -_OS::VideoDriver _OS::get_current_video_driver() const { - return (VideoDriver)OS::get_singleton()->get_current_video_driver(); -} - -int _OS::get_audio_driver_count() const { - return OS::get_singleton()->get_audio_driver_count(); -} - -String _OS::get_audio_driver_name(int p_driver) const { - return OS::get_singleton()->get_audio_driver_name(p_driver); -} - PackedStringArray _OS::get_connected_midi_inputs() { return OS::get_singleton()->get_connected_midi_inputs(); } @@ -282,198 +206,11 @@ void _OS::close_midi_inputs() { OS::get_singleton()->close_midi_inputs(); } -void _OS::set_video_mode(const Size2 &p_size, bool p_fullscreen, bool p_resizeable, int p_screen) { - - OS::VideoMode vm; - vm.width = p_size.width; - vm.height = p_size.height; - vm.fullscreen = p_fullscreen; - vm.resizable = p_resizeable; - OS::get_singleton()->set_video_mode(vm, p_screen); -} - -Size2 _OS::get_video_mode(int p_screen) const { - - OS::VideoMode vm; - vm = OS::get_singleton()->get_video_mode(p_screen); - return Size2(vm.width, vm.height); -} - -bool _OS::is_video_mode_fullscreen(int p_screen) const { - - OS::VideoMode vm; - vm = OS::get_singleton()->get_video_mode(p_screen); - return vm.fullscreen; -} - -int _OS::get_screen_count() const { - return OS::get_singleton()->get_screen_count(); -} - -int _OS::get_current_screen() const { - return OS::get_singleton()->get_current_screen(); -} - -void _OS::set_current_screen(int p_screen) { - OS::get_singleton()->set_current_screen(p_screen); -} - -Point2 _OS::get_screen_position(int p_screen) const { - return OS::get_singleton()->get_screen_position(p_screen); -} - -Size2 _OS::get_screen_size(int p_screen) const { - return OS::get_singleton()->get_screen_size(p_screen); -} - -int _OS::get_screen_dpi(int p_screen) const { - - return OS::get_singleton()->get_screen_dpi(p_screen); -} - -Point2 _OS::get_window_position() const { - return OS::get_singleton()->get_window_position(); -} - -void _OS::set_window_position(const Point2 &p_position) { - OS::get_singleton()->set_window_position(p_position); -} - -Size2 _OS::get_max_window_size() const { - return OS::get_singleton()->get_max_window_size(); -} - -Size2 _OS::get_min_window_size() const { - return OS::get_singleton()->get_min_window_size(); -} - -Size2 _OS::get_window_size() const { - return OS::get_singleton()->get_window_size(); -} - -Size2 _OS::get_real_window_size() const { - return OS::get_singleton()->get_real_window_size(); -} - -void _OS::set_max_window_size(const Size2 &p_size) { - OS::get_singleton()->set_max_window_size(p_size); -} - -void _OS::set_min_window_size(const Size2 &p_size) { - OS::get_singleton()->set_min_window_size(p_size); -} - -void _OS::set_window_size(const Size2 &p_size) { - OS::get_singleton()->set_window_size(p_size); -} - -Rect2 _OS::get_window_safe_area() const { - return OS::get_singleton()->get_window_safe_area(); -} - -void _OS::set_window_fullscreen(bool p_enabled) { - OS::get_singleton()->set_window_fullscreen(p_enabled); -} - -bool _OS::is_window_fullscreen() const { - return OS::get_singleton()->is_window_fullscreen(); -} - -void _OS::set_window_resizable(bool p_enabled) { - OS::get_singleton()->set_window_resizable(p_enabled); -} - -bool _OS::is_window_resizable() const { - return OS::get_singleton()->is_window_resizable(); -} - -void _OS::set_window_minimized(bool p_enabled) { - OS::get_singleton()->set_window_minimized(p_enabled); -} - -bool _OS::is_window_minimized() const { - return OS::get_singleton()->is_window_minimized(); -} - -void _OS::set_window_maximized(bool p_enabled) { - OS::get_singleton()->set_window_maximized(p_enabled); -} - -bool _OS::is_window_maximized() const { - return OS::get_singleton()->is_window_maximized(); -} - -void _OS::set_window_always_on_top(bool p_enabled) { - OS::get_singleton()->set_window_always_on_top(p_enabled); -} - -bool _OS::is_window_always_on_top() const { - return OS::get_singleton()->is_window_always_on_top(); -} - -bool _OS::is_window_focused() const { - return OS::get_singleton()->is_window_focused(); -} - -void _OS::set_borderless_window(bool p_borderless) { - OS::get_singleton()->set_borderless_window(p_borderless); -} - -bool _OS::get_window_per_pixel_transparency_enabled() const { - return OS::get_singleton()->get_window_per_pixel_transparency_enabled(); -} - -void _OS::set_window_per_pixel_transparency_enabled(bool p_enabled) { - OS::get_singleton()->set_window_per_pixel_transparency_enabled(p_enabled); -} - -bool _OS::get_borderless_window() const { - return OS::get_singleton()->get_borderless_window(); -} - -void _OS::set_ime_active(const bool p_active) { - - OS::get_singleton()->set_ime_active(p_active); -} - -void _OS::set_ime_position(const Point2 &p_pos) { - - OS::get_singleton()->set_ime_position(p_pos); -} - -Point2 _OS::get_ime_selection() const { - return OS::get_singleton()->get_ime_selection(); -} - -String _OS::get_ime_text() const { - return OS::get_singleton()->get_ime_text(); -} - void _OS::set_use_file_access_save_and_swap(bool p_enable) { FileAccess::set_backup_save(p_enable); } -bool _OS::is_video_mode_resizable(int p_screen) const { - - OS::VideoMode vm; - vm = OS::get_singleton()->get_video_mode(p_screen); - return vm.resizable; -} - -Array _OS::get_fullscreen_mode_list(int p_screen) const { - - List vmlist; - OS::get_singleton()->get_fullscreen_mode_list(&vmlist, p_screen); - Array vmarr; - for (List::Element *E = vmlist.front(); E; E = E->next()) { - - vmarr.push_back(Size2(E->get().width, E->get().height)); - } - - return vmarr; -} - void _OS::set_low_processor_usage_mode(bool p_enabled) { OS::get_singleton()->set_low_processor_usage_mode(p_enabled); @@ -562,52 +299,16 @@ String _OS::get_locale() const { return OS::get_singleton()->get_locale(); } -String _OS::get_latin_keyboard_variant() const { - switch (OS::get_singleton()->get_latin_keyboard_variant()) { - case OS::LATIN_KEYBOARD_QWERTY: return "QWERTY"; - case OS::LATIN_KEYBOARD_QWERTZ: return "QWERTZ"; - case OS::LATIN_KEYBOARD_AZERTY: return "AZERTY"; - case OS::LATIN_KEYBOARD_QZERTY: return "QZERTY"; - case OS::LATIN_KEYBOARD_DVORAK: return "DVORAK"; - case OS::LATIN_KEYBOARD_NEO: return "NEO"; - case OS::LATIN_KEYBOARD_COLEMAK: return "COLEMAK"; - default: return "ERROR"; - } -} - String _OS::get_model_name() const { return OS::get_singleton()->get_model_name(); } -bool _OS::is_ok_left_and_cancel_right() const { - - return OS::get_singleton()->get_swap_ok_cancel(); -} - Error _OS::set_thread_name(const String &p_name) { return Thread::set_name(p_name); }; -void _OS::set_use_vsync(bool p_enable) { - OS::get_singleton()->set_use_vsync(p_enable); -} - -bool _OS::is_vsync_enabled() const { - - return OS::get_singleton()->is_vsync_enabled(); -} - -void _OS::set_vsync_via_compositor(bool p_enable) { - OS::get_singleton()->set_vsync_via_compositor(p_enable); -} - -bool _OS::is_vsync_via_compositor_enabled() const { - - return OS::get_singleton()->is_vsync_via_compositor_enabled(); -} - bool _OS::has_feature(const String &p_feature) const { return OS::get_singleton()->has_feature(p_feature); @@ -667,16 +368,6 @@ uint64_t _OS::get_static_memory_peak_usage() const { return OS::get_singleton()->get_static_memory_peak_usage(); } -void _OS::set_native_icon(const String &p_filename) { - - OS::get_singleton()->set_native_icon(p_filename); -} - -void _OS::set_icon(const Ref &p_icon) { - - OS::get_singleton()->set_icon(p_icon); -} - int _OS::get_exit_code() const { return OS::get_singleton()->get_exit_code(); @@ -924,11 +615,6 @@ bool _OS::can_use_threads() const { return OS::get_singleton()->can_use_threads(); } -bool _OS::can_draw() const { - - return OS::get_singleton()->can_draw(); -} - bool _OS::is_userfs_persistent() const { return OS::get_singleton()->is_userfs_persistent(); @@ -1025,22 +711,6 @@ void _OS::print_resources_by_type(const Vector &p_types) { } }; -bool _OS::has_virtual_keyboard() const { - return OS::get_singleton()->has_virtual_keyboard(); -} - -void _OS::show_virtual_keyboard(const String &p_existing_text) { - OS::get_singleton()->show_virtual_keyboard(p_existing_text, Rect2()); -} - -void _OS::hide_virtual_keyboard() { - OS::get_singleton()->hide_virtual_keyboard(); -} - -int _OS::get_virtual_keyboard_height() { - return OS::get_singleton()->get_virtual_keyboard_height(); -} - void _OS::print_all_resources(const String &p_to_file) { OS::get_singleton()->print_all_resources(p_to_file); @@ -1061,45 +731,6 @@ String _OS::get_user_data_dir() const { return OS::get_singleton()->get_user_data_dir(); }; -Error _OS::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) { - - return OS::get_singleton()->native_video_play(p_path, p_volume, p_audio_track, p_subtitle_track); -}; - -bool _OS::native_video_is_playing() { - - return OS::get_singleton()->native_video_is_playing(); -}; - -void _OS::native_video_pause() { - - OS::get_singleton()->native_video_pause(); -}; - -void _OS::native_video_unpause() { - OS::get_singleton()->native_video_unpause(); -}; - -void _OS::native_video_stop() { - - OS::get_singleton()->native_video_stop(); -}; - -void _OS::request_attention() { - - OS::get_singleton()->request_attention(); -} - -void _OS::center_window() { - - OS::get_singleton()->center_window(); -} - -void _OS::move_window_to_foreground() { - - OS::get_singleton()->move_window_to_foreground(); -} - bool _OS::is_debug_build() const { #ifdef DEBUG_ENABLED @@ -1109,26 +740,6 @@ bool _OS::is_debug_build() const { #endif } -void _OS::set_screen_orientation(ScreenOrientation p_orientation) { - - OS::get_singleton()->set_screen_orientation(OS::ScreenOrientation(p_orientation)); -} - -_OS::ScreenOrientation _OS::get_screen_orientation() const { - - return ScreenOrientation(OS::get_singleton()->get_screen_orientation()); -} - -void _OS::set_keep_screen_on(bool p_enabled) { - - OS::get_singleton()->set_keep_screen_on(p_enabled); -} - -bool _OS::is_keep_screen_on() const { - - return OS::get_singleton()->is_keep_screen_on(); -} - String _OS::get_system_dir(SystemDir p_dir) const { return OS::get_singleton()->get_system_dir(OS::SystemDir(p_dir)); @@ -1149,11 +760,6 @@ int _OS::find_keycode_from_string(const String &p_code) const { return find_keycode(p_code); } -void _OS::alert(const String &p_alert, const String &p_title) { - - OS::get_singleton()->alert(p_alert, p_title); -} - bool _OS::request_permission(const String &p_name) { return OS::get_singleton()->request_permission(p_name); @@ -1169,90 +775,17 @@ Vector _OS::get_granted_permissions() const { return OS::get_singleton()->get_granted_permissions(); } +String _OS::get_unique_id() const { + return OS::get_singleton()->get_unique_id(); +} _OS *_OS::singleton = NULL; void _OS::_bind_methods() { - //ClassDB::bind_method(D_METHOD("get_mouse_position"),&_OS::get_mouse_position); - //ClassDB::bind_method(D_METHOD("is_mouse_grab_enabled"),&_OS::is_mouse_grab_enabled); - - ClassDB::bind_method(D_METHOD("set_clipboard", "clipboard"), &_OS::set_clipboard); - ClassDB::bind_method(D_METHOD("get_clipboard"), &_OS::get_clipboard); - - //will not delete for now, just unexpose - //ClassDB::bind_method(D_METHOD("set_video_mode","size","fullscreen","resizable","screen"),&_OS::set_video_mode,DEFVAL(0)); - //ClassDB::bind_method(D_METHOD("get_video_mode_size","screen"),&_OS::get_video_mode,DEFVAL(0)); - //ClassDB::bind_method(D_METHOD("is_video_mode_fullscreen","screen"),&_OS::is_video_mode_fullscreen,DEFVAL(0)); - //ClassDB::bind_method(D_METHOD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0)); - //ClassDB::bind_method(D_METHOD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); - - ClassDB::bind_method(D_METHOD("global_menu_add_item", "menu", "label", "id", "meta"), &_OS::global_menu_add_item); - ClassDB::bind_method(D_METHOD("global_menu_add_separator", "menu"), &_OS::global_menu_add_separator); - ClassDB::bind_method(D_METHOD("global_menu_remove_item", "menu", "idx"), &_OS::global_menu_remove_item); - ClassDB::bind_method(D_METHOD("global_menu_clear", "menu"), &_OS::global_menu_clear); - - ClassDB::bind_method(D_METHOD("get_video_driver_count"), &_OS::get_video_driver_count); - ClassDB::bind_method(D_METHOD("get_video_driver_name", "driver"), &_OS::get_video_driver_name); - ClassDB::bind_method(D_METHOD("get_current_video_driver"), &_OS::get_current_video_driver); - - ClassDB::bind_method(D_METHOD("get_audio_driver_count"), &_OS::get_audio_driver_count); - ClassDB::bind_method(D_METHOD("get_audio_driver_name", "driver"), &_OS::get_audio_driver_name); ClassDB::bind_method(D_METHOD("get_connected_midi_inputs"), &_OS::get_connected_midi_inputs); ClassDB::bind_method(D_METHOD("open_midi_inputs"), &_OS::open_midi_inputs); ClassDB::bind_method(D_METHOD("close_midi_inputs"), &_OS::close_midi_inputs); - ClassDB::bind_method(D_METHOD("get_screen_count"), &_OS::get_screen_count); - ClassDB::bind_method(D_METHOD("get_current_screen"), &_OS::get_current_screen); - ClassDB::bind_method(D_METHOD("set_current_screen", "screen"), &_OS::set_current_screen); - ClassDB::bind_method(D_METHOD("get_screen_position", "screen"), &_OS::get_screen_position, DEFVAL(-1)); - ClassDB::bind_method(D_METHOD("get_screen_size", "screen"), &_OS::get_screen_size, DEFVAL(-1)); - ClassDB::bind_method(D_METHOD("get_screen_dpi", "screen"), &_OS::get_screen_dpi, DEFVAL(-1)); - ClassDB::bind_method(D_METHOD("get_window_position"), &_OS::get_window_position); - ClassDB::bind_method(D_METHOD("set_window_position", "position"), &_OS::set_window_position); - ClassDB::bind_method(D_METHOD("get_window_size"), &_OS::get_window_size); - ClassDB::bind_method(D_METHOD("get_max_window_size"), &_OS::get_max_window_size); - ClassDB::bind_method(D_METHOD("get_min_window_size"), &_OS::get_min_window_size); - ClassDB::bind_method(D_METHOD("set_max_window_size", "size"), &_OS::set_max_window_size); - ClassDB::bind_method(D_METHOD("set_min_window_size", "size"), &_OS::set_min_window_size); - ClassDB::bind_method(D_METHOD("set_window_size", "size"), &_OS::set_window_size); - ClassDB::bind_method(D_METHOD("get_window_safe_area"), &_OS::get_window_safe_area); - ClassDB::bind_method(D_METHOD("set_window_fullscreen", "enabled"), &_OS::set_window_fullscreen); - ClassDB::bind_method(D_METHOD("is_window_fullscreen"), &_OS::is_window_fullscreen); - ClassDB::bind_method(D_METHOD("set_window_resizable", "enabled"), &_OS::set_window_resizable); - ClassDB::bind_method(D_METHOD("is_window_resizable"), &_OS::is_window_resizable); - ClassDB::bind_method(D_METHOD("set_window_minimized", "enabled"), &_OS::set_window_minimized); - ClassDB::bind_method(D_METHOD("is_window_minimized"), &_OS::is_window_minimized); - ClassDB::bind_method(D_METHOD("set_window_maximized", "enabled"), &_OS::set_window_maximized); - ClassDB::bind_method(D_METHOD("is_window_maximized"), &_OS::is_window_maximized); - ClassDB::bind_method(D_METHOD("set_window_always_on_top", "enabled"), &_OS::set_window_always_on_top); - ClassDB::bind_method(D_METHOD("is_window_always_on_top"), &_OS::is_window_always_on_top); - ClassDB::bind_method(D_METHOD("is_window_focused"), &_OS::is_window_focused); - ClassDB::bind_method(D_METHOD("request_attention"), &_OS::request_attention); - ClassDB::bind_method(D_METHOD("get_real_window_size"), &_OS::get_real_window_size); - ClassDB::bind_method(D_METHOD("center_window"), &_OS::center_window); - ClassDB::bind_method(D_METHOD("move_window_to_foreground"), &_OS::move_window_to_foreground); - - ClassDB::bind_method(D_METHOD("set_borderless_window", "borderless"), &_OS::set_borderless_window); - ClassDB::bind_method(D_METHOD("get_borderless_window"), &_OS::get_borderless_window); - - ClassDB::bind_method(D_METHOD("get_window_per_pixel_transparency_enabled"), &_OS::get_window_per_pixel_transparency_enabled); - ClassDB::bind_method(D_METHOD("set_window_per_pixel_transparency_enabled", "enabled"), &_OS::set_window_per_pixel_transparency_enabled); - - ClassDB::bind_method(D_METHOD("set_ime_active", "active"), &_OS::set_ime_active); - ClassDB::bind_method(D_METHOD("set_ime_position", "position"), &_OS::set_ime_position); - ClassDB::bind_method(D_METHOD("get_ime_selection"), &_OS::get_ime_selection); - ClassDB::bind_method(D_METHOD("get_ime_text"), &_OS::get_ime_text); - - ClassDB::bind_method(D_METHOD("set_screen_orientation", "orientation"), &_OS::set_screen_orientation); - ClassDB::bind_method(D_METHOD("get_screen_orientation"), &_OS::get_screen_orientation); - - ClassDB::bind_method(D_METHOD("set_keep_screen_on", "enabled"), &_OS::set_keep_screen_on); - ClassDB::bind_method(D_METHOD("is_keep_screen_on"), &_OS::is_keep_screen_on); - - ClassDB::bind_method(D_METHOD("has_touchscreen_ui_hint"), &_OS::has_touchscreen_ui_hint); - - ClassDB::bind_method(D_METHOD("set_window_title", "title"), &_OS::set_window_title); - ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode", "enable"), &_OS::set_low_processor_usage_mode); ClassDB::bind_method(D_METHOD("is_in_low_processor_usage_mode"), &_OS::is_in_low_processor_usage_mode); @@ -1283,9 +816,6 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_system_time_secs"), &_OS::get_system_time_secs); ClassDB::bind_method(D_METHOD("get_system_time_msecs"), &_OS::get_system_time_msecs); - ClassDB::bind_method(D_METHOD("set_native_icon", "filename"), &_OS::set_native_icon); - ClassDB::bind_method(D_METHOD("set_icon", "icon"), &_OS::set_icon); - ClassDB::bind_method(D_METHOD("get_exit_code"), &_OS::get_exit_code); ClassDB::bind_method(D_METHOD("set_exit_code", "code"), &_OS::set_exit_code); @@ -1295,10 +825,8 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_ticks_usec"), &_OS::get_ticks_usec); ClassDB::bind_method(D_METHOD("get_splash_tick_msec"), &_OS::get_splash_tick_msec); ClassDB::bind_method(D_METHOD("get_locale"), &_OS::get_locale); - ClassDB::bind_method(D_METHOD("get_latin_keyboard_variant"), &_OS::get_latin_keyboard_variant); ClassDB::bind_method(D_METHOD("get_model_name"), &_OS::get_model_name); - ClassDB::bind_method(D_METHOD("can_draw"), &_OS::can_draw); ClassDB::bind_method(D_METHOD("is_userfs_persistent"), &_OS::is_userfs_persistent); ClassDB::bind_method(D_METHOD("is_stdout_verbose"), &_OS::is_stdout_verbose); @@ -1310,10 +838,6 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("dump_memory_to_file", "file"), &_OS::dump_memory_to_file); ClassDB::bind_method(D_METHOD("dump_resources_to_file", "file"), &_OS::dump_resources_to_file); - ClassDB::bind_method(D_METHOD("has_virtual_keyboard"), &_OS::has_virtual_keyboard); - ClassDB::bind_method(D_METHOD("show_virtual_keyboard", "existing_text"), &_OS::show_virtual_keyboard, DEFVAL("")); - ClassDB::bind_method(D_METHOD("hide_virtual_keyboard"), &_OS::hide_virtual_keyboard); - ClassDB::bind_method(D_METHOD("get_virtual_keyboard_height"), &_OS::get_virtual_keyboard_height); ClassDB::bind_method(D_METHOD("print_resources_in_use", "short"), &_OS::print_resources_in_use, DEFVAL(false)); ClassDB::bind_method(D_METHOD("print_all_resources", "tofile"), &_OS::print_all_resources, DEFVAL("")); @@ -1324,81 +848,32 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_system_dir", "dir"), &_OS::get_system_dir); ClassDB::bind_method(D_METHOD("get_unique_id"), &_OS::get_unique_id); - ClassDB::bind_method(D_METHOD("is_ok_left_and_cancel_right"), &_OS::is_ok_left_and_cancel_right); - ClassDB::bind_method(D_METHOD("print_all_textures_by_size"), &_OS::print_all_textures_by_size); ClassDB::bind_method(D_METHOD("print_resources_by_type", "types"), &_OS::print_resources_by_type); - ClassDB::bind_method(D_METHOD("native_video_play", "path", "volume", "audio_track", "subtitle_track"), &_OS::native_video_play); - ClassDB::bind_method(D_METHOD("native_video_is_playing"), &_OS::native_video_is_playing); - ClassDB::bind_method(D_METHOD("native_video_stop"), &_OS::native_video_stop); - ClassDB::bind_method(D_METHOD("native_video_pause"), &_OS::native_video_pause); - ClassDB::bind_method(D_METHOD("native_video_unpause"), &_OS::native_video_unpause); - ClassDB::bind_method(D_METHOD("get_keycode_string", "code"), &_OS::get_keycode_string); ClassDB::bind_method(D_METHOD("is_keycode_unicode", "code"), &_OS::is_keycode_unicode); ClassDB::bind_method(D_METHOD("find_keycode_from_string", "string"), &_OS::find_keycode_from_string); ClassDB::bind_method(D_METHOD("set_use_file_access_save_and_swap", "enabled"), &_OS::set_use_file_access_save_and_swap); - ClassDB::bind_method(D_METHOD("alert", "text", "title"), &_OS::alert, DEFVAL("Alert!")); - ClassDB::bind_method(D_METHOD("set_thread_name", "name"), &_OS::set_thread_name); - ClassDB::bind_method(D_METHOD("set_use_vsync", "enable"), &_OS::set_use_vsync); - ClassDB::bind_method(D_METHOD("is_vsync_enabled"), &_OS::is_vsync_enabled); - - ClassDB::bind_method(D_METHOD("set_vsync_via_compositor", "enable"), &_OS::set_vsync_via_compositor); - ClassDB::bind_method(D_METHOD("is_vsync_via_compositor_enabled"), &_OS::is_vsync_via_compositor_enabled); - ClassDB::bind_method(D_METHOD("has_feature", "tag_name"), &_OS::has_feature); ClassDB::bind_method(D_METHOD("request_permission", "name"), &_OS::request_permission); ClassDB::bind_method(D_METHOD("request_permissions"), &_OS::request_permissions); ClassDB::bind_method(D_METHOD("get_granted_permissions"), &_OS::get_granted_permissions); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "clipboard"), "set_clipboard", "get_clipboard"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "current_screen"), "set_current_screen", "get_current_screen"); ADD_PROPERTY(PropertyInfo(Variant::INT, "exit_code"), "set_exit_code", "get_exit_code"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vsync_enabled"), "set_use_vsync", "is_vsync_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vsync_via_compositor"), "set_vsync_via_compositor", "is_vsync_via_compositor_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "low_processor_usage_mode"), "set_low_processor_usage_mode", "is_in_low_processor_usage_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "low_processor_usage_mode_sleep_usec"), "set_low_processor_usage_mode_sleep_usec", "get_low_processor_usage_mode_sleep_usec"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_screen_on"), "set_keep_screen_on", "is_keep_screen_on"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "min_window_size"), "set_min_window_size", "get_min_window_size"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "max_window_size"), "set_max_window_size", "get_max_window_size"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor"), "set_screen_orientation", "get_screen_orientation"); - ADD_GROUP("Window", "window_"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_borderless"), "set_borderless_window", "get_borderless_window"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_per_pixel_transparency_enabled"), "set_window_per_pixel_transparency_enabled", "get_window_per_pixel_transparency_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_fullscreen"), "set_window_fullscreen", "is_window_fullscreen"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_maximized"), "set_window_maximized", "is_window_maximized"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_minimized"), "set_window_minimized", "is_window_minimized"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_resizable"), "set_window_resizable", "is_window_resizable"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "window_position"), "set_window_position", "get_window_position"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "window_size"), "set_window_size", "get_window_size"); // Those default values need to be specified for the docs generator, // to avoid using values from the documentation writer's own OS instance. - ADD_PROPERTY_DEFAULT("clipboard", ""); - ADD_PROPERTY_DEFAULT("current_screen", 0); ADD_PROPERTY_DEFAULT("exit_code", 0); - ADD_PROPERTY_DEFAULT("vsync_enabled", true); - ADD_PROPERTY_DEFAULT("vsync_via_compositor", false); ADD_PROPERTY_DEFAULT("low_processor_usage_mode", false); ADD_PROPERTY_DEFAULT("low_processor_usage_mode_sleep_usec", 6900); - ADD_PROPERTY_DEFAULT("keep_screen_on", true); - ADD_PROPERTY_DEFAULT("min_window_size", Vector2()); - ADD_PROPERTY_DEFAULT("max_window_size", Vector2()); - ADD_PROPERTY_DEFAULT("screen_orientation", 0); - ADD_PROPERTY_DEFAULT("window_borderless", false); - ADD_PROPERTY_DEFAULT("window_per_pixel_transparency_enabled", false); - ADD_PROPERTY_DEFAULT("window_fullscreen", false); - ADD_PROPERTY_DEFAULT("window_maximized", false); - ADD_PROPERTY_DEFAULT("window_minimized", false); - ADD_PROPERTY_DEFAULT("window_resizable", true); - ADD_PROPERTY_DEFAULT("window_position", Vector2()); - ADD_PROPERTY_DEFAULT("window_size", Vector2()); BIND_ENUM_CONSTANT(VIDEO_DRIVER_GLES2); BIND_ENUM_CONSTANT(VIDEO_DRIVER_VULKAN); @@ -1424,14 +899,6 @@ void _OS::_bind_methods() { BIND_ENUM_CONSTANT(MONTH_NOVEMBER); BIND_ENUM_CONSTANT(MONTH_DECEMBER); - BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_LANDSCAPE); - BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_PORTRAIT); - BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_REVERSE_LANDSCAPE); - BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_REVERSE_PORTRAIT); - BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_SENSOR_LANDSCAPE); - BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_SENSOR_PORTRAIT); - BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_SENSOR); - BIND_ENUM_CONSTANT(SYSTEM_DIR_DESKTOP); BIND_ENUM_CONSTANT(SYSTEM_DIR_DCIM); BIND_ENUM_CONSTANT(SYSTEM_DIR_DOCUMENTS); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 3a5bd28ce8..510d87844d 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -145,83 +145,10 @@ public: MONTH_DECEMBER }; - void global_menu_add_item(const String &p_menu, const String &p_label, const Variant &p_signal, const Variant &p_meta); - void global_menu_add_separator(const String &p_menu); - void global_menu_remove_item(const String &p_menu, int p_idx); - void global_menu_clear(const String &p_menu); - - Point2 get_mouse_position() const; - void set_window_title(const String &p_title); - int get_mouse_button_state() const; - - void set_clipboard(const String &p_text); - String get_clipboard() const; - - void set_video_mode(const Size2 &p_size, bool p_fullscreen, bool p_resizeable, int p_screen = 0); - Size2 get_video_mode(int p_screen = 0) const; - bool is_video_mode_fullscreen(int p_screen = 0) const; - bool is_video_mode_resizable(int p_screen = 0) const; - Array get_fullscreen_mode_list(int p_screen = 0) const; - - virtual int get_video_driver_count() const; - virtual String get_video_driver_name(VideoDriver p_driver) const; - virtual VideoDriver get_current_video_driver() const; - - virtual int get_audio_driver_count() const; - virtual String get_audio_driver_name(int p_driver) const; - virtual PackedStringArray get_connected_midi_inputs(); virtual void open_midi_inputs(); virtual void close_midi_inputs(); - virtual int get_screen_count() const; - virtual int get_current_screen() const; - virtual void set_current_screen(int p_screen); - virtual Point2 get_screen_position(int p_screen = -1) const; - virtual Size2 get_screen_size(int p_screen = -1) const; - virtual int get_screen_dpi(int p_screen = -1) const; - virtual Point2 get_window_position() const; - virtual void set_window_position(const Point2 &p_position); - virtual Size2 get_max_window_size() const; - virtual Size2 get_min_window_size() const; - virtual Size2 get_window_size() const; - virtual Size2 get_real_window_size() const; - virtual Rect2 get_window_safe_area() const; - virtual void set_max_window_size(const Size2 &p_size); - virtual void set_min_window_size(const Size2 &p_size); - virtual void set_window_size(const Size2 &p_size); - virtual void set_window_fullscreen(bool p_enabled); - virtual bool is_window_fullscreen() const; - virtual void set_window_resizable(bool p_enabled); - virtual bool is_window_resizable() const; - virtual void set_window_minimized(bool p_enabled); - virtual bool is_window_minimized() const; - virtual void set_window_maximized(bool p_enabled); - virtual bool is_window_maximized() const; - virtual void set_window_always_on_top(bool p_enabled); - virtual bool is_window_always_on_top() const; - virtual bool is_window_focused() const; - virtual void request_attention(); - virtual void center_window(); - virtual void move_window_to_foreground(); - - virtual void set_borderless_window(bool p_borderless); - virtual bool get_borderless_window() const; - - virtual bool get_window_per_pixel_transparency_enabled() const; - virtual void set_window_per_pixel_transparency_enabled(bool p_enabled); - - virtual void set_ime_active(const bool p_active); - virtual void set_ime_position(const Point2 &p_pos); - virtual Point2 get_ime_selection() const; - virtual String get_ime_text() const; - - Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); - bool native_video_is_playing(); - void native_video_pause(); - void native_video_unpause(); - void native_video_stop(); - void set_low_processor_usage_mode(bool p_enabled); bool is_in_low_processor_usage_mode() const; @@ -243,25 +170,17 @@ public: Vector get_cmdline_args(); String get_locale() const; - String get_latin_keyboard_variant() const; String get_model_name() const; void dump_memory_to_file(const String &p_file); void dump_resources_to_file(const String &p_file); - bool has_virtual_keyboard() const; - void show_virtual_keyboard(const String &p_existing_text = ""); - void hide_virtual_keyboard(); - int get_virtual_keyboard_height(); - void print_resources_in_use(bool p_short = false); void print_all_resources(const String &p_to_file); void print_all_textures_by_size(); void print_resources_by_type(const Vector &p_types); - bool has_touchscreen_ui_hint() const; - bool is_debug_build() const; String get_unique_id() const; @@ -272,9 +191,6 @@ public: void set_use_file_access_save_and_swap(bool p_enable); - void set_native_icon(const String &p_filename); - void set_icon(const Ref &p_icon); - int get_exit_code() const; void set_exit_code(int p_code); Dictionary get_date(bool utc) const; @@ -298,8 +214,6 @@ public: bool can_use_threads() const; - bool can_draw() const; - bool is_userfs_persistent() const; bool is_stdout_verbose() const; @@ -317,39 +231,12 @@ public: SYSTEM_DIR_RINGTONES, }; - enum ScreenOrientation { - - SCREEN_ORIENTATION_LANDSCAPE, - SCREEN_ORIENTATION_PORTRAIT, - SCREEN_ORIENTATION_REVERSE_LANDSCAPE, - SCREEN_ORIENTATION_REVERSE_PORTRAIT, - SCREEN_ORIENTATION_SENSOR_LANDSCAPE, - SCREEN_ORIENTATION_SENSOR_PORTRAIT, - SCREEN_ORIENTATION_SENSOR, - }; - String get_system_dir(SystemDir p_dir) const; String get_user_data_dir() const; - void alert(const String &p_alert, const String &p_title = "ALERT!"); - - void set_screen_orientation(ScreenOrientation p_orientation); - ScreenOrientation get_screen_orientation() const; - - void set_keep_screen_on(bool p_enabled); - bool is_keep_screen_on() const; - - bool is_ok_left_and_cancel_right() const; - Error set_thread_name(const String &p_name); - void set_use_vsync(bool p_enable); - bool is_vsync_enabled() const; - - void set_vsync_via_compositor(bool p_enable); - bool is_vsync_via_compositor_enabled() const; - bool has_feature(const String &p_feature) const; bool request_permission(const String &p_name); @@ -365,7 +252,6 @@ VARIANT_ENUM_CAST(_OS::VideoDriver); VARIANT_ENUM_CAST(_OS::Weekday); VARIANT_ENUM_CAST(_OS::Month); VARIANT_ENUM_CAST(_OS::SystemDir); -VARIANT_ENUM_CAST(_OS::ScreenOrientation); class _Geometry : public Object { diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index 5f7ffb115c..b9db8ab1b0 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -33,11 +33,12 @@ #include "core/debugger/debugger_marshalls.h" #include "core/debugger/engine_debugger.h" #include "core/debugger/script_debugger.h" -#include "core/os/input.h" +#include "core/input/input_filter.h" #include "core/os/os.h" #include "core/project_settings.h" #include "core/script_language.h" #include "scene/main/node.h" +#include "servers/display_server.h" template void RemoteDebugger::_bind_profiler(const String &p_name, T *p_prof) { @@ -658,9 +659,9 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { servers_profiler->skip_profile_frame = true; // Avoid frame time spike in debug. - Input::MouseMode mouse_mode = Input::get_singleton()->get_mouse_mode(); - if (mouse_mode != Input::MOUSE_MODE_VISIBLE) - Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); + InputFilter::MouseMode mouse_mode = InputFilter::get_singleton()->get_mouse_mode(); + if (mouse_mode != InputFilter::MOUSE_MODE_VISIBLE) + InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE); uint64_t loop_begin_usec = 0; uint64_t loop_time_sec = 0; @@ -694,7 +695,7 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { } else if (command == "continue") { script_debugger->set_depth(-1); script_debugger->set_lines_left(-1); - OS::get_singleton()->move_window_to_foreground(); + DisplayServer::get_singleton()->window_move_to_foreground(); break; } else if (command == "break") { @@ -778,8 +779,8 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { send_message("debug_exit", Array()); - if (mouse_mode != Input::MOUSE_MODE_VISIBLE) - Input::get_singleton()->set_mouse_mode(mouse_mode); + if (mouse_mode != InputFilter::MOUSE_MODE_VISIBLE) + InputFilter::get_singleton()->set_mouse_mode(mouse_mode); } void RemoteDebugger::poll_events(bool p_is_idle) { diff --git a/core/global_constants.cpp b/core/global_constants.cpp index 0945240c1f..8706a38453 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -30,8 +30,8 @@ #include "global_constants.h" +#include "core/input/input_event.h" #include "core/object.h" -#include "core/os/input_event.h" #include "core/os/keyboard.h" #include "core/variant.h" diff --git a/core/input/SCsub b/core/input/SCsub new file mode 100644 index 0000000000..f1660932e5 --- /dev/null +++ b/core/input/SCsub @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +Import('env') + +from platform_methods import run_in_subprocess +import input_builders + + +# Order matters here. Higher index controller database files write on top of lower index database files. +controller_databases = ["#core/input/gamecontrollerdb_204.txt", "#core/input/gamecontrollerdb_205.txt", "#core/input/gamecontrollerdb.txt", "#core/input/godotcontrollerdb.txt"] + +env.Depends("#core/input/default_controller_mappings.gen.cpp", controller_databases) +env.CommandNoCache("#core/input/default_controller_mappings.gen.cpp", controller_databases, run_in_subprocess(input_builders.make_default_controller_mappings)) + +env.add_source_files(env.core_sources, "*.cpp") + +# Don't warn about duplicate entry here, we need it registered manually for first build, +# even if later builds will pick it up twice due to above *.cpp globbing. +env.add_source_files(env.core_sources, "#core/input/default_controller_mappings.gen.cpp", warn_duplicates=False) + diff --git a/main/default_controller_mappings.h b/core/input/default_controller_mappings.h similarity index 100% rename from main/default_controller_mappings.h rename to core/input/default_controller_mappings.h diff --git a/main/gamecontrollerdb.txt b/core/input/gamecontrollerdb.txt similarity index 100% rename from main/gamecontrollerdb.txt rename to core/input/gamecontrollerdb.txt diff --git a/main/gamecontrollerdb_204.txt b/core/input/gamecontrollerdb_204.txt similarity index 100% rename from main/gamecontrollerdb_204.txt rename to core/input/gamecontrollerdb_204.txt diff --git a/main/gamecontrollerdb_205.txt b/core/input/gamecontrollerdb_205.txt similarity index 100% rename from main/gamecontrollerdb_205.txt rename to core/input/gamecontrollerdb_205.txt diff --git a/main/godotcontrollerdb.txt b/core/input/godotcontrollerdb.txt similarity index 100% rename from main/godotcontrollerdb.txt rename to core/input/godotcontrollerdb.txt diff --git a/core/input/input_builders.py b/core/input/input_builders.py new file mode 100644 index 0000000000..ca142c0c80 --- /dev/null +++ b/core/input/input_builders.py @@ -0,0 +1,73 @@ +"""Functions used to generate source files during build time + +All such functions are invoked in a subprocess on Windows to prevent build flakiness. +""" + +from platform_methods import subprocess_main +from collections import OrderedDict + + +def make_default_controller_mappings(target, source, env): + dst = target[0] + g = open(dst, "w") + + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#include \"core/typedefs.h\"\n") + g.write("#include \"core/input/default_controller_mappings.h\"\n") + + # ensure mappings have a consistent order + platform_mappings = OrderedDict() + for src_path in source: + with open(src_path, "r") as f: + # read mapping file and skip header + mapping_file_lines = f.readlines()[2:] + + current_platform = None + for line in mapping_file_lines: + if not line: + continue + line = line.strip() + if len(line) == 0: + continue + if line[0] == "#": + current_platform = line[1:].strip() + if current_platform not in platform_mappings: + platform_mappings[current_platform] = {} + elif current_platform: + line_parts = line.split(",") + guid = line_parts[0] + if guid in platform_mappings[current_platform]: + g.write("// WARNING - DATABASE {} OVERWROTE PRIOR MAPPING: {} {}\n".format(src_path, current_platform, platform_mappings[current_platform][guid])) + valid_mapping = True + for input_map in line_parts[2:]: + if "+" in input_map or "-" in input_map or "~" in input_map: + g.write("// WARNING - DISCARDED UNSUPPORTED MAPPING TYPE FROM DATABASE {}: {} {}\n".format(src_path, current_platform, line)) + valid_mapping = False + break + if valid_mapping: + platform_mappings[current_platform][guid] = line + + platform_variables = { + "Linux": "#if X11_ENABLED", + "Windows": "#ifdef WINDOWS_ENABLED", + "Mac OS X": "#ifdef OSX_ENABLED", + "Android": "#if defined(__ANDROID__)", + "iOS": "#ifdef IPHONE_ENABLED", + "Javascript": "#ifdef JAVASCRIPT_ENABLED", + "UWP": "#ifdef UWP_ENABLED", + } + + g.write("const char* DefaultControllerMappings::mappings[] = {\n") + for platform, mappings in platform_mappings.items(): + variable = platform_variables[platform] + g.write("{}\n".format(variable)) + for mapping in mappings.values(): + g.write("\t\"{}\",\n".format(mapping)) + g.write("#endif\n") + + g.write("\tNULL\n};\n") + g.close() + + +if __name__ == '__main__': + subprocess_main(globals()) diff --git a/core/os/input_event.cpp b/core/input/input_event.cpp similarity index 97% rename from core/os/input_event.cpp rename to core/input/input_event.cpp index 204a36bf56..088d185b8d 100644 --- a/core/os/input_event.cpp +++ b/core/input/input_event.cpp @@ -30,7 +30,7 @@ #include "input_event.h" -#include "core/input_map.h" +#include "core/input/input_map.h" #include "core/os/keyboard.h" const int InputEvent::DEVICE_ID_TOUCH_MOUSE = -1; @@ -136,6 +136,25 @@ InputEvent::InputEvent() { device = 0; } +//////////////// + +void InputEventFromWindow::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_window_id", "id"), &InputEventFromWindow::set_window_id); + ClassDB::bind_method(D_METHOD("get_window_id"), &InputEventFromWindow::get_window_id); + ADD_PROPERTY(PropertyInfo(Variant::INT, "window_id"), "set_window_id", "get_window_id"); +} + +void InputEventFromWindow::set_window_id(int64_t p_id) { + window_id = p_id; +} +int64_t InputEventFromWindow::get_window_id() const { + return window_id; +} + +InputEventFromWindow::InputEventFromWindow() { + window_id = 0; +} ////////////////// @@ -499,7 +518,7 @@ Ref InputEventMouseButton::xformed_by(const Transform2D &p_xform, co mb.instance(); mb->set_device(get_device()); - + mb->set_window_id(get_window_id()); mb->set_modifiers_from_event(this); mb->set_position(l); @@ -650,6 +669,7 @@ Ref InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co mm.instance(); mm->set_device(get_device()); + mm->set_window_id(get_window_id()); mm->set_modifiers_from_event(this); @@ -697,6 +717,10 @@ bool InputEventMouseMotion::accumulate(const Ref &p_event) { if (motion.is_null()) return false; + if (get_window_id() != motion->get_window_id()) { + return false; + } + if (is_pressed() != motion->is_pressed()) { return false; } @@ -948,6 +972,7 @@ Ref InputEventScreenTouch::xformed_by(const Transform2D &p_xform, co Ref st; st.instance(); st->set_device(get_device()); + st->set_window_id(get_window_id()); st->set_index(index); st->set_position(p_xform.xform(pos + p_local_ofs)); st->set_pressed(pressed); @@ -1028,6 +1053,7 @@ Ref InputEventScreenDrag::xformed_by(const Transform2D &p_xform, con sd.instance(); sd->set_device(get_device()); + sd->set_window_id(get_window_id()); sd->set_index(index); sd->set_position(p_xform.xform(pos + p_local_ofs)); @@ -1186,6 +1212,8 @@ Ref InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, ev.instance(); ev->set_device(get_device()); + ev->set_window_id(get_window_id()); + ev->set_modifiers_from_event(this); ev->set_position(p_xform.xform(get_position() + p_local_ofs)); @@ -1228,6 +1256,8 @@ Ref InputEventPanGesture::xformed_by(const Transform2D &p_xform, con ev.instance(); ev->set_device(get_device()); + ev->set_window_id(get_window_id()); + ev->set_modifiers_from_event(this); ev->set_position(p_xform.xform(get_position() + p_local_ofs)); diff --git a/core/os/input_event.h b/core/input/input_event.h similarity index 96% rename from core/os/input_event.h rename to core/input/input_event.h index 21549d811f..2fdcdd0319 100644 --- a/core/os/input_event.h +++ b/core/input/input_event.h @@ -205,8 +205,24 @@ public: InputEvent(); }; -class InputEventWithModifiers : public InputEvent { - GDCLASS(InputEventWithModifiers, InputEvent); +class InputEventFromWindow : public InputEvent { + + GDCLASS(InputEventFromWindow, InputEvent); + + int64_t window_id; + +protected: + static void _bind_methods(); + +public: + void set_window_id(int64_t p_id); + int64_t get_window_id() const; + + InputEventFromWindow(); +}; + +class InputEventWithModifiers : public InputEventFromWindow { + GDCLASS(InputEventWithModifiers, InputEventFromWindow); bool shift; bool alt; @@ -440,8 +456,8 @@ public: InputEventJoypadButton(); }; -class InputEventScreenTouch : public InputEvent { - GDCLASS(InputEventScreenTouch, InputEvent); +class InputEventScreenTouch : public InputEventFromWindow { + GDCLASS(InputEventScreenTouch, InputEventFromWindow); int index; Vector2 pos; bool pressed; @@ -465,9 +481,9 @@ public: InputEventScreenTouch(); }; -class InputEventScreenDrag : public InputEvent { +class InputEventScreenDrag : public InputEventFromWindow { - GDCLASS(InputEventScreenDrag, InputEvent); + GDCLASS(InputEventScreenDrag, InputEventFromWindow); int index; Vector2 pos; Vector2 relative; diff --git a/main/input_default.cpp b/core/input/input_filter.cpp similarity index 68% rename from main/input_default.cpp rename to core/input/input_filter.cpp index aa9e772a38..088f7effd6 100644 --- a/main/input_default.cpp +++ b/core/input/input_filter.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* input_default.cpp */ +/* input_filter.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,134 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "input_default.h" +#include "input_filter.h" -#include "core/input_map.h" +#include "core/input/default_controller_mappings.h" +#include "core/input/input_map.h" #include "core/os/os.h" -#include "main/default_controller_mappings.h" -#include "scene/resources/texture.h" -#include "servers/visual_server.h" +#include "core/project_settings.h" -void InputDefault::SpeedTrack::update(const Vector2 &p_delta_p) { +#ifdef TOOLS_ENABLED +#include "editor/editor_settings.h" +#endif + +InputFilter *InputFilter::singleton = NULL; + +void (*InputFilter::set_mouse_mode_func)(InputFilter::MouseMode) = nullptr; +InputFilter::MouseMode (*InputFilter::get_mouse_mode_func)() = nullptr; +void (*InputFilter::warp_mouse_func)(const Vector2 &p_to_pos) = nullptr; +InputFilter::CursorShape (*InputFilter::get_current_cursor_shape_func)() = nullptr; +void (*InputFilter::set_custom_mouse_cursor_func)(const RES &, InputFilter::CursorShape, const Vector2 &) = nullptr; + +InputFilter *InputFilter::get_singleton() { + + return singleton; +} + +void InputFilter::set_mouse_mode(MouseMode p_mode) { + ERR_FAIL_INDEX((int)p_mode, 4); + set_mouse_mode_func(p_mode); +} + +InputFilter::MouseMode InputFilter::get_mouse_mode() const { + + return get_mouse_mode_func(); +} + +void InputFilter::_bind_methods() { + + ClassDB::bind_method(D_METHOD("is_key_pressed", "keycode"), &InputFilter::is_key_pressed); + ClassDB::bind_method(D_METHOD("is_mouse_button_pressed", "button"), &InputFilter::is_mouse_button_pressed); + ClassDB::bind_method(D_METHOD("is_joy_button_pressed", "device", "button"), &InputFilter::is_joy_button_pressed); + ClassDB::bind_method(D_METHOD("is_action_pressed", "action"), &InputFilter::is_action_pressed); + ClassDB::bind_method(D_METHOD("is_action_just_pressed", "action"), &InputFilter::is_action_just_pressed); + ClassDB::bind_method(D_METHOD("is_action_just_released", "action"), &InputFilter::is_action_just_released); + ClassDB::bind_method(D_METHOD("get_action_strength", "action"), &InputFilter::get_action_strength); + ClassDB::bind_method(D_METHOD("add_joy_mapping", "mapping", "update_existing"), &InputFilter::add_joy_mapping, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("remove_joy_mapping", "guid"), &InputFilter::remove_joy_mapping); + ClassDB::bind_method(D_METHOD("joy_connection_changed", "device", "connected", "name", "guid"), &InputFilter::joy_connection_changed); + ClassDB::bind_method(D_METHOD("is_joy_known", "device"), &InputFilter::is_joy_known); + ClassDB::bind_method(D_METHOD("get_joy_axis", "device", "axis"), &InputFilter::get_joy_axis); + ClassDB::bind_method(D_METHOD("get_joy_name", "device"), &InputFilter::get_joy_name); + ClassDB::bind_method(D_METHOD("get_joy_guid", "device"), &InputFilter::get_joy_guid); + ClassDB::bind_method(D_METHOD("get_connected_joypads"), &InputFilter::get_connected_joypads); + ClassDB::bind_method(D_METHOD("get_joy_vibration_strength", "device"), &InputFilter::get_joy_vibration_strength); + ClassDB::bind_method(D_METHOD("get_joy_vibration_duration", "device"), &InputFilter::get_joy_vibration_duration); + ClassDB::bind_method(D_METHOD("get_joy_button_string", "button_index"), &InputFilter::get_joy_button_string); + ClassDB::bind_method(D_METHOD("get_joy_button_index_from_string", "button"), &InputFilter::get_joy_button_index_from_string); + ClassDB::bind_method(D_METHOD("get_joy_axis_string", "axis_index"), &InputFilter::get_joy_axis_string); + ClassDB::bind_method(D_METHOD("get_joy_axis_index_from_string", "axis"), &InputFilter::get_joy_axis_index_from_string); + ClassDB::bind_method(D_METHOD("start_joy_vibration", "device", "weak_magnitude", "strong_magnitude", "duration"), &InputFilter::start_joy_vibration, DEFVAL(0)); + ClassDB::bind_method(D_METHOD("stop_joy_vibration", "device"), &InputFilter::stop_joy_vibration); + ClassDB::bind_method(D_METHOD("vibrate_handheld", "duration_ms"), &InputFilter::vibrate_handheld, DEFVAL(500)); + ClassDB::bind_method(D_METHOD("get_gravity"), &InputFilter::get_gravity); + ClassDB::bind_method(D_METHOD("get_accelerometer"), &InputFilter::get_accelerometer); + ClassDB::bind_method(D_METHOD("get_magnetometer"), &InputFilter::get_magnetometer); + ClassDB::bind_method(D_METHOD("get_gyroscope"), &InputFilter::get_gyroscope); + ClassDB::bind_method(D_METHOD("get_last_mouse_speed"), &InputFilter::get_last_mouse_speed); + ClassDB::bind_method(D_METHOD("get_mouse_button_mask"), &InputFilter::get_mouse_button_mask); + ClassDB::bind_method(D_METHOD("set_mouse_mode", "mode"), &InputFilter::set_mouse_mode); + ClassDB::bind_method(D_METHOD("get_mouse_mode"), &InputFilter::get_mouse_mode); + ClassDB::bind_method(D_METHOD("warp_mouse_position", "to"), &InputFilter::warp_mouse_position); + ClassDB::bind_method(D_METHOD("action_press", "action", "strength"), &InputFilter::action_press, DEFVAL(1.f)); + ClassDB::bind_method(D_METHOD("action_release", "action"), &InputFilter::action_release); + ClassDB::bind_method(D_METHOD("set_default_cursor_shape", "shape"), &InputFilter::set_default_cursor_shape, DEFVAL(CURSOR_ARROW)); + ClassDB::bind_method(D_METHOD("get_current_cursor_shape"), &InputFilter::get_current_cursor_shape); + ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image", "shape", "hotspot"), &InputFilter::set_custom_mouse_cursor, DEFVAL(CURSOR_ARROW), DEFVAL(Vector2())); + ClassDB::bind_method(D_METHOD("parse_input_event", "event"), &InputFilter::parse_input_event); + ClassDB::bind_method(D_METHOD("set_use_accumulated_input", "enable"), &InputFilter::set_use_accumulated_input); + + BIND_ENUM_CONSTANT(MOUSE_MODE_VISIBLE); + BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN); + BIND_ENUM_CONSTANT(MOUSE_MODE_CAPTURED); + BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED); + + BIND_ENUM_CONSTANT(CURSOR_ARROW); + BIND_ENUM_CONSTANT(CURSOR_IBEAM); + BIND_ENUM_CONSTANT(CURSOR_POINTING_HAND); + BIND_ENUM_CONSTANT(CURSOR_CROSS); + BIND_ENUM_CONSTANT(CURSOR_WAIT); + BIND_ENUM_CONSTANT(CURSOR_BUSY); + BIND_ENUM_CONSTANT(CURSOR_DRAG); + BIND_ENUM_CONSTANT(CURSOR_CAN_DROP); + BIND_ENUM_CONSTANT(CURSOR_FORBIDDEN); + BIND_ENUM_CONSTANT(CURSOR_VSIZE); + BIND_ENUM_CONSTANT(CURSOR_HSIZE); + BIND_ENUM_CONSTANT(CURSOR_BDIAGSIZE); + BIND_ENUM_CONSTANT(CURSOR_FDIAGSIZE); + BIND_ENUM_CONSTANT(CURSOR_MOVE); + BIND_ENUM_CONSTANT(CURSOR_VSPLIT); + BIND_ENUM_CONSTANT(CURSOR_HSPLIT); + BIND_ENUM_CONSTANT(CURSOR_HELP); + + ADD_SIGNAL(MethodInfo("joy_connection_changed", PropertyInfo(Variant::INT, "device"), PropertyInfo(Variant::BOOL, "connected"))); +} + +void InputFilter::get_argument_options(const StringName &p_function, int p_idx, List *r_options) const { +#ifdef TOOLS_ENABLED + + const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\""; + + String pf = p_function; + if (p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" || pf == "is_action_just_pressed" || pf == "is_action_just_released" || pf == "get_action_strength")) { + + List pinfo; + ProjectSettings::get_singleton()->get_property_list(&pinfo); + + for (List::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(quote_style + name + quote_style); + } + } +#endif +} + +void InputFilter::SpeedTrack::update(const Vector2 &p_delta_p) { uint64_t tick = OS::get_singleton()->get_ticks_usec(); uint32_t tdiff = tick - last_tick; @@ -60,26 +179,26 @@ void InputDefault::SpeedTrack::update(const Vector2 &p_delta_p) { } } -void InputDefault::SpeedTrack::reset() { +void InputFilter::SpeedTrack::reset() { last_tick = OS::get_singleton()->get_ticks_usec(); speed = Vector2(); accum_t = 0; } -InputDefault::SpeedTrack::SpeedTrack() { +InputFilter::SpeedTrack::SpeedTrack() { min_ref_frame = 0.1; max_ref_frame = 0.3; reset(); } -bool InputDefault::is_key_pressed(int p_keycode) const { +bool InputFilter::is_key_pressed(int p_keycode) const { _THREAD_SAFE_METHOD_ return keys_pressed.has(p_keycode); } -bool InputDefault::is_mouse_button_pressed(int p_button) const { +bool InputFilter::is_mouse_button_pressed(int p_button) const { _THREAD_SAFE_METHOD_ return (mouse_button_mask & (1 << (p_button - 1))) != 0; @@ -90,18 +209,18 @@ static int _combine_device(int p_value, int p_device) { return p_value | (p_device << 20); } -bool InputDefault::is_joy_button_pressed(int p_device, int p_button) const { +bool InputFilter::is_joy_button_pressed(int p_device, int p_button) const { _THREAD_SAFE_METHOD_ return joy_buttons_pressed.has(_combine_device(p_button, p_device)); } -bool InputDefault::is_action_pressed(const StringName &p_action) const { +bool InputFilter::is_action_pressed(const StringName &p_action) const { return action_state.has(p_action) && action_state[p_action].pressed; } -bool InputDefault::is_action_just_pressed(const StringName &p_action) const { +bool InputFilter::is_action_just_pressed(const StringName &p_action) const { const Map::Element *E = action_state.find(p_action); if (!E) @@ -114,7 +233,7 @@ bool InputDefault::is_action_just_pressed(const StringName &p_action) const { } } -bool InputDefault::is_action_just_released(const StringName &p_action) const { +bool InputFilter::is_action_just_released(const StringName &p_action) const { const Map::Element *E = action_state.find(p_action); if (!E) @@ -127,7 +246,7 @@ bool InputDefault::is_action_just_released(const StringName &p_action) const { } } -float InputDefault::get_action_strength(const StringName &p_action) const { +float InputFilter::get_action_strength(const StringName &p_action) const { const Map::Element *E = action_state.find(p_action); if (!E) return 0.0f; @@ -135,7 +254,7 @@ float InputDefault::get_action_strength(const StringName &p_action) const { return E->get().strength; } -float InputDefault::get_joy_axis(int p_device, int p_axis) const { +float InputFilter::get_joy_axis(int p_device, int p_axis) const { _THREAD_SAFE_METHOD_ int c = _combine_device(p_axis, p_device); @@ -146,13 +265,13 @@ float InputDefault::get_joy_axis(int p_device, int p_axis) const { } } -String InputDefault::get_joy_name(int p_idx) { +String InputFilter::get_joy_name(int p_idx) { _THREAD_SAFE_METHOD_ return joy_names[p_idx].name; }; -Vector2 InputDefault::get_joy_vibration_strength(int p_device) { +Vector2 InputFilter::get_joy_vibration_strength(int p_device) { if (joy_vibration.has(p_device)) { return Vector2(joy_vibration[p_device].weak_magnitude, joy_vibration[p_device].strong_magnitude); } else { @@ -160,7 +279,7 @@ Vector2 InputDefault::get_joy_vibration_strength(int p_device) { } } -uint64_t InputDefault::get_joy_vibration_timestamp(int p_device) { +uint64_t InputFilter::get_joy_vibration_timestamp(int p_device) { if (joy_vibration.has(p_device)) { return joy_vibration[p_device].timestamp; } else { @@ -168,7 +287,7 @@ uint64_t InputDefault::get_joy_vibration_timestamp(int p_device) { } } -float InputDefault::get_joy_vibration_duration(int p_device) { +float InputFilter::get_joy_vibration_duration(int p_device) { if (joy_vibration.has(p_device)) { return joy_vibration[p_device].duration; } else { @@ -188,7 +307,7 @@ static String _hex_str(uint8_t p_byte) { return ret; }; -void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) { +void InputFilter::joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) { _THREAD_SAFE_METHOD_ Joypad js; @@ -230,36 +349,36 @@ void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_ emit_signal("joy_connection_changed", p_idx, p_connected); }; -Vector3 InputDefault::get_gravity() const { +Vector3 InputFilter::get_gravity() const { _THREAD_SAFE_METHOD_ return gravity; } -Vector3 InputDefault::get_accelerometer() const { +Vector3 InputFilter::get_accelerometer() const { _THREAD_SAFE_METHOD_ return accelerometer; } -Vector3 InputDefault::get_magnetometer() const { +Vector3 InputFilter::get_magnetometer() const { _THREAD_SAFE_METHOD_ return magnetometer; } -Vector3 InputDefault::get_gyroscope() const { +Vector3 InputFilter::get_gyroscope() const { _THREAD_SAFE_METHOD_ return gyroscope; } -void InputDefault::parse_input_event(const Ref &p_event) { +void InputFilter::parse_input_event(const Ref &p_event) { _parse_input_event_impl(p_event, false); } -void InputDefault::_parse_input_event_impl(const Ref &p_event, bool p_is_emulated) { +void InputFilter::_parse_input_event_impl(const Ref &p_event, bool p_is_emulated) { // Notes on mouse-touch emulation: // - Emulated mouse events are parsed, that is, re-routed to this method, so they make the same effects @@ -293,12 +412,12 @@ void InputDefault::_parse_input_event_impl(const Ref &p_event, bool set_mouse_position(pos); } - if (main_loop && emulate_touch_from_mouse && !p_is_emulated && mb->get_button_index() == 1) { + if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mb->get_button_index() == 1) { Ref touch_event; touch_event.instance(); touch_event->set_pressed(mb->is_pressed()); touch_event->set_position(mb->get_position()); - main_loop->input_event(touch_event); + event_dispatch_function(touch_event); } } @@ -311,7 +430,7 @@ void InputDefault::_parse_input_event_impl(const Ref &p_event, bool set_mouse_position(pos); } - if (main_loop && emulate_touch_from_mouse && !p_is_emulated && mm->get_button_mask() & 1) { + if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mm->get_button_mask() & 1) { Ref drag_event; drag_event.instance(); @@ -319,7 +438,7 @@ void InputDefault::_parse_input_event_impl(const Ref &p_event, bool drag_event->set_relative(mm->get_relative()); drag_event->set_speed(mm->get_speed()); - main_loop->input_event(drag_event); + event_dispatch_function(drag_event); } } @@ -417,8 +536,8 @@ void InputDefault::_parse_input_event_impl(const Ref &p_event, bool if (ge.is_valid()) { - if (main_loop) { - main_loop->input_event(ge); + if (event_dispatch_function) { + event_dispatch_function(ge); } } @@ -438,18 +557,18 @@ void InputDefault::_parse_input_event_impl(const Ref &p_event, bool } } - if (main_loop) - main_loop->input_event(p_event); + if (event_dispatch_function) + event_dispatch_function(p_event); } -void InputDefault::set_joy_axis(int p_device, int p_axis, float p_value) { +void InputFilter::set_joy_axis(int p_device, int p_axis, float p_value) { _THREAD_SAFE_METHOD_ int c = _combine_device(p_axis, p_device); _joy_axis[c] = p_value; } -void InputDefault::start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration) { +void InputFilter::start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration) { _THREAD_SAFE_METHOD_ if (p_weak_magnitude < 0.f || p_weak_magnitude > 1.f || p_strong_magnitude < 0.f || p_strong_magnitude > 1.f) { return; @@ -462,7 +581,7 @@ void InputDefault::start_joy_vibration(int p_device, float p_weak_magnitude, flo joy_vibration[p_device] = vibration; } -void InputDefault::stop_joy_vibration(int p_device) { +void InputFilter::stop_joy_vibration(int p_device) { _THREAD_SAFE_METHOD_ VibrationInfo vibration; vibration.weak_magnitude = 0; @@ -472,68 +591,63 @@ void InputDefault::stop_joy_vibration(int p_device) { joy_vibration[p_device] = vibration; } -void InputDefault::vibrate_handheld(int p_duration_ms) { +void InputFilter::vibrate_handheld(int p_duration_ms) { OS::get_singleton()->vibrate_handheld(p_duration_ms); } -void InputDefault::set_gravity(const Vector3 &p_gravity) { +void InputFilter::set_gravity(const Vector3 &p_gravity) { _THREAD_SAFE_METHOD_ gravity = p_gravity; } -void InputDefault::set_accelerometer(const Vector3 &p_accel) { +void InputFilter::set_accelerometer(const Vector3 &p_accel) { _THREAD_SAFE_METHOD_ accelerometer = p_accel; } -void InputDefault::set_magnetometer(const Vector3 &p_magnetometer) { +void InputFilter::set_magnetometer(const Vector3 &p_magnetometer) { _THREAD_SAFE_METHOD_ magnetometer = p_magnetometer; } -void InputDefault::set_gyroscope(const Vector3 &p_gyroscope) { +void InputFilter::set_gyroscope(const Vector3 &p_gyroscope) { _THREAD_SAFE_METHOD_ gyroscope = p_gyroscope; } -void InputDefault::set_main_loop(MainLoop *p_main_loop) { - main_loop = p_main_loop; -} - -void InputDefault::set_mouse_position(const Point2 &p_posf) { +void InputFilter::set_mouse_position(const Point2 &p_posf) { mouse_speed_track.update(p_posf - mouse_pos); mouse_pos = p_posf; } -Point2 InputDefault::get_mouse_position() const { +Point2 InputFilter::get_mouse_position() const { return mouse_pos; } -Point2 InputDefault::get_last_mouse_speed() const { +Point2 InputFilter::get_last_mouse_speed() const { return mouse_speed_track.speed; } -int InputDefault::get_mouse_button_mask() const { +int InputFilter::get_mouse_button_mask() const { return mouse_button_mask; // do not trust OS implementation, should remove it - OS::get_singleton()->get_mouse_button_state(); } -void InputDefault::warp_mouse_position(const Vector2 &p_to) { - - OS::get_singleton()->warp_mouse_position(p_to); +void InputFilter::warp_mouse_position(const Vector2 &p_to) { + warp_mouse_func(p_to); } -Point2i InputDefault::warp_mouse_motion(const Ref &p_motion, const Rect2 &p_rect) { +Point2i InputFilter::warp_mouse_motion(const Ref &p_motion, const Rect2 &p_rect) { // The relative distance reported for the next event after a warp is in the boundaries of the // size of the rect on that axis, but it may be greater, in which case there's not problem as fmod() @@ -553,16 +667,16 @@ Point2i InputDefault::warp_mouse_motion(const Ref &p_moti const Point2i pos_local = p_motion->get_global_position() - p_rect.position; const Point2i pos_warped(Math::fposmod(pos_local.x, p_rect.size.x), Math::fposmod(pos_local.y, p_rect.size.y)); if (pos_warped != pos_local) { - OS::get_singleton()->warp_mouse_position(pos_warped + p_rect.position); + warp_mouse_position(pos_warped + p_rect.position); } return rel_warped; } -void InputDefault::iteration(float p_step) { +void InputFilter::iteration(float p_step) { } -void InputDefault::action_press(const StringName &p_action, float p_strength) { +void InputFilter::action_press(const StringName &p_action, float p_strength) { Action action; @@ -574,7 +688,7 @@ void InputDefault::action_press(const StringName &p_action, float p_strength) { action_state[p_action] = action; } -void InputDefault::action_release(const StringName &p_action) { +void InputFilter::action_release(const StringName &p_action) { Action action; @@ -586,19 +700,19 @@ void InputDefault::action_release(const StringName &p_action) { action_state[p_action] = action; } -void InputDefault::set_emulate_touch_from_mouse(bool p_emulate) { +void InputFilter::set_emulate_touch_from_mouse(bool p_emulate) { emulate_touch_from_mouse = p_emulate; } -bool InputDefault::is_emulating_touch_from_mouse() const { +bool InputFilter::is_emulating_touch_from_mouse() const { return emulate_touch_from_mouse; } // Calling this whenever the game window is focused helps unstucking the "touch mouse" // if the OS or its abstraction class hasn't properly reported that touch pointers raised -void InputDefault::ensure_touch_mouse_raised() { +void InputFilter::ensure_touch_mouse_raised() { if (mouse_from_touch_index != -1) { mouse_from_touch_index = -1; @@ -617,22 +731,22 @@ void InputDefault::ensure_touch_mouse_raised() { } } -void InputDefault::set_emulate_mouse_from_touch(bool p_emulate) { +void InputFilter::set_emulate_mouse_from_touch(bool p_emulate) { emulate_mouse_from_touch = p_emulate; } -bool InputDefault::is_emulating_mouse_from_touch() const { +bool InputFilter::is_emulating_mouse_from_touch() const { return emulate_mouse_from_touch; } -Input::CursorShape InputDefault::get_default_cursor_shape() const { +InputFilter::CursorShape InputFilter::get_default_cursor_shape() const { return default_shape; } -void InputDefault::set_default_cursor_shape(CursorShape p_shape) { +void InputFilter::set_default_cursor_shape(CursorShape p_shape) { if (default_shape == p_shape) return; @@ -647,19 +761,19 @@ void InputDefault::set_default_cursor_shape(CursorShape p_shape) { parse_input_event(mm); } -Input::CursorShape InputDefault::get_current_cursor_shape() const { +InputFilter::CursorShape InputFilter::get_current_cursor_shape() const { - return (Input::CursorShape)OS::get_singleton()->get_cursor_shape(); + return get_current_cursor_shape_func(); } -void InputDefault::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { +void InputFilter::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { if (Engine::get_singleton()->is_editor_hint()) return; - OS::get_singleton()->set_custom_mouse_cursor(p_cursor, (OS::CursorShape)p_shape, p_hotspot); + set_custom_mouse_cursor_func(p_cursor, p_shape, p_hotspot); } -void InputDefault::accumulate_input_event(const Ref &p_event) { +void InputFilter::accumulate_input_event(const Ref &p_event) { ERR_FAIL_COND(p_event.is_null()); if (!use_accumulated_input) { @@ -672,7 +786,7 @@ void InputDefault::accumulate_input_event(const Ref &p_event) { accumulated_events.push_back(p_event); } -void InputDefault::flush_accumulated_events() { +void InputFilter::flush_accumulated_events() { while (accumulated_events.front()) { parse_input_event(accumulated_events.front()->get()); @@ -680,12 +794,12 @@ void InputDefault::flush_accumulated_events() { } } -void InputDefault::set_use_accumulated_input(bool p_enable) { +void InputFilter::set_use_accumulated_input(bool p_enable) { use_accumulated_input = p_enable; } -void InputDefault::release_pressed_events() { +void InputFilter::release_pressed_events() { flush_accumulated_events(); // this is needed to release actions strengths @@ -693,61 +807,17 @@ void InputDefault::release_pressed_events() { joy_buttons_pressed.clear(); _joy_axis.clear(); - for (Map::Element *E = action_state.front(); E; E = E->next()) { + for (Map::Element *E = action_state.front(); E; E = E->next()) { if (E->get().pressed) action_release(E->key()); } } -InputDefault::InputDefault() { - - use_accumulated_input = true; - mouse_button_mask = 0; - emulate_touch_from_mouse = false; - emulate_mouse_from_touch = false; - mouse_from_touch_index = -1; - main_loop = NULL; - default_shape = CURSOR_ARROW; - - hat_map_default[HAT_UP].type = TYPE_BUTTON; - hat_map_default[HAT_UP].index = JOY_DPAD_UP; - hat_map_default[HAT_UP].value = 0; - - hat_map_default[HAT_RIGHT].type = TYPE_BUTTON; - hat_map_default[HAT_RIGHT].index = JOY_DPAD_RIGHT; - hat_map_default[HAT_RIGHT].value = 0; - - hat_map_default[HAT_DOWN].type = TYPE_BUTTON; - hat_map_default[HAT_DOWN].index = JOY_DPAD_DOWN; - hat_map_default[HAT_DOWN].value = 0; - - hat_map_default[HAT_LEFT].type = TYPE_BUTTON; - hat_map_default[HAT_LEFT].index = JOY_DPAD_LEFT; - hat_map_default[HAT_LEFT].value = 0; - - fallback_mapping = -1; - - // Parse default mappings. - { - int i = 0; - while (DefaultControllerMappings::mappings[i]) { - parse_mapping(DefaultControllerMappings::mappings[i++]); - } - } - - // If defined, parse SDL_GAMECONTROLLERCONFIG for possible new mappings/overrides. - String env_mapping = OS::get_singleton()->get_environment("SDL_GAMECONTROLLERCONFIG"); - if (env_mapping != "") { - Vector entries = env_mapping.split("\n"); - for (int i = 0; i < entries.size(); i++) { - if (entries[i] == "") - continue; - parse_mapping(entries[i]); - } - } +void InputFilter::set_event_dispatch_function(EventDispatchFunc p_function) { + event_dispatch_function = p_function; } -void InputDefault::joy_button(int p_device, int p_button, bool p_pressed) { +void InputFilter::joy_button(int p_device, int p_button, bool p_pressed) { _THREAD_SAFE_METHOD_; Joypad &joy = joy_names[p_device]; @@ -786,7 +856,7 @@ void InputDefault::joy_button(int p_device, int p_button, bool p_pressed) { // no event? } -void InputDefault::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { +void InputFilter::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { _THREAD_SAFE_METHOD_; @@ -901,7 +971,7 @@ void InputDefault::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { //printf("invalid mapping\n"); } -void InputDefault::joy_hat(int p_device, int p_val) { +void InputFilter::joy_hat(int p_device, int p_val) { _THREAD_SAFE_METHOD_; const Joypad &joy = joy_names[p_device]; @@ -933,7 +1003,7 @@ void InputDefault::joy_hat(int p_device, int p_val) { joy_names[p_device].hat_current = p_val; } -void InputDefault::_button_event(int p_device, int p_index, bool p_pressed) { +void InputFilter::_button_event(int p_device, int p_index, bool p_pressed) { Ref ievent; ievent.instance(); @@ -944,7 +1014,7 @@ void InputDefault::_button_event(int p_device, int p_index, bool p_pressed) { parse_input_event(ievent); } -void InputDefault::_axis_event(int p_device, int p_axis, float p_value) { +void InputFilter::_axis_event(int p_device, int p_axis, float p_value) { Ref ievent; ievent.instance(); @@ -955,7 +1025,7 @@ void InputDefault::_axis_event(int p_device, int p_axis, float p_value) { parse_input_event(ievent); }; -InputDefault::JoyEvent InputDefault::_find_to_event(String p_to) { +InputFilter::JoyEvent InputFilter::_find_to_event(String p_to) { // string names of the SDL buttons in the same order as input_event.h godot buttons static const char *buttons[] = { "a", "b", "x", "y", "leftshoulder", "rightshoulder", "lefttrigger", "righttrigger", "leftstick", "rightstick", "back", "start", "dpup", "dpdown", "dpleft", "dpright", "guide", NULL }; @@ -993,7 +1063,7 @@ InputDefault::JoyEvent InputDefault::_find_to_event(String p_to) { return ret; }; -void InputDefault::parse_mapping(String p_mapping) { +void InputFilter::parse_mapping(String p_mapping) { _THREAD_SAFE_METHOD_; JoyDeviceMapping mapping; @@ -1058,7 +1128,7 @@ void InputDefault::parse_mapping(String p_mapping) { //printf("added mapping with uuid %ls\n", mapping.uid.c_str()); }; -void InputDefault::add_joy_mapping(String p_mapping, bool p_update_existing) { +void InputFilter::add_joy_mapping(String p_mapping, bool p_update_existing) { parse_mapping(p_mapping); if (p_update_existing) { Vector entry = p_mapping.split(","); @@ -1071,7 +1141,7 @@ void InputDefault::add_joy_mapping(String p_mapping, bool p_update_existing) { } } -void InputDefault::remove_joy_mapping(String p_guid) { +void InputFilter::remove_joy_mapping(String p_guid) { for (int i = map_db.size() - 1; i >= 0; i--) { if (p_guid == map_db[i].uid) { map_db.remove(i); @@ -1084,7 +1154,7 @@ void InputDefault::remove_joy_mapping(String p_guid) { } } -void InputDefault::set_fallback_mapping(String p_guid) { +void InputFilter::set_fallback_mapping(String p_guid) { for (int i = 0; i < map_db.size(); i++) { if (map_db[i].uid == p_guid) { @@ -1094,28 +1164,18 @@ void InputDefault::set_fallback_mapping(String p_guid) { } } -//Defaults to simple implementation for platforms with a fixed gamepad layout, like consoles. -bool InputDefault::is_joy_known(int p_device) { - - return OS::get_singleton()->is_joy_known(p_device); -} - -String InputDefault::get_joy_guid(int p_device) const { - return OS::get_singleton()->get_joy_guid(p_device); -} - //platforms that use the remapping system can override and call to these ones -bool InputDefault::is_joy_mapped(int p_device) { +bool InputFilter::is_joy_known(int p_device) { int mapping = joy_names[p_device].mapping; return mapping != -1 ? (mapping != fallback_mapping) : false; } -String InputDefault::get_joy_guid_remapped(int p_device) const { +String InputFilter::get_joy_guid(int p_device) const { ERR_FAIL_COND_V(!joy_names.has(p_device), ""); return joy_names[p_device].uid; } -Array InputDefault::get_connected_joypads() { +Array InputFilter::get_connected_joypads() { Array ret; Map::Element *elem = joy_names.front(); while (elem) { @@ -1159,12 +1219,12 @@ static const char *_axes[JOY_AXIS_MAX] = { "" }; -String InputDefault::get_joy_button_string(int p_button) { +String InputFilter::get_joy_button_string(int p_button) { ERR_FAIL_INDEX_V(p_button, JOY_BUTTON_MAX, ""); return _buttons[p_button]; } -int InputDefault::get_joy_button_index_from_string(String p_button) { +int InputFilter::get_joy_button_index_from_string(String p_button) { for (int i = 0; i < JOY_BUTTON_MAX; i++) { if (p_button == _buttons[i]) { return i; @@ -1173,7 +1233,7 @@ int InputDefault::get_joy_button_index_from_string(String p_button) { ERR_FAIL_V(-1); } -int InputDefault::get_unused_joy_id() { +int InputFilter::get_unused_joy_id() { for (int i = 0; i < JOYPADS_MAX; i++) { if (!joy_names.has(i) || !joy_names[i].connected) { return i; @@ -1182,12 +1242,12 @@ int InputDefault::get_unused_joy_id() { return -1; } -String InputDefault::get_joy_axis_string(int p_axis) { +String InputFilter::get_joy_axis_string(int p_axis) { ERR_FAIL_INDEX_V(p_axis, JOY_AXIS_MAX, ""); return _axes[p_axis]; } -int InputDefault::get_joy_axis_index_from_string(String p_axis) { +int InputFilter::get_joy_axis_index_from_string(String p_axis) { for (int i = 0; i < JOY_AXIS_MAX; i++) { if (p_axis == _axes[i]) { return i; @@ -1195,3 +1255,55 @@ int InputDefault::get_joy_axis_index_from_string(String p_axis) { } ERR_FAIL_V(-1); } + +InputFilter::InputFilter() { + + singleton = this; + use_accumulated_input = true; + mouse_button_mask = 0; + mouse_window = 0; + emulate_touch_from_mouse = false; + emulate_mouse_from_touch = false; + mouse_from_touch_index = -1; + event_dispatch_function = nullptr; + default_shape = CURSOR_ARROW; + + hat_map_default[HAT_UP].type = TYPE_BUTTON; + hat_map_default[HAT_UP].index = JOY_DPAD_UP; + hat_map_default[HAT_UP].value = 0; + + hat_map_default[HAT_RIGHT].type = TYPE_BUTTON; + hat_map_default[HAT_RIGHT].index = JOY_DPAD_RIGHT; + hat_map_default[HAT_RIGHT].value = 0; + + hat_map_default[HAT_DOWN].type = TYPE_BUTTON; + hat_map_default[HAT_DOWN].index = JOY_DPAD_DOWN; + hat_map_default[HAT_DOWN].value = 0; + + hat_map_default[HAT_LEFT].type = TYPE_BUTTON; + hat_map_default[HAT_LEFT].index = JOY_DPAD_LEFT; + hat_map_default[HAT_LEFT].value = 0; + + fallback_mapping = -1; + + // Parse default mappings. + { + int i = 0; + while (DefaultControllerMappings::mappings[i]) { + parse_mapping(DefaultControllerMappings::mappings[i++]); + } + } + + // If defined, parse SDL_GAMECONTROLLERCONFIG for possible new mappings/overrides. + String env_mapping = OS::get_singleton()->get_environment("SDL_GAMECONTROLLERCONFIG"); + if (env_mapping != "") { + Vector entries = env_mapping.split("\n"); + for (int i = 0; i < entries.size(); i++) { + if (entries[i] == "") + continue; + parse_mapping(entries[i]); + } + } +} + +////////////////////////////////////////////////////////// diff --git a/main/input_default.h b/core/input/input_filter.h similarity index 60% rename from main/input_default.h rename to core/input/input_filter.h index 0ec31d417b..908a005228 100644 --- a/main/input_default.h +++ b/core/input/input_filter.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* input_default.h */ +/* input_filter.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,16 +28,78 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef INPUT_DEFAULT_H -#define INPUT_DEFAULT_H +#ifndef INPUT_H +#define INPUT_H -#include "core/os/input.h" +#include "core/input/input_event.h" +#include "core/object.h" +#include "core/os/thread_safe.h" -class InputDefault : public Input { +class InputFilter : public Object { - GDCLASS(InputDefault, Input); + GDCLASS(InputFilter, Object); _THREAD_SAFE_CLASS_ + static InputFilter *singleton; + +public: + enum MouseMode { + MOUSE_MODE_VISIBLE, + MOUSE_MODE_HIDDEN, + MOUSE_MODE_CAPTURED, + MOUSE_MODE_CONFINED + }; + +#undef CursorShape + enum CursorShape { + CURSOR_ARROW, + CURSOR_IBEAM, + CURSOR_POINTING_HAND, + CURSOR_CROSS, + CURSOR_WAIT, + CURSOR_BUSY, + CURSOR_DRAG, + CURSOR_CAN_DROP, + CURSOR_FORBIDDEN, + CURSOR_VSIZE, + CURSOR_HSIZE, + CURSOR_BDIAGSIZE, + CURSOR_FDIAGSIZE, + CURSOR_MOVE, + CURSOR_VSPLIT, + CURSOR_HSPLIT, + CURSOR_HELP, + CURSOR_MAX + }; + + enum HatMask { + HAT_MASK_CENTER = 0, + HAT_MASK_UP = 1, + HAT_MASK_RIGHT = 2, + HAT_MASK_DOWN = 4, + HAT_MASK_LEFT = 8, + }; + + enum HatDir { + HAT_UP, + HAT_RIGHT, + HAT_DOWN, + HAT_LEFT, + HAT_MAX, + }; + + enum { + JOYPADS_MAX = 16, + }; + + struct JoyAxis { + int min; + float value; + }; + + typedef void (*EventDispatchFunc)(const Ref &p_event); + +private: int mouse_button_mask; Set keys_pressed; @@ -49,7 +111,7 @@ class InputDefault : public Input { Vector3 magnetometer; Vector3 gyroscope; Vector2 mouse_pos; - MainLoop *main_loop; + int64_t mouse_window; struct Action { uint64_t physics_frame; @@ -123,33 +185,6 @@ class InputDefault : public Input { CursorShape default_shape; -public: - enum HatMask { - HAT_MASK_CENTER = 0, - HAT_MASK_UP = 1, - HAT_MASK_RIGHT = 2, - HAT_MASK_DOWN = 4, - HAT_MASK_LEFT = 8, - }; - - enum HatDir { - HAT_UP, - HAT_RIGHT, - HAT_DOWN, - HAT_LEFT, - HAT_MAX, - }; - - enum { - JOYPADS_MAX = 16, - }; - - struct JoyAxis { - int min; - float value; - }; - -private: enum JoyType { TYPE_BUTTON, TYPE_AXIS, @@ -185,38 +220,57 @@ private: List> accumulated_events; bool use_accumulated_input; + friend class DisplayServer; + + static void (*set_mouse_mode_func)(MouseMode); + static MouseMode (*get_mouse_mode_func)(); + static void (*warp_mouse_func)(const Vector2 &p_to_pos); + + static CursorShape (*get_current_cursor_shape_func)(); + static void (*set_custom_mouse_cursor_func)(const RES &, CursorShape, const Vector2 &); + + EventDispatchFunc event_dispatch_function; + +protected: + static void _bind_methods(); public: - virtual bool is_key_pressed(int p_keycode) const; - virtual bool is_mouse_button_pressed(int p_button) const; - virtual bool is_joy_button_pressed(int p_device, int p_button) const; - virtual bool is_action_pressed(const StringName &p_action) const; - virtual bool is_action_just_pressed(const StringName &p_action) const; - virtual bool is_action_just_released(const StringName &p_action) const; - virtual float get_action_strength(const StringName &p_action) const; + void set_mouse_mode(MouseMode p_mode); + MouseMode get_mouse_mode() const; + void get_argument_options(const StringName &p_function, int p_idx, List *r_options) const; - virtual float get_joy_axis(int p_device, int p_axis) const; + static InputFilter *get_singleton(); + + bool is_key_pressed(int p_keycode) const; + bool is_mouse_button_pressed(int p_button) const; + bool is_joy_button_pressed(int p_device, int p_button) const; + bool is_action_pressed(const StringName &p_action) const; + bool is_action_just_pressed(const StringName &p_action) const; + bool is_action_just_released(const StringName &p_action) const; + float get_action_strength(const StringName &p_action) const; + + float get_joy_axis(int p_device, int p_axis) const; String get_joy_name(int p_idx); - virtual Array get_connected_joypads(); - virtual Vector2 get_joy_vibration_strength(int p_device); - virtual float get_joy_vibration_duration(int p_device); - virtual uint64_t get_joy_vibration_timestamp(int p_device); + Array get_connected_joypads(); + Vector2 get_joy_vibration_strength(int p_device); + float get_joy_vibration_duration(int p_device); + uint64_t get_joy_vibration_timestamp(int p_device); void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid = ""); void parse_joypad_mapping(String p_mapping, bool p_update_existing); - virtual Vector3 get_gravity() const; - virtual Vector3 get_accelerometer() const; - virtual Vector3 get_magnetometer() const; - virtual Vector3 get_gyroscope() const; + Vector3 get_gravity() const; + Vector3 get_accelerometer() const; + Vector3 get_magnetometer() const; + Vector3 get_gyroscope() const; - virtual Point2 get_mouse_position() const; - virtual Point2 get_last_mouse_speed() const; - virtual int get_mouse_button_mask() const; + Point2 get_mouse_position() const; + Point2 get_last_mouse_speed() const; + int get_mouse_button_mask() const; - virtual void warp_mouse_position(const Vector2 &p_to); - virtual Point2i warp_mouse_motion(const Ref &p_motion, const Rect2 &p_rect); + void warp_mouse_position(const Vector2 &p_to); + Point2i warp_mouse_motion(const Ref &p_motion, const Rect2 &p_rect); - virtual void parse_input_event(const Ref &p_event); + void parse_input_event(const Ref &p_event); void set_gravity(const Vector3 &p_gravity); void set_accelerometer(const Vector3 &p_accel); @@ -224,11 +278,10 @@ public: void set_gyroscope(const Vector3 &p_gyroscope); void set_joy_axis(int p_device, int p_axis, float p_value); - virtual void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0); - virtual void stop_joy_vibration(int p_device); - virtual void vibrate_handheld(int p_duration_ms = 500); + void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0); + void stop_joy_vibration(int p_device); + void vibrate_handheld(int p_duration_ms = 500); - void set_main_loop(MainLoop *p_main_loop); void set_mouse_position(const Point2 &p_posf); void action_press(const StringName &p_action, float p_strength = 1.f); @@ -237,44 +290,48 @@ public: void iteration(float p_step); void set_emulate_touch_from_mouse(bool p_emulate); - virtual bool is_emulating_touch_from_mouse() const; + bool is_emulating_touch_from_mouse() const; void ensure_touch_mouse_raised(); void set_emulate_mouse_from_touch(bool p_emulate); - virtual bool is_emulating_mouse_from_touch() const; + bool is_emulating_mouse_from_touch() const; - virtual CursorShape get_default_cursor_shape() const; - virtual void set_default_cursor_shape(CursorShape p_shape); - virtual CursorShape get_current_cursor_shape() const; - virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = Input::CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()); + CursorShape get_default_cursor_shape() const; + void set_default_cursor_shape(CursorShape p_shape); + CursorShape get_current_cursor_shape() const; + void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = InputFilter::CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()); void parse_mapping(String p_mapping); void joy_button(int p_device, int p_button, bool p_pressed); void joy_axis(int p_device, int p_axis, const JoyAxis &p_value); void joy_hat(int p_device, int p_val); - virtual void add_joy_mapping(String p_mapping, bool p_update_existing = false); - virtual void remove_joy_mapping(String p_guid); - virtual bool is_joy_known(int p_device); - virtual String get_joy_guid(int p_device) const; + void add_joy_mapping(String p_mapping, bool p_update_existing = false); + void remove_joy_mapping(String p_guid); - virtual String get_joy_button_string(int p_button); - virtual String get_joy_axis_string(int p_axis); - virtual int get_joy_axis_index_from_string(String p_axis); - virtual int get_joy_button_index_from_string(String p_button); + String get_joy_button_string(int p_button); + String get_joy_axis_string(int p_axis); + int get_joy_axis_index_from_string(String p_axis); + int get_joy_button_index_from_string(String p_button); int get_unused_joy_id(); - bool is_joy_mapped(int p_device); - String get_joy_guid_remapped(int p_device) const; + bool is_joy_known(int p_device); + String get_joy_guid(int p_device) const; void set_fallback_mapping(String p_guid); - virtual void accumulate_input_event(const Ref &p_event); - virtual void flush_accumulated_events(); - virtual void set_use_accumulated_input(bool p_enable); + void accumulate_input_event(const Ref &p_event); + void flush_accumulated_events(); + void set_use_accumulated_input(bool p_enable); - virtual void release_pressed_events(); - InputDefault(); + void release_pressed_events(); + + void set_event_dispatch_function(EventDispatchFunc p_function); + + InputFilter(); }; -#endif // INPUT_DEFAULT_H +VARIANT_ENUM_CAST(InputFilter::MouseMode); +VARIANT_ENUM_CAST(InputFilter::CursorShape); + +#endif // INPUT_H diff --git a/core/input_map.cpp b/core/input/input_map.cpp similarity index 100% rename from core/input_map.cpp rename to core/input/input_map.cpp diff --git a/core/input_map.h b/core/input/input_map.h similarity index 99% rename from core/input_map.h rename to core/input/input_map.h index 6039d915c9..de6f57b0bf 100644 --- a/core/input_map.h +++ b/core/input/input_map.h @@ -31,8 +31,8 @@ #ifndef INPUT_MAP_H #define INPUT_MAP_H +#include "core/input/input_event.h" #include "core/object.h" -#include "core/os/input_event.h" class InputMap : public Object { diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h index d09242e2f1..7ae0a788bd 100644 --- a/core/method_ptrcall.h +++ b/core/method_ptrcall.h @@ -118,6 +118,9 @@ MAKE_PTRARG(String); MAKE_PTRARG(Vector2); MAKE_PTRARG(Rect2); MAKE_PTRARG_BY_REFERENCE(Vector3); +MAKE_PTRARG(Vector2i); +MAKE_PTRARG(Rect2i); +MAKE_PTRARG_BY_REFERENCE(Vector3i); MAKE_PTRARG(Transform2D); MAKE_PTRARG_BY_REFERENCE(Plane); MAKE_PTRARG(Quat); diff --git a/core/os/input.cpp b/core/os/input.cpp deleted file mode 100644 index 1768b851df..0000000000 --- a/core/os/input.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/*************************************************************************/ -/* input.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "input.h" - -#include "core/input_map.h" -#include "core/os/os.h" -#include "core/project_settings.h" - -#ifdef TOOLS_ENABLED -#include "editor/editor_settings.h" -#endif - -Input *Input::singleton = NULL; - -Input *Input::get_singleton() { - - return singleton; -} - -void Input::set_mouse_mode(MouseMode p_mode) { - ERR_FAIL_INDEX((int)p_mode, 4); - OS::get_singleton()->set_mouse_mode((OS::MouseMode)p_mode); -} - -Input::MouseMode Input::get_mouse_mode() const { - - return (MouseMode)OS::get_singleton()->get_mouse_mode(); -} - -void Input::_bind_methods() { - - ClassDB::bind_method(D_METHOD("is_key_pressed", "keycode"), &Input::is_key_pressed); - ClassDB::bind_method(D_METHOD("is_mouse_button_pressed", "button"), &Input::is_mouse_button_pressed); - ClassDB::bind_method(D_METHOD("is_joy_button_pressed", "device", "button"), &Input::is_joy_button_pressed); - ClassDB::bind_method(D_METHOD("is_action_pressed", "action"), &Input::is_action_pressed); - ClassDB::bind_method(D_METHOD("is_action_just_pressed", "action"), &Input::is_action_just_pressed); - ClassDB::bind_method(D_METHOD("is_action_just_released", "action"), &Input::is_action_just_released); - ClassDB::bind_method(D_METHOD("get_action_strength", "action"), &Input::get_action_strength); - ClassDB::bind_method(D_METHOD("add_joy_mapping", "mapping", "update_existing"), &Input::add_joy_mapping, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("remove_joy_mapping", "guid"), &Input::remove_joy_mapping); - ClassDB::bind_method(D_METHOD("joy_connection_changed", "device", "connected", "name", "guid"), &Input::joy_connection_changed); - ClassDB::bind_method(D_METHOD("is_joy_known", "device"), &Input::is_joy_known); - ClassDB::bind_method(D_METHOD("get_joy_axis", "device", "axis"), &Input::get_joy_axis); - ClassDB::bind_method(D_METHOD("get_joy_name", "device"), &Input::get_joy_name); - ClassDB::bind_method(D_METHOD("get_joy_guid", "device"), &Input::get_joy_guid); - ClassDB::bind_method(D_METHOD("get_connected_joypads"), &Input::get_connected_joypads); - ClassDB::bind_method(D_METHOD("get_joy_vibration_strength", "device"), &Input::get_joy_vibration_strength); - ClassDB::bind_method(D_METHOD("get_joy_vibration_duration", "device"), &Input::get_joy_vibration_duration); - ClassDB::bind_method(D_METHOD("get_joy_button_string", "button_index"), &Input::get_joy_button_string); - ClassDB::bind_method(D_METHOD("get_joy_button_index_from_string", "button"), &Input::get_joy_button_index_from_string); - ClassDB::bind_method(D_METHOD("get_joy_axis_string", "axis_index"), &Input::get_joy_axis_string); - ClassDB::bind_method(D_METHOD("get_joy_axis_index_from_string", "axis"), &Input::get_joy_axis_index_from_string); - ClassDB::bind_method(D_METHOD("start_joy_vibration", "device", "weak_magnitude", "strong_magnitude", "duration"), &Input::start_joy_vibration, DEFVAL(0)); - ClassDB::bind_method(D_METHOD("stop_joy_vibration", "device"), &Input::stop_joy_vibration); - ClassDB::bind_method(D_METHOD("vibrate_handheld", "duration_ms"), &Input::vibrate_handheld, DEFVAL(500)); - ClassDB::bind_method(D_METHOD("get_gravity"), &Input::get_gravity); - ClassDB::bind_method(D_METHOD("get_accelerometer"), &Input::get_accelerometer); - ClassDB::bind_method(D_METHOD("get_magnetometer"), &Input::get_magnetometer); - ClassDB::bind_method(D_METHOD("get_gyroscope"), &Input::get_gyroscope); - //ClassDB::bind_method(D_METHOD("get_mouse_position"),&Input::get_mouse_position); - this is not the function you want - ClassDB::bind_method(D_METHOD("get_last_mouse_speed"), &Input::get_last_mouse_speed); - ClassDB::bind_method(D_METHOD("get_mouse_button_mask"), &Input::get_mouse_button_mask); - ClassDB::bind_method(D_METHOD("set_mouse_mode", "mode"), &Input::set_mouse_mode); - ClassDB::bind_method(D_METHOD("get_mouse_mode"), &Input::get_mouse_mode); - ClassDB::bind_method(D_METHOD("warp_mouse_position", "to"), &Input::warp_mouse_position); - ClassDB::bind_method(D_METHOD("action_press", "action", "strength"), &Input::action_press, DEFVAL(1.f)); - ClassDB::bind_method(D_METHOD("action_release", "action"), &Input::action_release); - ClassDB::bind_method(D_METHOD("set_default_cursor_shape", "shape"), &Input::set_default_cursor_shape, DEFVAL(CURSOR_ARROW)); - ClassDB::bind_method(D_METHOD("get_current_cursor_shape"), &Input::get_current_cursor_shape); - ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image", "shape", "hotspot"), &Input::set_custom_mouse_cursor, DEFVAL(CURSOR_ARROW), DEFVAL(Vector2())); - ClassDB::bind_method(D_METHOD("parse_input_event", "event"), &Input::parse_input_event); - ClassDB::bind_method(D_METHOD("set_use_accumulated_input", "enable"), &Input::set_use_accumulated_input); - - BIND_ENUM_CONSTANT(MOUSE_MODE_VISIBLE); - BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN); - BIND_ENUM_CONSTANT(MOUSE_MODE_CAPTURED); - BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED); - - BIND_ENUM_CONSTANT(CURSOR_ARROW); - BIND_ENUM_CONSTANT(CURSOR_IBEAM); - BIND_ENUM_CONSTANT(CURSOR_POINTING_HAND); - BIND_ENUM_CONSTANT(CURSOR_CROSS); - BIND_ENUM_CONSTANT(CURSOR_WAIT); - BIND_ENUM_CONSTANT(CURSOR_BUSY); - BIND_ENUM_CONSTANT(CURSOR_DRAG); - BIND_ENUM_CONSTANT(CURSOR_CAN_DROP); - BIND_ENUM_CONSTANT(CURSOR_FORBIDDEN); - BIND_ENUM_CONSTANT(CURSOR_VSIZE); - BIND_ENUM_CONSTANT(CURSOR_HSIZE); - BIND_ENUM_CONSTANT(CURSOR_BDIAGSIZE); - BIND_ENUM_CONSTANT(CURSOR_FDIAGSIZE); - BIND_ENUM_CONSTANT(CURSOR_MOVE); - BIND_ENUM_CONSTANT(CURSOR_VSPLIT); - BIND_ENUM_CONSTANT(CURSOR_HSPLIT); - BIND_ENUM_CONSTANT(CURSOR_HELP); - - ADD_SIGNAL(MethodInfo("joy_connection_changed", PropertyInfo(Variant::INT, "device"), PropertyInfo(Variant::BOOL, "connected"))); -} - -void Input::get_argument_options(const StringName &p_function, int p_idx, List *r_options) const { -#ifdef TOOLS_ENABLED - - const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\""; - - String pf = p_function; - if (p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" || pf == "is_action_just_pressed" || pf == "is_action_just_released" || pf == "get_action_strength")) { - - List pinfo; - ProjectSettings::get_singleton()->get_property_list(&pinfo); - - for (List::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(quote_style + name + quote_style); - } - } -#endif -} - -Input::Input() { - - singleton = this; -} - -////////////////////////////////////////////////////////// diff --git a/core/os/input.h b/core/os/input.h deleted file mode 100644 index 55e0511080..0000000000 --- a/core/os/input.h +++ /dev/null @@ -1,146 +0,0 @@ -/*************************************************************************/ -/* input.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef INPUT_H -#define INPUT_H - -#include "core/object.h" -#include "core/os/main_loop.h" -#include "core/os/thread_safe.h" - -class Input : public Object { - - GDCLASS(Input, Object); - - static Input *singleton; - -protected: - static void _bind_methods(); - -public: - enum MouseMode { - MOUSE_MODE_VISIBLE, - MOUSE_MODE_HIDDEN, - MOUSE_MODE_CAPTURED, - MOUSE_MODE_CONFINED - }; - -#undef CursorShape - enum CursorShape { - CURSOR_ARROW, - CURSOR_IBEAM, - CURSOR_POINTING_HAND, - CURSOR_CROSS, - CURSOR_WAIT, - CURSOR_BUSY, - CURSOR_DRAG, - CURSOR_CAN_DROP, - CURSOR_FORBIDDEN, - CURSOR_VSIZE, - CURSOR_HSIZE, - CURSOR_BDIAGSIZE, - CURSOR_FDIAGSIZE, - CURSOR_MOVE, - CURSOR_VSPLIT, - CURSOR_HSPLIT, - CURSOR_HELP, - CURSOR_MAX - }; - - void set_mouse_mode(MouseMode p_mode); - MouseMode get_mouse_mode() const; - - static Input *get_singleton(); - - virtual bool is_key_pressed(int p_keycode) const = 0; - virtual bool is_mouse_button_pressed(int p_button) const = 0; - virtual bool is_joy_button_pressed(int p_device, int p_button) const = 0; - virtual bool is_action_pressed(const StringName &p_action) const = 0; - virtual bool is_action_just_pressed(const StringName &p_action) const = 0; - virtual bool is_action_just_released(const StringName &p_action) const = 0; - virtual float get_action_strength(const StringName &p_action) const = 0; - - virtual float get_joy_axis(int p_device, int p_axis) const = 0; - virtual String get_joy_name(int p_idx) = 0; - virtual Array get_connected_joypads() = 0; - virtual void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) = 0; - virtual void add_joy_mapping(String p_mapping, bool p_update_existing = false) = 0; - virtual void remove_joy_mapping(String p_guid) = 0; - virtual bool is_joy_known(int p_device) = 0; - virtual String get_joy_guid(int p_device) const = 0; - virtual Vector2 get_joy_vibration_strength(int p_device) = 0; - virtual float get_joy_vibration_duration(int p_device) = 0; - virtual uint64_t get_joy_vibration_timestamp(int p_device) = 0; - virtual void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0) = 0; - virtual void stop_joy_vibration(int p_device) = 0; - virtual void vibrate_handheld(int p_duration_ms = 500) = 0; - - virtual Point2 get_mouse_position() const = 0; - virtual Point2 get_last_mouse_speed() const = 0; - virtual int get_mouse_button_mask() const = 0; - - virtual void warp_mouse_position(const Vector2 &p_to) = 0; - virtual Point2i warp_mouse_motion(const Ref &p_motion, const Rect2 &p_rect) = 0; - - virtual Vector3 get_gravity() const = 0; - virtual Vector3 get_accelerometer() const = 0; - virtual Vector3 get_magnetometer() const = 0; - virtual Vector3 get_gyroscope() const = 0; - - virtual void action_press(const StringName &p_action, float p_strength = 1.f) = 0; - virtual void action_release(const StringName &p_action) = 0; - - void get_argument_options(const StringName &p_function, int p_idx, List *r_options) const; - - virtual bool is_emulating_touch_from_mouse() const = 0; - virtual bool is_emulating_mouse_from_touch() const = 0; - - virtual CursorShape get_default_cursor_shape() const = 0; - virtual void set_default_cursor_shape(CursorShape p_shape) = 0; - virtual CursorShape get_current_cursor_shape() const = 0; - virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()) = 0; - - virtual String get_joy_button_string(int p_button) = 0; - virtual String get_joy_axis_string(int p_axis) = 0; - virtual int get_joy_button_index_from_string(String p_button) = 0; - virtual int get_joy_axis_index_from_string(String p_axis) = 0; - - virtual void parse_input_event(const Ref &p_event) = 0; - virtual void accumulate_input_event(const Ref &p_event) = 0; - virtual void flush_accumulated_events() = 0; - virtual void set_use_accumulated_input(bool p_enable) = 0; - - Input(); -}; - -VARIANT_ENUM_CAST(Input::MouseMode); -VARIANT_ENUM_CAST(Input::CursorShape); - -#endif // INPUT_H diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index ab43ce4af7..0d1a080682 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -34,30 +34,16 @@ void MainLoop::_bind_methods() { - ClassDB::bind_method(D_METHOD("input_event", "event"), &MainLoop::input_event); - ClassDB::bind_method(D_METHOD("input_text", "text"), &MainLoop::input_text); ClassDB::bind_method(D_METHOD("init"), &MainLoop::init); ClassDB::bind_method(D_METHOD("iteration", "delta"), &MainLoop::iteration); ClassDB::bind_method(D_METHOD("idle", "delta"), &MainLoop::idle); ClassDB::bind_method(D_METHOD("finish"), &MainLoop::finish); - BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); - BIND_VMETHOD(MethodInfo("_input_text", PropertyInfo(Variant::STRING, "text"))); BIND_VMETHOD(MethodInfo("_initialize")); BIND_VMETHOD(MethodInfo(Variant::BOOL, "_iteration", PropertyInfo(Variant::FLOAT, "delta"))); BIND_VMETHOD(MethodInfo(Variant::BOOL, "_idle", PropertyInfo(Variant::FLOAT, "delta"))); - BIND_VMETHOD(MethodInfo("_drop_files", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files"), PropertyInfo(Variant::INT, "from_screen"))); BIND_VMETHOD(MethodInfo("_finalize")); - BIND_VMETHOD(MethodInfo("_global_menu_action", PropertyInfo(Variant::NIL, "id"), PropertyInfo(Variant::NIL, "meta"))); - - BIND_CONSTANT(NOTIFICATION_WM_MOUSE_ENTER); - BIND_CONSTANT(NOTIFICATION_WM_MOUSE_EXIT); - BIND_CONSTANT(NOTIFICATION_WM_FOCUS_IN); - BIND_CONSTANT(NOTIFICATION_WM_FOCUS_OUT); - BIND_CONSTANT(NOTIFICATION_WM_QUIT_REQUEST); - BIND_CONSTANT(NOTIFICATION_WM_GO_BACK_REQUEST); - BIND_CONSTANT(NOTIFICATION_WM_UNFOCUS_REQUEST); BIND_CONSTANT(NOTIFICATION_OS_MEMORY_WARNING); BIND_CONSTANT(NOTIFICATION_TRANSLATION_CHANGED); BIND_CONSTANT(NOTIFICATION_WM_ABOUT); @@ -80,18 +66,6 @@ MainLoop::MainLoop() { MainLoop::~MainLoop() { } -void MainLoop::input_text(const String &p_text) { - - if (get_script_instance()) - get_script_instance()->call("_input_text", p_text); -} - -void MainLoop::input_event(const Ref &p_event) { - - if (get_script_instance()) - get_script_instance()->call("_input_event", p_event); -} - void MainLoop::init() { if (init_script.is_valid()) @@ -115,18 +89,6 @@ bool MainLoop::idle(float p_time) { return false; } -void MainLoop::drop_files(const Vector &p_files, int p_from_screen) { - - if (get_script_instance()) - get_script_instance()->call("_drop_files", p_files, p_from_screen); -} - -void MainLoop::global_menu_action(const Variant &p_id, const Variant &p_meta) { - - if (get_script_instance()) - get_script_instance()->call("_global_menu_action", p_id, p_meta); -} - void MainLoop::finish() { if (get_script_instance()) { diff --git a/core/os/main_loop.h b/core/os/main_loop.h index 3fdfb77af2..8f6c8c91b1 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -31,7 +31,7 @@ #ifndef MAIN_LOOP_H #define MAIN_LOOP_H -#include "core/os/input_event.h" +#include "core/input/input_event.h" #include "core/reference.h" #include "core/script_language.h" @@ -48,33 +48,20 @@ protected: public: enum { //make sure these are replicated in Node - NOTIFICATION_WM_MOUSE_ENTER = 1002, - NOTIFICATION_WM_MOUSE_EXIT = 1003, - NOTIFICATION_WM_FOCUS_IN = 1004, - NOTIFICATION_WM_FOCUS_OUT = 1005, - NOTIFICATION_WM_QUIT_REQUEST = 1006, - NOTIFICATION_WM_GO_BACK_REQUEST = 1007, - NOTIFICATION_WM_UNFOCUS_REQUEST = 1008, - NOTIFICATION_OS_MEMORY_WARNING = 1009, - NOTIFICATION_TRANSLATION_CHANGED = 1010, - NOTIFICATION_WM_ABOUT = 1011, - NOTIFICATION_CRASH = 1012, - NOTIFICATION_OS_IME_UPDATE = 1013, - NOTIFICATION_APP_RESUMED = 1014, - NOTIFICATION_APP_PAUSED = 1015, + NOTIFICATION_OS_MEMORY_WARNING = 2009, + NOTIFICATION_TRANSLATION_CHANGED = 2010, + NOTIFICATION_WM_ABOUT = 2011, + NOTIFICATION_CRASH = 2012, + NOTIFICATION_OS_IME_UPDATE = 2013, + NOTIFICATION_APP_RESUMED = 2014, + NOTIFICATION_APP_PAUSED = 2015, }; - virtual void input_event(const Ref &p_event); - virtual void input_text(const String &p_text); - virtual void init(); virtual bool iteration(float p_time); virtual bool idle(float p_time); virtual void finish(); - virtual void drop_files(const Vector &p_files, int p_from_screen = 0); - virtual void global_menu_action(const Variant &p_id, const Variant &p_meta); - void set_init_script(const Ref