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 <[email protected]>
This commit is contained in:
Andrew Lindesay
2019-08-05 07:39:39 +00:00
parent 719cfad7fd
commit 02e836dc3c
2 changed files with 68 additions and 31 deletions
+66 -30
View File
@@ -183,39 +183,67 @@ BarberPole::MessageReceived(BMessage* message)
void void
BarberPole::Draw(BRect updateRect) 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(); void
fStripe.MapTo(stripeFrame, BarberPole::_DrawSpin(BRect updateRect)
stripeFrame.OffsetToCopy(position, 0.0)); {
FillPolygon(&fStripe); // 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; BRect stripeFrame = fStripe.Frame();
} fStripe.MapTo(stripeFrame,
SetDrawingMode(B_OP_COPY); stripeFrame.OffsetToCopy(position, 0.0));
// Draw box around it FillPolygon(&fStripe);
bounds = Bounds();
be_control_look->DrawBorder(this, bounds, updateRect, position += fStripeWidth;
ui_color(B_PANEL_BACKGROUND_COLOR), B_PLAIN_BORDER);
} }
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 BSize
BarberPole::MinSize() 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;
} }
+2 -1
View File
@@ -44,7 +44,8 @@ public:
private: private:
void _Spin(); void _Spin();
void _DrawSpin(BRect updateRect);
void _DrawNonSpin(BRect updateRect);
private: private:
bool fIsSpinning; bool fIsSpinning;
float fSpinSpeed; float fSpinSpeed;