Update CenterIn() and CenterOnScreen() methods in BWindow
* These methods now return the new point after centering. * But more importantly CenterIn() does some new adjustments to keep the window position inside the screen edge. If you pass the screen frame into CenterIn() it skips these adjustments.
This commit is contained in:
@@ -166,8 +166,8 @@ public:
|
||||
void ResizeBy(float dx, float dy);
|
||||
void ResizeTo(float width, float height);
|
||||
|
||||
void CenterIn(const BRect& rect);
|
||||
void CenterOnScreen();
|
||||
BPoint CenterIn(const BRect& rect);
|
||||
BPoint CenterOnScreen();
|
||||
|
||||
virtual void Show();
|
||||
virtual void Hide();
|
||||
|
||||
@@ -2584,23 +2584,62 @@ BWindow::ResizeTo(float width, float height)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
/*!
|
||||
\brief Center the window in the passed in rectangular area.
|
||||
\param rect The rectangle to center the window in.
|
||||
\return The new window position.
|
||||
*/
|
||||
BPoint
|
||||
BWindow::CenterIn(const BRect& rect)
|
||||
{
|
||||
// Set size limits now if needed
|
||||
UpdateSizeLimits();
|
||||
|
||||
MoveTo(BLayoutUtils::AlignInFrame(rect, Size(),
|
||||
BPoint point = BLayoutUtils::AlignInFrame(rect, Size(),
|
||||
BAlignment(B_ALIGN_HORIZONTAL_CENTER,
|
||||
B_ALIGN_VERTICAL_CENTER)).LeftTop());
|
||||
B_ALIGN_VERTICAL_CENTER)).LeftTop();
|
||||
|
||||
BRect screenFrame = (BScreen(this)).Frame();
|
||||
if (screenFrame == rect) {
|
||||
// if rect is the screen frame we can skip the ajustments below
|
||||
MoveTo(point);
|
||||
return point;
|
||||
}
|
||||
|
||||
float borderWidth;
|
||||
float tabHeight;
|
||||
_GetDecoratorSize(&borderWidth, &tabHeight);
|
||||
|
||||
// clip the x position within the horizontal edges of the screen
|
||||
if (point.x < screenFrame.left + borderWidth)
|
||||
point.x = screenFrame.left + borderWidth;
|
||||
else if (point.x + Frame().Width() > screenFrame.right - borderWidth)
|
||||
point.x = screenFrame.right - borderWidth - Frame().Width();
|
||||
|
||||
// If the window is covering the window tab lower it down
|
||||
if (point.y < rect.LeftTop().y + borderWidth)
|
||||
point.y = rect.LeftTop().y + borderWidth;
|
||||
|
||||
// clip the y position within the vertical edges of the screen
|
||||
if (point.y < screenFrame.top + borderWidth)
|
||||
point.y = screenFrame.top + borderWidth;
|
||||
else if (point.y + Frame().Height() > screenFrame.bottom - borderWidth)
|
||||
point.y = screenFrame.bottom - borderWidth - Frame().Height();
|
||||
|
||||
MoveTo(point);
|
||||
return point;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
/*!
|
||||
\brief Centers the window on the screen the window is currently on.
|
||||
\return The new window position.
|
||||
*/
|
||||
BPoint
|
||||
BWindow::CenterOnScreen()
|
||||
{
|
||||
BScreen screen(this);
|
||||
CenterIn(screen.Frame());
|
||||
return CenterIn(screen.Frame());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user