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:
@@ -14,6 +14,7 @@
|
||||
#include <List.h>
|
||||
#include <Looper.h>
|
||||
#include <Rect.h>
|
||||
#include <Size.h>
|
||||
#include <StorageDefs.h>
|
||||
#include <View.h>
|
||||
|
||||
@@ -167,6 +168,10 @@ public:
|
||||
void ResizeBy(float dx, float dy);
|
||||
void ResizeTo(float width, float height);
|
||||
|
||||
void CenterIn(BRect* rect);
|
||||
void CenterIn(BRect rect);
|
||||
void CenterOnScreen();
|
||||
|
||||
virtual void Show();
|
||||
virtual void Hide();
|
||||
bool IsHidden() const;
|
||||
@@ -188,6 +193,7 @@ public:
|
||||
BRect Bounds() const;
|
||||
BRect Frame() const;
|
||||
BRect DecoratorFrame() const;
|
||||
BSize Size() const;
|
||||
const char* Title() const;
|
||||
void SetTitle(const char* title);
|
||||
bool IsFront() const;
|
||||
|
||||
@@ -57,22 +57,8 @@ OpenWindow::OpenWindow()
|
||||
.Add(probeDeviceButton, 2, 1)
|
||||
.SetInsets(8, 8, 8, 8)
|
||||
);
|
||||
BScreen screen(this);
|
||||
// move the window offscreen..
|
||||
MoveTo(screen.Frame().right+20, screen.Frame().top);
|
||||
fCentered = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OpenWindow::FrameResized(float width, float height)
|
||||
{
|
||||
if (fCentered) {
|
||||
BScreen screen(this);
|
||||
MoveTo(screen.Frame().left + (screen.Frame().Width() - width) / 2,
|
||||
screen.Frame().top + (screen.Frame().Height() - height) / 2);
|
||||
}
|
||||
fCentered = false;
|
||||
CenterOnScreen();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,14 +20,11 @@ public:
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual bool QuitRequested();
|
||||
|
||||
virtual void FrameResized(float width, float height);
|
||||
|
||||
static void CollectDevices(BMenu* menu,
|
||||
BEntry* startEntry = NULL);
|
||||
|
||||
private:
|
||||
BMenu* fDevicesMenu;
|
||||
bool fCentered;
|
||||
};
|
||||
|
||||
#endif /* OPEN_WINDOW_H */
|
||||
|
||||
@@ -492,12 +492,7 @@ ScreenshotWindow::_AddItemToPathMenu(const char* path, BString& label,
|
||||
void
|
||||
ScreenshotWindow::_CenterAndShow()
|
||||
{
|
||||
BSize size = GetLayout()->PreferredSize();
|
||||
ResizeTo(size.Width(), size.Height());
|
||||
|
||||
BRect frame(BScreen(this).Frame());
|
||||
MoveTo((frame.Width() - size.Width()) / 2.0,
|
||||
(frame.Height() - size.Height()) / 2.0);
|
||||
CenterOnScreen();
|
||||
|
||||
Show();
|
||||
}
|
||||
|
||||
@@ -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