Use be_control_look for BScrollBar and FakeScrollBar.

Remove all code which checks for be_control_look being NULL.

Also fix the DrawArrowShape method in be_control_look so the arrow is aligned,
as per the previous commit. In addition the code to offset the arrow when the
scroll button is pressed was unnecessary.

There is still some room for improvement, and I am not happy with the
BControlLook behavior here, as noted in some TODOs.
This commit is contained in:
Ryan Leavengood
2013-03-03 17:50:51 -05:00
parent 8a9200992e
commit f9b1a47fa3
4 changed files with 60 additions and 368 deletions
+6 -11
View File
@@ -744,10 +744,10 @@ BControlLook::DrawArrowShape(BView* view, BRect& rect, const BRect& updateRect,
tri3.Set(rect.right, rect.bottom + 1); tri3.Set(rect.right, rect.bottom + 1);
break; break;
case B_RIGHT_ARROW: case B_RIGHT_ARROW:
tri1.Set(rect.left, rect.bottom + 1); tri1.Set(rect.left + 1, rect.bottom + 1);
tri2.Set(rect.left + rect.Width() / 1.33, tri2.Set(rect.left + 1 + rect.Width() / 1.33,
(rect.top + rect.bottom + 1) / 2); (rect.top + rect.bottom + 1) / 2);
tri3.Set(rect.left, rect.top); tri3.Set(rect.left + 1, rect.top);
break; break;
case B_UP_ARROW: case B_UP_ARROW:
tri1.Set(rect.left, rect.bottom); tri1.Set(rect.left, rect.bottom);
@@ -757,17 +757,12 @@ BControlLook::DrawArrowShape(BView* view, BRect& rect, const BRect& updateRect,
break; break;
case B_DOWN_ARROW: case B_DOWN_ARROW:
default: default:
tri1.Set(rect.left, rect.top); tri1.Set(rect.left, rect.top + 1);
tri2.Set((rect.left + rect.right + 1) / 2, tri2.Set((rect.left + rect.right + 1) / 2,
rect.top + rect.Height() / 1.33); rect.top + 1 + rect.Height() / 1.33);
tri3.Set(rect.right + 1, rect.top); tri3.Set(rect.right + 1, rect.top + 1);
break; break;
} }
// offset triangle if down
if ((flags & B_ACTIVATED) != 0)
view->MovePenTo(BPoint(1, 1));
else
view->MovePenTo(BPoint(0, 0));
BShape arrowShape; BShape arrowShape;
arrowShape.MoveTo(tri1); arrowShape.MoveTo(tri1);
+16 -276
View File
@@ -943,74 +943,8 @@ BScrollBar::Draw(BRect updateRect)
// background for thumb area // background for thumb area
BRect rect(fPrivateData->fThumbFrame); BRect rect(fPrivateData->fThumbFrame);
if (be_control_look == NULL) {
if (fOrientation == B_HORIZONTAL) {
BeginLineArray(8);
if (rect.left > thumbBG.left) {
AddLine(BPoint(thumbBG.left, thumbBG.bottom),
BPoint(thumbBG.left, thumbBG.top),
rect.left > thumbBG.left + 1 ? dark4 : dark);
}
if (rect.left > thumbBG.left + 1) {
AddLine(BPoint(thumbBG.left + 1, thumbBG.top + 1),
BPoint(thumbBG.left + 1, thumbBG.bottom), dark2);
AddLine(BPoint(thumbBG.left + 1, thumbBG.top),
BPoint(rect.left - 1, thumbBG.top), dark2);
AddLine(BPoint(rect.left - 1, thumbBG.bottom),
BPoint(thumbBG.left + 2, thumbBG.bottom), normal);
}
if (rect.right < thumbBG.right - 1) {
AddLine(BPoint(rect.right + 2, thumbBG.top + 1),
BPoint(rect.right + 2, thumbBG.bottom), dark2);
AddLine(BPoint(rect.right + 1, thumbBG.top),
BPoint(thumbBG.right, thumbBG.top), dark2);
AddLine(BPoint(thumbBG.right - 1, thumbBG.bottom),
BPoint(rect.right + 3, thumbBG.bottom), normal);
}
if (rect.right < thumbBG.right) {
AddLine(BPoint(thumbBG.right, thumbBG.top),
BPoint(thumbBG.right, thumbBG.bottom), dark);
}
EndLineArray();
} else {
BeginLineArray(8);
if (rect.top > thumbBG.top) {
AddLine(BPoint(thumbBG.left, thumbBG.top),
BPoint(thumbBG.right, thumbBG.top),
rect.top > thumbBG.top + 1 ? dark4 : dark);
}
if (rect.top > thumbBG.top + 1) {
AddLine(BPoint(thumbBG.left + 1, thumbBG.top + 1),
BPoint(thumbBG.right, thumbBG.top + 1), dark2);
AddLine(BPoint(thumbBG.left, rect.top - 1),
BPoint(thumbBG.left, thumbBG.top + 1), dark2);
AddLine(BPoint(thumbBG.right, rect.top - 1),
BPoint(thumbBG.right, thumbBG.top + 2), normal);
}
if (rect.bottom < thumbBG.bottom - 1) {
AddLine(BPoint(thumbBG.left + 1, rect.bottom + 2),
BPoint(thumbBG.right, rect.bottom + 2), dark2);
AddLine(BPoint(thumbBG.left, rect.bottom + 1),
BPoint(thumbBG.left, thumbBG.bottom - 1), dark2);
AddLine(BPoint(thumbBG.right, rect.bottom + 3),
BPoint(thumbBG.right, thumbBG.bottom - 1), normal);
}
if (rect.bottom < thumbBG.bottom) {
AddLine(BPoint(thumbBG.left, thumbBG.bottom),
BPoint(thumbBG.right, thumbBG.bottom), dark);
}
EndLineArray();
}
}
SetHighColor(dark1); SetHighColor(dark1);
if (be_control_look != NULL) {
uint32 flags = 0; uint32 flags = 0;
if (!enabled) if (!enabled)
flags |= BControlLook::B_DISABLED; flags |= BControlLook::B_DISABLED;
@@ -1034,85 +968,12 @@ BScrollBar::Draw(BRect updateRect)
be_control_look->DrawScrollBarBackground(this, topOfThumb, be_control_look->DrawScrollBarBackground(this, topOfThumb,
bottomOfThumb, updateRect, normal, flags, fOrientation); bottomOfThumb, updateRect, normal, flags, fOrientation);
} }
}
// Draw scroll thumb // Draw scroll thumb
if (enabled) { if (enabled) {
if (be_control_look == NULL) {
// fill and additional dark lines
thumbBG.InsetBy(1.0, 1.0);
if (fOrientation == B_HORIZONTAL) {
BRect leftOfThumb(thumbBG.left + 1, thumbBG.top, rect.left - 1,
thumbBG.bottom);
if (leftOfThumb.IsValid())
FillRect(leftOfThumb);
BRect rightOfThumb(rect.right + 3, thumbBG.top, thumbBG.right,
thumbBG.bottom);
if (rightOfThumb.IsValid())
FillRect(rightOfThumb);
// dark lines before and after thumb
if (rect.left > thumbBG.left) {
SetHighColor(dark);
StrokeLine(BPoint(rect.left - 1, rect.top),
BPoint(rect.left - 1, rect.bottom));
}
if (rect.right < thumbBG.right) {
SetHighColor(dark4);
StrokeLine(BPoint(rect.right + 1, rect.top),
BPoint(rect.right + 1, rect.bottom));
}
} else {
BRect topOfThumb(thumbBG.left, thumbBG.top + 1,
thumbBG.right, rect.top - 1);
if (topOfThumb.IsValid())
FillRect(topOfThumb);
BRect bottomOfThumb(thumbBG.left, rect.bottom + 3,
thumbBG.right, thumbBG.bottom);
if (bottomOfThumb.IsValid())
FillRect(bottomOfThumb);
// dark lines before and after thumb
if (rect.top > thumbBG.top) {
SetHighColor(dark);
StrokeLine(BPoint(rect.left, rect.top - 1),
BPoint(rect.right, rect.top - 1));
}
if (rect.bottom < thumbBG.bottom) {
SetHighColor(dark4);
StrokeLine(BPoint(rect.left, rect.bottom + 1),
BPoint(rect.right, rect.bottom + 1));
}
}
}
// fill the clickable surface of the thumb // fill the clickable surface of the thumb
if (be_control_look != NULL) {
be_control_look->DrawButtonBackground(this, rect, updateRect, be_control_look->DrawButtonBackground(this, rect, updateRect,
normal, 0, BControlLook::B_ALL_BORDERS, fOrientation); normal, 0, BControlLook::B_ALL_BORDERS, fOrientation);
} else {
BeginLineArray(4);
AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.left, rect.top), light);
AddLine(BPoint(rect.left + 1, rect.top),
BPoint(rect.right, rect.top), light);
AddLine(BPoint(rect.right, rect.top + 1),
BPoint(rect.right, rect.bottom), dark1);
AddLine(BPoint(rect.right - 1, rect.bottom),
BPoint(rect.left + 1, rect.bottom), dark1);
EndLineArray();
// fill
rect.InsetBy(1.0, 1.0);
/*if (fPrivateData->fButtonDown == THUMB)
SetHighColor(tint_color(normal, (B_NO_TINT + B_DARKEN_1_TINT) / 2));
else*/
SetHighColor(normal);
FillRect(rect);
}
// TODO: Add the other thumb styles - dots and lines // TODO: Add the other thumb styles - dots and lines
} else { } else {
if (fMin >= fMax || fProportion >= 1.0 || fProportion < 0.0) { if (fMin >= fMax || fProportion >= 1.0 || fProportion < 0.0) {
@@ -1749,152 +1610,31 @@ BScrollBar::_DrawDisabledBackground(BRect area,
void void
BScrollBar::_DrawArrowButton(int32 direction, bool doubleArrows, BRect r, BScrollBar::_DrawArrowButton(int32 direction, bool doubleArrows, BRect rect,
const BRect& updateRect, bool enabled, bool down) const BRect& updateRect, bool enabled, bool down)
{ {
if (!updateRect.Intersects(r)) if (!updateRect.Intersects(rect))
return; return;
rgb_color c = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color light, dark, darker, normal, arrow;
if (down && fPrivateData->fDoRepeat) {
light = tint_color(c, (B_DARKEN_1_TINT + B_DARKEN_2_TINT) / 2.0);
dark = darker = c;
normal = tint_color(c, B_DARKEN_1_TINT);
arrow = tint_color(c, B_DARKEN_MAX_TINT);
} else {
// Add a usability perk - disable buttons if they would not do anything
// - like a left arrow if the value == fMin
// NOTE: disabled because of too much visual noise/distraction
/* if ((direction == ARROW_LEFT || direction == ARROW_UP)
&& (fValue == fMin)) {
use_enabled_colors = false;
} else if ((direction == ARROW_RIGHT || direction == ARROW_DOWN)
&& (fValue == fMax)) {
use_enabled_colors = false;
}*/
if (enabled) {
light = tint_color(c, B_LIGHTEN_MAX_TINT);
dark = tint_color(c, B_DARKEN_1_TINT);
darker = tint_color(c, B_DARKEN_2_TINT);
normal = c;
arrow = tint_color(c, (B_DARKEN_MAX_TINT + B_DARKEN_4_TINT) / 2.0);
} else {
light = tint_color(c, B_LIGHTEN_MAX_TINT);
dark = tint_color(c, B_LIGHTEN_1_TINT);
darker = tint_color(c, B_DARKEN_2_TINT);
normal = tint_color(c, B_LIGHTEN_2_TINT);
arrow = tint_color(c, B_DARKEN_1_TINT);
}
}
BPoint tri1, tri2, tri3;
float hInset = r.Width() / 3;
float vInset = r.Height() / 3;
r.InsetBy(hInset, vInset);
switch (direction) {
case ARROW_LEFT:
tri1.Set(r.right, r.top);
tri2.Set(r.right - r.Width() / 1.33, (r.top + r.bottom + 1) /2 );
tri3.Set(r.right, r.bottom + 1);
break;
case ARROW_RIGHT:
tri1.Set(r.left + 1, r.bottom + 1);
tri2.Set(r.left + 1 + r.Width() / 1.33, (r.top + r.bottom + 1) / 2);
tri3.Set(r.left + 1, r.top);
break;
case ARROW_UP:
tri1.Set(r.left, r.bottom);
tri2.Set((r.left + r.right + 1) / 2, r.bottom - r.Height() / 1.33);
tri3.Set(r.right + 1, r.bottom);
break;
default:
tri1.Set(r.left, r.top + 1);
tri2.Set((r.left + r.right + 1) / 2, r.top + 1 + r.Height() / 1.33);
tri3.Set(r.right + 1, r.top + 1);
break;
}
// offset triangle if down
if (down && fPrivateData->fDoRepeat) {
BPoint offset(1.0, 1.0);
tri1 = tri1 + offset;
tri2 = tri2 + offset;
tri3 = tri3 + offset;
}
r.InsetBy(-(hInset - 1), -(vInset - 1));
if (be_control_look != NULL) {
BRect temp(r.InsetByCopy(-1, -1));
uint32 flags = 0; uint32 flags = 0;
if (down) if (!enabled)
flags |= BControlLook::B_DISABLED;
if (down && fPrivateData->fDoRepeat)
flags |= BControlLook::B_ACTIVATED; flags |= BControlLook::B_ACTIVATED;
be_control_look->DrawButtonBackground(this, temp, updateRect,
down ? c : normal, flags, BControlLook::B_ALL_BORDERS,
fOrientation);
} else {
SetHighColor(normal);
FillRect(r);
}
BShape arrowShape; // TODO: Why does BControlLook need this as the base color for the
arrowShape.MoveTo(tri1); // scrollbar to look right?
arrowShape.LineTo(tri2); rgb_color baseColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
arrowShape.LineTo(tri3); B_LIGHTEN_1_TINT);
SetHighColor(arrow); be_control_look->DrawButtonBackground(this, rect, updateRect, baseColor,
SetPenSize(ceilf(hInset / 2.0)); flags, BControlLook::B_ALL_BORDERS, fOrientation);
StrokeShape(&arrowShape);
SetPenSize(1.0);
if (be_control_look != NULL) // TODO: Why does BControlLook need this negative inset for the arrow to
return; // look right?
rect.InsetBy(-1, -1);
r.InsetBy(-1, -1); be_control_look->DrawArrowShape(this, rect, updateRect,
BeginLineArray(4); baseColor, direction, flags, B_DARKEN_MAX_TINT);
if (direction == ARROW_LEFT || direction == ARROW_RIGHT) {
// horizontal
if (doubleArrows && direction == ARROW_LEFT) {
// draw in such a way that the arrows are
// more visually separated
AddLine(BPoint(r.left + 1, r.top),
BPoint(r.right - 1, r.top), light);
AddLine(BPoint(r.right, r.top),
BPoint(r.right, r.bottom), darker);
} else {
AddLine(BPoint(r.left + 1, r.top),
BPoint(r.right, r.top), light);
AddLine(BPoint(r.right, r.top + 1),
BPoint(r.right, r.bottom), dark);
}
AddLine(BPoint(r.left, r.bottom),
BPoint(r.left, r.top), light);
AddLine(BPoint(r.right - 1, r.bottom),
BPoint(r.left + 1, r.bottom), dark);
} else {
// vertical
if (doubleArrows && direction == ARROW_UP) {
// draw in such a way that the arrows are
// more visually separated
AddLine(BPoint(r.left, r.bottom - 1),
BPoint(r.left, r.top), light);
AddLine(BPoint(r.right, r.bottom),
BPoint(r.left, r.bottom), darker);
} else {
AddLine(BPoint(r.left, r.bottom),
BPoint(r.left, r.top), light);
AddLine(BPoint(r.right, r.bottom),
BPoint(r.left + 1, r.bottom), dark);
}
AddLine(BPoint(r.left + 1, r.top),
BPoint(r.right, r.top), light);
AddLine(BPoint(r.right, r.top + 1),
BPoint(r.right, r.bottom - 1), dark);
}
EndLineArray();
} }
+14 -56
View File
@@ -99,16 +99,16 @@ FakeScrollBar::Draw(BRect updateRect)
BRect buttonFrame(bounds.left, bounds.top, BRect buttonFrame(bounds.left, bounds.top,
bounds.left + bounds.Height(), bounds.bottom); bounds.left + bounds.Height(), bounds.bottom);
_DrawArrowButton(ARROW_LEFT, fDoubleArrows, buttonFrame, updateRect); _DrawArrowButton(ARROW_LEFT, buttonFrame, updateRect);
if (fDoubleArrows) { if (fDoubleArrows) {
buttonFrame.OffsetBy(bounds.Height() + 1, 0.0); buttonFrame.OffsetBy(bounds.Height() + 1, 0.0);
_DrawArrowButton(ARROW_RIGHT, fDoubleArrows, buttonFrame, _DrawArrowButton(ARROW_RIGHT, buttonFrame,
updateRect); updateRect);
buttonFrame.OffsetTo(bounds.right - ((bounds.Height() * 2) + 1), buttonFrame.OffsetTo(bounds.right - ((bounds.Height() * 2) + 1),
bounds.top); bounds.top);
_DrawArrowButton(ARROW_LEFT, fDoubleArrows, buttonFrame, _DrawArrowButton(ARROW_LEFT, buttonFrame,
updateRect); updateRect);
thumbBG.left += bounds.Height() * 2 + 2; thumbBG.left += bounds.Height() * 2 + 2;
@@ -119,7 +119,7 @@ FakeScrollBar::Draw(BRect updateRect)
} }
buttonFrame.OffsetTo(bounds.right - bounds.Height(), bounds.top); buttonFrame.OffsetTo(bounds.right - bounds.Height(), bounds.top);
_DrawArrowButton(ARROW_RIGHT, fDoubleArrows, buttonFrame, updateRect); _DrawArrowButton(ARROW_RIGHT, buttonFrame, updateRect);
SetDrawingMode(B_OP_COPY); SetDrawingMode(B_OP_COPY);
@@ -261,63 +261,21 @@ FakeScrollBar::SetFromScrollBarInfo(const scroll_bar_info &info)
void void
FakeScrollBar::_DrawArrowButton(int32 direction, bool doubleArrows, BRect r, FakeScrollBar::_DrawArrowButton(int32 direction, BRect rect,
const BRect& updateRect) const BRect& updateRect)
{ {
if (!updateRect.Intersects(r)) if (!updateRect.Intersects(rect))
return; return;
rgb_color c = ui_color(B_PANEL_BACKGROUND_COLOR); uint32 flags = 0;
rgb_color light = tint_color(c, B_LIGHTEN_MAX_TINT);
rgb_color dark = tint_color(c, B_DARKEN_1_TINT);
rgb_color darker = tint_color(c, B_DARKEN_2_TINT);
rgb_color normal = c;
rgb_color arrow = tint_color(c,
(B_DARKEN_MAX_TINT + B_DARKEN_4_TINT) / 2.0);
BPoint tri1, tri2, tri3; rgb_color baseColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
float hInset = r.Width() / 3; B_LIGHTEN_1_TINT);
float vInset = r.Height() / 3;
r.InsetBy(hInset, vInset);
switch (direction) { be_control_look->DrawButtonBackground(this, rect, updateRect, baseColor,
case ARROW_LEFT: flags, BControlLook::B_ALL_BORDERS, B_HORIZONTAL);
tri1.Set(r.right, r.top);
tri2.Set(r.right - r.Width() / 1.33, (r.top + r.bottom + 1) / 2);
tri3.Set(r.right, r.bottom + 1);
break;
case ARROW_RIGHT: rect.InsetBy(-1, -1);
tri1.Set(r.left + 1, r.bottom + 1); be_control_look->DrawArrowShape(this, rect, updateRect,
tri2.Set(r.left + 1 + r.Width() / 1.33, (r.top + r.bottom + 1) / 2); baseColor, direction, flags, B_DARKEN_MAX_TINT);
tri3.Set(r.left + 1, r.top);
break;
case ARROW_UP:
tri1.Set(r.left, r.bottom);
tri2.Set((r.left + r.right + 1) / 2, r.bottom - r.Height() / 1.33);
tri3.Set(r.right + 1, r.bottom);
break;
default:
tri1.Set(r.left, r.top + 1);
tri2.Set((r.left + r.right + 1) / 2, r.top + 1 + r.Height() / 1.33);
tri3.Set(r.right + 1, r.top + 1);
break;
}
r.InsetBy(-(hInset - 1), -(vInset - 1));
BRect temp(r.InsetByCopy(-1, -1));
be_control_look->DrawButtonBackground(this, temp, updateRect,
normal, 0, BControlLook::B_ALL_BORDERS, B_HORIZONTAL);
BShape arrowShape;
arrowShape.MoveTo(tri1);
arrowShape.LineTo(tri2);
arrowShape.LineTo(tri3);
SetHighColor(arrow);
SetPenSize(ceilf(hInset / 2.0));
StrokeShape(&arrowShape);
SetPenSize(1.0);
} }
+1 -2
View File
@@ -34,8 +34,7 @@ public:
void SetFromScrollBarInfo(const scroll_bar_info &info); void SetFromScrollBarInfo(const scroll_bar_info &info);
private: private:
void _DrawArrowButton(int32 direction, void _DrawArrowButton(int32 direction, BRect r,
bool doubleArrows, BRect r,
const BRect& updateRect); const BRect& updateRect);
bool fDrawArrows; bool fDrawArrows;