Skip to content

Instantly share code, notes, and snippets.

@Stuyk
Created May 15, 2019 18:28
Show Gist options
  • Save Stuyk/140a90954f878b34dbe1b491a1622d55 to your computer and use it in GitHub Desktop.
Save Stuyk/140a90954f878b34dbe1b491a1622d55 to your computer and use it in GitHub Desktop.
Small update to screen res so it supports mouse inconsistencies and such.
using RAGE;
using System;
using System.Collections.Generic;
using System.Text;
namespace CoffeeVClient.Utility
{
public struct Vector2
{
public int X { get; set; }
public int Y { get; set; }
}
public class RealScreenRes : Events.Script
{
private static int ResActX = 0;
private static int ResActY = 0;
private static int ResX = 0;
private static int ResY = 0;
private static int MouseX = 0;
private static int MouseY = 0;
public static int GridWidthCount = 16;
public static int GridHeightCount = 16;
public RealScreenRes()
{
Events.Tick += Tick;
}
private void Tick(List<Events.TickNametagData> nametags)
{
RAGE.Game.Graphics.GetActiveScreenResolution(ref ResActX, ref ResActY);
RAGE.Game.Graphics.GetScreenResolution(ref ResX, ref ResY);
float x = RAGE.Ui.Cursor.Position.X;
float y = RAGE.Ui.Cursor.Position.Y;
float NewX = x / ResActX;
float NewY = y / ResActY;
MouseX = Convert.ToInt32(1280 * NewX);
MouseY = Convert.ToInt32(720 * NewY);
}
/// <summary>
/// Returns X Width and Y Height Per Grid Element
/// </summary>
/// <returns></returns>
public static Vector2 GetGrid()
{
return new Vector2() { X = (ResX / GridWidthCount), Y = (ResY / GridHeightCount) };
}
/// <summary>
/// Returns the true X and Y parameter for a mouse with the weird scaling issues.
/// </summary>
/// <returns></returns>
public static Vector2 GetMouse()
{
return new Vector2() { X = MouseX, Y = MouseY };
}
/// <summary>
/// Returns the true Screen Solution associated with current game.
/// </summary>
/// <returns></returns>
public static Vector2 Screen()
{
return new Vector2() { X = ResX, Y = ResY };
}
public static Vector2 ClosestGridToMouse()
{
Vector2 grid = GetGrid();
Vector2 mouse = GetMouse();
Vector2 pos = new Vector2();
pos.X = 0;
pos.Y = 0;
for(int x = 0; x < grid.X; x++)
{
if (mouse.X > (grid.X * x) && mouse.X < (grid.X * x + (grid.X)))
pos.X = x;
}
for(int y = 0; y < grid.Y; y++)
{
if (mouse.Y > (grid.Y * y) && mouse.Y < (grid.Y * y + (grid.Y)))
pos.Y = y;
}
return pos;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment