Incredibly smart BWindow::MoveOnScreen() method added.
* Makes sure that the window is as complete as possible on screen.
This commit is contained in:
parent
b7d0120074
commit
ebf4cbe6e7
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2011, Haiku, Inc. All rights reserved.
|
* Copyright 2001-2015, Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _WINDOW_H
|
#ifndef _WINDOW_H
|
||||||
@ -170,6 +170,7 @@ public:
|
|||||||
void CenterIn(const BRect& rect);
|
void CenterIn(const BRect& rect);
|
||||||
void CenterOnScreen();
|
void CenterOnScreen();
|
||||||
void CenterOnScreen(screen_id id);
|
void CenterOnScreen(screen_id id);
|
||||||
|
void MoveOnScreen();
|
||||||
|
|
||||||
virtual void Show();
|
virtual void Show();
|
||||||
virtual void Hide();
|
virtual void Hide();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2014 Haiku, Inc. All rights reserved
|
* Copyright 2001-2015 Haiku, Inc. All rights reserved
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@ -2568,6 +2568,47 @@ BWindow::CenterOnScreen(screen_id id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BWindow::MoveOnScreen()
|
||||||
|
{
|
||||||
|
// Set size limits now if needed
|
||||||
|
UpdateSizeLimits();
|
||||||
|
|
||||||
|
BRect screenFrame = BScreen(this).Frame();
|
||||||
|
BRect frame = Frame();
|
||||||
|
|
||||||
|
float borderWidth;
|
||||||
|
float tabHeight;
|
||||||
|
_GetDecoratorSize(&borderWidth, &tabHeight);
|
||||||
|
|
||||||
|
frame.InsetBy(-borderWidth, -borderWidth);
|
||||||
|
frame.top -= tabHeight;
|
||||||
|
|
||||||
|
if (!frame.Intersects(screenFrame)) {
|
||||||
|
// Off and away
|
||||||
|
CenterOnScreen();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move such that the upper left corner, and most of the window
|
||||||
|
// will be visible.
|
||||||
|
float left = frame.left;
|
||||||
|
if (left < screenFrame.left)
|
||||||
|
left = screenFrame.left;
|
||||||
|
else if (frame.right > screenFrame.right)
|
||||||
|
left = std::max(0.f, screenFrame.right - frame.Width());
|
||||||
|
|
||||||
|
float top = frame.top;
|
||||||
|
if (top < screenFrame.top)
|
||||||
|
top = screenFrame.top;
|
||||||
|
else if (frame.bottom > screenFrame.bottom)
|
||||||
|
top = std::max(0.f, screenFrame.bottom - frame.Height());
|
||||||
|
|
||||||
|
if (top != frame.top || left != frame.left)
|
||||||
|
MoveTo(left + borderWidth, top + tabHeight + borderWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BWindow::Show()
|
BWindow::Show()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user