Drawing Rectangles not positioning properly?

I’m trying to draw a rectangle on the screen, I just worked out that the x, y, width and height needs to be a percentage between 0.0-1.0, but when I try to draw a rectangle at the moment, it doesn’t position properly at all. Below is the code I’m currently using to display it.

local ScrW, ScrH = GetScreenResolution()
local widthOfWindow, heightOfWindow = 750, 550
local w, h = (widthOfWindow / 1.5) / ScrW, (heightOfWindow / 1.5) / ScrH
local x, y = ((ScrW / 2) - (widthOfWindow / 2)) / ScrW, ((ScrH / 1.5) - (heightOfWindow / 1.5)) / ScrH

DrawRect( x, y, w, h, 0, 0, 0, 200 )

In theory, this code should make a window that’s evenly sized on the left and right, then place it centered in the screen, but it doesn’t, it’s off the screen, any help?

GetScreenResolution() will not necessarily return the resolution you’re currently using, only the aspect ratio. For example if I play on 1920x1080 and use GetScreenResolution() - it will return 1280x720. Which is a ratio of 16:9.

So what I do is to just use relative values. And then I draw the rectangle like this;

DrawRect(posX+(sizeX/2), posY+(sizeY/2), sizeX, sizeY, colourRed, colourGreen, colourBlue, colourAlpha)

Now if you enter 0.0 as the X and Y position it will draw in the top left corner of the screen. This is in my opinion how it should work, instead of drawing from the center outwards.