From d6e12af1fb46154568773d7db7ea539553e053a5 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 02:08:37 -0300 Subject: [PATCH] Renamed all of the Absolute references to Scaled The Absolute resolution is now the size of the game render window Fixes #144 --- LemonUI/Elements/ScaledText.cs | 20 ++++++------ LemonUI/Extensions/FloatExtensions.cs | 16 +++++----- LemonUI/Extensions/PointExtensions.cs | 10 +++--- LemonUI/Extensions/SizeExtensions.cs | 10 +++--- LemonUI/Menus/NativeMenu.cs | 8 ++--- LemonUI/Screen.cs | 4 +-- LemonUI/Tools/Extensions.cs | 44 +++++++++++++-------------- LemonUI/Tools/GameScreen.cs | 18 +++++------ LemonUI/Tools/SafeZone.cs | 6 ++-- 9 files changed, 68 insertions(+), 68 deletions(-) diff --git a/LemonUI/Elements/ScaledText.cs b/LemonUI/Elements/ScaledText.cs index 9c105a4..05fffb2 100644 --- a/LemonUI/Elements/ScaledText.cs +++ b/LemonUI/Elements/ScaledText.cs @@ -37,9 +37,9 @@ public class ScaledText : IText #region Fields /// - /// The absolute 1080p based screen position. + /// The scaled 1080p based screen position. /// - private PointF absolutePosition = PointF.Empty; + private PointF scaledPosition = PointF.Empty; /// /// The relative 0-1 relative position. /// @@ -74,10 +74,10 @@ public class ScaledText : IText /// public PointF Position { - get => absolutePosition; + get => scaledPosition; set { - absolutePosition = value; + scaledPosition = value; relativePosition = value.ToRelative(); } } @@ -150,23 +150,23 @@ public float Width #if FIVEM API.BeginTextCommandWidth("CELL_EMAIL_BCON"); Add(); - return API.EndTextCommandGetWidth(true) * 1f.ToXAbsolute(); + return API.EndTextCommandGetWidth(true) * 1f.ToXScaled(); #elif ALTV Alt.Natives.BeginTextCommandGetScreenWidthOfDisplayText("CELL_EMAIL_BCON"); Add(); - return Alt.Natives.EndTextCommandGetScreenWidthOfDisplayText(true) * 1f.ToXAbsolute(); + return Alt.Natives.EndTextCommandGetScreenWidthOfDisplayText(true) * 1f.ToXScaled(); #elif RAGEMP Invoker.Invoke(Natives.BeginTextCommandWidth, "CELL_EMAIL_BCON"); Add(); - return Invoker.Invoke(Natives.EndTextCommandGetWidth) * 1f.ToXAbsolute(); + return Invoker.Invoke(Natives.EndTextCommandGetWidth) * 1f.ToXScaled(); #elif RPH NativeFunction.CallByHash(0x54CE8AC98E120CAB, "CELL_EMAIL_BCON"); Add(); - return NativeFunction.CallByHash(0x85F061DA64ED2F67, true) * 1f.ToXAbsolute(); + return NativeFunction.CallByHash(0x85F061DA64ED2F67, true) * 1f.ToXScaled(); #elif SHVDN3 || SHVDNC Function.Call(Hash.BEGIN_TEXT_COMMAND_GET_SCREEN_WIDTH_OF_DISPLAY_TEXT, "CELL_EMAIL_BCON"); Add(); - return Function.Call(Hash.END_TEXT_COMMAND_GET_SCREEN_WIDTH_OF_DISPLAY_TEXT, true) * 1f.ToXAbsolute(); + return Function.Call(Hash.END_TEXT_COMMAND_GET_SCREEN_WIDTH_OF_DISPLAY_TEXT, true) * 1f.ToXScaled(); #endif } } @@ -505,7 +505,7 @@ private void Slice() public void Recalculate() { // Do the normal Size and Position recalculation - relativePosition = absolutePosition.ToRelative(); + relativePosition = scaledPosition.ToRelative(); // And recalculate the word wrap if necessary if (internalWrap <= 0) { diff --git a/LemonUI/Extensions/FloatExtensions.cs b/LemonUI/Extensions/FloatExtensions.cs index 0b82150..ddc7340 100644 --- a/LemonUI/Extensions/FloatExtensions.cs +++ b/LemonUI/Extensions/FloatExtensions.cs @@ -9,28 +9,28 @@ namespace LemonUI.Extensions public static class FloatExtensions { /// - /// Converts an absolute X or Width float to a relative one. + /// Converts a scaled X or Width float to a relative one. /// /// The float to convert. /// A relative float between 0 and 1. public static float ToXRelative(this float fin) => Tools.Extensions.ToXRelative(fin); /// - /// Converts an absolute Y or Height float to a relative one. + /// Converts a scaled Y or Height float to a relative one. /// /// The float to convert. /// A relative float between 0 and 1. public static float ToYRelative(this float fin) => Tools.Extensions.ToYRelative(fin); /// - /// Converts an relative X or Width float to an absolute one. + /// Converts an relative X or Width float to an scaled one. /// /// The float to convert. - /// An absolute float. - public static float ToXAbsolute(this float fin) => Tools.Extensions.ToXAbsolute(fin); + /// A scaled float. + public static float ToXAbsolute(this float fin) => Tools.Extensions.ToXScaled(fin); /// - /// Converts an relative Y or Height float to an absolute one. + /// Converts an relative Y or Height float to an scaled one. /// /// The float to convert. - /// An absolute float. - public static float ToYAbsolute(this float fin) => Tools.Extensions.ToYAbsolute(fin); + /// A scaled float. + public static float ToYAbsolute(this float fin) => Tools.Extensions.ToYScaled(fin); } } diff --git a/LemonUI/Extensions/PointExtensions.cs b/LemonUI/Extensions/PointExtensions.cs index 5d55083..5f0c267 100644 --- a/LemonUI/Extensions/PointExtensions.cs +++ b/LemonUI/Extensions/PointExtensions.cs @@ -10,16 +10,16 @@ namespace LemonUI.Extensions public static class PointExtensions { /// - /// Converts an absolute 1080-based position into a relative one. + /// Converts a scaled 1080-based position into a relative one. /// - /// The absolute PointF. + /// The scaled PointF. /// A new PointF with relative values. public static PointF ToRelative(this PointF point) => Tools.Extensions.ToRelative(point); /// - /// Converts a normalized 0-1 position into an absolute one. + /// Converts a normalized 0-1 position into a scaled one. /// /// The relative PointF. - /// A new PointF with absolute values. - public static PointF ToAbsolute(this PointF point) => Tools.Extensions.ToAbsolute(point); + /// A new PointF with scaled values. + public static PointF ToAbsolute(this PointF point) => Tools.Extensions.ToScaled(point); } } diff --git a/LemonUI/Extensions/SizeExtensions.cs b/LemonUI/Extensions/SizeExtensions.cs index 5d86e1e..0660a34 100644 --- a/LemonUI/Extensions/SizeExtensions.cs +++ b/LemonUI/Extensions/SizeExtensions.cs @@ -10,16 +10,16 @@ namespace LemonUI.Extensions public static class SizeExtensions { /// - /// Converts an absolute 1080-based size into a relative one. + /// Converts a scaled 1080-based size into a relative one. /// - /// The absolute SizeF. + /// The scaled SizeF. /// A new SizeF with relative values. public static SizeF ToRelative(this SizeF size) => Tools.Extensions.ToRelative(size); /// - /// Converts a normalized 0-1 size into an absolute one. + /// Converts a normalized 0-1 size into a scaled one. /// /// The relative SizeF. - /// A new SizeF with absolute values. - public static SizeF ToAbsolute(this SizeF size) => Tools.Extensions.ToAbsolute(size); + /// A new SizeF with scaled values. + public static SizeF ToAbsolute(this SizeF size) => Tools.Extensions.ToScaled(size); } } diff --git a/LemonUI/Menus/NativeMenu.cs b/LemonUI/Menus/NativeMenu.cs index 8a8edbb..c941294 100644 --- a/LemonUI/Menus/NativeMenu.cs +++ b/LemonUI/Menus/NativeMenu.cs @@ -976,7 +976,7 @@ public void ResetCursor() x = Offset.X + Width + extraX; break; case Alignment.Right: - x = 1f.ToXAbsolute() - Offset.X - Width - extraX; + x = 1f.ToXScaled() - Offset.X - Width - extraX; break; } pos = new PointF(x, Offset.Y + extraY).ToRelative(); @@ -1026,7 +1026,7 @@ private void UpdateItems() x = Offset.X; break; case Alignment.Right: - x = 1f.ToXAbsolute() - Width - Offset.X; + x = 1f.ToXScaled() - Width - Offset.X; break; } pos = new PointF(x, Offset.Y); @@ -1693,7 +1693,7 @@ public virtual void Recalculate() x = Offset.X; break; case Alignment.Right: - x = 1f.ToXAbsolute() - Width - Offset.X; + x = 1f.ToXScaled() - Width - Offset.X; break; } pos = new PointF(x, Offset.Y); @@ -1734,7 +1734,7 @@ public virtual void Recalculate() descriptionText.WordWrap = width - posXDescTxt; // Set the right size of the rotation - searchAreaRight = new PointF(1f.ToXAbsolute() - 30, 0); + searchAreaRight = new PointF(1f.ToXScaled() - 30, 0); // Then, continue with an item update UpdateItems(); diff --git a/LemonUI/Screen.cs b/LemonUI/Screen.cs index 52df2b2..639c260 100644 --- a/LemonUI/Screen.cs +++ b/LemonUI/Screen.cs @@ -67,8 +67,8 @@ public static Size Resolution /// The value of Y scaled to 1080p. public static void ToAbsolute(float relativeX, float relativeY, out float absoluteX, out float absoluteY) { - absoluteX = relativeX.ToXAbsolute(); - absoluteY = relativeY.ToYAbsolute(); + absoluteX = relativeX.ToXScaled(); + absoluteY = relativeY.ToYScaled(); } /// /// Converts a 1080p-based resolution into relative values. diff --git a/LemonUI/Tools/Extensions.cs b/LemonUI/Tools/Extensions.cs index 70461c0..d3f6556 100644 --- a/LemonUI/Tools/Extensions.cs +++ b/LemonUI/Tools/Extensions.cs @@ -3,70 +3,70 @@ namespace LemonUI.Tools { /// - /// Extensions for converting values between relative and absolute. + /// Extensions for converting values between relative and scaled. /// public static class Extensions { #region Float /// - /// Converts an absolute X or Width float to a relative one. + /// Converts the scaled X or Width to a relative one. /// - /// The float to convert. + /// The value to convert. /// A relative float between 0 and 1. public static float ToXRelative(this float x) => x / (1080f * GameScreen.AspectRatio); /// - /// Converts an absolute Y or Height float to a relative one. + /// Converts the scaled Y or Height to a relative one. /// - /// The float to convert. + /// The value to convert. /// A relative float between 0 and 1. public static float ToYRelative(this float y) => y / 1080f; /// - /// Converts an relative X or Width float to an absolute one. + /// Converts the relative X or Width float to a scaled one. /// /// The float to convert. - /// An absolute float. - public static float ToXAbsolute(this float x) => (1080f * GameScreen.AspectRatio) * x; + /// A scaled float. + public static float ToXScaled(this float x) => (1080f * GameScreen.AspectRatio) * x; /// - /// Converts an relative Y or Height float to an absolute one. + /// Converts the relative Y or Height float to a scaled one. /// /// The float to convert. - /// An absolute float. - public static float ToYAbsolute(this float y) => 1080f * y; + /// A scaled float. + public static float ToYScaled(this float y) => 1080f * y; #endregion #region PointF /// - /// Converts an absolute 1080-based position into a relative one. + /// Converts a scaled 1080p-based position into a relative one. /// - /// The absolute PointF. + /// The scaled PointF. /// A new PointF with relative values. public static PointF ToRelative(this PointF point) => new PointF(point.X.ToXRelative(), point.Y.ToYRelative()); /// - /// Converts a normalized 0-1 position into an absolute one. + /// Converts a relative 0-1 position into a scaled one. /// /// The relative PointF. - /// A new PointF with absolute values. - public static PointF ToAbsolute(this PointF point) => new PointF(point.X.ToXAbsolute(), point.Y.ToYAbsolute()); + /// A new PointF with scaled values. + public static PointF ToScaled(this PointF point) => new PointF(point.X.ToXScaled(), point.Y.ToYScaled()); #endregion #region SizeF /// - /// Converts an absolute 1080-based size into a relative one. + /// Converts a scaled 1080p-based position into a relative one. /// - /// The absolute SizeF. + /// The scaled SizeF. /// A new SizeF with relative values. - public static SizeF ToRelative(this SizeF size) => new SizeF(size.Width.ToXAbsolute(), size.Height.ToYAbsolute()); + public static SizeF ToRelative(this SizeF size) => new SizeF(size.Width.ToXScaled(), size.Height.ToYScaled()); /// - /// Converts a normalized 0-1 size into an absolute one. + /// Converts a relative 0-1 position into a scaled one. /// /// The relative SizeF. - /// A new SizeF with absolute values. - public static SizeF ToAbsolute(this SizeF size) => new SizeF(size.Width.ToXRelative(), size.Height.ToYRelative()); + /// A new SizeF with scaled values. + public static SizeF ToScaled(this SizeF size) => new SizeF(size.Width.ToXRelative(), size.Height.ToYRelative()); #endregion } diff --git a/LemonUI/Tools/GameScreen.cs b/LemonUI/Tools/GameScreen.cs index 5c15b6b..5556d59 100644 --- a/LemonUI/Tools/GameScreen.cs +++ b/LemonUI/Tools/GameScreen.cs @@ -69,7 +69,7 @@ public static PointF Cursor float cursorX = Function.Call(Hash.GET_CONTROL_NORMAL, 0, (int)Control.CursorX); float cursorY = Function.Call(Hash.GET_CONTROL_NORMAL, 0, (int)Control.CursorY); #endif - return new PointF(cursorX.ToXAbsolute(), cursorY.ToYAbsolute()); + return new PointF(cursorX.ToXScaled(), cursorY.ToYScaled()); } } @@ -78,19 +78,19 @@ public static PointF Cursor #region Functions /// - /// Checks if the cursor is inside of the absolute area. + /// Checks if the cursor is inside of the scaled area. /// - /// The absolute position. - /// The absolute size of the area. + /// The scaled position. + /// The scaled size of the area. /// if the cursor is in the specified bounds, otherwise. public static bool IsCursorInArea(PointF pos, SizeF size) => IsCursorInArea(pos.X, pos.Y, size.Width, size.Height); /// - /// Checks if the cursor is inside of the absolute area. + /// Checks if the cursor is inside of the scaled area. /// - /// The absolute X position. - /// The absolute Y position. - /// The absolute width of the area. - /// The absolute height of the area. + /// The scaled X position. + /// The scaled Y position. + /// The scaled width of the area. + /// The scaled height of the area. /// if the cursor is in the specified bounds, otherwise. public static bool IsCursorInArea(float x, float y, float width, float height) { diff --git a/LemonUI/Tools/SafeZone.cs b/LemonUI/Tools/SafeZone.cs index a146eae..43be35b 100644 --- a/LemonUI/Tools/SafeZone.cs +++ b/LemonUI/Tools/SafeZone.cs @@ -109,7 +109,7 @@ public static PointF GetSafePosition(float x, float y) } #endif - return new PointF(realX.ToXAbsolute(), realY.ToYAbsolute()); + return new PointF(realX.ToXScaled(), realY.ToYScaled()); } /// /// Sets the alignment for the safe zone. @@ -164,7 +164,7 @@ public static void ResetAlignment() /// The position to get. /// The horizontal alignment. /// The vertical alignment. - /// The absolute safe zone alignment. + /// The safe zone alignment. public static PointF GetPositionAt(PointF position, Alignment horizontal, GFXAlignment vertical) => GetPositionAt(position, AlignmentToGFXAlignment(horizontal), vertical); /// /// Gets the specified position with the specified safe zone alignment. @@ -172,7 +172,7 @@ public static void ResetAlignment() /// The position to get. /// The horizontal alignment. /// The vertical alignment. - /// The absolute safe zone alignment. + /// The scaled safe zone alignment. public static PointF GetPositionAt(PointF position, GFXAlignment horizontal, GFXAlignment vertical) { SetAlignment(horizontal, vertical);