Jump to content

guiGetScreenSize


Newbie

Recommended Posts

If you used absolute positions, you can divide the absolute value with your resolution - and then multiply it with the currently used one. For example; (Using 1360x768)

local screenX, screenY = guiGetScreenSize() 
  
local exampleWindow = guiCreateWindow(screenX*(400/1360), screenY*(600/768), screenX*(150/1360), screenY*(300/768), "Example", true) 

In some cases it might not yield the result you want, and more complicated calculations might be needed. However, I have always used this method and it has always satisfied my needs so far. :)

Link to comment
  • Moderators
I have made a panel GUI

with:

button = {}

window = {}

staticimage = {}

label = {}

How can i make them stay on the screen at same point of all resolutions ?

If you used the guieditor resource, you should set the parents relative to the screen. (Right click somewhere on the screen (but not on a gui element) and click on Rel/Abs parent or something.)

This way it will generate the gui code using relative values. guiGetScreenSize is only needed to set the rel values in absolute one right before you use dx functions (they only support/accept absolute values).

For the gui elements, there is no need to use that function since they accept both values but you have to specify that functions if you are sending him absolute or relative values by using the boolean argument "relative" (check the wiki pages to know which one is the "relative" arguement).

So the Dealman's example is wrong because he uses guiGetScreenSize to tansform relative values into absolute one but still saying to the gui function the values he is sending to it are relative ones.

So check the next examples (fixing the Dealman's post):

local screenX, screenY = guiGetScreenSize() 
local exampleWindow = guiCreateWindow(screenX*(400/1360), screenY*(600/768), screenX*(150/1360), screenY*(300/768), "Example", false) 

is the same as:

local exampleWindow = guiCreateWindow( 400/1360, 600/768, 150/1360, 300/768, "Example", true) 

Both examples will be placed correctly on all resolutions.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...