From 464b0b5e08a1c51e2feeb96a525bdf32791e0b14 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 15 Apr 2023 11:02:41 +0200 Subject: [PATCH] Ported: Add Color + alpha constructor for Color - timothyqiu https://github.com/godotengine/godot/commit/3544cd1dad902232291c091a778ef3b93546b46a --- core/variant/variant_call.cpp | 8 +++----- doc/classes/Color.xml | 11 +++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index af11fb65b..4c7648411 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1831,11 +1831,8 @@ struct _VariantCall { } static void Color_init3(Variant &r_ret, const Variant **p_args) { - r_ret = Color::html(*p_args[0]); - } - - static void Color_init4(Variant &r_ret, const Variant **p_args) { - r_ret = Color::hex(*p_args[0]); + Color c = *p_args[0]; + r_ret = Color(c.r, c.g, c.b, *p_args[1]); } static void add_constructor(VariantConstructFunc p_func, const Variant::Type p_type, @@ -3456,6 +3453,7 @@ void register_variant_methods() { _VariantCall::add_constructor(_VariantCall::Color_init1, Variant::COLOR, "r", Variant::REAL, "g", Variant::REAL, "b", Variant::REAL, "a", Variant::REAL); _VariantCall::add_constructor(_VariantCall::Color_init2, Variant::COLOR, "r", Variant::REAL, "g", Variant::REAL, "b", Variant::REAL); + _VariantCall::add_constructor(_VariantCall::Color_init3, Variant::COLOR, "from", Variant::COLOR, "alpha", Variant::REAL); _VariantCall::add_constructor(_VariantCall::AABB_init1, Variant::AABB, "position", Variant::VECTOR3, "size", Variant::VECTOR3); diff --git a/doc/classes/Color.xml b/doc/classes/Color.xml index 68693dd96..0d00f2a02 100644 --- a/doc/classes/Color.xml +++ b/doc/classes/Color.xml @@ -40,6 +40,17 @@ [/codeblock] + + + + + + Constructs a color from the existing color, with [member a] set to the given [code]alpha[/code] value. + [codeblock] + var red = Color(Color.red, 0.2) # 20% opaque red. + [/codeblock] + +