Jump to content

Function:centerWindow


Recommended Posts

Posted

function centerWindow(center_window) 
    local screenW,screenH=guiGetScreenSize() 
    local windowW,windowH=guiGetSize(center_window,false) 
    local x,y = (screenW-windowW)/2,(screenH-windowH)/2 
    guiSetPosition(center_window,x,y,false) 
end 
  

Example

  
local wnd = guiCreateWindow(...) 
centerWindow(wnd) 
  

Posted

You could make it;

function centerWindow(window) 
    local resX,resY = guiGetScreenSize() 
    local w,h = guiGetSize(window,false) 
    guiSetPosition(window,(resX/2)-(w/2),(resY/2)-(h/2),false) 
end 

Posted

it would be most effective and recommended to put guiGetScreenSize() at front of any clientside script with dx/gui functions, so you don't have to call twice.

Posted
2 lines are needed
guiSetProperty( gui-window, "HorizontalAlignment", "Centre") 
guiSetProperty( gui-window, "VerticalAlignment", "Centre") 

I think, shut up.

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