summaryrefslogtreecommitdiff
path: root/core/variant
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-11-12 23:39:17 +0100
committerGitHub <noreply@github.com>2021-11-12 23:39:17 +0100
commit5aae92f069b47c040d93e5edba2aad5b104fd1a5 (patch)
treee6d222c6488c1e4f1a9e4ffa68c1404473a00843 /core/variant
parent4f85cad013c5469a39287e9aa474735f950e302c (diff)
parent3c0fdcc8acfadb124fbfa914532868948561c351 (diff)
Merge pull request #51684 from aaronfranke/enum-class
Diffstat (limited to 'core/variant')
-rw-r--r--core/variant/binder_common.h2
-rw-r--r--core/variant/variant.h17
2 files changed, 18 insertions, 1 deletions
diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h
index f06d767cf5..98be62391f 100644
--- a/core/variant/binder_common.h
+++ b/core/variant/binder_common.h
@@ -80,7 +80,7 @@ struct VariantCaster<const T &> {
} \
typedef int64_t EncodeT; \
_FORCE_INLINE_ static void encode(m_enum p_val, const void *p_ptr) { \
- *(int64_t *)p_ptr = p_val; \
+ *(int64_t *)p_ptr = (int64_t)p_val; \
} \
};
diff --git a/core/variant/variant.h b/core/variant/variant.h
index 8ce5e7dcd2..230ed33c0c 100644
--- a/core/variant/variant.h
+++ b/core/variant/variant.h
@@ -31,6 +31,7 @@
#ifndef VARIANT_H
#define VARIANT_H
+#include "core/input/input_enums.h"
#include "core/io/ip_address.h"
#include "core/math/aabb.h"
#include "core/math/basis.h"
@@ -43,6 +44,7 @@
#include "core/math/vector3.h"
#include "core/math/vector3i.h"
#include "core/object/object_id.h"
+#include "core/os/keyboard.h"
#include "core/string/node_path.h"
#include "core/string/ustring.h"
#include "core/templates/rid.h"
@@ -430,6 +432,21 @@ public:
Variant(const IPAddress &p_address);
+#define VARIANT_ENUM_CLASS_CONSTRUCTOR(m_enum) \
+ Variant(const m_enum &p_value) { \
+ type = INT; \
+ _data._int = (int64_t)p_value; \
+ }
+
+ // Only enum classes that need to be bound need this to be defined.
+ VARIANT_ENUM_CLASS_CONSTRUCTOR(JoyAxis)
+ VARIANT_ENUM_CLASS_CONSTRUCTOR(JoyButton)
+ VARIANT_ENUM_CLASS_CONSTRUCTOR(Key)
+ VARIANT_ENUM_CLASS_CONSTRUCTOR(MIDIMessage)
+ VARIANT_ENUM_CLASS_CONSTRUCTOR(MouseButton)
+
+#undef VARIANT_ENUM_CLASS_CONSTRUCTOR
+
// If this changes the table in variant_op must be updated
enum Operator {
//comparison