Jump to content

GUI on all resolutions


harryh

Recommended Posts

How do I do this. I currently have this which I got from the wiki but it doesn't work. As the GUI is off the screen.

local sW, sH = guiGetScreenSize() 
     
    showCursor(true) 
     
    modwindow = guiCreateWindow(sW*442, sH*181, sW*506, sH*420, "Autoparts Modshop", false) 

Link to comment
because you do a big fail xD

example if your screen sW is 1024 then

sW*442 is same as 1024x442

the others values are same by same example i mean

If you not going to help, please don't comment... I just looked at the wiki and thats what it said. Not my fault.

Link to comment

The following will center gui on all resolutions

local x, y = guiGetScreenSize() 
local Width = ( x - 541 )/2 
local Height = ( y - 332 )/2 
 testWindow = guiCreateWindow(Width, Height, 541, 332, "test window",  false) 

you can replace 541 and 332 with everything you want, i added them just for test

Edited by Guest
Link to comment

Easiest way to do this is using values between 0 and 1. As an example;

local x, y = guiGetScreenSize(); 
  
testWindow = guiCreateWindow ( x * 0.4, y * 0.3, x * 0.2, y * 0.35, "test window", false ); 

This will create a window at the center of the screen, with a width of 0.2, and a height of 0.35. It will always look good on every screen! :)

Link to comment
  • Moderators
Easiest way to do this is using values between 0 and 1. As an example;
local x, y = guiGetScreenSize(); 
  
testWindow = guiCreateWindow ( x * 0.4, y * 0.3, x * 0.2, y * 0.35, "test window", false ); 

This will create a window at the center of the screen, with a width of 0.2, and a height of 0.35. It will always look good on every screen!

And the most easiest way to do this is using values between 0 and 1 AND not translating it in absolute values:

testWindow = guiCreateWindow ( 0.4, 0.3, 0.2, 0.35, "test window", true) 

(And no need to use ; too)

Link to comment
  • Moderators
I think the problem is already solved, I tested my code and it's working...

It wasn't about the the resolution of his problem, it's about to let you guys know relative values doesn't need to be translated in absolute ones when using gui functions. It just add code that is already written in the original functions ...

(And it's not because your solution is working that it's a good solution ...)

Link to comment
I think the problem is already solved, I tested my code and it's working...

It wasn't about the the resolution of his problem, it's about to let you guys know relative values doesn't need to be translated in absolute ones when using gui functions. It just add code that is already written in the original functions ...

(And it's not because your solution is working that it's a good solution ...)

How do you know where 0.4, 0.8 etc etc. will be on the screen?

Link to comment
How do I do this. I currently have this which I got from the wiki but it doesn't work. As the GUI is off the screen.
local sW, sH = guiGetScreenSize() 
     
    showCursor(true) 
     
    modwindow = guiCreateWindow(sW*442, sH*181, sW*506, sH*420, "Autoparts Modshop", false) 

Use your resolution, example: your resolution is 1366 x 768 (Is mine)

local sW, sH = guiGetScreenSize() 
     
    showCursor(true) 
     
    modwindow = guiCreateWindow((442/1366)*sW, (181/768)*sH, (506/1366)*sW, (420/768)*sH, "Autoparts Modshop", false) 

Sorry for my bad English

  • Like 1
Link to comment
  • Moderators
I think the problem is already solved, I tested my code and it's working...

It wasn't about the the resolution of his problem, it's about to let you guys know relative values doesn't need to be translated in absolute ones when using gui functions. It just add code that is already written in the original functions ...

(And it's not because your solution is working that it's a good solution ...)

How do you know where 0.4, 0.8 etc etc. will be on the screen?

It's really simple but maybe hard to get it at the begining. So here is what you have to know:

on the horizontal axis: 0 (0%) is the left side of your screen (of every screens) and 1(100%) is the right side of your screen (of every screens too).

on the vertical axis: 0 (0%) is the top side of your screen (of every screens) and 1 (100%) is the bottom side of your screen (of every screens too).

So instead of using pixels to place and size your gui elements (which will not be rendered the same on every resolutions) then you use percentages of the screen.

The gui elements are placed using the top left corner of that gui element. So if you place it at 1, 1 (100%, 100%) then your gui element will be rendered out of the screen. So to place it correctly at the bottom right corner, you have to use:

100 - , 100 -

So as another example, if you wan to create a window pefectly centered on every screens:

guiCreateWindow(50% - 30%/2, 50% - 40%/2, 30%, 40%, "My window", true) --just for comprehension 
-- so: 
guiCreateWindow(0.5 - 0.15, 0.5 - 0.2, 0.3, 0.4, "My window", true) -- will work 
guiCreateWindow(0.5 - 0.15, 0.5 - 0.2, 0.3, 0.4, "My window", true) -- will work too 

Note:

0.5 = 50%

0.15 is half of 0.3

0.2 is half of 0.4

Link to comment
  • Moderators
How can I get the position of top right corner of screen?

If you had read and understand what I just wrote, then you would find out by yourself...

If you want to place a window of size 20% ,30% (width and height) at the top right corner for every resolutions:

x: 100% - 20%/2 means the right side of the screen

y: 0% means the top side of your screen

width: 20%

height: 30%

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...