Jump to content

[HELP] Make guiCreateWindow scale to all resolutions


Backsage

Recommended Posts

I'll show you an example

local sW, sH = guiGetScreenSize() 
local sx, sy = sW/1920, sH/1080 
  
addEventHandler ( "onClientRender", root, function ( ) 
    dxCreateRectangle ( sW*0.5 - 50*sx, sH*0.5 - 50*sy, 100*sx, 100*sy, tocolor ( 255, 0, 0 ), true ) 
end ) 

This rectangle will have the same scale in every resolution.

But in your code:

sW*0.5-481/2 

sW*0.5 is good, but 481/2 will be different in every resolution.

local sW, sH = guiGetScreenSize() 
local sx, sy = sW/1920, sH/1080 
GUIEditor.window[1] = guiCreateWindow(sW*0.5-481/2*sx, sH*0.5-412/2*sy, 481*sy, 412*sy, "", false) 

This will solve your problem

Link to comment
Well, I am trying to create a window and I want it to scale properly on all resolutions. I tried using TEDERI's method, but it won't scale properly. I tried previewing it in different resolutions, but it doesn't scale.

https://forum.multitheftauto.com/viewto ... 91&t=33149

http://pastebin.com/3N8Jb3iq

So if you want to create an element im the middle of the screen this might help you

  
local screenW, screenH = guiGetScreenSize() 
local elemW, elemH = 300,400 --Your element width and height  
  
function testWindow() 
      local theWindow = guiCreateWindow( (screenW - elemW)/2,(screenH-elemH)/2,elemW,elemH,"Test") 
end 
addEventHandler("onClientResourceStart, getRootElement(),testWindow) 
  
  
 

The formula to make a GUI elem in the middle of the screen is

  
guiCreate(yourElement)( (screenWidth - elementWidth)/2,(screenHeight - elementHeight)/2,screenWidth,screenHeight,...) 
  

Link to comment
  • 3 weeks later...
Well, I am trying to create a window and I want it to scale properly on all resolutions. I tried using TEDERI's method, but it won't scale properly. I tried previewing it in different resolutions, but it doesn't scale.

https://forum.multitheftauto.com/viewto ... 91&t=33149

http://pastebin.com/3N8Jb3iq

So if you want to create an element im the middle of the screen this might help you

  
local screenW, screenH = guiGetScreenSize() 
local elemW, elemH = 300,400 --Your element width and height  
  
function testWindow() 
      local theWindow = guiCreateWindow( (screenW - elemW)/2,(screenH-elemH)/2,elemW,elemH,"Test") 
end 
addEventHandler("onClientResourceStart, getRootElement(),testWindow) 
  
  
  
 

The formula to make a GUI elem in the middle of the screen is

  
guiCreate(yourElement)( (screenWidth - elementWidth)/2,(screenHeight - elementHeight)/2,screenWidth,screenHeight,...) 
  

All this does is center it to the screen. I'm talking about making it actually scale based on the resolution. How is it that this only works when using relative values, but not for absolute values? If I use the relative argument, I have to do that on every single GUI element that's on the window, including the window, so that it'll scale properly. I can't just do it for the window or else the other GUI elements will be too big. I hope you understand what I mean.
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...