From 33571562d5a98241c19ec5d17657a9ec1be63392 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Fri, 24 May 2024 06:46:48 -0400 Subject: [PATCH] Added custom shadow styles Closes #169 --- LemonUI/Elements/ScaledText.cs | 79 +++++++++++++++++++++++++++++----- LemonUI/Elements/Shadow.cs | 23 ++++++++++ 2 files changed, 91 insertions(+), 11 deletions(-) create mode 100644 LemonUI/Elements/Shadow.cs diff --git a/LemonUI/Elements/ScaledText.cs b/LemonUI/Elements/ScaledText.cs index 9da274f..e7b9421 100644 --- a/LemonUI/Elements/ScaledText.cs +++ b/LemonUI/Elements/ScaledText.cs @@ -107,9 +107,31 @@ public string Text /// public float Scale { get; set; } = 1f; /// + /// The shadow style used for this element. + /// + public Shadow ShadowStyle { get; set; } + /// /// If the text should have a drop down shadow. /// - public bool Shadow { get; set; } = false; + [Obsolete("Please use ShadowStyle with UseClassic set to true", true)] + public bool Shadow + { + get => ShadowStyle != null; + set + { + if (value) + { + ShadowStyle = new Shadow + { + UseClassic = true + }; + } + else + { + ShadowStyle = null; + } + } + } /// /// If the test should have an outline. /// @@ -283,9 +305,16 @@ private void Add() API.SetTextScale(1f, Scale); API.SetTextColour(Color.R, Color.G, Color.B, Color.A); API.SetTextJustification((int)Alignment); - if (Shadow) + if (ShadowStyle != null) { - API.SetTextDropShadow(); + if (ShadowStyle.UseClassic) + { + API.SetTextDropShadow(); + } + else + { + API.SetTextDropshadow(ShadowStyle.Distance, ShadowStyle.Color.R, ShadowStyle.Color.G, ShadowStyle.Color.B, ShadowStyle.Color.A); + } } if (Outline) { @@ -319,9 +348,16 @@ private void Add() Alt.Natives.SetTextScale(1f, Scale); Alt.Natives.SetTextColour(Color.R, Color.G, Color.B, Color.A); Alt.Natives.SetTextJustification((int)Alignment); - if (Shadow) + if (ShadowStyle != null) { - Alt.Natives.SetTextDropShadow(); + if (ShadowStyle.UseClassic) + { + Alt.Natives.SetTextDropShadow(); + } + else + { + Alt.Natives.SetTextDropshadow(ShadowStyle.Distance, ShadowStyle.Color.R, ShadowStyle.Color.G, ShadowStyle.Color.B, ShadowStyle.Color.A); + } } if (Outline) { @@ -355,9 +391,16 @@ private void Add() Invoker.Invoke(Natives.SetTextScale, 1f, Scale); Invoker.Invoke(Natives.SetTextColour, Color.R, Color.G, Color.B, Color.A); Invoker.Invoke(Natives.SetTextJustification, (int)Alignment); - if (Shadow) + if (ShadowStyle != null) { - Invoker.Invoke(Natives.SetTextDropShadow); + if (ShadowStyle.UseClassic) + { + Invoker.Invoke(Natives.SetTextDropShadow); + } + else + { + Invoker.Invoke(Natives.SetTextDropshadow, ShadowStyle.Distance, ShadowStyle.Color.R, ShadowStyle.Color.G, ShadowStyle.Color.B, ShadowStyle.Color.A); + } } if (Outline) { @@ -391,9 +434,16 @@ private void Add() NativeFunction.CallByHash(0x07C837F9A01C34C9, 1f, Scale); NativeFunction.CallByHash(0xBE6B23FFA53FB442, Color.R, Color.G, Color.B, Color.A); NativeFunction.CallByHash(0x4E096588B13FFECA, (int)Alignment); - if (Shadow) + if (ShadowStyle != null) { - NativeFunction.CallByHash(0x1CA3E9EAC9D93E5E); + if (ShadowStyle.UseClassic) + { + NativeFunction.CallByHash(0x1CA3E9EAC9D93E5E); + } + else + { + NativeFunction.CallByHash(0x465C84BC39F1C351, ShadowStyle.Distance, ShadowStyle.Color.R, ShadowStyle.Color.G, ShadowStyle.Color.B, ShadowStyle.Color.A); + } } if (Outline) { @@ -427,9 +477,16 @@ private void Add() Function.Call(Hash.SET_TEXT_SCALE, 1f, Scale); Function.Call(Hash.SET_TEXT_COLOUR, Color.R, Color.G, Color.B, Color.A); Function.Call(Hash.SET_TEXT_JUSTIFICATION, (int)Alignment); - if (Shadow) + if (ShadowStyle != null) { - Function.Call(Hash.SET_TEXT_DROP_SHADOW); + if (ShadowStyle.UseClassic) + { + Function.Call(Hash.SET_TEXT_DROP_SHADOW); + } + else + { + Function.Call(Hash.SET_TEXT_DROPSHADOW, ShadowStyle.Distance, ShadowStyle.Color.R, ShadowStyle.Color.G, ShadowStyle.Color.B, ShadowStyle.Color.A); + } } if (Outline) { diff --git a/LemonUI/Elements/Shadow.cs b/LemonUI/Elements/Shadow.cs new file mode 100644 index 0000000..19dc2e0 --- /dev/null +++ b/LemonUI/Elements/Shadow.cs @@ -0,0 +1,23 @@ +using System.Drawing; + +namespace LemonUI.Elements +{ + /// + /// Defines the shadow style for a . + /// + public class Shadow + { + /// + /// The color used for the shadow. + /// + public Color Color { get; set; } + /// + /// The distance of the shadow. + /// + public int Distance { get; set; } + /// + /// Whether the shadow should use the classic non configurable style. + /// + public bool UseClassic { get; set; } + } +}