From f9b1a47fa329a440024cfcb45a82841ff6961f42 Mon Sep 17 00:00:00 2001 From: Ryan Leavengood Date: Sun, 3 Mar 2013 17:45:47 -0500 Subject: [PATCH] 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. --- src/kits/interface/ControlLook.cpp | 19 +- src/kits/interface/ScrollBar.cpp | 336 +++---------------- src/preferences/appearance/FakeScrollBar.cpp | 70 +--- src/preferences/appearance/FakeScrollBar.h | 3 +- 4 files changed, 60 insertions(+), 368 deletions(-) diff --git a/src/kits/interface/ControlLook.cpp b/src/kits/interface/ControlLook.cpp index 4b0910e19b..3e00369bcb 100644 --- a/src/kits/interface/ControlLook.cpp +++ b/src/kits/interface/ControlLook.cpp @@ -740,14 +740,14 @@ BControlLook::DrawArrowShape(BView* view, BRect& rect, const BRect& updateRect, case B_LEFT_ARROW: tri1.Set(rect.right, rect.top); tri2.Set(rect.right - rect.Width() / 1.33, - (rect.top + rect.bottom + 1) /2 ); + (rect.top + rect.bottom + 1) / 2); tri3.Set(rect.right, rect.bottom + 1); break; case B_RIGHT_ARROW: - tri1.Set(rect.left, rect.bottom + 1); - tri2.Set(rect.left + rect.Width() / 1.33, + tri1.Set(rect.left + 1, rect.bottom + 1); + tri2.Set(rect.left + 1 + rect.Width() / 1.33, (rect.top + rect.bottom + 1) / 2); - tri3.Set(rect.left, rect.top); + tri3.Set(rect.left + 1, rect.top); break; case B_UP_ARROW: tri1.Set(rect.left, rect.bottom); @@ -757,17 +757,12 @@ BControlLook::DrawArrowShape(BView* view, BRect& rect, const BRect& updateRect, break; case B_DOWN_ARROW: default: - tri1.Set(rect.left, rect.top); + tri1.Set(rect.left, rect.top + 1); tri2.Set((rect.left + rect.right + 1) / 2, - rect.top + rect.Height() / 1.33); - tri3.Set(rect.right + 1, rect.top); + rect.top + 1 + rect.Height() / 1.33); + tri3.Set(rect.right + 1, rect.top + 1); break; } - // offset triangle if down - if ((flags & B_ACTIVATED) != 0) - view->MovePenTo(BPoint(1, 1)); - else - view->MovePenTo(BPoint(0, 0)); BShape arrowShape; arrowShape.MoveTo(tri1); diff --git a/src/kits/interface/ScrollBar.cpp b/src/kits/interface/ScrollBar.cpp index ea9918d841..44c2382333 100644 --- a/src/kits/interface/ScrollBar.cpp +++ b/src/kits/interface/ScrollBar.cpp @@ -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); } diff --git a/src/preferences/appearance/FakeScrollBar.cpp b/src/preferences/appearance/FakeScrollBar.cpp index 7393b946f1..e8a792928e 100644 --- a/src/preferences/appearance/FakeScrollBar.cpp +++ b/src/preferences/appearance/FakeScrollBar.cpp @@ -99,16 +99,16 @@ FakeScrollBar::Draw(BRect updateRect) BRect buttonFrame(bounds.left, bounds.top, bounds.left + bounds.Height(), bounds.bottom); - _DrawArrowButton(ARROW_LEFT, fDoubleArrows, buttonFrame, updateRect); + _DrawArrowButton(ARROW_LEFT, buttonFrame, updateRect); if (fDoubleArrows) { buttonFrame.OffsetBy(bounds.Height() + 1, 0.0); - _DrawArrowButton(ARROW_RIGHT, fDoubleArrows, buttonFrame, + _DrawArrowButton(ARROW_RIGHT, buttonFrame, updateRect); buttonFrame.OffsetTo(bounds.right - ((bounds.Height() * 2) + 1), bounds.top); - _DrawArrowButton(ARROW_LEFT, fDoubleArrows, buttonFrame, + _DrawArrowButton(ARROW_LEFT, buttonFrame, updateRect); thumbBG.left += bounds.Height() * 2 + 2; @@ -119,7 +119,7 @@ FakeScrollBar::Draw(BRect updateRect) } buttonFrame.OffsetTo(bounds.right - bounds.Height(), bounds.top); - _DrawArrowButton(ARROW_RIGHT, fDoubleArrows, buttonFrame, updateRect); + _DrawArrowButton(ARROW_RIGHT, buttonFrame, updateRect); SetDrawingMode(B_OP_COPY); @@ -261,63 +261,21 @@ FakeScrollBar::SetFromScrollBarInfo(const scroll_bar_info &info) void -FakeScrollBar::_DrawArrowButton(int32 direction, bool doubleArrows, BRect r, +FakeScrollBar::_DrawArrowButton(int32 direction, BRect rect, const BRect& updateRect) { - if (!updateRect.Intersects(r)) + if (!updateRect.Intersects(rect)) return; - rgb_color c = ui_color(B_PANEL_BACKGROUND_COLOR); - 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); + uint32 flags = 0; - BPoint tri1, tri2, tri3; - float hInset = r.Width() / 3; - float vInset = r.Height() / 3; - r.InsetBy(hInset, vInset); + rgb_color baseColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), + B_LIGHTEN_1_TINT); - 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; + be_control_look->DrawButtonBackground(this, rect, updateRect, baseColor, + flags, BControlLook::B_ALL_BORDERS, B_HORIZONTAL); - 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; - } - - 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); + rect.InsetBy(-1, -1); + be_control_look->DrawArrowShape(this, rect, updateRect, + baseColor, direction, flags, B_DARKEN_MAX_TINT); } diff --git a/src/preferences/appearance/FakeScrollBar.h b/src/preferences/appearance/FakeScrollBar.h index 74e034b4cd..c02571ed82 100644 --- a/src/preferences/appearance/FakeScrollBar.h +++ b/src/preferences/appearance/FakeScrollBar.h @@ -34,8 +34,7 @@ public: void SetFromScrollBarInfo(const scroll_bar_info &info); private: - void _DrawArrowButton(int32 direction, - bool doubleArrows, BRect r, + void _DrawArrowButton(int32 direction, BRect r, const BRect& updateRect); bool fDrawArrows;