dynamically compute refresh bounds and other fixes

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5872 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
shatty 2004-01-02 06:34:38 +00:00
parent 1d63afff42
commit 7c0a9f8327
5 changed files with 58 additions and 51 deletions

View File

@ -25,6 +25,7 @@ static const uint32 MAKE_INITIAL_MSG = 'mkin';
//Constants //Constants
static const char kAppSignature[] = "application/x-vnd.Be-SCRN"; static const char kAppSignature[] = "application/x-vnd.Be-SCRN";
static const int32 gMaxRefresh = 120; //This is the maximum selectable refresh static const int32 gMinRefresh = 45; //This is the minimum selectable refresh
static const int32 gMaxRefresh = 140; //This is the maximum selectable refresh
#endif //CONSTANTS_H #endif //CONSTANTS_H

View File

@ -6,7 +6,8 @@
#include "Constants.h" #include "Constants.h"
RefreshSlider::RefreshSlider(BRect frame) RefreshSlider::RefreshSlider(BRect frame)
:BSlider(frame, "Screen", "Refresh Rate:", new BMessage(SLIDER_INVOKE_MSG), 450, gMaxRefresh * 10), :BSlider(frame, "Screen", "Refresh Rate:",
new BMessage(SLIDER_INVOKE_MSG), gMinRefresh * 10, gMaxRefresh * 10),
fStatus(new char[32]) fStatus(new char[32])
{ {
} }

View File

@ -21,14 +21,16 @@ RefreshWindow::RefreshWindow(BRect frame, int32 value)
BRect sliderRect; BRect sliderRect;
BString maxRefresh; BString maxRefresh;
maxRefresh << gMaxRefresh; maxRefresh << gMaxRefresh;
BString minRefresh;
minRefresh << gMinRefresh;
sliderRect.Set(10.0, 35.0, 299.0, 60.0); sliderRect.Set(10.0, 35.0, 299.0, 60.0);
fRefreshSlider = new RefreshSlider(sliderRect); fRefreshSlider = new RefreshSlider(sliderRect);
fRefreshSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fRefreshSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
fRefreshSlider->SetHashMarkCount(10); fRefreshSlider->SetHashMarkCount((gMaxRefresh-gMinRefresh)/5+1);
fRefreshSlider->SetLimitLabels("45.0", maxRefresh.String()); fRefreshSlider->SetLimitLabels(minRefresh.String(), maxRefresh.String());
fRefreshSlider->SetKeyIncrementValue(1); fRefreshSlider->SetKeyIncrementValue(1);
fRefreshSlider->SetValue(value); fRefreshSlider->SetValue(value);
fRefreshSlider->SetSnoozeAmount(1); fRefreshSlider->SetSnoozeAmount(1);

View File

@ -176,6 +176,7 @@ ScreenWindow::ScreenWindow(ScreenSettings *Settings)
fResolutionMenu = new BPopUpMenu("", true, true); fResolutionMenu = new BPopUpMenu("", true, true);
fColorsMenu = new BPopUpMenu("", true, true); fColorsMenu = new BPopUpMenu("", true, true);
fRefreshMenu = new BPopUpMenu("", true, true);
CheckUpdateDisplayModes(); CheckUpdateDisplayModes();
@ -201,30 +202,11 @@ ScreenWindow::ScreenWindow(ScreenSettings *Settings)
fColorsField->SetDivider(colorsWidth); fColorsField->SetDivider(colorsWidth);
controlsBox->AddChild(fColorsField); controlsBox->AddChild(fColorsField);
// XXX: When we'll start to use OpenBeOS BScreen, we will be able to dynamically
// build this menu using the available refresh rates, without limiting ourself
// to 85 hz.
fRefreshMenu = new BPopUpMenu("", true, true);
char str[256];
refresh_rate_to_string(56,str);
fRefreshMenu->AddItem(new BMenuItem(str, new BMessage(POP_REFRESH_MSG)));
refresh_rate_to_string(60,str);
fRefreshMenu->AddItem(new BMenuItem(str, new BMessage(POP_REFRESH_MSG)));
refresh_rate_to_string(70,str);
fRefreshMenu->AddItem(new BMenuItem(str, new BMessage(POP_REFRESH_MSG)));
refresh_rate_to_string(75,str);
fRefreshMenu->AddItem(new BMenuItem(str, new BMessage(POP_REFRESH_MSG)));
refresh_rate_to_string(85,str);
fRefreshMenu->AddItem(new BMenuItem(str, new BMessage(POP_REFRESH_MSG)));
refresh_rate_to_string(100,str);
fRefreshMenu->AddItem(new BMenuItem(str, new BMessage(POP_REFRESH_MSG)));
fOtherRefresh = new BMenuItem("Other...", new BMessage(POP_OTHER_REFRESH_MSG)); fOtherRefresh = new BMenuItem("Other...", new BMessage(POP_OTHER_REFRESH_MSG));
fRefreshMenu->AddItem(fOtherRefresh); fRefreshMenu->AddItem(fOtherRefresh);
const char * refreshLabel = "Refresh Rate: "; const char * refreshLabel = "Refresh Rate: ";
float refreshWidth = controlsBox->StringWidth(refreshLabel); float refreshWidth = controlsBox->StringWidth(refreshLabel);
controlMenuRect.Set(88.0-refreshWidth, 86.0, 171.0, 104.0); controlMenuRect.Set(88.0-refreshWidth, 86.0, 171.0, 104.0);
@ -410,29 +392,35 @@ ScreenWindow::MessageReceived(BMessage* message)
(frame.top + 34.0), (frame.left + 509.0), (frame.top + 34.0), (frame.left + 509.0),
(frame.top + 169.0)), value); (frame.top + 169.0)), value);
fRefreshWindow->Show(); fRefreshWindow->Show();
BMenuItem *other = fRefreshMenu->FindItem(POP_OTHER_REFRESH_MSG);
BString string;
string << other->Label();
int32 point = string.FindFirst('z');
string.Truncate(point + 1);
fRefreshMenu->Superitem()->SetLabel(string.String());
break; break;
} }
case BUTTON_DEFAULTS_MSG: case BUTTON_DEFAULTS_MSG:
{ {
fResolutionMenu->ItemAt(0)->SetMarked(true); char str[256];
fColorsMenu->FindItem("8 Bits/Pixel")->SetMarked(true); BMenuItem * item = 0;
fRefreshMenu->FindItem("60 Hz")->SetMarked(true); display_mode mode;
mode.virtual_width = 640;
mode.virtual_height = 480;
mode_to_string(mode,str);
if ((item = fResolutionMenu->FindItem(str)) != NULL) {
item->SetMarked(true);
} else {
fResolutionMenu->ItemAt(0)->SetMarked(true);
}
colorspace_to_string(B_CMAP8,str);
if ((item = fColorsMenu->FindItem(str)) != NULL) {
item->SetMarked(true);
} else {
fColorsMenu->ItemAt(0)->SetMarked(true);
}
refresh_rate_to_string(60.0,str);
if ((item = fRefreshMenu->FindItem(str)) != NULL) {
item->SetMarked(true);
} else {
fRefreshMenu->ItemAt(0)->SetMarked(true);
}
CheckApplyEnabled(); CheckApplyEnabled();
break; break;
} }
@ -583,17 +571,30 @@ ScreenWindow::CheckUpdateDisplayModes()
if (!fColorsMenu->FindItem(colorSpace)) if (!fColorsMenu->FindItem(colorSpace))
fColorsMenu->AddItem(new BMenuItem(colorSpace, new BMessage(POP_COLORS_MSG))); fColorsMenu->AddItem(new BMenuItem(colorSpace, new BMessage(POP_COLORS_MSG)));
} }
/*XXX: BeOS's BScreen limits the refresh to 85 hz (or is it the nvidia driver?). // Add supported refresh rates to the menu
I hope that OpenBeOS BScreen will remove float min_refresh = 120, max_refresh = 0;
this limitation.
for (c = 0; c < fTotalModes; c++) { for (c = 0; c < fTotalModes; c++) {
display_mode *mode = &fSupportedModes[c]; display_mode mode = fSupportedModes[c];
int32 refresh = (mode->timing.pixel_clock * 1000) / (mode->timing.h_total * mode->timing.v_total); BScreen screen;
printf("width %d, height %d, refresh %d\n", mode->virtual_width, mode->virtual_height, refresh); uint32 low_clock, high_clock;
screen.GetPixelClockLimits(&mode,&low_clock,&high_clock);
mode.timing.pixel_clock = low_clock;
min_refresh = min_c(min_refresh,get_refresh_rate(mode));
mode.timing.pixel_clock = high_clock;
max_refresh = max_c(max_refresh,get_refresh_rate(mode));
} }
*/ char refresh[128];
float refreshes[] = { 56.0, 60.0, 70.0, 75.0, 85.0, 100.0, 120.0, 140.0 } ;
for (uint i = 0 ; i < sizeof(refreshes)/sizeof(float) ; i++) {
if ((min_refresh <= refreshes[i]) && (refreshes[i] <= max_refresh)) {
refresh_rate_to_string(refreshes[i],refresh);
if (!fRefreshMenu->FindItem(refresh))
fRefreshMenu->AddItem(new BMenuItem(refresh, new BMessage(POP_REFRESH_MSG)));
}
}
fMinRefresh = min_refresh;
fMaxRefresh = max_refresh;
} }

View File

@ -58,6 +58,8 @@ private:
display_mode *fSupportedModes; display_mode *fSupportedModes;
uint32 fTotalModes; uint32 fTotalModes;
float fMinRefresh;
float fMaxRefresh;
float fCustomRefresh; float fCustomRefresh;
float fInitialRefreshN; float fInitialRefreshN;
}; };