summaryrefslogtreecommitdiffstats
path: root/core/variant
diff options
context:
space:
mode:
authorbonjorno7 <jorijndegraaf@gmail.com>2023-04-25 16:25:50 +0200
committerbonjorno7 <jorijndegraaf@gmail.com>2023-05-09 17:43:10 +0200
commit0b7fd664c1ba372a77f78764b4ff9acfeb1f8052 (patch)
treeae6ee8d8e1ebcff0db8e814b876e41ec061eca0a /core/variant
parentee865051367a78bf20f50500520af13ef8f1097b (diff)
downloadredot-engine-0b7fd664c1ba372a77f78764b4ff9acfeb1f8052.tar.gz
Add API for HSL conversion
Math ported pretty much 1:1 from https://en.wikipedia.org/wiki/HSL_and_HSV Style doesn't match the existing HSV code exactly, but should be close enough.
Diffstat (limited to 'core/variant')
-rw-r--r--core/variant/variant_call.cpp1
-rw-r--r--core/variant/variant_setget.cpp4
-rw-r--r--core/variant/variant_setget.h4
3 files changed, 9 insertions, 0 deletions
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index e83b6dc183..185e30311b 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -2000,6 +2000,7 @@ static void _register_variant_builtin_methods() {
bind_static_method(Color, html_is_valid, sarray("color"), varray());
bind_static_method(Color, from_string, sarray("str", "default"), varray());
bind_static_method(Color, from_hsv, sarray("h", "s", "v", "alpha"), varray(1.0));
+ bind_static_method(Color, from_hsl, sarray("h", "s", "l", "alpha"), varray(1.0));
bind_static_method(Color, from_ok_hsl, sarray("h", "s", "l", "alpha"), varray(1.0));
bind_static_method(Color, from_rgbe9995, sarray("rgbe"), varray());
diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp
index 30fb5d0e9f..ce035f5f7a 100644
--- a/core/variant/variant_setget.cpp
+++ b/core/variant/variant_setget.cpp
@@ -139,6 +139,10 @@ void register_named_setters_getters() {
REGISTER_MEMBER(Color, h);
REGISTER_MEMBER(Color, s);
REGISTER_MEMBER(Color, v);
+
+ REGISTER_MEMBER(Color, hsl_h);
+ REGISTER_MEMBER(Color, hsl_s);
+ REGISTER_MEMBER(Color, hsl_l);
}
void unregister_named_setters_getters() {
diff --git a/core/variant/variant_setget.h b/core/variant/variant_setget.h
index 176967344f..db6e273817 100644
--- a/core/variant/variant_setget.h
+++ b/core/variant/variant_setget.h
@@ -344,6 +344,10 @@ SETGET_NUMBER_STRUCT_FUNC(Color, double, h, set_h, get_h)
SETGET_NUMBER_STRUCT_FUNC(Color, double, s, set_s, get_s)
SETGET_NUMBER_STRUCT_FUNC(Color, double, v, set_v, get_v)
+SETGET_NUMBER_STRUCT_FUNC(Color, double, hsl_h, set_hsl_h, get_hsl_h)
+SETGET_NUMBER_STRUCT_FUNC(Color, double, hsl_s, set_hsl_s, get_hsl_s)
+SETGET_NUMBER_STRUCT_FUNC(Color, double, hsl_l, set_hsl_l, get_hsl_l)
+
SETGET_NUMBER_STRUCT_FUNC(Color, double, ok_hsl_h, set_ok_hsl_h, get_ok_hsl_h)
SETGET_NUMBER_STRUCT_FUNC(Color, double, ok_hsl_s, set_ok_hsl_s, get_ok_hsl_s)
SETGET_NUMBER_STRUCT_FUNC(Color, double, ok_hsl_l, set_ok_hsl_l, get_ok_hsl_l)