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
+38 -298
View File
@@ -943,176 +943,37 @@ BScrollBar::Draw(BRect updateRect)
// background for thumb area
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);
if (be_control_look != NULL) {
uint32 flags = 0;
if (!enabled)
flags |= BControlLook::B_DISABLED;
uint32 flags = 0;
if (!enabled)
flags |= BControlLook::B_DISABLED;
// fill background besides the thumb
if (fOrientation == B_HORIZONTAL) {
BRect leftOfThumb(thumbBG.left, thumbBG.top, rect.left - 1,
thumbBG.bottom);
BRect rightOfThumb(rect.right + 1, thumbBG.top, thumbBG.right,
thumbBG.bottom);
// fill background besides the thumb
if (fOrientation == B_HORIZONTAL) {
BRect leftOfThumb(thumbBG.left, thumbBG.top, rect.left - 1,
thumbBG.bottom);
BRect rightOfThumb(rect.right + 1, thumbBG.top, thumbBG.right,
thumbBG.bottom);
be_control_look->DrawScrollBarBackground(this, leftOfThumb,
rightOfThumb, updateRect, normal, flags, fOrientation);
} else {
BRect topOfThumb(thumbBG.left, thumbBG.top,
thumbBG.right, rect.top - 1);
be_control_look->DrawScrollBarBackground(this, leftOfThumb,
rightOfThumb, updateRect, normal, flags, fOrientation);
} else {
BRect topOfThumb(thumbBG.left, thumbBG.top,
thumbBG.right, rect.top - 1);
BRect bottomOfThumb(thumbBG.left, rect.bottom + 1,
thumbBG.right, thumbBG.bottom);
BRect bottomOfThumb(thumbBG.left, rect.bottom + 1,
thumbBG.right, thumbBG.bottom);
be_control_look->DrawScrollBarBackground(this, topOfThumb,
bottomOfThumb, updateRect, normal, flags, fOrientation);
}
be_control_look->DrawScrollBarBackground(this, topOfThumb,
bottomOfThumb, updateRect, normal, flags, fOrientation);
}
// Draw scroll thumb
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
if (be_control_look != NULL) {
be_control_look->DrawButtonBackground(this, rect, updateRect,
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);
}
be_control_look->DrawButtonBackground(this, rect, updateRect,
normal, 0, BControlLook::B_ALL_BORDERS, fOrientation);
// TODO: Add the other thumb styles - dots and lines
} else {
if (fMin >= fMax || fProportion >= 1.0 || fProportion < 0.0) {
@@ -1749,152 +1610,31 @@ BScrollBar::_DrawDisabledBackground(BRect area,
void
BScrollBar::_DrawArrowButton(int32 direction, bool doubleArrows, BRect r,
BScrollBar::_DrawArrowButton(int32 direction, bool doubleArrows, BRect rect,
const BRect& updateRect, bool enabled, bool down)
{
if (!updateRect.Intersects(r))
if (!updateRect.Intersects(rect))
return;
rgb_color c = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color light, dark, darker, normal, arrow;
uint32 flags = 0;
if (!enabled)
flags |= BControlLook::B_DISABLED;
if (down && fPrivateData->fDoRepeat)
flags |= BControlLook::B_ACTIVATED;
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);
// TODO: Why does BControlLook need this as the base color for the
// scrollbar to look right?
rgb_color baseColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_LIGHTEN_1_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;
}*/
be_control_look->DrawButtonBackground(this, rect, updateRect, baseColor,
flags, BControlLook::B_ALL_BORDERS, fOrientation);
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;
if (down)
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;
arrowShape.MoveTo(tri1);
arrowShape.LineTo(tri2);
arrowShape.LineTo(tri3);
SetHighColor(arrow);
SetPenSize(ceilf(hInset / 2.0));
StrokeShape(&arrowShape);
SetPenSize(1.0);
if (be_control_look != NULL)
return;
r.InsetBy(-1, -1);
BeginLineArray(4);
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();
// TODO: Why does BControlLook need this negative inset for the arrow to
// look right?
rect.InsetBy(-1, -1);
be_control_look->DrawArrowShape(this, rect, updateRect,
baseColor, direction, flags, B_DARKEN_MAX_TINT);
}