Skip to content

Commit

Permalink
Renamed all of the Absolute references to Scaled
Browse files Browse the repository at this point in the history
The Absolute resolution is now the size of the game render window

Fixes #144
  • Loading branch information
justalemon committed Dec 16, 2023
1 parent 4793173 commit d6e12af
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 68 deletions.
20 changes: 10 additions & 10 deletions LemonUI/Elements/ScaledText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public class ScaledText : IText
#region Fields

/// <summary>
/// The absolute 1080p based screen position.
/// The scaled 1080p based screen position.
/// </summary>
private PointF absolutePosition = PointF.Empty;
private PointF scaledPosition = PointF.Empty;
/// <summary>
/// The relative 0-1 relative position.
/// </summary>
Expand Down Expand Up @@ -74,10 +74,10 @@ public class ScaledText : IText
/// </summary>
public PointF Position
{
get => absolutePosition;
get => scaledPosition;
set
{
absolutePosition = value;
scaledPosition = value;
relativePosition = value.ToRelative();
}
}
Expand Down Expand Up @@ -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<float>(Natives.EndTextCommandGetWidth) * 1f.ToXAbsolute();
return Invoker.Invoke<float>(Natives.EndTextCommandGetWidth) * 1f.ToXScaled();
#elif RPH
NativeFunction.CallByHash<int>(0x54CE8AC98E120CAB, "CELL_EMAIL_BCON");
Add();
return NativeFunction.CallByHash<float>(0x85F061DA64ED2F67, true) * 1f.ToXAbsolute();
return NativeFunction.CallByHash<float>(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<float>(Hash.END_TEXT_COMMAND_GET_SCREEN_WIDTH_OF_DISPLAY_TEXT, true) * 1f.ToXAbsolute();
return Function.Call<float>(Hash.END_TEXT_COMMAND_GET_SCREEN_WIDTH_OF_DISPLAY_TEXT, true) * 1f.ToXScaled();
#endif
}
}
Expand Down Expand Up @@ -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)
{
Expand Down
16 changes: 8 additions & 8 deletions LemonUI/Extensions/FloatExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ namespace LemonUI.Extensions
public static class FloatExtensions
{
/// <summary>
/// Converts an absolute X or Width float to a relative one.
/// Converts a scaled X or Width float to a relative one.
/// </summary>
/// <param name="fin">The float to convert.</param>
/// <returns>A relative float between 0 and 1.</returns>
public static float ToXRelative(this float fin) => Tools.Extensions.ToXRelative(fin);
/// <summary>
/// Converts an absolute Y or Height float to a relative one.
/// Converts a scaled Y or Height float to a relative one.
/// </summary>
/// <param name="fin">The float to convert.</param>
/// <returns>A relative float between 0 and 1.</returns>
public static float ToYRelative(this float fin) => Tools.Extensions.ToYRelative(fin);
/// <summary>
/// Converts an relative X or Width float to an absolute one.
/// Converts an relative X or Width float to an scaled one.
/// </summary>
/// <param name="fin">The float to convert.</param>
/// <returns>An absolute float.</returns>
public static float ToXAbsolute(this float fin) => Tools.Extensions.ToXAbsolute(fin);
/// <returns>A scaled float.</returns>
public static float ToXAbsolute(this float fin) => Tools.Extensions.ToXScaled(fin);
/// <summary>
/// Converts an relative Y or Height float to an absolute one.
/// Converts an relative Y or Height float to an scaled one.
/// </summary>
/// <param name="fin">The float to convert.</param>
/// <returns>An absolute float.</returns>
public static float ToYAbsolute(this float fin) => Tools.Extensions.ToYAbsolute(fin);
/// <returns>A scaled float.</returns>
public static float ToYAbsolute(this float fin) => Tools.Extensions.ToYScaled(fin);
}
}
10 changes: 5 additions & 5 deletions LemonUI/Extensions/PointExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ namespace LemonUI.Extensions
public static class PointExtensions
{
/// <summary>
/// Converts an absolute 1080-based position into a relative one.
/// Converts a scaled 1080-based position into a relative one.
/// </summary>
/// <param name="point">The absolute PointF.</param>
/// <param name="point">The scaled PointF.</param>
/// <returns>A new PointF with relative values.</returns>
public static PointF ToRelative(this PointF point) => Tools.Extensions.ToRelative(point);
/// <summary>
/// Converts a normalized 0-1 position into an absolute one.
/// Converts a normalized 0-1 position into a scaled one.
/// </summary>
/// <param name="point">The relative PointF.</param>
/// <returns>A new PointF with absolute values.</returns>
public static PointF ToAbsolute(this PointF point) => Tools.Extensions.ToAbsolute(point);
/// <returns>A new PointF with scaled values.</returns>
public static PointF ToAbsolute(this PointF point) => Tools.Extensions.ToScaled(point);
}
}
10 changes: 5 additions & 5 deletions LemonUI/Extensions/SizeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ namespace LemonUI.Extensions
public static class SizeExtensions
{
/// <summary>
/// Converts an absolute 1080-based size into a relative one.
/// Converts a scaled 1080-based size into a relative one.
/// </summary>
/// <param name="size">The absolute SizeF.</param>
/// <param name="size">The scaled SizeF.</param>
/// <returns>A new SizeF with relative values.</returns>
public static SizeF ToRelative(this SizeF size) => Tools.Extensions.ToRelative(size);
/// <summary>
/// Converts a normalized 0-1 size into an absolute one.
/// Converts a normalized 0-1 size into a scaled one.
/// </summary>
/// <param name="size">The relative SizeF.</param>
/// <returns>A new SizeF with absolute values.</returns>
public static SizeF ToAbsolute(this SizeF size) => Tools.Extensions.ToAbsolute(size);
/// <returns>A new SizeF with scaled values.</returns>
public static SizeF ToAbsolute(this SizeF size) => Tools.Extensions.ToScaled(size);
}
}
8 changes: 4 additions & 4 deletions LemonUI/Menus/NativeMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions LemonUI/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public static Size Resolution
/// <param name="absoluteY">The value of Y scaled to 1080p.</param>
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();
}
/// <summary>
/// Converts a 1080p-based resolution into relative values.
Expand Down
44 changes: 22 additions & 22 deletions LemonUI/Tools/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,70 @@
namespace LemonUI.Tools
{
/// <summary>
/// Extensions for converting values between relative and absolute.
/// Extensions for converting values between relative and scaled.
/// </summary>
public static class Extensions
{
#region Float

/// <summary>
/// Converts an absolute X or Width float to a relative one.
/// Converts the scaled X or Width to a relative one.
/// </summary>
/// <param name="x">The float to convert.</param>
/// <param name="x">The value to convert.</param>
/// <returns>A relative float between 0 and 1.</returns>
public static float ToXRelative(this float x) => x / (1080f * GameScreen.AspectRatio);
/// <summary>
/// Converts an absolute Y or Height float to a relative one.
/// Converts the scaled Y or Height to a relative one.
/// </summary>
/// <param name="y">The float to convert.</param>
/// <param name="y">The value to convert.</param>
/// <returns>A relative float between 0 and 1.</returns>
public static float ToYRelative(this float y) => y / 1080f;
/// <summary>
/// Converts an relative X or Width float to an absolute one.
/// Converts the relative X or Width float to a scaled one.
/// </summary>
/// <param name="x">The float to convert.</param>
/// <returns>An absolute float.</returns>
public static float ToXAbsolute(this float x) => (1080f * GameScreen.AspectRatio) * x;
/// <returns>A scaled float.</returns>
public static float ToXScaled(this float x) => (1080f * GameScreen.AspectRatio) * x;
/// <summary>
/// Converts an relative Y or Height float to an absolute one.
/// Converts the relative Y or Height float to a scaled one.
/// </summary>
/// <param name="y">The float to convert.</param>
/// <returns>An absolute float.</returns>
public static float ToYAbsolute(this float y) => 1080f * y;
/// <returns>A scaled float.</returns>
public static float ToYScaled(this float y) => 1080f * y;

#endregion

#region PointF

/// <summary>
/// Converts an absolute 1080-based position into a relative one.
/// Converts a scaled 1080p-based position into a relative one.
/// </summary>
/// <param name="point">The absolute PointF.</param>
/// <param name="point">The scaled PointF.</param>
/// <returns>A new PointF with relative values.</returns>
public static PointF ToRelative(this PointF point) => new PointF(point.X.ToXRelative(), point.Y.ToYRelative());
/// <summary>
/// Converts a normalized 0-1 position into an absolute one.
/// Converts a relative 0-1 position into a scaled one.
/// </summary>
/// <param name="point">The relative PointF.</param>
/// <returns>A new PointF with absolute values.</returns>
public static PointF ToAbsolute(this PointF point) => new PointF(point.X.ToXAbsolute(), point.Y.ToYAbsolute());
/// <returns>A new PointF with scaled values.</returns>
public static PointF ToScaled(this PointF point) => new PointF(point.X.ToXScaled(), point.Y.ToYScaled());

#endregion

#region SizeF

/// <summary>
/// Converts an absolute 1080-based size into a relative one.
/// Converts a scaled 1080p-based position into a relative one.
/// </summary>
/// <param name="size">The absolute SizeF.</param>
/// <param name="size">The scaled SizeF.</param>
/// <returns>A new SizeF with relative values.</returns>
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());
/// <summary>
/// Converts a normalized 0-1 size into an absolute one.
/// Converts a relative 0-1 position into a scaled one.
/// </summary>
/// <param name="size">The relative SizeF.</param>
/// <returns>A new SizeF with absolute values.</returns>
public static SizeF ToAbsolute(this SizeF size) => new SizeF(size.Width.ToXRelative(), size.Height.ToYRelative());
/// <returns>A new SizeF with scaled values.</returns>
public static SizeF ToScaled(this SizeF size) => new SizeF(size.Width.ToXRelative(), size.Height.ToYRelative());

#endregion
}
Expand Down
18 changes: 9 additions & 9 deletions LemonUI/Tools/GameScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static PointF Cursor
float cursorX = Function.Call<float>(Hash.GET_CONTROL_NORMAL, 0, (int)Control.CursorX);
float cursorY = Function.Call<float>(Hash.GET_CONTROL_NORMAL, 0, (int)Control.CursorY);
#endif
return new PointF(cursorX.ToXAbsolute(), cursorY.ToYAbsolute());
return new PointF(cursorX.ToXScaled(), cursorY.ToYScaled());
}
}

Expand All @@ -78,19 +78,19 @@ public static PointF Cursor
#region Functions

/// <summary>
/// Checks if the cursor is inside of the absolute area.
/// Checks if the cursor is inside of the scaled area.
/// </summary>
/// <param name="pos">The absolute position.</param>
/// <param name="size">The absolute size of the area.</param>
/// <param name="pos">The scaled position.</param>
/// <param name="size">The scaled size of the area.</param>
/// <returns><see langword="true"/> if the cursor is in the specified bounds, <see langword="false"/> otherwise.</returns>
public static bool IsCursorInArea(PointF pos, SizeF size) => IsCursorInArea(pos.X, pos.Y, size.Width, size.Height);
/// <summary>
/// Checks if the cursor is inside of the absolute area.
/// Checks if the cursor is inside of the scaled area.
/// </summary>
/// <param name="x">The absolute X position.</param>
/// <param name="y">The absolute Y position.</param>
/// <param name="width">The absolute width of the area.</param>
/// <param name="height">The absolute height of the area.</param>
/// <param name="x">The scaled X position.</param>
/// <param name="y">The scaled Y position.</param>
/// <param name="width">The scaled width of the area.</param>
/// <param name="height">The scaled height of the area.</param>
/// <returns><see langword="true"/> if the cursor is in the specified bounds, <see langword="false"/> otherwise.</returns>
public static bool IsCursorInArea(float x, float y, float width, float height)
{
Expand Down
6 changes: 3 additions & 3 deletions LemonUI/Tools/SafeZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
/// <summary>
/// Sets the alignment for the safe zone.
Expand Down Expand Up @@ -164,15 +164,15 @@ public static void ResetAlignment()
/// <param name="position">The position to get.</param>
/// <param name="horizontal">The horizontal alignment.</param>
/// <param name="vertical">The vertical alignment.</param>
/// <returns>The absolute safe zone alignment.</returns>
/// <returns>The safe zone alignment.</returns>
public static PointF GetPositionAt(PointF position, Alignment horizontal, GFXAlignment vertical) => GetPositionAt(position, AlignmentToGFXAlignment(horizontal), vertical);
/// <summary>
/// Gets the specified position with the specified safe zone alignment.
/// </summary>
/// <param name="position">The position to get.</param>
/// <param name="horizontal">The horizontal alignment.</param>
/// <param name="vertical">The vertical alignment.</param>
/// <returns>The absolute safe zone alignment.</returns>
/// <returns>The scaled safe zone alignment.</returns>
public static PointF GetPositionAt(PointF position, GFXAlignment horizontal, GFXAlignment vertical)
{
SetAlignment(horizontal, vertical);
Expand Down

0 comments on commit d6e12af

Please sign in to comment.