diff options
Diffstat (limited to 'core/os')
-rw-r--r-- | core/os/file_access.cpp | 2 | ||||
-rw-r--r-- | core/os/input_event.cpp | 24 | ||||
-rw-r--r-- | core/os/input_event.h | 9 | ||||
-rw-r--r-- | core/os/os.cpp | 22 | ||||
-rw-r--r-- | core/os/os.h | 2 |
5 files changed, 50 insertions, 9 deletions
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 5fdd2b9135..7b2062936b 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -481,7 +481,7 @@ Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path) { ERR_FAIL_COND_V(!f, Vector<uint8_t>()); Vector<uint8_t> data; data.resize(f->get_len()); - f->get_buffer(data.ptr(), data.size()); + f->get_buffer(data.ptrw(), data.size()); memdelete(f); return data; } diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 3cdd9ae0e0..9b2bd30868 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -939,6 +939,14 @@ void InputEventGesture::set_position(const Vector2 &p_pos) { pos = p_pos; } +void InputEventGesture::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventGesture::set_position); + ClassDB::bind_method(D_METHOD("get_position"), &InputEventGesture::get_position); + + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position"); +} + Vector2 InputEventGesture::get_position() const { return pos; @@ -970,6 +978,14 @@ Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, return ev; } +void InputEventMagnifyGesture::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMagnifyGesture::set_factor); + ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMagnifyGesture::get_factor); + + ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor"); +} + InputEventMagnifyGesture::InputEventMagnifyGesture() { factor = 1.0; @@ -1000,6 +1016,14 @@ Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, con return ev; } +void InputEventPanGesture::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_delta", "delta"), &InputEventPanGesture::set_delta); + ClassDB::bind_method(D_METHOD("get_delta"), &InputEventPanGesture::get_delta); + + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "delta"), "set_delta", "get_delta"); +} + InputEventPanGesture::InputEventPanGesture() { delta = Vector2(0, 0); diff --git a/core/os/input_event.h b/core/os/input_event.h index 2cba60bede..614a3289ba 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -476,6 +476,9 @@ class InputEventGesture : public InputEventWithModifiers { Vector2 pos; +protected: + static void _bind_methods(); + public: void set_position(const Vector2 &p_pos); Vector2 get_position() const; @@ -486,6 +489,9 @@ class InputEventMagnifyGesture : public InputEventGesture { GDCLASS(InputEventMagnifyGesture, InputEventGesture) real_t factor; +protected: + static void _bind_methods(); + public: void set_factor(real_t p_factor); real_t get_factor() const; @@ -500,6 +506,9 @@ class InputEventPanGesture : public InputEventGesture { GDCLASS(InputEventPanGesture, InputEventGesture) Vector2 delta; +protected: + static void _bind_methods(); + public: void set_delta(const Vector2 &p_delta); Vector2 get_delta() const; diff --git a/core/os/os.cpp b/core/os/os.cpp index a39dfcc003..8088a6fa74 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -279,14 +279,22 @@ String OS::get_locale() const { return "en"; } -// Helper function used by OS_Unix and OS_Windows -String OS::get_safe_application_name() const { - String an = ProjectSettings::get_singleton()->get("application/config/name"); - Vector<String> invalid_char = String("\\ / : * ? \" < > |").split(" "); - for (int i = 0; i < invalid_char.size(); i++) { - an = an.replace(invalid_char[i], "-"); +// Helper function to ensure that a dir name/path will be valid on the OS +String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator) const { + + Vector<String> invalid_chars = String(": * ? \" < > |").split(" "); + if (p_allow_dir_separator) { + // Dir separators are allowed, but disallow ".." to avoid going up the filesystem + invalid_chars.push_back(".."); + } else { + invalid_chars.push_back("/"); + } + + String safe_dir_name = p_dir_name.replace("\\", "/").strip_edges(); + for (int i = 0; i < invalid_chars.size(); i++) { + safe_dir_name = safe_dir_name.replace(invalid_chars[i], "-"); } - return an; + return safe_dir_name; } // Path to data, config, cache, etc. OS-specific folders diff --git a/core/os/os.h b/core/os/os.h index d7a1512e39..c72696fe37 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -338,7 +338,7 @@ public: virtual String get_locale() const; - String get_safe_application_name() const; + String get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator = false) const; virtual String get_godot_dir_name() const; virtual String get_data_path() const; |