Appearance Prefs: Add scroll bar knob setting

Check values before setting them in SetFromScrollBarInfo

Pin arrow and knob settings to the top so they are aligned
Adjust vertical spacing on single/double to match knob style height

Only draw arrows on single/double FakeScrollBar

Change-Id: I6be89f86181a87808ba5201caf88a33c4414d4c8
This commit is contained in:
John Scipione 2015-01-23 19:07:16 -05:00 committed by waddlesplash
parent ec1b18c58a
commit 0988f80fed
4 changed files with 236 additions and 76 deletions

View File

@ -1,10 +1,10 @@
/*
* Copyright 2010-2012 Haiku, Inc. All rights reserved.
* Copyright 2010-2015 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
* John Scipione <jscipione@gmail.com>
* DarkWyrm, bpmagic@columbus.rr.com
* John Scipione, jscipione@gmail.com
*/
@ -27,13 +27,23 @@ typedef enum {
ARROW_NONE
} arrow_direction;
typedef enum {
KNOB_NONE = 0,
KNOB_DOTS,
KNOB_LINES
} knob_style;
// #pragma mark - FakeScrollBar
FakeScrollBar::FakeScrollBar(bool drawArrows, bool doubleArrows,
BMessage* message)
uint32 knobStyle, BMessage* message)
:
BControl("FakeScrollBar", NULL, message, B_WILL_DRAW | B_NAVIGABLE),
fDrawArrows(drawArrows),
fDoubleArrows(doubleArrows)
fDoubleArrows(doubleArrows),
fKnobStyle(knobStyle)
{
// add some height to draw the ring around the scroll bar
float height = B_H_SCROLL_BAR_HEIGHT + 8;
@ -78,11 +88,19 @@ FakeScrollBar::Draw(BRect updateRect)
SetHighColor(tint_color(base, B_DARKEN_1_TINT));
StrokeRect(rect);
rect.InsetBy(1, 1);
SetHighColor(base);
be_control_look->DrawScrollBar(this, rect, updateRect, base,
flags, B_HORIZONTAL, fDoubleArrows);
float less = floorf(rect.Width() / 3); // thumb takes up 1/3 full width
if (fDrawArrows) {
be_control_look->DrawScrollBar(this, rect, updateRect, base,
flags, B_HORIZONTAL, fDoubleArrows);
} else {
// do not draw scroll bar arrows, fake the border
rgb_color borderColor = tint_color(base, B_DARKEN_2_TINT);
rgb_color navigation = ui_color(B_KEYBOARD_NAVIGATION_COLOR);
SetHighColor(IsFocus() ? navigation : borderColor);
StrokeRect(rect);
rect.InsetBy(1, 1);
}
float less = floorf(rect.Width() / 4); // thumb takes up 3/4 width
BRect thumbRect(rect.left + less, rect.top, rect.right - less, rect.bottom);
be_control_look->DrawScrollBarThumb(this, rect, thumbRect, updateRect, base,
flags, B_HORIZONTAL, fKnobStyle);
@ -90,29 +108,29 @@ FakeScrollBar::Draw(BRect updateRect)
void
FakeScrollBar::MouseDown(BPoint point)
FakeScrollBar::MouseDown(BPoint where)
{
BControl::MouseDown(point);
BControl::MouseDown(where);
}
void
FakeScrollBar::MouseMoved(BPoint point, uint32 transit,
const BMessage* message)
FakeScrollBar::MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage)
{
BControl::MouseMoved(point, transit, message);
BControl::MouseMoved(where, transit, dragMessage);
}
void
FakeScrollBar::MouseUp(BPoint point)
FakeScrollBar::MouseUp(BPoint where)
{
SetValue(B_CONTROL_ON);
Invoke();
Invalidate();
BControl::MouseUp(point);
BControl::MouseUp(where);
}
@ -124,7 +142,7 @@ FakeScrollBar::SetValue(int32 value)
Invalidate();
}
if (!value)
if (value == 0)
return;
BView* parent = Parent();
@ -147,10 +165,10 @@ FakeScrollBar::SetValue(int32 value)
child = parent->ChildAt(0);
} else
child = Window()->ChildAt(0);
} else if (Window())
} else if (Window() != NULL)
child = Window()->ChildAt(0);
while (child) {
while (child != NULL) {
FakeScrollBar* scrollbar = dynamic_cast<FakeScrollBar*>(child);
if (scrollbar != NULL && (scrollbar != this))
@ -174,12 +192,12 @@ FakeScrollBar::SetValue(int32 value)
}
// #pragma mark -
void
FakeScrollBar::SetDoubleArrows(bool doubleArrows)
{
if (fDoubleArrows == doubleArrows)
return;
fDoubleArrows = doubleArrows;
Invalidate();
}
@ -188,6 +206,9 @@ FakeScrollBar::SetDoubleArrows(bool doubleArrows)
void
FakeScrollBar::SetKnobStyle(uint32 knobStyle)
{
if (fKnobStyle == knobStyle)
return;
fKnobStyle = knobStyle;
Invalidate();
}
@ -196,13 +217,16 @@ FakeScrollBar::SetKnobStyle(uint32 knobStyle)
void
FakeScrollBar::SetFromScrollBarInfo(const scroll_bar_info &info)
{
if (fDoubleArrows == info.double_arrows && (int32)fKnobStyle == info.knob)
return;
fDoubleArrows = info.double_arrows;
fKnobStyle = info.knob;
Invalidate();
}
// #pragma mark -
// #pragma mark - Private methods
void

View File

@ -1,10 +1,10 @@
/*
* Copyright 2010-2012 Haiku, Inc. All rights reserved.
* Copyright 2010-2015 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
* John Scipione <jscipione@gmail.com>
* DarkWyrm, bpmagic@columbus.rr.com
* John Scipione, jscipione@gmail.com
*/
#ifndef FAKE_SCROLL_BAR_H
#define FAKE_SCROLL_BAR_H
@ -16,7 +16,7 @@
class FakeScrollBar : public BControl {
public:
FakeScrollBar(bool drawArrows, bool doubleArrows,
BMessage* message);
uint32 knobStyle, BMessage* message);
~FakeScrollBar(void);
virtual void MouseDown(BPoint point);
@ -39,7 +39,7 @@ private:
bool fDrawArrows;
bool fDoubleArrows;
int32 fKnobStyle;
uint32 fKnobStyle;
};
#endif // FAKE_SCROLL_BAR_H

View File

@ -1,12 +1,12 @@
/*
* Copyright 2010-2012 Haiku, Inc. All rights reserved.
* Copyright 2010-2015 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
* Alexander von Gluck <kallisti5@unixzen.com>
* John Scipione <jscipione@gmail.com>
* Ryan Leavengood <leavengood@gmail.com>
* Stephan Aßmus, superstippi@gmx.de
* Alexander von Gluck, kallisti5@unixzen.com
* Ryan Leavengood, leavengood@gmail.com
* John Scipione, jscipione@gmail.com
*/
@ -27,6 +27,7 @@
#include <MenuField.h>
#include <MenuItem.h>
#include <PopUpMenu.h>
#include <RadioButton.h>
#include <ScrollBar.h>
#include <StringView.h>
#include <Size.h>
@ -44,6 +45,13 @@
// This was not renamed to keep from breaking translations
typedef enum {
KNOB_NONE = 0,
KNOB_DOTS,
KNOB_LINES
} knob_style;
static const int32 kMsgSetDecor = 'deco';
static const int32 kMsgDecorInfo = 'idec';
@ -59,7 +67,7 @@ static const int32 kMsgKnobStyleLines = 'mksl';
static const bool kDefaultDoubleScrollBarArrowsSetting = false;
// #pragma mark -
// #pragma mark - LookAndFeelSettingsView
LookAndFeelSettingsView::LookAndFeelSettingsView(const char* name)
@ -67,7 +75,16 @@ LookAndFeelSettingsView::LookAndFeelSettingsView(const char* name)
BView(name, 0),
fDecorInfoButton(NULL),
fDecorMenuField(NULL),
fDecorMenu(NULL)
fDecorMenu(NULL),
fSavedDecor(NULL),
fCurrentDecor(NULL),
fArrowStyleSingle(NULL),
fArrowStyleDouble(NULL),
fKnobStyleNone(NULL),
fKnobStyleDots(NULL),
fKnobStyleLines(NULL),
fSavedKnobStyleValue(_ScrollBarKnobStyle()),
fSavedDoubleArrowsValue(_DoubleScrollBarArrows())
{
// Decorator menu
_BuildDecorMenu();
@ -81,43 +98,72 @@ LookAndFeelSettingsView::LookAndFeelSettingsView(const char* name)
BBox* arrowStyleBox = new BBox("arrow style");
arrowStyleBox->SetLabel(B_TRANSLATE("Arrow style"));
fSavedDoubleArrowsValue = _DoubleScrollBarArrows();
fArrowStyleSingle = new FakeScrollBar(true, false,
fArrowStyleSingle = new FakeScrollBar(true, false, _ScrollBarKnobStyle(),
new BMessage(kMsgArrowStyleSingle));
fArrowStyleDouble = new FakeScrollBar(true, true,
fArrowStyleDouble = new FakeScrollBar(true, true, _ScrollBarKnobStyle(),
new BMessage(kMsgArrowStyleDouble));
BView* arrowStyleView;
arrowStyleView = BLayoutBuilder::Group<>()
.AddGroup(B_VERTICAL, 1)
.Add(new BStringView("single", B_TRANSLATE("Single:")))
.Add(fArrowStyleSingle)
.AddStrut(B_USE_DEFAULT_SPACING)
.Add(new BStringView("double", B_TRANSLATE("Double:")))
.Add(fArrowStyleDouble)
.SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING,
B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
.End()
BView* arrowStyleView = BLayoutBuilder::Group<>(B_VERTICAL, 1)
.AddStrut(B_USE_DEFAULT_SPACING)
.Add(new BStringView("single", B_TRANSLATE("Single:")))
.Add(fArrowStyleSingle)
.AddStrut(B_USE_DEFAULT_SPACING)
.AddStrut(B_USE_DEFAULT_SPACING)
.Add(new BStringView("double", B_TRANSLATE("Double:")))
.Add(fArrowStyleDouble)
.AddStrut(B_USE_DEFAULT_SPACING)
.AddStrut(B_USE_SMALL_SPACING)
.SetInsets(B_USE_DEFAULT_SPACING)
.View();
arrowStyleBox->AddChild(arrowStyleView);
arrowStyleBox->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
B_ALIGN_VERTICAL_CENTER));
arrowStyleBox->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
BStringView* scrollBarLabel
= new BStringView("scroll bar", B_TRANSLATE("Scroll bar:"));
scrollBarLabel->SetExplicitAlignment(
BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP));
// scrollbar knob style
BBox* knobStyleBox = new BBox("knob style");
knobStyleBox->SetLabel(B_TRANSLATE("Knob style"));
fKnobStyleNone = new FakeScrollBar(false, false, KNOB_NONE,
new BMessage(kMsgKnobStyleNone));
fKnobStyleDots = new FakeScrollBar(false, false, KNOB_DOTS,
new BMessage(kMsgKnobStyleDots));
fKnobStyleLines = new FakeScrollBar(false, false, KNOB_LINES,
new BMessage(kMsgKnobStyleLines));
BView* knobStyleView;
knobStyleView = BLayoutBuilder::Group<>(B_VERTICAL, 0)
.Add(new BStringView("none", B_TRANSLATE("None:")))
.Add(fKnobStyleNone)
.AddStrut(B_USE_DEFAULT_SPACING)
.Add(new BStringView("none", B_TRANSLATE("Dots:")))
.Add(fKnobStyleDots)
.AddStrut(B_USE_DEFAULT_SPACING)
.Add(new BStringView("none", B_TRANSLATE("Lines:")))
.Add(fKnobStyleLines)
.SetInsets(B_USE_DEFAULT_SPACING)
.View();
knobStyleBox->AddChild(knobStyleView);
// control layout
BLayoutBuilder::Grid<>(this, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
.Add(fDecorMenuField->CreateLabelLayoutItem(), 0, 0)
.Add(fDecorMenuField->CreateMenuBarLayoutItem(), 1, 0)
.Add(fDecorInfoButton, 2, 0)
.Add(scrollBarLabel, 0, 1)
.Add(arrowStyleBox, 1, 1)
.AddGlue(0, 2)
BLayoutBuilder::Group<>(this, B_VERTICAL)
.AddGrid(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
.Add(fDecorMenuField->CreateLabelLayoutItem(), 0, 0)
.Add(fDecorMenuField->CreateMenuBarLayoutItem(), 1, 0)
.Add(fDecorInfoButton, 2, 0)
.End()
.Add(new BStringView("scroll bar", B_TRANSLATE("Scroll bar:")))
.AddGroup(B_HORIZONTAL)
.AddGroup(B_VERTICAL)
.Add(arrowStyleBox)
.AddGlue()
.End()
.AddGroup(B_VERTICAL)
.Add(knobStyleBox)
.AddGlue()
.End()
.End()
.AddGlue()
.SetInsets(B_USE_WINDOW_SPACING);
// TODO : Decorator Preview Image?
@ -141,22 +187,40 @@ LookAndFeelSettingsView::AttachedToWindow()
fDecorInfoButton->SetTarget(this);
fArrowStyleSingle->SetTarget(this);
fArrowStyleDouble->SetTarget(this);
fKnobStyleNone->SetTarget(this);
fKnobStyleDots->SetTarget(this);
fKnobStyleLines->SetTarget(this);
if (fSavedDoubleArrowsValue)
fArrowStyleDouble->SetValue(B_CONTROL_ON);
else
fArrowStyleSingle->SetValue(B_CONTROL_ON);
switch (fSavedKnobStyleValue) {
case KNOB_DOTS:
fKnobStyleDots->SetValue(B_CONTROL_ON);
break;
case KNOB_LINES:
fKnobStyleLines->SetValue(B_CONTROL_ON);
break;
default:
case KNOB_NONE:
fKnobStyleNone->SetValue(B_CONTROL_ON);
break;
}
}
void
LookAndFeelSettingsView::MessageReceived(BMessage *msg)
LookAndFeelSettingsView::MessageReceived(BMessage* message)
{
switch (msg->what) {
switch (message->what) {
case kMsgSetDecor:
{
BString newDecor;
if (msg->FindString("decor", &newDecor) == B_OK)
if (message->FindString("decor", &newDecor) == B_OK)
_SetDecor(newDecor);
break;
}
@ -181,9 +245,10 @@ LookAndFeelSettingsView::MessageReceived(BMessage *msg)
infoText.ReplaceFirst("%decorAuthors", authorsText.String());
infoText.ReplaceFirst("%decorLic", decor->LicenseName().String());
infoText.ReplaceFirst("%decorURL", decor->SupportURL().String());
infoText.ReplaceFirst("%decorDesc", decor->ShortDescription().String());
infoText.ReplaceFirst("%decorDesc",
decor->ShortDescription().String());
BAlert *infoAlert = new BAlert(B_TRANSLATE("About decorator"),
BAlert* infoAlert = new BAlert(B_TRANSLATE("About decorator"),
infoText.String(), B_TRANSLATE("OK"));
infoAlert->SetFlags(infoAlert->Flags() | B_CLOSE_ON_ESCAPE);
infoAlert->Go();
@ -199,8 +264,20 @@ LookAndFeelSettingsView::MessageReceived(BMessage *msg)
_SetDoubleScrollBarArrows(true);
break;
case kMsgKnobStyleNone:
_SetScrollBarKnobStyle(KNOB_NONE);
break;
case kMsgKnobStyleDots:
_SetScrollBarKnobStyle(KNOB_DOTS);
break;
case kMsgKnobStyleLines:
_SetScrollBarKnobStyle(KNOB_LINES);
break;
default:
BView::MessageReceived(msg);
BView::MessageReceived(message);
break;
}
}
@ -286,6 +363,9 @@ LookAndFeelSettingsView::_SetDoubleScrollBarArrows(bool doubleArrows)
scroll_bar_info info;
get_scroll_bar_info(&info);
if (info.double_arrows == doubleArrows)
return;
info.double_arrows = doubleArrows;
set_scroll_bar_info(&info);
@ -298,11 +378,56 @@ LookAndFeelSettingsView::_SetDoubleScrollBarArrows(bool doubleArrows)
}
int32
LookAndFeelSettingsView::_ScrollBarKnobStyle()
{
scroll_bar_info info;
get_scroll_bar_info(&info);
return info.knob;
}
void
LookAndFeelSettingsView::_SetScrollBarKnobStyle(int32 knobStyle)
{
scroll_bar_info info;
get_scroll_bar_info(&info);
if (info.knob == knobStyle)
return;
info.knob = knobStyle;
set_scroll_bar_info(&info);
switch (knobStyle) {
case KNOB_DOTS:
fKnobStyleDots->SetValue(B_CONTROL_ON);
break;
case KNOB_LINES:
fKnobStyleLines->SetValue(B_CONTROL_ON);
break;
default:
case KNOB_NONE:
fKnobStyleNone->SetValue(B_CONTROL_ON);
break;
}
fArrowStyleSingle->SetKnobStyle(knobStyle);
fArrowStyleDouble->SetKnobStyle(knobStyle);
Window()->PostMessage(kMsgUpdate);
}
bool
LookAndFeelSettingsView::IsDefaultable()
{
return fCurrentDecor != fDecorUtility.DefaultDecorator()->Name()
|| _DoubleScrollBarArrows() != false;
|| _DoubleScrollBarArrows() != false
|| _ScrollBarKnobStyle() != KNOB_NONE;
}
@ -311,6 +436,7 @@ LookAndFeelSettingsView::SetDefaults()
{
_SetDecor(fDecorUtility.DefaultDecorator());
_SetDoubleScrollBarArrows(false);
_SetScrollBarKnobStyle(KNOB_NONE);
}
@ -318,7 +444,8 @@ bool
LookAndFeelSettingsView::IsRevertable()
{
return fCurrentDecor != fSavedDecor
|| _DoubleScrollBarArrows() != fSavedDoubleArrowsValue;
|| _DoubleScrollBarArrows() != fSavedDoubleArrowsValue
|| _ScrollBarKnobStyle() != fSavedKnobStyleValue;
}
@ -328,5 +455,6 @@ LookAndFeelSettingsView::Revert()
if (IsRevertable()) {
_SetDecor(fSavedDecor);
_SetDoubleScrollBarArrows(fSavedDoubleArrowsValue);
_SetScrollBarKnobStyle(fSavedKnobStyleValue);
}
}

View File

@ -1,12 +1,12 @@
/*
* Copyright 2010-2012 Haiku, Inc. All rights reserved.
* Copyright 2010-2015 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
* Alexander von Gluck <kallisti5@unixzen.com>
* John Scipione <jscipione@gmail.com>
* Ryan Leavengood <leavengood@gmail.com>
* Stephan Aßmus, superstippi@gmx.de
* Alexander von Gluck, kallisti5@unixzen.com
* Ryan Leavengood, leavengood@gmail.com
* John Scipione, jscipione@gmail.com
*/
#ifndef LOOK_AND_FEEL_SETTINGS_VIEW_H
#define LOOK_AND_FEEL_SETTINGS_VIEW_H
@ -48,20 +48,28 @@ private:
bool _DoubleScrollBarArrows();
void _SetDoubleScrollBarArrows(bool doubleArrows);
int32 _ScrollBarKnobStyle();
void _SetScrollBarKnobStyle(int32 knobStyle);
private:
DecorInfoUtility fDecorUtility;
BButton* fDecorInfoButton;
BMenuField* fDecorMenuField;
BPopUpMenu* fDecorMenu;
BString fSavedDecor;
BString fCurrentDecor;
FakeScrollBar* fArrowStyleSingle;
FakeScrollBar* fArrowStyleDouble;
BString fSavedDecor;
BString fCurrentDecor;
FakeScrollBar* fKnobStyleNone;
FakeScrollBar* fKnobStyleDots;
FakeScrollBar* fKnobStyleLines;
int32 fSavedKnobStyleValue;
bool fSavedDoubleArrowsValue;
};
#endif // LOOK_AND_FEEL_SETTINGS_VIEW_H