Skip to content

Commit

Permalink
Merge branch 'master' into feat/spacers
Browse files Browse the repository at this point in the history
  • Loading branch information
justalemon authored Dec 16, 2023
2 parents 258deb9 + ee5a2a6 commit 431a0ee
Show file tree
Hide file tree
Showing 16 changed files with 533 additions and 357 deletions.
2 changes: 1 addition & 1 deletion LemonUI/Elements/BaseElement.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using LemonUI.Extensions;
using System.Drawing;
using LemonUI.Tools;

namespace LemonUI.Elements
{
Expand Down
22 changes: 11 additions & 11 deletions LemonUI/Elements/ScaledText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using LemonUI.Extensions;
using LemonUI.Tools;

namespace LemonUI.Elements
{
Expand All @@ -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
43 changes: 13 additions & 30 deletions LemonUI/Extensions/FloatExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,36 @@
using System;

namespace LemonUI.Extensions
{
/// <summary>
/// Extensions for the float class.
/// </summary>
[Obsolete("Please use LemonUI.Tools.Extensions instead.", true)]
public static class FloatExtensions
{
#region Extensions

/// <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)
{
Screen.ToRelative(fin, 0, out float fout, out _);
return fout;
}
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)
{
Screen.ToRelative(0, fin, out _, out float fout);
return fout;
}
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)
{
Screen.ToAbsolute(fin, 0, out float fout, out _);
return fout;
}
/// <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)
{
Screen.ToAbsolute(0, fin, out _, out float fout);
return fout;
}

#endregion
/// <returns>A scaled float.</returns>
public static float ToYAbsolute(this float fin) => Tools.Extensions.ToYScaled(fin);
}
}
26 changes: 8 additions & 18 deletions LemonUI/Extensions/PointExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
using System;
using System.Drawing;

namespace LemonUI.Extensions
{
/// <summary>
/// Extensions for the Point and PointF classes.
/// </summary>
[Obsolete("Please use LemonUI.Tools.Extensions instead.", true)]
public static class PointExtensions
{
#region Extensions

/// <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)
{
Screen.ToRelative(point.X, point.Y, out float x, out float y);
return new PointF(x, y);
}
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)
{
Screen.ToAbsolute(point.X, point.Y, out float x, out float y);
return new PointF(x, y);
}

#endregion
/// <returns>A new PointF with scaled values.</returns>
public static PointF ToAbsolute(this PointF point) => Tools.Extensions.ToScaled(point);
}
}
26 changes: 8 additions & 18 deletions LemonUI/Extensions/SizeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
using System;
using System.Drawing;

namespace LemonUI.Extensions
{
/// <summary>
/// Extensions for the Size and SizeF classes.
/// </summary>
[Obsolete("Please use LemonUI.Tools.Extensions instead.", true)]
public static class SizeExtensions
{
#region Extensions

/// <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)
{
Screen.ToRelative(size.Width, size.Height, out float width, out float height);
return new SizeF(width, height);
}
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)
{
Screen.ToAbsolute(size.Width, size.Height, out float width, out float height);
return new SizeF(width, height);
}

#endregion
/// <returns>A new SizeF with scaled values.</returns>
public static SizeF ToAbsolute(this SizeF size) => Tools.Extensions.ToScaled(size);
}
}
15 changes: 7 additions & 8 deletions LemonUI/Menus/NativeGridPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
using Control = Rage.GameControl;
#elif SHVDN3 || SHVDNC
using GTA;
using GTA.Native;
using GTA.UI;
#endif
using LemonUI.Elements;
using LemonUI.Extensions;
using System;
using System.Drawing;
using LemonUI.Tools;

namespace LemonUI.Menus
{
Expand Down Expand Up @@ -290,16 +289,16 @@ public override void Process()

if (!Controls.IsUsingController)
{
if (Screen.IsCursorInArea(grid.Position, grid.Size) && Controls.IsPressed(Control.CursorAccept))
if (GameScreen.IsCursorInArea(grid.Position, grid.Size) && Controls.IsPressed(Control.CursorAccept))
{
PointF cursor = Screen.CursorPositionRelative;
PointF pos = innerPosition.ToRelative();
PointF cursor = GameScreen.Cursor;
PointF pos = innerPosition;

PointF start = new PointF(cursor.X - pos.X, cursor.Y - pos.Y);
SizeF size = innerSize.ToRelative();
SizeF size = innerSize;

x = start.X / size.Width;
y = start.Y / size.Height;
x = (start.X / size.Width).ToXRelative();
y = (start.Y / size.Height).ToYRelative();
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion LemonUI/Menus/NativeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using LemonUI.Elements;
using System;
using System.Drawing;
using LemonUI.Tools;

namespace LemonUI.Menus
{
Expand Down Expand Up @@ -230,7 +231,7 @@ public ColorSet Colors
/// <summary>
/// If this item is being hovered.
/// </summary>
public bool IsHovered => Screen.IsCursorInArea(background.Position, background.Size);
public bool IsHovered => GameScreen.IsCursorInArea(background.Position, background.Size);

#endregion

Expand Down
2 changes: 1 addition & 1 deletion LemonUI/Menus/NativeListItem{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public T SelectedItem
{
if (Items.Count == 0)
{
throw new InvalidOperationException("There are no available items.");
return;
}

int newIndex = Items.IndexOf(value);
Expand Down
Loading

0 comments on commit 431a0ee

Please sign in to comment.