diff options
Diffstat (limited to 'core/os')
-rw-r--r-- | core/os/file_access.cpp | 17 | ||||
-rw-r--r-- | core/os/file_access.h | 1 | ||||
-rw-r--r-- | core/os/input.cpp | 1 | ||||
-rw-r--r-- | core/os/input.h | 3 | ||||
-rw-r--r-- | core/os/input_event.cpp | 57 | ||||
-rw-r--r-- | core/os/input_event.h | 7 | ||||
-rw-r--r-- | core/os/main_loop.h | 28 | ||||
-rw-r--r-- | core/os/midi_driver.cpp | 5 | ||||
-rw-r--r-- | core/os/os.cpp | 11 | ||||
-rw-r--r-- | core/os/os.h | 25 | ||||
-rw-r--r-- | core/os/shell.cpp | 46 | ||||
-rw-r--r-- | core/os/shell.h | 52 |
12 files changed, 129 insertions, 124 deletions
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index d1f8236898..39d9f45bd7 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -409,6 +409,23 @@ int FileAccess::get_buffer(uint8_t *p_dst, int p_length) const { return i; } +String FileAccess::get_as_utf8_string() const { + PoolVector<uint8_t> sourcef; + int len = get_len(); + sourcef.resize(len + 1); + + PoolVector<uint8_t>::Write w = sourcef.write(); + int r = get_buffer(w.ptr(), len); + ERR_FAIL_COND_V(r != len, String()); + w[len] = 0; + + String s; + if (s.parse_utf8((const char *)w.ptr())) { + return String(); + } + return s; +} + void FileAccess::store_16(uint16_t p_dest) { uint8_t a, b; diff --git a/core/os/file_access.h b/core/os/file_access.h index 7bfbf6e7f0..c65b75369c 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -113,6 +113,7 @@ public: virtual String get_line() const; virtual String get_token() const; virtual Vector<String> get_csv_line(const String &p_delim = ",") const; + virtual String get_as_utf8_string() const; /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac) * It's not about the current CPU type but file formats. diff --git a/core/os/input.cpp b/core/os/input.cpp index cf11ba3c6d..caa9fb1493 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -91,6 +91,7 @@ void Input::_bind_methods() { ClassDB::bind_method(D_METHOD("set_default_cursor_shape", "shape"), &Input::set_default_cursor_shape, DEFVAL(CURSOR_ARROW)); 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); diff --git a/core/os/input.h b/core/os/input.h index b354acd961..c8b80b28d0 100644 --- a/core/os/input.h +++ b/core/os/input.h @@ -132,6 +132,9 @@ public: virtual int get_joy_axis_index_from_string(String p_axis) = 0; virtual void parse_input_event(const Ref<InputEvent> &p_event) = 0; + virtual void accumulate_input_event(const Ref<InputEvent> &p_event) = 0; + virtual void flush_accumulated_events() = 0; + virtual void set_use_accumulated_input(bool p_enable) = 0; Input(); }; diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 1e0e83c8d2..25a5c2afeb 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -33,6 +33,9 @@ #include "core/input_map.h" #include "core/os/keyboard.h" +const int InputEvent::DEVICE_ID_TOUCH_MOUSE = -1; +const int InputEvent::DEVICE_ID_INTERNAL = -2; + void InputEvent::set_device(int p_device) { device = p_device; } @@ -122,6 +125,8 @@ void InputEvent::_bind_methods() { ClassDB::bind_method(D_METHOD("is_action_type"), &InputEvent::is_action_type); + ClassDB::bind_method(D_METHOD("accumulate", "with_event"), &InputEvent::accumulate); + ClassDB::bind_method(D_METHOD("xformed_by", "xform", "local_ofs"), &InputEvent::xformed_by, DEFVAL(Vector2())); ADD_PROPERTY(PropertyInfo(Variant::INT, "device"), "set_device", "get_device"); @@ -620,6 +625,44 @@ String InputEventMouseMotion::as_text() const { return "InputEventMouseMotion : button_mask=" + button_mask_string + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")"; } +bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) { + + Ref<InputEventMouseMotion> motion = p_event; + if (motion.is_null()) + return false; + + if (is_pressed() != motion->is_pressed()) { + return false; + } + + if (get_button_mask() != motion->get_button_mask()) { + return false; + } + + if (get_shift() != motion->get_shift()) { + return false; + } + + if (get_control() != motion->get_control()) { + return false; + } + + if (get_alt() != motion->get_alt()) { + return false; + } + + if (get_metakey() != motion->get_metakey()) { + return false; + } + + set_position(motion->get_position()); + set_global_position(motion->get_global_position()); + set_speed(motion->get_speed()); + relative += motion->get_relative(); + + return true; +} + void InputEventMouseMotion::_bind_methods() { ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative); @@ -749,6 +792,15 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool * return match; } +bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) const { + + Ref<InputEventJoypadButton> button = p_event; + if (button.is_null()) + return false; + + return button_index == button->button_index; +} + String InputEventJoypadButton::as_text() const { return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure)); @@ -950,11 +1002,10 @@ bool InputEventAction::is_pressed() const { } bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const { - Ref<InputEventKey> event = p_event; - if (event.is_null()) + if (p_event.is_null()) return false; - return event->is_action(action); + return p_event->is_action(action); } bool InputEventAction::is_action(const StringName &p_action) const { diff --git a/core/os/input_event.h b/core/os/input_event.h index db31055b5f..ba01516519 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -165,6 +165,9 @@ protected: static void _bind_methods(); public: + static const int DEVICE_ID_TOUCH_MOUSE; + static const int DEVICE_ID_INTERNAL; + void set_device(int p_device); int get_device() const; @@ -186,6 +189,7 @@ public: virtual bool shortcut_match(const Ref<InputEvent> &p_event) const; virtual bool is_action_type() const; + virtual bool accumulate(const Ref<InputEvent> &p_event) { return false; } InputEvent(); }; @@ -351,6 +355,8 @@ public: virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const; virtual String as_text() const; + virtual bool accumulate(const Ref<InputEvent> &p_event); + InputEventMouseMotion(); }; @@ -400,6 +406,7 @@ public: float get_pressure() const; virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const; + virtual bool shortcut_match(const Ref<InputEvent> &p_event) const; virtual bool is_action_type() const { return true; } virtual String as_text() const; diff --git a/core/os/main_loop.h b/core/os/main_loop.h index bfdf92acfa..ad734d3fc8 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -51,21 +51,19 @@ protected: public: enum { - NOTIFICATION_WM_MOUSE_ENTER = 2, - NOTIFICATION_WM_MOUSE_EXIT = 3, - NOTIFICATION_WM_FOCUS_IN = 4, - NOTIFICATION_WM_FOCUS_OUT = 5, - NOTIFICATION_WM_QUIT_REQUEST = 6, - NOTIFICATION_WM_GO_BACK_REQUEST = 7, - NOTIFICATION_WM_UNFOCUS_REQUEST = 8, - NOTIFICATION_OS_MEMORY_WARNING = 9, - // Note: NOTIFICATION_TRANSLATION_CHANGED and NOTIFICATION_WM_ABOUT used to have id=10 and id=11 but these - // conflict with NOTIFICATION_ENTER_TREE (id=10) and NOTIFICATION_EXIT_TREE (id=11), so id=90 and id=91 - // fixes this issue. - NOTIFICATION_TRANSLATION_CHANGED = 90, - NOTIFICATION_WM_ABOUT = 91, - NOTIFICATION_CRASH = 92, - NOTIFICATION_OS_IME_UPDATE = 93, + //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, }; virtual void input_event(const Ref<InputEvent> &p_event); diff --git a/core/os/midi_driver.cpp b/core/os/midi_driver.cpp index 0d7ad23d68..7cb7ae130f 100644 --- a/core/os/midi_driver.cpp +++ b/core/os/midi_driver.cpp @@ -75,6 +75,11 @@ void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_ if (length >= 3) { event->set_pitch(data[1]); event->set_velocity(data[2]); + + if (event->get_message() == MIDI_MESSAGE_NOTE_ON && event->get_velocity() == 0) { + // https://www.midi.org/forum/228-writing-midi-software-send-note-off,-or-zero-velocity-note-on + event->set_message(MIDI_MESSAGE_NOTE_OFF); + } } break; diff --git a/core/os/os.cpp b/core/os/os.cpp index d2d39d253a..03e63f636e 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -569,6 +569,11 @@ int OS::get_power_percent_left() { return -1; } +void OS::set_has_server_feature_callback(HasServerFeatureCallback p_callback) { + + has_server_feature_callback = p_callback; +} + bool OS::has_feature(const String &p_feature) { if (p_feature == get_name()) @@ -625,6 +630,10 @@ bool OS::has_feature(const String &p_feature) { if (_check_internal_feature_support(p_feature)) return true; + if (has_server_feature_callback && has_server_feature_callback(p_feature)) { + return true; + } + if (ProjectSettings::get_singleton()->has_custom_feature(p_feature)) return true; @@ -729,6 +738,8 @@ OS::OS() { _logger = NULL; + has_server_feature_callback = NULL; + Vector<Logger *> loggers; loggers.push_back(memnew(StdLogger)); _set_logger(memnew(CompositeLogger(loggers))); diff --git a/core/os/os.h b/core/os/os.h index a08bdcb608..d02d5a2c84 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -45,12 +45,6 @@ @author Juan Linietsky <reduzio@gmail.com> */ -enum VideoDriver { - VIDEO_DRIVER_GLES3, - VIDEO_DRIVER_GLES2, - VIDEO_DRIVER_MAX, -}; - class OS { static OS *singleton; @@ -83,6 +77,7 @@ protected: public: typedef void (*ImeCallback)(void *p_inp, String p_text, Point2 p_selection); + typedef bool (*HasServerFeatureCallback)(const String &p_feature); enum PowerState { POWERSTATE_UNKNOWN, /**< cannot determine power status */ @@ -127,6 +122,7 @@ public: protected: friend class Main; + HasServerFeatureCallback has_server_feature_callback; RenderThreadMode _render_thread_mode; // functions used by main to initialize/deinitialize the OS @@ -152,8 +148,8 @@ public: static OS *get_singleton(); void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, Logger::ErrorType p_type = Logger::ERR_ERROR); - void print(const char *p_format, ...); - void printerr(const char *p_format, ...); + void print(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3; + void printerr(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3; virtual void alert(const String &p_alert, const String &p_title = "ALERT!") = 0; virtual String get_stdin_string(bool p_block = true) = 0; @@ -184,9 +180,16 @@ public: virtual VideoMode get_video_mode(int p_screen = 0) const = 0; virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const = 0; + enum VideoDriver { + VIDEO_DRIVER_GLES3, + VIDEO_DRIVER_GLES2, + VIDEO_DRIVER_MAX, + }; + virtual int get_video_driver_count() const; virtual const char *get_video_driver_name(int p_driver) const; virtual int get_current_video_driver() const = 0; + virtual int get_audio_driver_count() const; virtual const char *get_audio_driver_name(int p_driver) const; @@ -266,6 +269,7 @@ public: virtual bool has_environment(const String &p_var) const = 0; virtual String get_environment(const String &p_var) const = 0; + virtual bool set_environment(const String &p_var, const String &p_value) const = 0; virtual String get_name() = 0; virtual List<String> get_cmdline_args() const { return _cmdline; } @@ -505,6 +509,8 @@ public: virtual void force_process_input(){}; bool has_feature(const String &p_feature); + void set_has_server_feature_callback(HasServerFeatureCallback p_callback); + bool is_layered_allowed() const { return _allow_layered; } bool is_hidpi_allowed() const { return _allow_hidpi; } @@ -512,6 +518,9 @@ public: bool is_restart_on_exit_set() const; List<String> get_restart_on_exit_arguments() const; + virtual bool request_permission(const String &p_name) { return true; } + + virtual void process_and_drop_events() {} OS(); virtual ~OS(); }; diff --git a/core/os/shell.cpp b/core/os/shell.cpp deleted file mode 100644 index a859241cb6..0000000000 --- a/core/os/shell.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************/ -/* shell.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 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 "shell.h" - -Shell *Shell::singleton = NULL; - -Shell *Shell::get_singleton() { - - return singleton; -} - -Shell::~Shell() { -} - -Shell::Shell() { - - singleton = this; -} diff --git a/core/os/shell.h b/core/os/shell.h deleted file mode 100644 index c1bd995b5b..0000000000 --- a/core/os/shell.h +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************/ -/* shell.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 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 SHELL_H -#define SHELL_H - -#include "core/typedefs.h" -#include "core/ustring.h" - -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ -class Shell { - - static Shell *singleton; - -public: - static Shell *get_singleton(); - virtual void execute(String p_path) = 0; - - Shell(); - virtual ~Shell(); -}; - -#endif |