Centre a window on the Mac?

BlitzMax Forums/BlitzMax Programming/Centre a window on the Mac?

Grey Alien(Posted 2007) [#1]
Hi, I've had a good search but come up with nothing so far...

I can centre a graphics window created with Graphics 800,600,0 very nicely on the PC with an API call.

Does anyone have any idea how to do this on the Mac please?

Thanks very much.


jhans0n(Posted 2007) [#2]
This works - but it uses MaxGUI.

Local SW:Int = 800
Local SH:Int = 600

MyWindow:TGadget=CreateWindow(AppTitle, (GadgetWidth(Desktop())-SW)/2,(GadgetHeight(Desktop())-SH)/2,SW,SH,Null,WINDOW_CLIENTCOORDS|WINDOW_TITLEBAR)



Grey Alien(Posted 2007) [#3]
OK thx. But I need a non Max Gui Way.

For the PC I got the handle to the current window (via API) then called an API function with some new coordinates that made it centred. There must be something similar for the Mac.


Yan(Posted 2007) [#4]
I'm not too familiar with Objective-C/Cocoa, but I always got the impression from 'glgraphics.macos.m' that windowed mode was already centred on a mac?

Is this not the case then?


Grey Alien(Posted 2007) [#5]
Uh I didn't think it was but I guess I should go and test...


Grey Alien(Posted 2007) [#6]
OK here's what happens. If you load an app and it starts in Windows mode (due to Graphics 800,600,0) then it is centred Horizontally and placed close to the top of the screen. If I drag the window, next time I load the app it is back at that same place, so yes something automatic is happening.

HOWEVER, If I run the game in full screen with Graphics 800,600,32 and then I swap to windowed mode by calling End Graphics and then Graphics 800,600,0, the window is in the bottom left of the desktop, not centred at all. Swapping to full-screen and back to windowed mode THEN centres it. This is weird.

I'd like to sort this behaviour with an API call unless it's a BMax issue because if a user goes into Options in the game and turns off full-screen, they'll think it's odd that the window is down in that corner.

Any ideas? BRL any ideas?