summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-05-07 21:16:51 +0200
committerGitHub <noreply@github.com>2020-05-07 21:16:51 +0200
commitae33cf5f458a57fbf8aa3ec0a65c94e86cd4d6f4 (patch)
treebad1a6e46923b7ea1f77d328bb47525e5e348d12 /core
parentbef52957d00c50323824e4fa0a778453214721cf (diff)
parent90df1d67cbc06f2742c11dad57ca940b9ed7c0d4 (diff)
Merge pull request #36379 from aaronfranke/color-constructors
Add a Color constructor for Color with alpha
Diffstat (limited to 'core')
-rw-r--r--core/color.h12
-rw-r--r--core/variant.cpp5
-rw-r--r--core/variant_call.cpp7
3 files changed, 18 insertions, 6 deletions
diff --git a/core/color.h b/core/color.h
index d95e80f5da..8b689fdde1 100644
--- a/core/color.h
+++ b/core/color.h
@@ -205,7 +205,7 @@ struct Color {
operator String() const;
/**
- * No construct parameters, r=0, g=0, b=0. a=255
+ * No construct parameters, r=0, g=0, b=0. a=1
*/
_FORCE_INLINE_ Color() {
r = 0;
@@ -223,6 +223,16 @@ struct Color {
b = p_b;
a = p_a;
}
+
+ /**
+ * Construct a Color from another Color, but with the specified alpha value.
+ */
+ _FORCE_INLINE_ Color(const Color &p_c, float p_a) {
+ r = p_c.r;
+ g = p_c.g;
+ b = p_c.b;
+ a = p_a;
+ }
};
bool Color::operator<(const Color &p_color) const {
diff --git a/core/variant.cpp b/core/variant.cpp
index b3611536b8..a91876dd98 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -102,11 +102,6 @@ String Variant::get_type_name(Variant::Type p_type) {
return "Plane";
} break;
- /*
- case QUAT: {
-
-
- } break;*/
case AABB: {
return "AABB";
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 09094f3cc8..9fffb42ff6 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -1075,6 +1075,11 @@ struct _VariantCall {
r_ret = Color::hex(*p_args[0]);
}
+ static void Color_init5(Variant &r_ret, const Variant **p_args) {
+
+ r_ret = Color(((Color)(*p_args[0])), *p_args[1]);
+ }
+
static void AABB_init1(Variant &r_ret, const Variant **p_args) {
r_ret = ::AABB(*p_args[0], *p_args[1]);
@@ -2211,6 +2216,8 @@ void register_variant_methods() {
_VariantCall::add_constructor(_VariantCall::Color_init1, Variant::COLOR, "r", Variant::FLOAT, "g", Variant::FLOAT, "b", Variant::FLOAT, "a", Variant::FLOAT);
_VariantCall::add_constructor(_VariantCall::Color_init2, Variant::COLOR, "r", Variant::FLOAT, "g", Variant::FLOAT, "b", Variant::FLOAT);
+ // init3 and init4 are the constructors for HTML hex strings and integers respectively which don't need binding here, so we skip to init5.
+ _VariantCall::add_constructor(_VariantCall::Color_init5, Variant::COLOR, "c", Variant::COLOR, "a", Variant::FLOAT);
_VariantCall::add_constructor(_VariantCall::AABB_init1, Variant::AABB, "position", Variant::VECTOR3, "size", Variant::VECTOR3);