Center a window in BMax

BlitzMax Forums/MaxGUI Module/Center a window in BMax

AD(Posted 2007) [#1]
How do you centre a window in BMax on your screen?

Local window:TGadget
Local w = 600
Local h = 800

window=CreateWindow( myAppTitle$, 40, 40,h,w,,WINDOW_TITLEBAR)

While True
   WaitEvent 
   Print CurrentEvent.ToString()
   Select EventID()
   	Case EVENT_WINDOWCLOSE
   		End
   End Select
Wend



degac(Posted 2007) [#2]
Local window:TGadget
Local w = 600
Local h = 400
Local dx:Int = ClientWidth(Desktop() )
Local dy:Int = ClientHeight(Desktop() )

dx = dx / 2 - w / 2
dy = dy/2 -h/2


window=CreateWindow( myAppTitle$, dx,dy,w,h,,WINDOW_TITLEBAR)

While True
   WaitEvent 
   Print CurrentEvent.ToString()
   Select EventID()
   	Case EVENT_WINDOWCLOSE
   		End
   End Select
Wend



plash(Posted 2007) [#3]
Here's a function for centering a gadget based on another gadgets position.
It's default setup is for a window.

Function CenterGadgetPos(Wnd:TGadget, Gadget:TGadget = Desktop()) 
  'If Gadget = Null Then Gadget = Desktop()
   Local width:Int = GadgetWidth(Wnd)
   Local Height:Int = GadgetHeight(Wnd) 
	'DebugLog GadgetX(gadget) + "," + GadgetY(gadget) 
	'DebugLog "x" + ((ClientWidth (Gadget) / 2) - (width / 2)) + "y" + ((ClientHeight (Gadget) / 2) - (Height / 2)) + "w" + width + "h" + Height
	SetGadgetShape(Wnd, (ClientWidth (Gadget) / 2) - (width / 2), (ClientHeight (Gadget) / 2) - (Height / 2), width, Height) 

End Function