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:
Axel Dörfler
2015-09-14 20:45:58 +02:00
parent 4d9fc65ec7
commit 8bf216d6dd
2 changed files with 15 additions and 32 deletions
+7 -27
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2009, Haiku. * Copyright 2001-2015, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -9,48 +9,28 @@
*/ */
#include <StorageKit.h>
#include <Screen.h>
#include "ScreenSettings.h" #include "ScreenSettings.h"
#include <File.h>
#include <FindDirectory.h>
#include <Path.h>
static const char* kSettingsFileName = "Screen_data"; static const char* kSettingsFileName = "Screen_data";
ScreenSettings::ScreenSettings() ScreenSettings::ScreenSettings()
{ {
BScreen screen(B_MAIN_SCREEN_ID); fWindowFrame.Set(-1, -1, 450, 250);
BRect screenFrame = screen.Frame();
fWindowFrame.Set(0, 0, 450, 250);
BPath path; BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
path.Append(kSettingsFileName); path.Append(kSettingsFileName);
BFile file(path.Path(), B_READ_ONLY); BFile file(path.Path(), B_READ_ONLY);
if (file.InitCheck() == B_OK) { if (file.InitCheck() == B_OK)
file.Read(&fWindowFrame, sizeof(BRect)); 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);
} }
+8 -5
View File
@@ -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:
@@ -226,8 +226,9 @@ ScreenWindow::ScreenWindow(ScreenSettings* settings)
fDeviceInfo->SetAlignment(B_ALIGN_CENTER); fDeviceInfo->SetAlignment(B_ALIGN_CENTER);
screenBox->AddChild(fDeviceInfo); screenBox->AddChild(fDeviceInfo);
fMonitorView = new MonitorView(BRect(0.0, 0.0, 80.0, 80.0), float scaling = std::max(1.0f, be_plain_font->Size() / 12.0f);
"monitor", screen.Frame().IntegerWidth() + 1, fMonitorView = new MonitorView(BRect(0.0, 0.0, 80.0 * scaling,
80.0 * scaling), "monitor", screen.Frame().IntegerWidth() + 1,
screen.Frame().IntegerHeight() + 1); screen.Frame().IntegerHeight() + 1);
screenBox->AddChild(fMonitorView); screenBox->AddChild(fMonitorView);
@@ -538,6 +539,8 @@ ScreenWindow::ScreenWindow(ScreenSettings* settings)
_UpdateControls(); _UpdateControls();
_UpdateMonitor(); _UpdateMonitor();
MoveOnScreen();
} }
@@ -1237,10 +1240,10 @@ ScreenWindow::_UpdateMonitor()
fMonitorInfo->SetText(text); fMonitorInfo->SetText(text);
if (fMonitorInfo->IsHidden()) if (fMonitorInfo->IsHidden(fMonitorInfo))
fMonitorInfo->Show(); fMonitorInfo->Show();
} else { } else {
if (!fMonitorInfo->IsHidden()) if (!fMonitorInfo->IsHidden(fMonitorInfo))
fMonitorInfo->Hide(); fMonitorInfo->Hide();
} }