BWindow: CenterOnScreen a bit above center

BWindow docs: Document changes to CenterOnScreen()

https://68.media.tumblr.com/d8dff7a17b9d90b41e32c5a2a0312513/tumblr_oj2wg1tmKs1r0f0hfo1_1280.png

Will revert if not appreciated.
This commit is contained in:
John Scipione 2016-12-31 16:59:00 -08:00
parent 879db60ae0
commit a5be1832cc
3 changed files with 59 additions and 4 deletions

View File

@ -1954,7 +1954,11 @@
/*!
\fn void BWindow::CenterOnScreen()
\brief Centers the window on the screen the window is currently on.
\brief Centers the window on the current screen.
The window is positioned on the screen a bit above center. If you want to
center the window exactly in the middle you'll need to use
BWindow::CenterIn() instead.
\since Haiku R1
*/
@ -1964,6 +1968,12 @@
\fn void BWindow::CenterOnScreen(screen_id id)
\brief Centers the window on the screen with the passed in \a id.
\param id The screen_id of the screen to center the window in.
The window is positioned on the screen a bit above center. If you want to
center the window exactly in the middle you'll need to use
BWindow::CenterIn() instead.
\since Haiku R1
*/

View File

@ -366,6 +366,8 @@ private:
float* _tabHeight) const;
void _SendShowOrHideMessage();
void _CenterAboveCenter(BRect rect);
private:
char* fTitle;
int32 _unused0;

View File

@ -2568,6 +2568,7 @@ BWindow::ResizeToPreferred()
}
// Centers the window in rect.
void
BWindow::CenterIn(const BRect& rect)
{
@ -2582,18 +2583,21 @@ BWindow::CenterIn(const BRect& rect)
}
// Centers the window offset a bit above center on the current screen.
void
BWindow::CenterOnScreen()
{
CenterIn(BScreen(this).Frame());
BRect screenFrame(BScreen(this).Frame());
_CenterAboveCenter(screenFrame);
}
// Centers the window on the screen with the passed in id.
// Centers the window offset a bit above center on the screen specified by id.
void
BWindow::CenterOnScreen(screen_id id)
{
CenterIn(BScreen(id).Frame());
BRect screenFrame(BScreen(id).Frame());
_CenterAboveCenter(screenFrame);
}
@ -4180,6 +4184,45 @@ BWindow::_SendShowOrHideMessage()
}
// Centers the window in the rect offset a bit above center.
void
BWindow::_CenterAboveCenter(BRect rect)
{
BAutolock locker(this);
// Set size limits now if needed
UpdateSizeLimits();
BPoint centered = BLayoutUtils::AlignInFrame(rect, Size(),
BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER))
.LeftTop();
centered.y -= floorf(rect.Height() / 16);
// Offset y coordinate so that the window is positioned like this:
// ----------------------------------------------------------
// | |
// | |
// | _________ |
// | [_]_______|_____________ |
// | | | |
// | | | |
// | | | |
// | | | |
// | | | |
// | | | |
// | |_______________________| |
// | |
// | |
// | |
// | |
// | |
// | |
// ----------------------------------------------------------
MoveTo(centered);
}
// #pragma mark - C++ binary compatibility kludge