* The saved screen position is now checked; if not at least 40 pixels of the
window are on screen in any direction, it will fall back to the default position (ie. centered on screen). * Centering the window now takes an eventual screen offset into account. * Cleanup, added license. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16874 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,40 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2001-2006, Haiku.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Rafael Romo
|
||||||
|
* Stefano Ceccherini ([email protected])
|
||||||
|
* Axel Dörfler, [email protected]
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <StorageKit.h>
|
#include <StorageKit.h>
|
||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
|
|
||||||
#include "ScreenSettings.h"
|
#include "ScreenSettings.h"
|
||||||
|
|
||||||
const char ScreenSettings::fScreenSettingsFile[] = "Screen_data";
|
|
||||||
|
static const char* kSettingsFileName = "Screen_data";
|
||||||
|
|
||||||
|
|
||||||
ScreenSettings::ScreenSettings()
|
ScreenSettings::ScreenSettings()
|
||||||
{
|
{
|
||||||
BScreen screen(B_MAIN_SCREEN_ID);
|
BScreen screen(B_MAIN_SCREEN_ID);
|
||||||
|
BRect screenFrame = screen.Frame();
|
||||||
if (!screen.IsValid())
|
|
||||||
; //Debugger() ?
|
|
||||||
|
|
||||||
fWindowFrame.Set(0, 0, 356, 202);
|
fWindowFrame.Set(0, 0, 356, 202);
|
||||||
|
|
||||||
BRect screenFrame = screen.Frame();
|
|
||||||
|
|
||||||
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(fScreenSettingsFile);
|
|
||||||
|
|
||||||
BFile file(path.Path(), B_READ_ONLY);
|
BFile file(path.Path(), B_READ_ONLY);
|
||||||
if (file.InitCheck() == B_OK)
|
if (file.InitCheck() == B_OK) {
|
||||||
{
|
|
||||||
BPoint point;
|
BPoint point;
|
||||||
file.Read(&point, sizeof(BPoint));
|
file.Read(&point, sizeof(BPoint));
|
||||||
fWindowFrame.OffsetTo(point);
|
fWindowFrame.OffsetTo(point);
|
||||||
|
|
||||||
if (screen.Frame().right >= fWindowFrame.right
|
// make sure the window is visible on screen
|
||||||
&& screen.Frame().bottom >= fWindowFrame.bottom)
|
if (screenFrame.right >= fWindowFrame.left + 40
|
||||||
|
&& screenFrame.bottom >= fWindowFrame.top + 40
|
||||||
|
&& screenFrame.left <= fWindowFrame.right - 40
|
||||||
|
&& screenFrame.top <= fWindowFrame.bottom - 40)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fWindowFrame.OffsetTo((screenFrame.Width() - fWindowFrame.Width()) / 2,
|
|
||||||
(screenFrame.Height() - fWindowFrame.Height()) /2 );
|
fWindowFrame.OffsetTo(screenFrame.left + (screenFrame.Width() - fWindowFrame.Width()) / 2,
|
||||||
|
screenFrame.top + (screenFrame.Height() - fWindowFrame.Height()) /2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -44,7 +55,7 @@ ScreenSettings::~ScreenSettings()
|
|||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
path.Append(fScreenSettingsFile);
|
path.Append(kSettingsFileName);
|
||||||
|
|
||||||
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
|
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
|
||||||
if (file.InitCheck() == B_OK) {
|
if (file.InitCheck() == B_OK) {
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
#ifndef __SCREENSETTINGS_H
|
/*
|
||||||
#define __SCREENSETTINGS_H
|
* Copyright 2001-2006, Haiku.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Rafael Romo
|
||||||
|
* Stefano Ceccherini ([email protected])
|
||||||
|
* Axel Dörfler, [email protected]
|
||||||
|
*/
|
||||||
|
#ifndef SCREEN_SETTINGS_H
|
||||||
|
#define SCREEN_SETTINGS_H
|
||||||
|
|
||||||
#include <View.h>
|
|
||||||
|
|
||||||
class ScreenSettings
|
#include <Rect.h>
|
||||||
{
|
|
||||||
|
|
||||||
|
class ScreenSettings {
|
||||||
public:
|
public:
|
||||||
ScreenSettings();
|
ScreenSettings();
|
||||||
virtual ~ScreenSettings();
|
virtual ~ScreenSettings();
|
||||||
@@ -13,8 +23,7 @@ public:
|
|||||||
void SetWindowFrame(BRect);
|
void SetWindowFrame(BRect);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const char fScreenSettingsFile[];
|
|
||||||
BRect fWindowFrame;
|
BRect fWindowFrame;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // SCREEN_SETTINGS_H
|
||||||
|
|||||||
Reference in New Issue
Block a user