Huge commit. Fixed screen preflet. It does work now. Still has some minor bugs, but it's fully functional.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2070 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2002-11-24 00:26:55 +00:00
parent 673ecc16e5
commit a4cd2d3f33
16 changed files with 311 additions and 902 deletions
+11 -11
View File
@@ -4,27 +4,29 @@
#include "AlertView.h"
#include "Bitmaps.h"
#include "Constants.h"
#include "Utility.h"
AlertView::AlertView(BRect frame, char *name)
: BView(frame, name, B_FOLLOW_ALL, B_WILL_DRAW)
{
Count = 10;
Count = 8;
fBitmap = new BBitmap(BRect(0, 0, 31, 31), B_COLOR_8_BIT);
fBitmap->SetBits(BitmapBits, 32 * 32, 0, B_COLOR_8_BIT);
}
void AlertView::AttachedToWindow()
void
AlertView::AttachedToWindow()
{
rgb_color greyColor = {216, 216, 216, 255};
SetViewColor(greyColor);
}
void AlertView::Draw(BRect updateRect)
{
rgb_color darkColor = {184, 184, 184, 255};
rgb_color blackColor = {0, 0, 0, 255};
void
AlertView::Draw(BRect updateRect)
{
SetHighColor(darkColor);
FillRect(BRect(0.0, 0.0, 30.0, 100.0));
@@ -39,9 +41,7 @@ void AlertView::Draw(BRect updateRect)
SetFont(be_bold_font);
MovePenTo(60.0, 20.0);
DrawString("Do you wish to keep these settings?");
DrawString("Do you wish to keep these settings?", BPoint(60.0, 20.0));
MovePenTo(60.0, 37.0);
+4 -4
View File
@@ -8,10 +8,10 @@ class AlertView : public BView
{
public:
AlertView(BRect frame, char *name);
virtual void AttachedToWindow();
virtual void Draw(BRect updateRect);
int32 Count;
AlertView(BRect frame, char *name);
virtual void AttachedToWindow();
virtual void Draw(BRect updateRect);
int32 Count;
private:
BBitmap *fBitmap;
+8 -4
View File
@@ -49,16 +49,20 @@ AlertWindow::AlertWindow(BRect frame)
Show();
}
bool AlertWindow::QuitRequested()
bool
AlertWindow::QuitRequested()
{
delete fRunner;
Quit();
return(true);
return true;
}
void AlertWindow::MessageReceived(BMessage *message)
void
AlertWindow::MessageReceived(BMessage *message)
{
switch (message->what)
{
+5 -1
View File
@@ -1,6 +1,7 @@
#ifndef CONSTANTS_H
#define CONSTANTS_H
//Messages
#define WORKSPACE_CHECK_MSG 'wchk'
#define BUTTON_DEFAULTS_MSG 'bdef'
#define BUTTON_REVERT_MSG 'brev'
@@ -22,4 +23,7 @@
#define DIM_COUNT_MSG 'scrf'
#define MAKE_INITIAL_MSG 'mkin'
#endif
//Constants
static const char kAppSignature[] = "application/x-vnd.RR-SCRN";
#endif //CONSTANTS_H
+1 -1
View File
@@ -2,6 +2,6 @@ SubDir OBOS_TOP src prefs screen ;
AddResources Screen : Screen.rsrc ;
Preference Screen : AlertView.cpp AlertWindow.cpp RefreshSlider.cpp RefreshView.cpp RefreshWindow.cpp Screen.cpp ScreenDrawView.cpp ScreenSettings.cpp ScreenView.cpp ScreenWindow.cpp ;
Preference Screen : AlertView.cpp AlertWindow.cpp RefreshSlider.cpp RefreshView.cpp RefreshWindow.cpp Screen.cpp ScreenDrawView.cpp ScreenSettings.cpp ScreenView.cpp ScreenWindow.cpp Utility.cpp ;
LinkSharedOSLibs Screen : be root ;
+31 -37
View File
@@ -11,41 +11,40 @@
#include "Constants.h"
RefreshSlider::RefreshSlider(BRect frame)
: BSlider(frame, "Screen", "Refresh Rate:", new BMessage(SLIDER_INVOKE_MSG), 450, 845)
{
fStatus = (char*)malloc(64);
: BSlider(frame, "Screen", "Refresh Rate:", new BMessage(SLIDER_INVOKE_MSG), 450, 900),
fStatus(new char[64])
{
}
RefreshSlider::~RefreshSlider()
{
if (fStatus)
free(fStatus);
delete[] fStatus;
}
void RefreshSlider::DrawFocusMark()
void
RefreshSlider::DrawFocusMark()
{
if (IsFocus())
{
rgb_color blueColor = {0, 0, 229, 255};
rgb_color blueColor = { 0, 0, 229, 255 };
BRect Rect;
BRect rect(ThumbFrame());
BView *view = OffscreenView();
rect.InsetBy(2.0, 2.0);
rect.right--;
rect.bottom--;
BView *View;
Rect = ThumbFrame();
View = OffscreenView();
Rect.InsetBy(2.0, 2.0);
Rect.right = Rect.right - 1;
Rect.bottom = Rect.bottom - 1;
View->SetHighColor(blueColor);
View->StrokeRect(Rect);
view->SetHighColor(blueColor);
view->StrokeRect(rect);
}
}
void RefreshSlider::KeyDown(const char *bytes, int32 numBytes)
void
RefreshSlider::KeyDown(const char *bytes, int32 numBytes)
{
switch ( *bytes )
{
@@ -72,30 +71,25 @@ void RefreshSlider::KeyDown(const char *bytes, int32 numBytes)
}
}
char* RefreshSlider::UpdateText() const
char*
RefreshSlider::UpdateText() const
{
if (fStatus && Window()->Lock())
{
BString String;
String << Value();
int32 Len = String.Length()+1;
strcpy(fStatus, String.LockBuffer(Len));
char Last = fStatus[2];
String.CopyInto(fStatus, 0, String.Length() + 1);
String.UnlockBuffer(Len);
String.Truncate(2);
char Last = fStatus[2];
String.Truncate(2);
String << "." << Last << " Hz";
strcpy(fStatus, String.LockBuffer(Len));
String.UnlockBuffer(Len);
return(fStatus);
String.CopyInto(fStatus, 0, String.Length() + 1);
return fStatus;
}
else
{
+14 -11
View File
@@ -1,36 +1,39 @@
#include <View.h>
#include "RefreshView.h"
#include "Utility.h"
RefreshView::RefreshView(BRect rect, char *name)
: BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW)
{
}
void RefreshView::AttachedToWindow()
void
RefreshView::AttachedToWindow()
{
rgb_color greyColor = {216, 216, 216, 255};
SetViewColor(greyColor);
}
void RefreshView::Draw(BRect updateRect)
void
RefreshView::Draw(BRect updateRect)
{
rgb_color whiteColor = {255, 255, 255, 255};
rgb_color darkColor = {128, 128, 128, 255};
rgb_color blackColor = {0, 0, 0, 255};
rgb_color darkColor = { 128, 128, 128, 255 };
BRect bounds(Bounds());
SetHighColor(whiteColor);
StrokeLine(BPoint(Bounds().left, Bounds().top), BPoint(Bounds().right, Bounds().top));
StrokeLine(BPoint(Bounds().left, Bounds().top), BPoint(Bounds().left, Bounds().bottom));
StrokeLine(BPoint(bounds.left, bounds.top), BPoint(bounds.right, bounds.top));
StrokeLine(BPoint(bounds.left, bounds.top), BPoint(bounds.left, bounds.bottom));
SetHighColor(darkColor);
StrokeLine(BPoint(Bounds().left, Bounds().bottom), BPoint(Bounds().right, Bounds().bottom));
StrokeLine(BPoint(Bounds().right, Bounds().bottom), BPoint(Bounds().right, Bounds().top));
StrokeLine(BPoint(bounds.left, bounds.bottom), BPoint(bounds.right, bounds.bottom));
StrokeLine(BPoint(bounds.right, bounds.bottom), BPoint(bounds.right, bounds.top));
SetHighColor(blackColor);
SetLowColor(ViewColor());
DrawString("Type or use the left and right arrow keys.", BPoint(10.0, 23.0));
}
+14 -26
View File
@@ -13,8 +13,6 @@
RefreshWindow::RefreshWindow(BRect frame, int32 value)
: BWindow(frame, "Refresh Rate", B_MODAL_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_ALL_WORKSPACES)
{
int32 Value = value * 10;
frame = Bounds();
fRefreshView = new RefreshView(frame, "RefreshView");
@@ -29,20 +27,18 @@ RefreshWindow::RefreshWindow(BRect frame, int32 value)
fRefreshSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
fRefreshSlider->SetHashMarkCount(10);
fRefreshSlider->SetLimitLabels("45.0", "84.5");
fRefreshSlider->SetLimitLabels("45.0", "90.0");
fRefreshSlider->SetKeyIncrementValue(1);
fRefreshSlider->SetValue(Value);
fRefreshSlider->SetValue(value);
fRefreshSlider->SetSnoozeAmount(1);
fRefreshSlider->SetModificationMessage(new BMessage(SLIDER_MODIFICATION_MSG));
fRefreshView->AddChild(fRefreshSlider);
BRect ButtonRect;
ButtonRect.Set(219.0, 97.0, 230.0, 120.0);
BRect ButtonRect(219.0, 97.0, 230.0, 120.0);
fDoneButton = new BButton(ButtonRect, "DoneButton", "Done",
new BMessage(BUTTON_DONE_MSG));
new BMessage(BUTTON_DONE_MSG));
fDoneButton->ResizeToPreferred();
fDoneButton->MakeDefault(true);
@@ -52,7 +48,7 @@ RefreshWindow::RefreshWindow(BRect frame, int32 value)
ButtonRect.Set(130.0, 97.0, 200.0, 120.0);
fCancelButton = new BButton(ButtonRect, "CancelButton", "Cancel",
new BMessage(BUTTON_CANCEL_MSG));
new BMessage(BUTTON_CANCEL_MSG));
fCancelButton->ResizeToPreferred();
@@ -63,32 +59,25 @@ RefreshWindow::RefreshWindow(BRect frame, int32 value)
PostMessage(SLIDER_INVOKE_MSG);
}
bool RefreshWindow::QuitRequested()
void
RefreshWindow::WindowActivated(bool active)
{
return(true);
fRefreshSlider->MakeFocus(active);
}
void RefreshWindow::WindowActivated(bool active)
{
if (active == true)
fRefreshSlider->MakeFocus(true);
else
fRefreshSlider->MakeFocus(false);
}
void RefreshWindow::MessageReceived(BMessage* message)
void
RefreshWindow::MessageReceived(BMessage* message)
{
switch(message->what)
{
case BUTTON_DONE_MSG:
{
BMessenger Messenger("application/x-vnd.RR-SCRN");
BMessenger Messenger(kAppSignature);
BMessage Message(SET_CUSTOM_REFRESH_MSG);
float Value;
Value = (float)fRefreshSlider->Value() / 10;
float Value = (float)fRefreshSlider->Value() / 10;
Message.AddFloat("refresh", Value);
@@ -114,8 +103,7 @@ void RefreshWindow::MessageReceived(BMessage* message)
}
default:
BWindow::MessageReceived(message);
BWindow::MessageReceived(message);
break;
}
}
+3 -4
View File
@@ -10,10 +10,9 @@ class RefreshWindow : public BWindow
{
public:
RefreshWindow(BRect frame, int32 value);
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
virtual void WindowActivated(bool active);
RefreshWindow(BRect frame, int32 value);
virtual void MessageReceived(BMessage *message);
virtual void WindowActivated(bool active);
private:
RefreshView *fRefreshView;
+23 -19
View File
@@ -1,6 +1,7 @@
// Screen V0.9 build 1 by Rafael Romo for the OpenBeOS Preferences team.
// Screen V1.00 by Rafael Romo for the OpenBeOS Preferences team.
// web.tiscalinet.it/rockman
// [email protected]
// Modified by Stefano Ceccherini ( [email protected] )
#include <Application.h>
#include <Alert.h>
@@ -14,21 +15,25 @@
#include "Constants.h"
ScreenApplication::ScreenApplication()
: BApplication("application/x-vnd.RR-SCRN")
:
BApplication(kAppSignature),
fScreenWindow(new ScreenWindow(new ScreenSettings()))
{
fScreenWindow = new ScreenWindow(new ScreenSettings());
}
void ScreenApplication::AboutRequested()
void
ScreenApplication::AboutRequested()
{
BAlert *AboutAlert = new BAlert("About", "Screen by Rafael Romo\nThe OBOS place to configure your monitor",
"Ok", NULL, NULL,
B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_INFO_ALERT);
BAlert *AboutAlert = new BAlert("About", "Screen by Rafael Romo, Stefano Ceccherini\nThe OBOS place to configure your monitor",
"Ok", NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_INFO_ALERT);
AboutAlert->SetShortcut(0, B_OK);
AboutAlert->Go();
}
void ScreenApplication::MessageReceived(BMessage* message)
void
ScreenApplication::MessageReceived(BMessage* message)
{
switch(message->what)
{
@@ -41,17 +46,15 @@ void ScreenApplication::MessageReceived(BMessage* message)
case SET_CUSTOM_REFRESH_MSG:
{
BMessage *Message;
Message = new BMessage(SET_CUSTOM_REFRESH_MSG);
BMessage message(SET_CUSTOM_REFRESH_MSG);
float Value;
message->FindFloat("refresh", &Value);
message.FindFloat("refresh", &Value);
Message->AddFloat("refresh", Value);
message.AddFloat("refresh", Value);
fScreenWindow->PostMessage(Message);
fScreenWindow->PostMessage(&message);
break;
}
@@ -64,17 +67,18 @@ void ScreenApplication::MessageReceived(BMessage* message)
}
default:
BApplication::MessageReceived(message);
BApplication::MessageReceived(message);
break;
}
}
int main()
int
main()
{
ScreenApplication MyApplication;
ScreenApplication Application;
MyApplication.Run();
Application.Run();
return(0);
}
+3 -3
View File
@@ -7,9 +7,9 @@ class ScreenApplication : public BApplication
{
public:
ScreenApplication();
virtual void MessageReceived(BMessage *message);
virtual void AboutRequested();
ScreenApplication();
virtual void MessageReceived(BMessage *message);
virtual void AboutRequested();
private:
ScreenWindow *fScreenWindow;
+29 -42
View File
@@ -1,46 +1,55 @@
#include <InterfaceDefs.h>
#include <Message.h>
#include <Screen.h>
#include <Roster.h>
#include <Screen.h>
#include <String.h>
#include <View.h>
#include <cstring>
#include <cstdlib>
#include "ScreenDrawView.h"
#include "Constants.h"
#include "Utility.h"
ScreenDrawView::ScreenDrawView(BRect rect, char *name)
: BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW)
: BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW),
fScreen(new BScreen(B_MAIN_SCREEN_ID))
{
fScreen = new BScreen(B_MAIN_SCREEN_ID);
if (!fScreen->IsValid())
; //Debugger() ?
desktopColor = fScreen->DesktopColor(current_workspace());
display_mode Mode;
fScreen->GetMode(&Mode);
display_mode mode;
fScreen->GetMode(&mode);
fResolution = Mode.virtual_width;
fResolution = mode.virtual_width;
}
void ScreenDrawView::AttachedToWindow()
void
ScreenDrawView::AttachedToWindow()
{
rgb_color greyColor = {216, 216, 216, 255};
rgb_color greyColor = { 216, 216, 216, 255 };
SetViewColor(greyColor);
}
void ScreenDrawView::MouseDown(BPoint point)
void
ScreenDrawView::MouseDown(BPoint point)
{
be_roster->Launch("application/x-vnd.Be-BACK");
}
void ScreenDrawView::Draw(BRect updateRect)
void
ScreenDrawView::Draw(BRect updateRect)
{
//FIXME: Make the draw code resolution independent
if (fResolution == 1600)
{
rgb_color darkColor = {160, 160, 160, 255};
rgb_color blackColor = {0, 0, 0, 255};
rgb_color redColor = {228, 0, 0, 255};
SetHighColor(darkColor);
@@ -65,8 +74,6 @@ void ScreenDrawView::Draw(BRect updateRect)
else if(fResolution == 1280)
{
rgb_color darkColor = {160, 160, 160, 255};
rgb_color blackColor = {0, 0, 0, 255};
rgb_color redColor = {228, 0, 0, 255};
SetHighColor(darkColor);
@@ -91,8 +98,6 @@ void ScreenDrawView::Draw(BRect updateRect)
else if(fResolution == 1152)
{
rgb_color darkColor = {160, 160, 160, 255};
rgb_color blackColor = {0, 0, 0, 255};
rgb_color redColor = {228, 0, 0, 255};
SetHighColor(darkColor);
@@ -117,8 +122,6 @@ void ScreenDrawView::Draw(BRect updateRect)
else if(fResolution == 1024)
{
rgb_color darkColor = {160, 160, 160, 255};
rgb_color blackColor = {0, 0, 0, 255};
rgb_color redColor = {228, 0, 0, 255};
SetHighColor(darkColor);
@@ -143,7 +146,6 @@ void ScreenDrawView::Draw(BRect updateRect)
else if(fResolution == 800)
{
rgb_color darkColor = {160, 160, 160, 255};
rgb_color blackColor = {0, 0, 0, 255};
rgb_color redColor = {228, 0, 0, 255};
SetHighColor(darkColor);
@@ -169,8 +171,6 @@ void ScreenDrawView::Draw(BRect updateRect)
else if(fResolution == 640)
{
rgb_color darkColor = {160, 160, 160, 255};
rgb_color blackColor = {0, 0, 0, 255};
rgb_color redColor = {228, 0, 0, 255};
SetHighColor(darkColor);
@@ -194,31 +194,18 @@ void ScreenDrawView::Draw(BRect updateRect)
}
}
void ScreenDrawView::MessageReceived(BMessage* message)
void
ScreenDrawView::MessageReceived(BMessage* message)
{
switch(message->what)
{
case UPDATE_DESKTOP_MSG:
{
const char *Resolution;
int32 NextfResolution;
BString Resolution;
message->FindString("resolution", &Resolution);
if (strcmp(Resolution, "640 x 480") == 0)
NextfResolution = 640;
else if (strcmp(Resolution, "800 x 600") == 0)
NextfResolution = 800;
else if (strcmp(Resolution, "1024 x 768") == 0)
NextfResolution = 1024;
else if (strcmp(Resolution, "1152 x 864") == 0)
NextfResolution = 1152;
else if (strcmp(Resolution, "1280 x 1024") == 0)
NextfResolution = 1280;
else if (strcmp(Resolution, "1600 x 1200") == 0)
NextfResolution = 1600;
else
NextfResolution = 640;
int32 NextfResolution = atoi(Resolution.String());
if (fResolution != NextfResolution)
{
+20 -12
View File
@@ -3,37 +3,43 @@
#include "ScreenSettings.h"
const char ScreenSettings::fScreenSettingsFile[] = "RRScreen_Data";
const char ScreenSettings::fScreenSettingsFile[] = "OBOS_Screen_data";
ScreenSettings::ScreenSettings()
{
BScreen screen(B_MAIN_SCREEN_ID);
if (!screen.IsValid())
; //Debugger() ?
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) == B_OK)
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK)
{
path.Append(fScreenSettingsFile);
BFile file(path.Path(), B_READ_ONLY);
if (file.InitCheck() == B_OK && file.Read(&fWindowFrame, sizeof(BRect)) == sizeof(BRect))
if (file.InitCheck() == B_OK)
{
BScreen Screen;
if (Screen.Frame().right >= fWindowFrame.right
&& Screen.Frame().bottom >= fWindowFrame.bottom)
file.Read(&fWindowFrame, sizeof(BRect));
if (screen.Frame().right >= fWindowFrame.right
&& screen.Frame().bottom >= fWindowFrame.bottom)
return;
}
}
BScreen Screen;
fWindowFrame = Screen.Frame();
fWindowFrame.left = (Screen.Frame().right / 2) - 178;
fWindowFrame.top = (Screen.Frame().right / 2) - 101;
fWindowFrame = screen.Frame();
fWindowFrame.left = (fWindowFrame.right / 2) - 178;
fWindowFrame.top = (fWindowFrame.right / 2) - 101;
fWindowFrame.right = fWindowFrame.left + 356;
fWindowFrame.bottom = fWindowFrame.top + 202;
}
ScreenSettings::~ScreenSettings()
{
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) < B_OK)
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
return;
path.Append(fScreenSettingsFile);
@@ -43,7 +49,9 @@ ScreenSettings::~ScreenSettings()
file.Write(&fWindowFrame, sizeof(BRect));
}
void ScreenSettings::SetWindowFrame(BRect frame)
void
ScreenSettings::SetWindowFrame(BRect frame)
{
fWindowFrame = frame;
}
+7 -5
View File
@@ -1,23 +1,25 @@
#include <View.h>
#include "ScreenView.h"
#include "Utility.h"
ScreenView::ScreenView(BRect rect, char *name)
: BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW)
{
}
void ScreenView::AttachedToWindow()
void
ScreenView::AttachedToWindow()
{
rgb_color greyColor = {216, 216, 216, 255};
SetViewColor(greyColor);
}
void ScreenView::Draw(BRect updateRect)
void
ScreenView::Draw(BRect updateRect)
{
rgb_color whiteColor = {255, 255, 255, 255};
rgb_color darkColor = {128, 128, 128, 255};
rgb_color blackColor = {0, 0, 0, 255};
SetHighColor(whiteColor);
File diff suppressed because it is too large Load Diff
+9 -7
View File
@@ -16,13 +16,13 @@ class ScreenWindow : public BWindow
{
public:
ScreenWindow(ScreenSettings *Settings);
virtual ~ScreenWindow();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
virtual void WorkspaceActivated(int32 ws, bool state);
virtual void FrameMoved(BPoint position);
virtual void ScreenChanged(BRect frame, color_space mode);
ScreenWindow(ScreenSettings *Settings);
virtual ~ScreenWindow();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
virtual void WorkspaceActivated(int32 ws, bool state);
virtual void FrameMoved(BPoint position);
virtual void ScreenChanged(BRect frame, color_space mode);
private:
void CheckApplyEnabled();
@@ -51,6 +51,8 @@ private:
BMenuItem *fInitialColors;
BMenuItem *fInitialRefresh;
display_mode fInitialMode;
display_mode *fSupportedModes;
uint32 fTotalModes;
float fCustomRefresh;
float fInitialRefreshN;
};