* Made the refresh selection window font sensitive.

* Nicer separation from RefreshSlider.
* Got rid of the RefreshView class (a BStringView does its job now).
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17147 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-04-16 20:55:53 +00:00
parent e762848ab2
commit c5d10f7ae5
9 changed files with 114 additions and 132 deletions
+4 -1
View File
@@ -9,6 +9,10 @@
#ifndef CONSTANTS_H
#define CONSTANTS_H
#include <SupportDefs.h>
// Messages
static const uint32 WORKSPACE_CHECK_MSG = 'wchk';
static const uint32 BUTTON_LAUNCH_BACKGROUNDS_MSG = 'blbk';
@@ -16,7 +20,6 @@ static const uint32 BUTTON_DEFAULTS_MSG = 'bdef';
static const uint32 BUTTON_REVERT_MSG = 'brev';
static const uint32 BUTTON_APPLY_MSG = 'bapl';
static const uint32 BUTTON_DONE_MSG = 'bdon';
static const uint32 BUTTON_CANCEL_MSG = 'bcnc';
static const uint32 BUTTON_KEEP_MSG = 'bkep';
static const uint32 POP_WORKSPACE_CHANGED_MSG = 'pwsc';
static const uint32 POP_RESOLUTION_MSG = 'pres';
-1
View File
@@ -11,7 +11,6 @@ Preference Screen :
MonitorView.cpp
multimon.cpp
RefreshSlider.cpp
RefreshView.cpp
RefreshWindow.cpp
ScreenApplication.cpp
ScreenMode.cpp
+33 -11
View File
@@ -1,16 +1,40 @@
/*
* 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 "RefreshSlider.h"
#include "Constants.h"
#include <String.h>
#include <Window.h>
#include <new>
#include <stdio.h>
RefreshSlider::RefreshSlider(BRect frame)
:BSlider(frame, "Screen", "Refresh Rate:",
new BMessage(SLIDER_INVOKE_MSG), gMinRefresh * 10, gMaxRefresh * 10),
fStatus(new char[32])
{
RefreshSlider::RefreshSlider(BRect frame, float min, float max, uint32 resizingMode)
: BSlider(frame, "Screen", "Refresh Rate:",
new BMessage(SLIDER_INVOKE_MSG), rintf(min * 10), rintf(max * 10),
B_BLOCK_THUMB, resizingMode),
fStatus(new (std::nothrow) char[32])
{
BString minRefresh;
minRefresh << (uint32)min;
BString maxRefresh;
maxRefresh << (uint32)max;
SetLimitLabels(minRefresh.String(), maxRefresh.String());
SetHashMarks(B_HASH_MARKS_BOTTOM);
SetHashMarkCount(uint32(max - min) / 5 + 1);
SetKeyIncrementValue(1);
}
@@ -66,10 +90,8 @@ RefreshSlider::KeyDown(const char *bytes, int32 numBytes)
char*
RefreshSlider::UpdateText() const
{
if (fStatus) {
sprintf(fStatus, "%.1f Hz", (float)Value() / 10);
return fStatus;
} else
return NULL;
}
if (fStatus != NULL)
snprintf(fStatus, 32, "%.1f Hz", (float)Value() / 10);
return fStatus;
}
+25 -14
View File
@@ -1,19 +1,30 @@
#ifndef __REFRESHSLIDER_H
#define __REFRESHSLIDER_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 REFRESH_SLIDER_H
#define REFRESH_SLIDER_H
#include <Slider.h>
class RefreshSlider : public BSlider
{
public:
RefreshSlider(BRect frame);
~RefreshSlider();
virtual void DrawFocusMark();
virtual char *UpdateText() const;
virtual void KeyDown(const char *bytes, int32 numBytes);
private:
char* fStatus;
class RefreshSlider : public BSlider {
public:
RefreshSlider(BRect frame, float min, float max, uint32 resizingMode);
virtual ~RefreshSlider();
virtual void DrawFocusMark();
virtual char* UpdateText() const;
virtual void KeyDown(const char* bytes, int32 numBytes);
private:
char* fStatus;
};
#endif
#endif // REFRESH_SLIDER_H
-20
View File
@@ -1,20 +0,0 @@
#include "RefreshView.h"
RefreshView::RefreshView(BRect rect, char *name)
: BBox(rect, name)
{
}
void
RefreshView::Draw(BRect updateRect)
{
rgb_color black = { 0, 0, 0, 255 };
BBox::Draw(updateRect);
SetHighColor(black);
SetLowColor(ViewColor());
DrawString("Type or use the left and right arrow keys.", BPoint(10.0, 23.0));
}
-13
View File
@@ -1,13 +0,0 @@
#ifndef __REFRESHVIEW_H
#define __REFRESHVIEW_H
#include <Box.h>
class RefreshView : public BBox
{
public:
RefreshView(BRect frame, char *name);
virtual void Draw(BRect updateRect);
};
#endif
+45 -60
View File
@@ -10,68 +10,66 @@
#include "RefreshWindow.h"
#include "RefreshView.h"
#include "RefreshSlider.h"
#include "Constants.h"
#include "RefreshSlider.h"
#include <Alert.h>
#include <Application.h>
#include <Button.h>
#include <String.h>
#include <StringView.h>
#include <Window.h>
RefreshWindow::RefreshWindow(BRect frame, float current, float min, float max)
: BWindow(frame, "Refresh Rate", B_MODAL_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE,
B_ALL_WORKSPACES)
RefreshWindow::RefreshWindow(BPoint position, float current, float min, float max)
: BWindow(BRect(0, 0, 300, 200), "Refresh Rate", B_MODAL_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS, B_ALL_WORKSPACES)
{
BRect bounds(Bounds());
bounds.InsetBy(-1, -1);
fRefreshView = new RefreshView(bounds, "RefreshView");
AddChild(fRefreshView);
min = ceilf(min);
max = floorf(max);
BRect sliderRect;
BString maxRefresh;
maxRefresh << (uint32)min;
BString minRefresh;
minRefresh << (uint32)max;
BView* topView = new BView(Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW);
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(topView);
sliderRect.Set(10.0, 35.0, 299.0, 60.0);
BRect rect = Bounds().InsetByCopy(8, 8);
BStringView* stringView = new BStringView(rect, "info",
"Type or use the left and right arrow keys.");
stringView->ResizeToPreferred();
topView->AddChild(stringView);
fRefreshSlider = new RefreshSlider(sliderRect);
fRefreshSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
fRefreshSlider->SetHashMarkCount(uint32(max - min) / 5 + 1);
fRefreshSlider->SetLimitLabels(minRefresh.String(), maxRefresh.String());
fRefreshSlider->SetKeyIncrementValue(1);
rect.top += stringView->Bounds().Height() + 14;
fRefreshSlider = new RefreshSlider(rect, min, max, B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);
fRefreshSlider->SetValue(rint(current * 10));
fRefreshSlider->SetSnoozeAmount(1);
fRefreshSlider->SetModificationMessage(new BMessage(SLIDER_MODIFICATION_MSG));
float width, height;
fRefreshSlider->GetPreferredSize(&width, &height);
fRefreshSlider->ResizeTo(rect.Width(), height);
topView->AddChild(fRefreshSlider);
fRefreshView->AddChild(fRefreshSlider);
BButton* doneButton = new BButton(rect, "DoneButton", "Done",
new BMessage(BUTTON_DONE_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
doneButton->ResizeToPreferred();
doneButton->MoveTo(Bounds().Width() - doneButton->Bounds().Width() - 8,
Bounds().Height() - doneButton->Bounds().Height() - 8);
topView->AddChild(doneButton);
BRect ButtonRect(219.0, 97.0, 230.0, 120.0);
BButton* button = new BButton(doneButton->Frame(), "CancelButton", "Cancel",
new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
button->ResizeToPreferred();
button->MoveBy(-button->Bounds().Width() - 10, 0);
topView->AddChild(button);
fDoneButton = new BButton(ButtonRect, "DoneButton", "Done",
new BMessage(BUTTON_DONE_MSG));
doneButton->MakeDefault(true);
fDoneButton->ResizeToPreferred();
fDoneButton->MakeDefault(true);
fRefreshView->AddChild(fDoneButton);
ButtonRect.Set(130.0, 97.0, 200.0, 120.0);
fCancelButton = new BButton(ButtonRect, "CancelButton", "Cancel",
new BMessage(BUTTON_CANCEL_MSG));
fCancelButton->ResizeToPreferred();
fRefreshView->AddChild(fCancelButton);
width = stringView->Bounds().Width() + 100;
if (width < Bounds().Width())
width = Bounds().Width();
height = fRefreshSlider->Frame().bottom + button->Bounds().Height() + 20.0f;
ResizeTo(width, height);
MoveTo(position.x - width / 2.5f, position.y - height / 1.9f);
}
@@ -85,36 +83,23 @@ RefreshWindow::WindowActivated(bool active)
void
RefreshWindow::MessageReceived(BMessage* message)
{
switch(message->what)
{
switch (message->what) {
case BUTTON_DONE_MSG:
{
BMessage message(SET_CUSTOM_REFRESH_MSG);
float value = (float)fRefreshSlider->Value() / 10;
BMessage message(SET_CUSTOM_REFRESH_MSG);
message.AddFloat("refresh", value);
be_app->PostMessage(&message);
PostMessage(B_QUIT_REQUESTED);
break;
}
case BUTTON_CANCEL_MSG:
{
PostMessage(B_QUIT_REQUESTED);
break;
}
case SLIDER_INVOKE_MSG:
{
fRefreshSlider->MakeFocus(true);
break;
}
default:
BWindow::MessageReceived(message);
break;
+5 -8
View File
@@ -13,21 +13,18 @@
#include <Window.h>
#include "RefreshView.h"
#include "RefreshSlider.h"
class BSlider;
class RefreshWindow : public BWindow {
public:
RefreshWindow(BRect frame, float current, float min, float max);
RefreshWindow(BPoint position, float current, float min, float max);
virtual void MessageReceived(BMessage *message);
virtual void MessageReceived(BMessage* message);
virtual void WindowActivated(bool active);
private:
RefreshView *fRefreshView;
RefreshSlider *fRefreshSlider;
BButton *fDoneButton;
BButton *fCancelButton;
BSlider* fRefreshSlider;
};
#endif // REFRESH_WINDOW_H
+2 -4
View File
@@ -820,10 +820,8 @@ ScreenWindow::MessageReceived(BMessage* message)
if (max > gMaxRefresh)
max = gMaxRefresh;
BRect frame(Frame());
RefreshWindow *fRefreshWindow = new RefreshWindow(BRect(frame.left + 201.0,
frame.top + 34.0, frame.left + 509.0, frame.top + 169.0),
fSelected.refresh, min, max);
RefreshWindow *fRefreshWindow = new RefreshWindow(
fRefreshField->ConvertToScreen(B_ORIGIN), fSelected.refresh, min, max);
fRefreshWindow->Show();
break;
}