Finally implemented BWindow::CenterOnScreen, with associated CenterIn(BRect)
methods as well as Size(). To avoid the problem of centering the window before it has been resized by the layout system, I force the resizing early. If there is a better way to do this or some way to avoid doing it repeatedly, let me know. But I figure the Center* methods should not be called that often. Updated Screenshot and DiskProbe to use this new method as a test. It certainly cleaned up DiskProbe. I will update other code over the next few days (if anyone wants to help, please do :) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32612 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
#include <Bitmap.h>
|
||||
#include <Button.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Layout.h>
|
||||
#include <LayoutUtils.h>
|
||||
#include <MenuBar.h>
|
||||
#include <MenuItem.h>
|
||||
#include <MessageQueue.h>
|
||||
@@ -2026,6 +2028,13 @@ BWindow::DecoratorFrame() const
|
||||
}
|
||||
|
||||
|
||||
BSize
|
||||
BWindow::Size() const
|
||||
{
|
||||
return BSize(fFrame.Width(), fFrame.Height());
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
BWindow::Title() const
|
||||
{
|
||||
@@ -2448,6 +2457,36 @@ BWindow::ResizeTo(float width, float height)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BWindow::CenterIn(BRect rect)
|
||||
{
|
||||
// Force layout resizing if needed
|
||||
if (GetLayout() != NULL) {
|
||||
BSize size = GetLayout()->PreferredSize();
|
||||
ResizeTo(size.Width(), size.Height());
|
||||
}
|
||||
|
||||
MoveTo(BLayoutUtils::AlignInFrame(rect, Size(),
|
||||
BAlignment(B_ALIGN_HORIZONTAL_CENTER,
|
||||
B_ALIGN_VERTICAL_CENTER)).LeftTop());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BWindow::CenterIn(BRect* rect)
|
||||
{
|
||||
CenterIn(*rect);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BWindow::CenterOnScreen()
|
||||
{
|
||||
BScreen screen(this);
|
||||
CenterIn(screen.Frame());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BWindow::Show()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user