Screen: improved window position, fixed empty line.
* The monitor size now scales with the font size. * It now uses BWindow::MoveOnScreen() to find a good position on screen. * The monitor info is now properly hidden when there is no info (this removes a blank line at the top of the left box).
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2009, Haiku.
|
||||
* Copyright 2001-2015, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -9,48 +9,28 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <StorageKit.h>
|
||||
#include <Screen.h>
|
||||
|
||||
#include "ScreenSettings.h"
|
||||
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
|
||||
|
||||
static const char* kSettingsFileName = "Screen_data";
|
||||
|
||||
|
||||
ScreenSettings::ScreenSettings()
|
||||
{
|
||||
BScreen screen(B_MAIN_SCREEN_ID);
|
||||
BRect screenFrame = screen.Frame();
|
||||
|
||||
fWindowFrame.Set(0, 0, 450, 250);
|
||||
fWindowFrame.Set(-1, -1, 450, 250);
|
||||
|
||||
BPath path;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
|
||||
path.Append(kSettingsFileName);
|
||||
|
||||
BFile file(path.Path(), B_READ_ONLY);
|
||||
if (file.InitCheck() == B_OK) {
|
||||
if (file.InitCheck() == B_OK)
|
||||
file.Read(&fWindowFrame, sizeof(BRect));
|
||||
|
||||
// make sure the window is visible on screen
|
||||
if (fWindowFrame.Width() > screenFrame.Width())
|
||||
fWindowFrame.right = fWindowFrame.left + 450;
|
||||
if (fWindowFrame.Height() > screenFrame.Height())
|
||||
fWindowFrame.bottom = fWindowFrame.top + 250;
|
||||
|
||||
if (screenFrame.right >= fWindowFrame.left + 40
|
||||
&& screenFrame.bottom >= fWindowFrame.top + 40
|
||||
&& screenFrame.left <= fWindowFrame.right - 40
|
||||
&& screenFrame.top <= fWindowFrame.bottom - 40)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Center on screen
|
||||
fWindowFrame.OffsetTo(
|
||||
screenFrame.left + (screenFrame.Width() - fWindowFrame.Width()) / 2,
|
||||
screenFrame.top + (screenFrame.Height() - fWindowFrame.Height()) /2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* Authors:
|
||||
@@ -226,8 +226,9 @@ ScreenWindow::ScreenWindow(ScreenSettings* settings)
|
||||
fDeviceInfo->SetAlignment(B_ALIGN_CENTER);
|
||||
screenBox->AddChild(fDeviceInfo);
|
||||
|
||||
fMonitorView = new MonitorView(BRect(0.0, 0.0, 80.0, 80.0),
|
||||
"monitor", screen.Frame().IntegerWidth() + 1,
|
||||
float scaling = std::max(1.0f, be_plain_font->Size() / 12.0f);
|
||||
fMonitorView = new MonitorView(BRect(0.0, 0.0, 80.0 * scaling,
|
||||
80.0 * scaling), "monitor", screen.Frame().IntegerWidth() + 1,
|
||||
screen.Frame().IntegerHeight() + 1);
|
||||
screenBox->AddChild(fMonitorView);
|
||||
|
||||
@@ -538,6 +539,8 @@ ScreenWindow::ScreenWindow(ScreenSettings* settings)
|
||||
|
||||
_UpdateControls();
|
||||
_UpdateMonitor();
|
||||
|
||||
MoveOnScreen();
|
||||
}
|
||||
|
||||
|
||||
@@ -1237,10 +1240,10 @@ ScreenWindow::_UpdateMonitor()
|
||||
|
||||
fMonitorInfo->SetText(text);
|
||||
|
||||
if (fMonitorInfo->IsHidden())
|
||||
if (fMonitorInfo->IsHidden(fMonitorInfo))
|
||||
fMonitorInfo->Show();
|
||||
} else {
|
||||
if (!fMonitorInfo->IsHidden())
|
||||
if (!fMonitorInfo->IsHidden(fMonitorInfo))
|
||||
fMonitorInfo->Hide();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user