From e14977562f0020748b1a380c42f1be08ec20d993 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Tue, 26 Nov 2002 06:21:36 +0000 Subject: [PATCH] Maximum refresh selectable at compile time, some minor fixes, some cleanups git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2090 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/prefs/screen/Constants.h | 43 ++++++++++----------- src/prefs/screen/RefreshSlider.cpp | 19 ++-------- src/prefs/screen/RefreshSlider.h | 6 +-- src/prefs/screen/RefreshWindow.cpp | 4 +- src/prefs/screen/Screen.cpp | 24 +----------- src/prefs/screen/ScreenWindow.cpp | 60 +++++++++++++++--------------- src/prefs/screen/Utility.cpp | 12 ++---- 7 files changed, 68 insertions(+), 100 deletions(-) diff --git a/src/prefs/screen/Constants.h b/src/prefs/screen/Constants.h index ff77e9a208..1214b14056 100644 --- a/src/prefs/screen/Constants.h +++ b/src/prefs/screen/Constants.h @@ -2,28 +2,29 @@ #define CONSTANTS_H //Messages -#define WORKSPACE_CHECK_MSG 'wchk' -#define BUTTON_DEFAULTS_MSG 'bdef' -#define BUTTON_REVERT_MSG 'brev' -#define BUTTON_APPLY_MSG 'bapl' -#define BUTTON_DONE_MSG 'bdon' -#define BUTTON_CANCEL_MSG 'bcnc' -#define BUTTON_KEEP_MSG 'bkep' -#define POP_WORKSPACE_CHANGED_MSG 'pwsc' -#define POP_RESOLUTION_MSG 'pres' -#define POP_COLORS_MSG 'pclr' -#define POP_REFRESH_MSG 'prfr' -#define POP_OTHER_REFRESH_MSG 'porf' -#define UPDATE_DESKTOP_COLOR_MSG 'udsc' -#define UPDATE_DESKTOP_MSG 'udsk' -#define SLIDER_MODIFICATION_MSG 'sldm' -#define SLIDER_INVOKE_MSG 'sldi' -#define SET_INITIAL_MODE_MSG 'sinm' -#define SET_CUSTOM_REFRESH_MSG 'scrf' -#define DIM_COUNT_MSG 'scrf' -#define MAKE_INITIAL_MSG 'mkin' +static const int32 WORKSPACE_CHECK_MSG = 'wchk'; +static const int32 BUTTON_DEFAULTS_MSG = 'bdef'; +static const int32 BUTTON_REVERT_MSG = 'brev'; +static const int32 BUTTON_APPLY_MSG = 'bapl'; +static const int32 BUTTON_DONE_MSG = 'bdon'; +static const int32 BUTTON_CANCEL_MSG = 'bcnc'; +static const int32 BUTTON_KEEP_MSG = 'bkep'; +static const int32 POP_WORKSPACE_CHANGED_MSG = 'pwsc'; +static const int32 POP_RESOLUTION_MSG = 'pres'; +static const int32 POP_COLORS_MSG = 'pclr'; +static const int32 POP_REFRESH_MSG = 'prfr'; +static const int32 POP_OTHER_REFRESH_MSG = 'porf'; +static const int32 UPDATE_DESKTOP_COLOR_MSG = 'udsc'; +static const int32 UPDATE_DESKTOP_MSG = 'udsk'; +static const int32 SLIDER_MODIFICATION_MSG = 'sldm'; +static const int32 SLIDER_INVOKE_MSG = 'sldi'; +static const int32 SET_INITIAL_MODE_MSG = 'sinm'; +static const int32 SET_CUSTOM_REFRESH_MSG = 'scrf'; +static const int32 DIM_COUNT_MSG = 'scrf'; +static const int32 MAKE_INITIAL_MSG = 'mkin'; //Constants -static const char kAppSignature[] = "application/x-vnd.RR-SCRN"; +static const char kAppSignature[] = "application/x-vnd.Be-SCRN"; +static const int32 gMaxRefresh = 120; //This is the maximum selectable refresh #endif //CONSTANTS_H diff --git a/src/prefs/screen/RefreshSlider.cpp b/src/prefs/screen/RefreshSlider.cpp index 4201e79229..e1f7f3eccc 100644 --- a/src/prefs/screen/RefreshSlider.cpp +++ b/src/prefs/screen/RefreshSlider.cpp @@ -2,17 +2,17 @@ #include #include #include -#include #include #include +#include #include "RefreshSlider.h" #include "Constants.h" RefreshSlider::RefreshSlider(BRect frame) - : BSlider(frame, "Screen", "Refresh Rate:", new BMessage(SLIDER_INVOKE_MSG), 450, 900), - fStatus(new char[64]) + : BSlider(frame, "Screen", "Refresh Rate:", new BMessage(SLIDER_INVOKE_MSG), 450, gMaxRefresh * 10), + fStatus(new char[32]) { } @@ -77,18 +77,7 @@ RefreshSlider::UpdateText() const { if (fStatus && Window()->Lock()) { - BString String; - - String << Value(); - String.CopyInto(fStatus, 0, String.Length() + 1); - - char Last = fStatus[2]; - - String.Truncate(2); - String << "." << Last << " Hz"; - - String.CopyInto(fStatus, 0, String.Length() + 1); - + sprintf(fStatus, "%.1f Hz", (float)Value() / 10); return fStatus; } else diff --git a/src/prefs/screen/RefreshSlider.h b/src/prefs/screen/RefreshSlider.h index 18c65ad034..e50c36e6e9 100644 --- a/src/prefs/screen/RefreshSlider.h +++ b/src/prefs/screen/RefreshSlider.h @@ -7,14 +7,14 @@ class RefreshSlider : public BSlider { public: - RefreshSlider(BRect frame); - ~RefreshSlider(); + RefreshSlider(BRect frame); + ~RefreshSlider(); virtual void DrawFocusMark(); virtual char* UpdateText() const; virtual void KeyDown(const char *bytes, int32 numBytes); private: - char* fStatus; + char* fStatus; }; #endif diff --git a/src/prefs/screen/RefreshWindow.cpp b/src/prefs/screen/RefreshWindow.cpp index 04a46193f5..3f1d22dc7d 100644 --- a/src/prefs/screen/RefreshWindow.cpp +++ b/src/prefs/screen/RefreshWindow.cpp @@ -20,6 +20,8 @@ RefreshWindow::RefreshWindow(BRect frame, int32 value) AddChild(fRefreshView); BRect SliderRect; + BString maxRefresh; + maxRefresh << gMaxRefresh; SliderRect.Set(10.0, 35.0, 299.0, 60.0); @@ -27,7 +29,7 @@ RefreshWindow::RefreshWindow(BRect frame, int32 value) fRefreshSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fRefreshSlider->SetHashMarkCount(10); - fRefreshSlider->SetLimitLabels("45.0", "90.0"); + fRefreshSlider->SetLimitLabels("45.0", maxRefresh.String()); fRefreshSlider->SetKeyIncrementValue(1); fRefreshSlider->SetValue(value); fRefreshSlider->SetSnoozeAmount(1); diff --git a/src/prefs/screen/Screen.cpp b/src/prefs/screen/Screen.cpp index bdc3c591ae..0888a6c101 100644 --- a/src/prefs/screen/Screen.cpp +++ b/src/prefs/screen/Screen.cpp @@ -38,34 +38,12 @@ ScreenApplication::MessageReceived(BMessage* message) switch(message->what) { case SET_INITIAL_MODE_MSG: - { - fScreenWindow->PostMessage(new BMessage(SET_INITIAL_MODE_MSG)); - - break; - } - case SET_CUSTOM_REFRESH_MSG: - { - BMessage message(SET_CUSTOM_REFRESH_MSG); - - float Value; - - message.FindFloat("refresh", &Value); - - message.AddFloat("refresh", Value); - - fScreenWindow->PostMessage(&message); - - break; - } - case MAKE_INITIAL_MSG: { - fScreenWindow->PostMessage(new BMessage(MAKE_INITIAL_MSG)); - + fScreenWindow->PostMessage(message); break; } - default: BApplication::MessageReceived(message); break; diff --git a/src/prefs/screen/ScreenWindow.cpp b/src/prefs/screen/ScreenWindow.cpp index 31ea06f40d..2855dfebf9 100644 --- a/src/prefs/screen/ScreenWindow.cpp +++ b/src/prefs/screen/ScreenWindow.cpp @@ -405,7 +405,8 @@ ScreenWindow::MessageReceived(BMessage* message) String << Other->Label(); - String.Truncate(7); + int32 point = String.FindFirst('z'); + String.Truncate(point + 1); fRefreshMenu->Superitem()->SetLabel(String.String()); @@ -435,17 +436,18 @@ ScreenWindow::MessageReceived(BMessage* message) if (fInitialRefresh == Other) { - BString string; - + BString string; string << fInitialRefreshN; - - string.Truncate(4); + + int32 point = string.FindFirst('.'); + string.Truncate(point + 2); string << " Hz/Other..."; fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG)->SetLabel(string.String()); - string.Truncate(7); + point = string.FindFirst('/'); + string.Truncate(point); fRefreshMenu->Superitem()->SetLabel(string.String()); } @@ -469,10 +471,15 @@ ScreenWindow::MessageReceived(BMessage* message) BString menuLabel = fResolutionMenu->FindMarked()->Label(); int32 space = menuLabel.FindFirst(' '); menuLabel.MoveInto(string, 0, space); - menuLabel.Remove(0, 3); + menuLabel.Remove(0, 3); + width = atoi(string.String()); height = atoi(menuLabel.String()); - refresh = atof(fRefreshMenu->FindMarked()->Label()); + + if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG)) + refresh = fCustomRefresh; + else + refresh = atof(fRefreshMenu->FindMarked()->Label()); for(uint32 c = 0; c < fTotalModes; c++) { @@ -482,12 +489,8 @@ ScreenWindow::MessageReceived(BMessage* message) mode = &fSupportedModes[c]; } - if (fRefreshMenu->FindMarked() == fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG)) - mode->timing.pixel_clock = (uint32)((mode->timing.h_total * mode->timing.v_total) * fCustomRefresh / 1000); - else - mode->timing.pixel_clock = (uint32)((mode->timing.h_total * mode->timing.v_total) * refresh / 1000); - - + mode->timing.pixel_clock = (uint32)((mode->timing.h_total * mode->timing.v_total) * refresh / 1000); + if (fColorsMenu->FindMarked() == fColorsMenu->FindItem("8 Bits/Pixel")) { @@ -510,12 +513,11 @@ ScreenWindow::MessageReceived(BMessage* message) mode->v_display_start = 0; if (fWorkspaceMenu->FindMarked() == fWorkspaceMenu->FindItem("All Workspaces")) - { - int32 button; - + { BAlert *WorkspacesAlert = new BAlert("WorkspacesAlert", "Change all workspaces? -This action cannot be reverted", "Okay", "Cancel", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); - button = WorkspacesAlert->Go(); + This action cannot be reverted", "Okay", "Cancel", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); + + int32 button = WorkspacesAlert->Go(); if (button == 1) break; @@ -556,17 +558,17 @@ This action cannot be reverted", "Okay", "Cancel", NULL, B_WIDTH_AS_USUAL, B_WAR { Other->SetMarked(true); - BString String; - + BString String; String << fInitialRefreshN; - - String.Truncate(4); + int32 point = String.FindFirst('.'); + String.Truncate(point + 2); String << " Hz/Other..."; fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG)->SetLabel(String.String()); - String.Truncate(7); + point = String.FindFirst('/'); + String.Truncate(point); fRefreshMenu->Superitem()->SetLabel(String.String()); } @@ -584,17 +586,17 @@ This action cannot be reverted", "Okay", "Cancel", NULL, B_WIDTH_AS_USUAL, B_WAR Other->SetMarked(true); - BString String; - + BString String; String << fCustomRefresh; - - String.Truncate(4); + int32 point = String.FindFirst('.'); + String.Truncate(point + 2); String << " Hz/Other..."; fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG)->SetLabel(String.String()); - String.Truncate(7); + point = String.FindFirst('z'); + String.Truncate(point + 1); fRefreshMenu->Superitem()->SetLabel(String.String()); diff --git a/src/prefs/screen/Utility.cpp b/src/prefs/screen/Utility.cpp index d52d8fa0ce..fc0254ee9e 100644 --- a/src/prefs/screen/Utility.cpp +++ b/src/prefs/screen/Utility.cpp @@ -8,16 +8,12 @@ rgb_color whiteColor = { 255, 255, 255, 255 }; rgb_color redColor = { 228, 0, 0, 255 }; float round(float n, int32 max) -{ - float result; - int32 tmp; - max *= 10; +{ + max = (int32)pow(10, (float)max); n *= max; n += 0.5; - tmp = (int32)floor(n); - result = (float)tmp / (max); - - return result; + int32 tmp = (int32)floor(n); + return (float)tmp / (max); }