Removed the duplicated settings handling - now just uses MouseSettings instead.

Removed all code that now belongs to the MouseView class.
Moved some member variables into the private section.
Removed now unused variables.
Now overloads GetPreferredSize() with something useful instead of just
resizing to these values at constructions.
Added a destructor that frees the created bitmaps.
Renamed focusMenu to fFocusMenu, and mouseTypeMenu to fTypeMenu.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5961 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-01-07 08:14:46 +00:00
parent 7116278ebd
commit 87e0ec1168
2 changed files with 128 additions and 257 deletions

View File

@ -29,66 +29,84 @@
#include <Window.h>
#include "SettingsView.h"
#include "MouseMessages.h"
#include "MouseBitmap.h"
#include "MouseConstants.h"
#include "MouseSettings.h"
#include "MouseView.h"
static int32
mouse_mode_to_index(mode_mouse mode)
{
switch (mode) {
case B_NORMAL_MOUSE:
default:
return 0;
case B_FOCUS_FOLLOWS_MOUSE:
return 1;
case B_WARP_MOUSE:
return 2;
case B_INSTANT_WARP_MOUSE:
return 3;
}
}
// #pragma mark -
SettingsView::SettingsView(BRect rect, MouseSettings &settings)
: BBox(rect, "main_view"),
fCurrentButton(-1),
fSettings(settings),
fButtons(0),
fOldButtons(0)
fSettings(settings)
{
ResizeTo(397 - 22, 293 - 55);
// ToDo: fixed values for now
ResizeToPreferred();
BTextControl *textcontrol;
BMenuField *menufield;
BRect frame;
fDoubleClickBitmap = BTranslationUtils::GetBitmap("double_click_bmap");
fSpeedBitmap = BTranslationUtils::GetBitmap("speed_bmap");
fAccelerationBitmap = BTranslationUtils::GetBitmap("acceleration_bmap");
// i don't really understand this bitmap SetBits : i have to substract 4 lines and add 15 pixels
BRect mouseRect(0,0,kMouseWidth-1,kMouseHeight-5);
fMouseBitmap = new BBitmap(mouseRect, B_CMAP8);
fMouseBitmap->SetBits(kMouseBits, kMouseWidth*kMouseHeight + 15, 0, kMouseColorSpace);
BRect mouseDownRect(0,0,kMouseDownWidth-1,kMouseDownHeight-1);
fMouseDownBitmap = new BBitmap(mouseDownRect, B_CMAP8);
fMouseDownBitmap->SetBits(kMouseDownBits, kMouseDownWidth*kMouseDownHeight + 30, 0, kMouseDownColorSpace);
// Add the "Mouse Type" pop up menu
mouseTypeMenu = new BPopUpMenu("Mouse Type Menu");
mouseTypeMenu->AddItem(new BMenuItem("1-Button", new BMessage(POPUP_MOUSE_TYPE)));
mouseTypeMenu->AddItem(new BMenuItem("2-Button", new BMessage(POPUP_MOUSE_TYPE)));
mouseTypeMenu->AddItem(new BMenuItem("3-Button", new BMessage(POPUP_MOUSE_TYPE)));
fTypeMenu = new BPopUpMenu("unknown");
fTypeMenu->AddItem(new BMenuItem("1-Button", new BMessage(POPUP_MOUSE_TYPE)));
fTypeMenu->AddItem(new BMenuItem("2-Button", new BMessage(POPUP_MOUSE_TYPE)));
fTypeMenu->AddItem(new BMenuItem("3-Button", new BMessage(POPUP_MOUSE_TYPE)));
frame.Set(7,8,208,20);
menufield = new BMenuField(frame, "mouse_type", "Mouse type", mouseTypeMenu);
menufield->SetDivider(menufield->Divider() - 29);
menufield->SetAlignment(B_ALIGN_RIGHT);
AddChild(menufield);
BMenuField *field = new BMenuField(BRect(7, 8, 155, 190), "mouse_type", "Mouse type:", fTypeMenu);
field->ResizeToPreferred();
field->SetAlignment(B_ALIGN_RIGHT);
AddChild(field);
fMouseView = new MouseView(BRect(7, 28, 155, 190), fSettings);
fMouseView->ResizeToPreferred();
fMouseView->MoveBy((142 - fMouseView->Bounds().Width()) / 2,
(108 - fMouseView->Bounds().Height()) / 2);
AddChild(fMouseView);
// Add the "Focus follows mouse" pop up menu
focusMenu = new BPopUpMenu("Focus Follows Mouse Menu");
focusMenu->AddItem(new BMenuItem("Disabled",new BMessage(POPUP_MOUSE_FOCUS)));
focusMenu->AddItem(new BMenuItem("Enabled",new BMessage(POPUP_MOUSE_FOCUS)));
focusMenu->AddItem(new BMenuItem("Warping",new BMessage(POPUP_MOUSE_FOCUS)));
focusMenu->AddItem(new BMenuItem("Instant-Warping",new BMessage(POPUP_MOUSE_FOCUS)));
fFocusMenu = new BPopUpMenu("Disabled");
const char *focusLabels[] = {"Disabled", "Enabled", "Warping", "Instant-Warping"};
const mode_mouse focusModes[] = {B_NORMAL_MOUSE, B_FOCUS_FOLLOWS_MOUSE,
B_WARP_MOUSE, B_INSTANT_WARP_MOUSE};
for (int i = 0; i < 4; i++) {
BMessage *message = new BMessage(POPUP_MOUSE_FOCUS);
message->AddInt32("mode", focusModes[i]);
fFocusMenu->AddItem(new BMenuItem(focusLabels[i], message));
}
frame.Set(165, 208, 440, 200);
menufield = new BMenuField(frame, "Focus follows mouse", "Focus follows mouse", focusMenu);
menufield->SetDivider(menufield->Divider() - 18);
menufield->SetAlignment(B_ALIGN_RIGHT);
AddChild(menufield);
field = new BMenuField(frame, "ffm", "Focus follows mouse:", fFocusMenu);
field->SetDivider(field->StringWidth(field->Label()) + kItemSpace);
field->SetAlignment(B_ALIGN_RIGHT);
AddChild(field);
// Create the "Double-click speed slider...
frame.Set(166, 11, 328, 50);
dcSpeedSlider = new BSlider(frame,"double_click_speed","Double-click speed",
dcSpeedSlider = new BSlider(frame, "double_click_speed", "Double-click speed",
new BMessage(SLIDER_DOUBLE_CLICK_SPEED), 0, 1000, B_BLOCK_THUMB, B_FOLLOW_LEFT, B_WILL_DRAW);
dcSpeedSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
dcSpeedSlider->SetHashMarkCount(5);
@ -121,77 +139,32 @@ SettingsView::SettingsView(BRect rect, MouseSettings &settings)
textcontrol = new BTextControl(frame,"double_click_test_area",NULL,"Double-click test area", new BMessage(DOUBLE_CLICK_TEST_AREA),B_FOLLOW_LEFT,B_WILL_DRAW);
textcontrol->SetAlignment(B_ALIGN_LEFT,B_ALIGN_CENTER);
AddChild(textcontrol);
mouseMapMenu = new BPopUpMenu("Mouse Map Menu", true, true);
mouseMapMenu->AddItem(new BMenuItem("1", new BMessage(POPUP_MOUSE_MAP)));
mouseMapMenu->AddItem(new BMenuItem("2", new BMessage(POPUP_MOUSE_MAP)));
mouseMapMenu->AddItem(new BMenuItem("3", new BMessage(POPUP_MOUSE_MAP)));
}
void
SettingsView::MouseDown(BPoint where)
SettingsView::~SettingsView()
{
int32 index = mouseTypeMenu->IndexOf(mouseTypeMenu->FindMarked());
fCurrentButton = -1;
if ((index == 0) && BRect(50,41,105,73).Contains(where))
fCurrentButton = 0;
else if (index == 1) {
if(BRect(50,41,77,73).Contains(where))
fCurrentButton = 0;
else if (BRect(77,41,105,73).Contains(where))
fCurrentButton = 1;
} else {
if(BRect(50,41,68,73).Contains(where))
fCurrentButton = 0;
else if (BRect(86,41,105,73).Contains(where))
fCurrentButton = 1;
else if (BRect(68,41,86,73).Contains(where))
fCurrentButton = 2;
}
if (fCurrentButton >= 0) {
int32 number = 0;
switch (fCurrentMouseMap.button[fCurrentButton]) {
case B_PRIMARY_MOUSE_BUTTON: number = 0; break;
case B_SECONDARY_MOUSE_BUTTON: number = 1; break;
case B_TERTIARY_MOUSE_BUTTON: number = 2; break;
}
mouseMapMenu->ItemAt(number)->SetMarked(true);
ConvertToScreen(&where);
mouseMapMenu->Go(where, true);
}
delete fDoubleClickBitmap;
delete fSpeedBitmap;
delete fAccelerationBitmap;
}
void
SettingsView::AttachedToWindow()
{
get_click_speed(&fClickSpeed);
get_mouse_speed(&fMouseSpeed);
get_mouse_acceleration(&fMouseAcc);
get_mouse_type(&fMouseType);
fMouseMode = mouse_mode();
get_mouse_map(&fMouseMap);
get_mouse_map(&fCurrentMouseMap);
Init();
mouseMapMenu->SetTargetForItems(Window());
UpdateFromSettings();
}
void
SettingsView::Pulse()
void
SettingsView::GetPreferredSize(float *_width, float *_height)
{
BPoint point;
GetMouse(&point, &fButtons, true);
if (fOldButtons != fButtons) {
printf("buttons: old = %ld, new = %ld\n", fOldButtons, fButtons);
Invalidate();
fOldButtons = fButtons;
}
// ToDo: fixed values for now
if (_width)
*_width = 397 - 22;
if (_height)
*_height = 293 - 55;
}
@ -200,17 +173,19 @@ SettingsView::Draw(BRect updateFrame)
{
inherited::Draw(updateFrame);
SetHighColor(120,120,120);
SetLowColor(255,255,255);
SetHighColor(120, 120, 120);
SetLowColor(255, 255, 255);
// Line above the test area
StrokeLine(BPoint(8,198),BPoint(149,198),B_SOLID_HIGH);
StrokeLine(BPoint(8,199),BPoint(149,199),B_SOLID_LOW);
StrokeLine(BPoint(8, 198), BPoint(149, 198), B_SOLID_HIGH);
StrokeLine(BPoint(8, 199), BPoint(149, 199), B_SOLID_LOW);
// Line above focus follows mouse
StrokeLine(BPoint(164,198),BPoint(367,198),B_SOLID_HIGH);
StrokeLine(BPoint(164,199),BPoint(367,199),B_SOLID_LOW);
StrokeLine(BPoint(164, 198), BPoint(367, 198), B_SOLID_HIGH);
StrokeLine(BPoint(164, 199), BPoint(367, 199), B_SOLID_LOW);
// Line in the middle
StrokeLine(BPoint(156,10),BPoint(156,230),B_SOLID_HIGH);
StrokeLine(BPoint(157,11),BPoint(157,230),B_SOLID_LOW);
StrokeLine(BPoint(156, 10), BPoint(156, 230), B_SOLID_HIGH);
StrokeLine(BPoint(157, 11), BPoint(157, 230), B_SOLID_LOW);
SetDrawingMode(B_OP_OVER);
// Draw the icons
if (updateFrame.Intersects( // i have to add 10 pixels width and height, so weird
@ -224,148 +199,52 @@ SettingsView::Draw(BRect updateFrame)
DrawBitmapAsync(fAccelerationBitmap, BPoint(333, 155));
}
// Draw the mouse
// i have to add 10 pixels width and height, so weird
if (updateFrame.Intersects(BRect(50,41,60+kMouseWidth,51+kMouseHeight))) {
SetDrawingMode(B_OP_OVER);
// Draw the mouse top
DrawBitmapAsync(fMouseBitmap,BPoint(50, 41));
int32 index = mouseTypeMenu->IndexOf(mouseTypeMenu->FindMarked());
if (index == 0) { // 1 button
if (fButtons & fCurrentMouseMap.button[0]) {
DrawBitmapAsync(fMouseDownBitmap,BPoint(50, 47));
SetHighColor(64,64,64);
}
} else if (index == 1) { // 2 button
if ( fButtons & fCurrentMouseMap.button[0]) {
DrawBitmapAsync(fMouseDownBitmap, BRect(0,0,27,28), BRect(50,47,77,75));
SetHighColor(120,120,120);
} else
SetHighColor(184,184,184);
StrokeLine(BPoint(76,49),BPoint(76,71),B_SOLID_HIGH);
if (fButtons & fCurrentMouseMap.button[1]) {
SetHighColor(120,120,120);
DrawBitmapAsync(fMouseDownBitmap, BRect(27,0,54,28), BRect(77,47,104,75));
} else
SetHighColor(255,255,255);
StrokeLine(BPoint(78,49),BPoint(78,71),B_SOLID_HIGH);
if ((fButtons & fCurrentMouseMap.button[0]) || (fButtons & fCurrentMouseMap.button[1]))
SetHighColor(48,48,48);
else
SetHighColor(88,88,88);
StrokeLine(BPoint(77,48),BPoint(77,72),B_SOLID_HIGH);
} else { // 3 button
if (fButtons & fCurrentMouseMap.button[0]) {
DrawBitmapAsync(fMouseDownBitmap, BRect(0,0,18,28), BRect(50,47,68,75));
SetHighColor(120,120,120);
} else
SetHighColor(184,184,184);
StrokeLine(BPoint(67,49),BPoint(67,71),B_SOLID_HIGH);
if (fButtons & fCurrentMouseMap.button[2]) {
DrawBitmapAsync(fMouseDownBitmap, BRect(18,0,36,28), BRect(68,47,86,75));
SetHighColor(120,120,120);
} else
SetHighColor(184,184,184);
StrokeLine(BPoint(85,49),BPoint(85,71),B_SOLID_HIGH);
if (fButtons & fCurrentMouseMap.button[2])
SetHighColor(120,120,120);
else
SetHighColor(255,255,255);
StrokeLine(BPoint(69,49),BPoint(69,71),B_SOLID_HIGH);
if (fButtons & fCurrentMouseMap.button[1]) {
DrawBitmapAsync(fMouseDownBitmap, BRect(36,0,54,28), BRect(86,47,104,75));
SetHighColor(120,120,120);
} else
SetHighColor(255,255,255);
StrokeLine(BPoint(87,49),BPoint(87,71),B_SOLID_HIGH);
if ((fButtons & fCurrentMouseMap.button[0]) || (fButtons & fCurrentMouseMap.button[2]))
SetHighColor(48,48,48);
else
SetHighColor(88,88,88);
StrokeLine(BPoint(68,48),BPoint(68,72),B_SOLID_HIGH);
if ((fButtons & fCurrentMouseMap.button[2]) || (fButtons & fCurrentMouseMap.button[1]))
SetHighColor(48,48,48);
else
SetHighColor(88,88,88);
StrokeLine(BPoint(86,48),BPoint(86,72),B_SOLID_HIGH);
}
SetHighColor(32,32,32);
SetFont(be_plain_font);
for(int32 i=0; i<index+1; i++) {
char number[2] = "1";
switch (fCurrentMouseMap.button[i]) {
case B_PRIMARY_MOUSE_BUTTON: *number = '1'; break;
case B_SECONDARY_MOUSE_BUTTON: *number = '2'; break;
case B_TERTIARY_MOUSE_BUTTON: *number = '3'; break;
}
int32 offsets[][3] = { {75},
{61, 88},
{57, 92, 74} };
MovePenTo(offsets[index][i], 65);
DrawString(number);
}
}
Sync();
SetDrawingMode(B_OP_COPY);
}
void
SettingsView::Init()
SettingsView::SetMouseType(int32 type)
{
int32 value;
// slow = 1000000, fast = 0
value = (int32) ((1000000 - fClickSpeed) / 1000);
if (value > 1000) value = 1000;
if (value < 0) value = 0;
dcSpeedSlider->SetValue(value);
// slow = 8192, fast = 524287
value = (int32) (( log(fMouseSpeed / 8192) / log(2)) * 1000 / 6);
if (value > 1000) value = 1000;
if (value < 0) value = 0;
mouseSpeedSlider->SetValue(value);
// slow = 0, fast = 262144
value = (int32) (sqrt(fMouseAcc / 16384) * 1000 / 4);
if (value > 1000) value = 1000;
if (value < 0) value = 0;
mouseAccSlider->SetValue(value);
if (fMouseType < 1)
fMouseType = 1;
if (fMouseType > 3)
fMouseType = 3;
BMenuItem *item = mouseTypeMenu->ItemAt(fMouseType - 1);
if (item)
item->SetMarked(true);
int32 mode;
switch (fMouseMode) {
case B_NORMAL_MOUSE: mode = 0; break;
case B_FOCUS_FOLLOWS_MOUSE: mode = 1; break;
case B_WARP_MOUSE: mode = 2; break;
case B_INSTANT_WARP_MOUSE: mode = 3; break;
default : mode = 0; break;
}
item = focusMenu->ItemAt(mode);
if (item)
item->SetMarked(true);
printf("click_speed : %lli, mouse_speed : %li, mouse_acc : %li, mouse_type : %li\n",
fClickSpeed, fMouseSpeed, fMouseAcc, fMouseType);
fMouseView->SetMouseType(type);
}
void
SettingsView::UpdateFromSettings()
{
int32 value = int32(fSettings.ClickSpeed() / 1000);
// slow = 1000000, fast = 0
if (value < 0)
value = 0;
else if (value > 1000)
value = 1000;
dcSpeedSlider->SetValue(value);
value = int32((log(fSettings.MouseSpeed() / 8192) / log(2)) * 1000 / 6);
// slow = 8192, fast = 524287
if (value < 0)
value = 0;
else if (value > 1000)
value = 1000;
mouseSpeedSlider->SetValue(value);
value = int32(sqrt(fSettings.AccelerationFactor() / 16384) * 1000 / 4);
// slow = 0, fast = 262144
if (value < 0)
value = 0;
else if (value > 1000)
value = 1000;
mouseAccSlider->SetValue(value);
BMenuItem *item = fTypeMenu->ItemAt(fSettings.MouseType() - 1);
if (item != NULL)
item->SetMarked(true);
fMouseView->SetMouseType(fSettings.MouseType());
item = fFocusMenu->ItemAt(mouse_mode_to_index(fSettings.MouseMode()));
if (item != NULL)
item->SetMarked(true);
}

View File

@ -26,39 +26,31 @@
class MouseSettings;
class MouseView;
class SettingsView : public BBox {
public:
SettingsView(BRect frame, MouseSettings &settings);
virtual ~SettingsView();
virtual void AttachedToWindow();
virtual void MouseDown(BPoint where);
virtual void GetPreferredSize(float *_width, float *_height);
virtual void Draw(BRect frame);
virtual void Pulse();
void Init();
BSlider *dcSpeedSlider, *mouseSpeedSlider, *mouseAccSlider;
BPopUpMenu *mouseTypeMenu, *focusMenu, *mouseMapMenu;
bigtime_t fClickSpeed;
int32 fMouseSpeed;
int32 fMouseAcc;
int32 fMouseType;
mode_mouse fMouseMode;
mouse_map fMouseMap, fCurrentMouseMap;
int32 fCurrentButton;
void SetMouseType(int32 type);
void UpdateFromSettings();
private:
typedef BBox inherited;
MouseSettings &fSettings;
const MouseSettings &fSettings;
uint32 fButtons;
uint32 fOldButtons;
BPopUpMenu *fTypeMenu, *fFocusMenu;
MouseView *fMouseView;
BSlider *dcSpeedSlider, *mouseSpeedSlider, *mouseAccSlider;
BBitmap *fDoubleClickBitmap, *fSpeedBitmap, *fAccelerationBitmap;
BBitmap *fMouseBitmap, *fMouseDownBitmap;
BBitmap *fDoubleClickBitmap, *fSpeedBitmap, *fAccelerationBitmap;
};
#endif /* SETTINGS_VIEW_H */