From 02e836dc3c3850e5f3d00bf6b85563d3900c6ec8 Mon Sep 17 00:00:00 2001 From: Andrew Lindesay Date: Sat, 3 Aug 2019 23:13:21 +1200 Subject: [PATCH] HaikuDepot: Barber Pole Idle Appearance This change renders a striped background in the 'barber pole' in HaikuDepot application when it is idle. This makes the 'barber pole' easier to use in situations where the space that the UI control takes up should not be blank. The logic for the striped background is from the 'drivesetup' application. Change-Id: I87791c70b4d1a21d91e661433d6c940ca69ece87 Reviewed-on: https://review.haiku-os.org/c/1674 Reviewed-by: Adrien Destugues --- src/apps/haikudepot/ui_generic/BarberPole.cpp | 96 +++++++++++++------ src/apps/haikudepot/ui_generic/BarberPole.h | 3 +- 2 files changed, 68 insertions(+), 31 deletions(-) diff --git a/src/apps/haikudepot/ui_generic/BarberPole.cpp b/src/apps/haikudepot/ui_generic/BarberPole.cpp index 00318c7c3e..9319757ca5 100644 --- a/src/apps/haikudepot/ui_generic/BarberPole.cpp +++ b/src/apps/haikudepot/ui_generic/BarberPole.cpp @@ -183,39 +183,67 @@ BarberPole::MessageReceived(BMessage* message) void BarberPole::Draw(BRect updateRect) { + if (fIsSpinning) + _DrawSpin(updateRect); + else + _DrawNonSpin(updateRect); +} - if (fIsSpinning) { - // Draw color stripes - float position = -fStripeWidth * (fNumColors + 0.5) + fScrollOffset; - // Starting position: beginning of the second color cycle - // The + 0.5 is so we start out without a partially visible stripe - // on the left side (makes it simpler to loop) - BRect bounds = Bounds(); - bounds.InsetBy(-2, -2); - be_control_look->DrawStatusBar(this, bounds, updateRect, - ui_color(B_PANEL_BACKGROUND_COLOR), ui_color(B_STATUS_BAR_COLOR), - bounds.Width()); - SetDrawingMode(B_OP_ALPHA); - uint32 colorIndex = 0; - for (uint32 i = 0; i < fNumStripes; i++) { - SetHighColor(fColors[colorIndex]); - colorIndex++; - if (colorIndex >= fNumColors) - colorIndex = 0; - BRect stripeFrame = fStripe.Frame(); - fStripe.MapTo(stripeFrame, - stripeFrame.OffsetToCopy(position, 0.0)); - FillPolygon(&fStripe); +void +BarberPole::_DrawSpin(BRect updateRect) +{ + // Draw color stripes + float position = -fStripeWidth * (fNumColors + 0.5) + fScrollOffset; + // Starting position: beginning of the second color cycle + // The + 0.5 is so we start out without a partially visible stripe + // on the left side (makes it simpler to loop) + BRect bounds = Bounds(); + bounds.InsetBy(-2, -2); + be_control_look->DrawStatusBar(this, bounds, updateRect, + ui_color(B_PANEL_BACKGROUND_COLOR), ui_color(B_STATUS_BAR_COLOR), + bounds.Width()); + SetDrawingMode(B_OP_ALPHA); + uint32 colorIndex = 0; + for (uint32 i = 0; i < fNumStripes; i++) { + SetHighColor(fColors[colorIndex]); + colorIndex++; + if (colorIndex >= fNumColors) + colorIndex = 0; - position += fStripeWidth; - } - SetDrawingMode(B_OP_COPY); - // Draw box around it - bounds = Bounds(); - be_control_look->DrawBorder(this, bounds, updateRect, - ui_color(B_PANEL_BACKGROUND_COLOR), B_PLAIN_BORDER); + BRect stripeFrame = fStripe.Frame(); + fStripe.MapTo(stripeFrame, + stripeFrame.OffsetToCopy(position, 0.0)); + FillPolygon(&fStripe); + + position += fStripeWidth; } + + SetDrawingMode(B_OP_COPY); + // Draw box around it + bounds = Bounds(); + be_control_look->DrawBorder(this, bounds, updateRect, + ui_color(B_PANEL_BACKGROUND_COLOR), B_PLAIN_BORDER); +} + + +/*! This will show something in the place of the spinner when there is no + spinning going on. The logic to render the striped background comes + from the 'drivesetup' application. +*/ + +void +BarberPole::_DrawNonSpin(BRect updateRect) +{ + // approach copied from the DiskSetup application. + static const pattern kStripes = { { 0xc7, 0x8f, 0x1f, 0x3e, 0x7c, + 0xf8, 0xf1, 0xe3 } }; + BRect bounds = Bounds(); + SetHighUIColor(B_PANEL_BACKGROUND_COLOR, B_DARKEN_1_TINT); + SetLowUIColor(B_PANEL_BACKGROUND_COLOR); + FillRect(bounds, kStripes); + be_control_look->DrawBorder(this, bounds, updateRect, + ui_color(B_PANEL_BACKGROUND_COLOR), B_PLAIN_BORDER); } @@ -259,7 +287,15 @@ BarberPole::FrameResized(float width, float height) BSize BarberPole::MinSize() { - return BSize(50, 5); + BSize result = BView::MinSize(); + + if (result.width < 50) + result.SetWidth(50); + + if (result.height < 5) + result.SetHeight(5); + + return result; } diff --git a/src/apps/haikudepot/ui_generic/BarberPole.h b/src/apps/haikudepot/ui_generic/BarberPole.h index cfd98a627c..23edb8fb6c 100644 --- a/src/apps/haikudepot/ui_generic/BarberPole.h +++ b/src/apps/haikudepot/ui_generic/BarberPole.h @@ -44,7 +44,8 @@ public: private: void _Spin(); - + void _DrawSpin(BRect updateRect); + void _DrawNonSpin(BRect updateRect); private: bool fIsSpinning; float fSpinSpeed;