It is currently Fri May 26, 2017 8:30 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Centering window on screen [RESOLVED]
PostPosted: Wed Dec 07, 2016 7:46 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Jun 21, 2011 10:39 am
Posts: 326
Why are windows opened with the screen centered flag not centered vertically on the y axis?
Code:
OpenWindow(0, 0, 0, 300, 300, "Center Screen", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow


Last edited by coder14 on Sun Dec 18, 2016 11:01 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Centering window on screen
PostPosted: Wed Dec 07, 2016 1:03 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Jun 21, 2011 10:39 am
Posts: 326
Still cannot get it to center vertically. A bug?


Top
 Profile  
Reply with quote  
 Post subject: Re: Centering window on screen
PostPosted: Wed Dec 07, 2016 8:04 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Apr 29, 2003 9:18 pm
Posts: 1426
Location: North by Northwest
Hi,
using:
Code:
OpenWindow(0, 0, 0, 300, 300, "Center Screen", #PB_Window_SystemMenu)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

shows that #PB_Window_ScreenCentered really does something.

Using:
Code:
OpenWindow(0, 0, 0, 300, 300, "Center Screen", #PB_Window_SystemMenu)
CocoaMessage(0,WindowID(0),"center")
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

gives exactly the same result.

Doing a little bit more digging reveals this:

    The window is placed exactly in the center horizontally and somewhat above center vertically.
    Such a placement carries a certain visual immediacy and importance.


This is the source: https://developer.apple.com/reference/appkit/nswindow/1419090-center

So the answer is: it's by Apple's UI design :shock:

If you still want to have your window better "somewhat" centered you have to do it with code...
(quick and dirty...)
Code:
ExamineDesktops()

Procedure TryToCenterTheWindow(window)
  ; not 100% centered on Y axis because of titlebar
  Protected xPos = (DesktopWidth(0) / 2) - (WindowWidth(window) / 2)
  Protected yPos = (DesktopHeight(0) / 2) - (WindowHeight(window) / 2)
 
  ResizeWindow(window, xPos, yPos, #PB_Ignore, #PB_Ignore)
EndProcedure

OpenWindow(0, 0, 0, 300, 300, "Center Screen", #PB_Window_SystemMenu)
TryToCenterTheWindow(0)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

This quick and dirty code doesn't take into account how many monitors are used...

Looking at both solutions Apple's placement really seems to be "nicer" to look at.

As aways: Perception is reality...

:mrgreen:

_________________

I am to provide the public with beneficial shocks.
Alfred Hitshock


Top
 Profile  
Reply with quote  
 Post subject: Re: Centering window on screen
PostPosted: Sun Dec 18, 2016 11:01 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Jun 21, 2011 10:39 am
Posts: 326
Thanks fsw! Sorry for the late reply. :oops:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye