From a71a8c6e1e3e3be617436b6789552177d67b36e3 Mon Sep 17 00:00:00 2001 From: LuoZhihao Date: Thu, 9 Jan 2025 19:05:57 +0800 Subject: [PATCH] C#: Expose OKHSL properties of Color --- .../glue/GodotSharp/GodotSharp/Core/Color.cs | 45 +++++++++++++++++++ .../Core/NativeInterop/NativeFuncs.cs | 6 +++ modules/mono/glue/runtime_interop.cpp | 15 +++++++ 3 files changed, 66 insertions(+) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs index d3b9f2d2aed..b78788a861f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs @@ -193,6 +193,51 @@ namespace Godot } } + /// + /// The OKHSL hue of this color, on the range 0 to 1. + /// + public float OkHslH + { + readonly get + { + return NativeFuncs.godotsharp_color_get_ok_hsl_h(this); + } + set + { + this = FromOkHsl(value, OkHslS, OkHslL, A); + } + } + + /// + /// The OKHSL saturation of this color, on the range 0 to 1. + /// + public float OkHslS + { + readonly get + { + return NativeFuncs.godotsharp_color_get_ok_hsl_s(this); + } + set + { + this = FromOkHsl(OkHslH, value, OkHslL, A); + } + } + + /// + /// The OKHSL lightness of this color, on the range 0 to 1. + /// + public float OkHslL + { + readonly get + { + return NativeFuncs.godotsharp_color_get_ok_hsl_l(this); + } + set + { + this = FromOkHsl(OkHslH, OkHslS, value, A); + } + } + /// /// Returns the light intensity of the color, as a value between 0.0 and 1.0 (inclusive). /// This is useful when determining light or dark color. Colors with a luminance smaller diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs index 021a701521e..eb6fbdda77a 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs @@ -167,6 +167,12 @@ namespace Godot.NativeInterop internal static partial Color godotsharp_color_from_ok_hsl(float p_h, float p_s, float p_l, float p_alpha); + internal static partial float godotsharp_color_get_ok_hsl_h(in Color p_self); + + internal static partial float godotsharp_color_get_ok_hsl_s(in Color p_self); + + internal static partial float godotsharp_color_get_ok_hsl_l(in Color p_self); + // GDNative functions // gdnative.h diff --git a/modules/mono/glue/runtime_interop.cpp b/modules/mono/glue/runtime_interop.cpp index 6975c0bbf4f..ab49560e01c 100644 --- a/modules/mono/glue/runtime_interop.cpp +++ b/modules/mono/glue/runtime_interop.cpp @@ -559,6 +559,18 @@ godot_color godotsharp_color_from_ok_hsl(float p_h, float p_s, float p_l, float return ret; } +float godotsharp_color_get_ok_hsl_h(const Color *p_self) { + return p_self->get_ok_hsl_h(); +} + +float godotsharp_color_get_ok_hsl_s(const Color *p_self) { + return p_self->get_ok_hsl_s(); +} + +float godotsharp_color_get_ok_hsl_l(const Color *p_self) { + return p_self->get_ok_hsl_l(); +} + // GDNative functions // gdnative.h @@ -1551,6 +1563,9 @@ static const void *unmanaged_callbacks[]{ (void *)godotsharp_callable_call, (void *)godotsharp_callable_call_deferred, (void *)godotsharp_color_from_ok_hsl, + (void *)godotsharp_color_get_ok_hsl_h, + (void *)godotsharp_color_get_ok_hsl_s, + (void *)godotsharp_color_get_ok_hsl_l, (void *)godotsharp_method_bind_ptrcall, (void *)godotsharp_method_bind_call, (void *)godotsharp_variant_new_string_name,