summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/config/engine.cpp10
-rw-r--r--core/config/engine.h5
-rw-r--r--core/input/input_event.cpp34
-rw-r--r--core/input/input_event.h6
4 files changed, 51 insertions, 4 deletions
diff --git a/core/config/engine.cpp b/core/config/engine.cpp
index b0037ffb37..8e2ab094b0 100644
--- a/core/config/engine.cpp
+++ b/core/config/engine.cpp
@@ -219,3 +219,13 @@ Engine *Engine::get_singleton() {
Engine::Engine() {
singleton = this;
}
+
+Engine::Singleton::Singleton(const StringName &p_name, Object *p_ptr) :
+ name(p_name),
+ ptr(p_ptr) {
+#ifdef DEBUG_ENABLED
+ if (Object::cast_to<Reference>(p_ptr)) {
+ ERR_PRINT("A class intended to be used as a singleton must *not* inherit from Reference.");
+ }
+#endif
+}
diff --git a/core/config/engine.h b/core/config/engine.h
index 1d3d963b39..0d9aa02f28 100644
--- a/core/config/engine.h
+++ b/core/config/engine.h
@@ -41,10 +41,7 @@ public:
struct Singleton {
StringName name;
Object *ptr;
- Singleton(const StringName &p_name = StringName(), Object *p_ptr = nullptr) :
- name(p_name),
- ptr(p_ptr) {
- }
+ Singleton(const StringName &p_name = StringName(), Object *p_ptr = nullptr);
};
private:
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index 31ce1bb892..41bc5e84b0 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -143,6 +143,14 @@ int64_t InputEventFromWindow::get_window_id() const {
///////////////////////////////////
+void InputEventWithModifiers::set_store_command(bool p_enabled) {
+ store_command = p_enabled;
+}
+
+bool InputEventWithModifiers::is_storing_command() const {
+ return store_command;
+}
+
void InputEventWithModifiers::set_shift(bool p_enabled) {
shift = p_enabled;
}
@@ -191,6 +199,9 @@ void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModif
}
void InputEventWithModifiers::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_store_command", "enable"), &InputEventWithModifiers::set_store_command);
+ ClassDB::bind_method(D_METHOD("is_storing_command"), &InputEventWithModifiers::is_storing_command);
+
ClassDB::bind_method(D_METHOD("set_alt", "enable"), &InputEventWithModifiers::set_alt);
ClassDB::bind_method(D_METHOD("get_alt"), &InputEventWithModifiers::get_alt);
@@ -206,6 +217,7 @@ void InputEventWithModifiers::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_command", "enable"), &InputEventWithModifiers::set_command);
ClassDB::bind_method(D_METHOD("get_command"), &InputEventWithModifiers::get_command);
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "store_command"), "set_store_command", "is_storing_command");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alt"), "set_alt", "get_alt");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shift"), "set_shift", "get_shift");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "control"), "set_control", "get_control");
@@ -213,6 +225,28 @@ void InputEventWithModifiers::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command"), "set_command", "get_command");
}
+void InputEventWithModifiers::_validate_property(PropertyInfo &property) const {
+ if (store_command) {
+ // If we only want to Store "Command".
+#ifdef APPLE_STYLE_KEYS
+ // Don't store "Meta" on Mac.
+ if (property.name == "meta") {
+ property.usage ^= PROPERTY_USAGE_STORAGE;
+ }
+#else
+ // Don't store "Control".
+ if (property.name == "control") {
+ property.usage ^= PROPERTY_USAGE_STORAGE;
+ }
+#endif
+ } else {
+ // We don't want to store command, only control or meta (on mac).
+ if (property.name == "command") {
+ property.usage ^= PROPERTY_USAGE_STORAGE;
+ }
+ }
+}
+
///////////////////////////////////
void InputEventKey::set_pressed(bool p_pressed) {
diff --git a/core/input/input_event.h b/core/input/input_event.h
index b0e3b3cd95..0eae3a2bbe 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -163,6 +163,8 @@ public:
class InputEventWithModifiers : public InputEventFromWindow {
GDCLASS(InputEventWithModifiers, InputEventFromWindow);
+ bool store_command = true;
+
bool shift = false;
bool alt = false;
#ifdef APPLE_STYLE_KEYS
@@ -182,8 +184,12 @@ class InputEventWithModifiers : public InputEventFromWindow {
protected:
static void _bind_methods();
+ virtual void _validate_property(PropertyInfo &property) const override;
public:
+ void set_store_command(bool p_enabled);
+ bool is_storing_command() const;
+
void set_shift(bool p_enabled);
bool get_shift() const;