1 #include <StorageKit.h> 2 #include <Screen.h> 3 4 #include "ScreenSettings.h" 5 6 const char ScreenSettings::fScreenSettingsFile[] = "Screen_data"; 7 8 ScreenSettings::ScreenSettings() 9 { 10 BScreen screen(B_MAIN_SCREEN_ID); 11 12 if (!screen.IsValid()) 13 ; //Debugger() ? 14 15 fWindowFrame.Set( 0, 0, 356, 202 ); 16 17 BRect screenFrame = screen.Frame(); 18 19 BPath path; 20 if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) 21 { 22 path.Append(fScreenSettingsFile); 23 24 BFile file(path.Path(), B_READ_ONLY); 25 if (file.InitCheck() == B_OK) 26 { 27 BPoint point; 28 file.Read(&point, sizeof(BPoint)); 29 fWindowFrame.OffsetTo(point); 30 31 if (screen.Frame().right >= fWindowFrame.right 32 && screen.Frame().bottom >= fWindowFrame.bottom) 33 return; 34 } 35 } 36 fWindowFrame.OffsetTo((screenFrame.Width() - fWindowFrame.Width()) / 2, 37 (screenFrame.Height() - fWindowFrame.Height()) /2 ); 38 } 39 40 41 ScreenSettings::~ScreenSettings() 42 { 43 BPath path; 44 if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK) 45 return; 46 47 path.Append(fScreenSettingsFile); 48 49 BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE); 50 if (file.InitCheck() == B_OK) { 51 BPoint point(fWindowFrame.LeftTop()); 52 file.Write(&point, sizeof(BPoint)); 53 } 54 } 55 56 57 void 58 ScreenSettings::SetWindowFrame(BRect frame) 59 { 60 fWindowFrame = frame; 61 } 62