Skip to content

Commit

Permalink
Added property to get the absolute screen resolution
Browse files Browse the repository at this point in the history
Fixes #143
  • Loading branch information
justalemon committed Dec 16, 2023
1 parent d6e12af commit 74ee5d2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 35 deletions.
27 changes: 3 additions & 24 deletions LemonUI/ObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using LemonUI.Tools;

namespace LemonUI
{
Expand All @@ -28,17 +29,7 @@ public class ObjectPool : IEnumerable<IProcessable>
/// <summary>
/// The last known resolution by the object pool.
/// </summary>
#if FIVEM
private SizeF lastKnownResolution = CitizenFX.Core.UI.Screen.Resolution;
#elif ALTV
private SizeF lastKnownResolution = Screen.Resolution;
#elif RAGEMP
private SizeF lastKnownResolution = new SizeF(Game.ScreenResolution.Width, Game.ScreenResolution.Height);
#elif RPH
private SizeF lastKnownResolution = Game.Resolution;
#elif SHVDN3 || SHVDNC
private SizeF lastKnownResolution = GTA.UI.Screen.Resolution;
#endif
private SizeF lastKnownResolution = GameScreen.AbsoluteResolution;
/// <summary>
/// The last know Safezone size.
/// </summary>
Expand All @@ -53,7 +44,6 @@ public class ObjectPool : IEnumerable<IProcessable>
#elif SHVDN3 || SHVDNC
private float lastKnownSafezone = Function.Call<float>(Hash.GET_SAFE_ZONE_SIZE);
#endif

/// <summary>
/// The list of processable objects.
/// </summary>
Expand Down Expand Up @@ -104,18 +94,7 @@ public bool AreAnyVisible
private void DetectResolutionChanges()
{
// Get the current resolution
#if FIVEM
SizeF resolution = CitizenFX.Core.UI.Screen.Resolution;
#elif ALTV
SizeF resolution = Screen.Resolution;
#elif RAGEMP
ScreenResolutionType raw = Game.ScreenResolution;
SizeF resolution = new SizeF(raw.Width, raw.Height);
#elif RPH
SizeF resolution = Game.Resolution;
#elif SHVDN3 || SHVDNC
SizeF resolution = GTA.UI.Screen.Resolution;
#endif
SizeF resolution = GameScreen.AbsoluteResolution;
// If the old res does not matches the current one
if (lastKnownResolution != resolution)
{
Expand Down
13 changes: 2 additions & 11 deletions LemonUI/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,11 @@ public static class Screen
/// The Aspect Ratio of the screen resolution.
/// </summary>
public static float AspectRatio => GameScreen.AspectRatio;

#if ALTV
/// <summary>
/// Gets the actual Screen resolution the game is being rendered at
/// Gets the actual Screen resolution the game is being rendered at.
/// </summary>
public static Size Resolution
{
get
{
int height = 0, width = 0;
Alt.Natives.GetActualScreenResolution(ref width, ref height);
return new Size(width, height);
}
}
public static Size Resolution => GameScreen.AbsoluteResolution.ToSize();
#endif
/// <summary>
/// The location of the cursor on screen between 0 and 1.
Expand Down
24 changes: 24 additions & 0 deletions LemonUI/Tools/GameScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using CitizenFX.Core.UI;
#elif RAGEMP
using RAGE.Game;
using RAGE.NUI;
#elif RPH
using Rage;
using Rage.Native;
Expand All @@ -26,6 +27,29 @@ public static class GameScreen
{
#region Properties

/// <summary>
/// Gets the actual Screen resolution the game is being rendered at.
/// </summary>
public static SizeF AbsoluteResolution
{
get
{
#if ALTV
int height = 0, width = 0;
Alt.Natives.GetActualScreenResolution(ref width, ref height);
return new SizeF(width, height);
#elif FIVEM
return CitizenFX.Core.UI.Screen.Resolution;
#elif RAGEMP
ScreenResolutionType raw = Game.ScreenResolution;
return new SizeF(raw.Width, raw.Height);
#elif RPH
return Game.Resolution;
#elif SHVDN3 || SHVDNC
return GTA.UI.Screen.Resolution;
#endif
}
}
/// <summary>
/// The Aspect Ratio of the screen.
/// </summary>
Expand Down

0 comments on commit 74ee5d2

Please sign in to comment.