ID:161392
 
When you open a new interface window on top of the main window, is there some way that you can center the window in the middle of the player's monitor, or in the center of the game's window?

Currently, when you open a new window, they typically start out aligned with the top of the screen. With a full screen game, its kind of annoying to have to move the window down back into a better spot.
Try this.

control_id: id of the window/pane/control that you want to center
loc_id: id of the mainwindow

It wont work well if the "is-maximized" parameter of any of the two is true.

mob
proc
center(control_id,loc_id)
if(!(control_id&&loc_id))
return
var/size = winget(src, control_id, "size")
var/pos = findtext(size,"x",1,0)
var/w = text2num(copytext(size,1,pos))
var/h = text2num(copytext(size,pos+1))
var/Size = winget(src, loc_id, "size")
var/x_pos = findtext(Size,"x",1,0)
var/W = text2num(copytext(Size,1,x_pos))
var/H = text2num(copytext(Size,x_pos+1))
var/Pos = winget(src, loc_id, "pos")
var/c_pos = findtext(Pos,",",1,0)
var/X = text2num(copytext(Pos,1,c_pos))
var/Y = text2num(copytext(Pos,c_pos+1))
var/x = (W - w) / 2 + X
var/y = (H - h) / 2 + Y
winset(src, control_id, "pos=[x],[y]")