Trouble centering a panel in a window

BlitzMax Forums/BlitzMax GUI Programming/Trouble centering a panel in a window

This ends up centered by width but is off by height. What am I doing wrong?... I can't spot it.

 SuperStrict
Import MaxGui.Drivers
Local W:Int = 640, H:Int = 480

Local MyWindow:TGadget=CreateWindow("Panel Background Image", 200,200,W,H)
Local Panel2D:TGadget=CreatePanel(W/4,H/4,W/2,H/2, MyWindow,PANEL_GROUP )

Local image:TPixmap=LoadPixmap("B-max.png")
'SetGadgetPixmap Panel2D, image, PANELPIXMAP_STRETCH

Repeat
  WaitEvent()
  Select EventID()
  Case EVENT_WINDOWCLOSE
     End
   End Select
Forever
 


The width and height of the window includes the titlebar and borders and menubar and so on, but the position of the panel is relative to the usable area of the window, which is just beneath the menu bar.

That's why your panel is off a bit.

Don't know if there's a cross-platform clean solution to find the usable area of the window. I usually just subtract some hardcoded values from the window sizes and go with that.

Use ClientWidth() and ClientHeight() instead! And better no hardcoded values:)

 SuperStrict
Import MaxGui.Drivers
Local W:Int = 640, H:Int = 480

Local MyWindow:TGadget=CreateWindow("Panel Background Image", 200,200,W,H)
Local Panel2D:TGadget=CreatePanel(ClientWidth(MyWindow)/4,ClientHeight(MyWindow)/4,ClientWidth(MyWindow)/2,ClientHeight(MyWindow)/2, MyWindow,PANEL_GROUP )
'Local Panel2D:TGadget=CreatePanel(W/4,H/4,W/2,H/2, MyWindow,PANEL_GROUP )

Local image:TPixmap=LoadPixmap("B-max.png")
'SetGadgetPixmap Panel2D, image, PANELPIXMAP_STRETCH

Repeat
  WaitEvent()
  Select EventID()
  Case EVENT_WINDOWCLOSE
     End
   End Select
Forever
 


Oooooh, so that's what ClientWidth() and ClientHeight() are for. Thanks jsp! Now I feel really dumb for not figuring that out. :)

Or use the WINDOW_CLIENTCOORDS flag with your CreateWindow() call, in which case the window will be created such that the window's client area dimensions are the supplied width and height (W and H).

Very helpful. All is good :)
Thanks!

If you you didn't use ClientWidth() and ClientHeight() before, than you may not know that it can be used not only for windows but all other gadgets as well (container gadgets obviously, GroupPanel, BorderPanel and such). For the Desktop() it retrieves the primary screen size when there is more than one screen/monitor.