Skip to content

Commit

Permalink
Nicer looking spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Feb 15, 2025
1 parent eb23669 commit b038cc9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Source/Dialogs/Deken.h
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ class Deken final : public Component
ListBox listBox;
BouncingViewport viewport;
std::unique_ptr<HeaderWarning> headerWarning;
int const headerHeight = 40;
int const headerHeight = ProjectInfo::isStandalone ? 0 : 40;
};

// List component to list packages
Expand Down
4 changes: 2 additions & 2 deletions Source/Heavy/ExportingProgressView.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ class ExportingProgressView final : public Component
if (state == Exporting) {
Fonts::drawStyledText(g, "Exporting...", 0, 25, getWidth(), 40, findColour(PlugDataColour::panelTextColourId), Bold, 32, Justification::centred);

getLookAndFeel().drawSpinningWaitAnimation(g, findColour(PlugDataColour::panelTextColourId), getWidth() / 2 - 16, getHeight() / 2 + 135, 32, 32);
getLookAndFeel().drawSpinningWaitAnimation(g, findColour(PlugDataColour::panelTextColourId), getWidth() / 2 - 16, getHeight() / 2 + 118, 32, 32);
} else if (state == Flashing) {
Fonts::drawStyledText(g, "Flashing...", 0, 25, getWidth(), 40, findColour(PlugDataColour::panelTextColourId), Bold, 32, Justification::centred);

getLookAndFeel().drawSpinningWaitAnimation(g, findColour(PlugDataColour::panelTextColourId), getWidth() / 2 - 16, getHeight() / 2 + 135, 32, 32);
getLookAndFeel().drawSpinningWaitAnimation(g, findColour(PlugDataColour::panelTextColourId), getWidth() / 2 - 16, getHeight() / 2 + 118, 32, 32);
} else if (state == Success) {
Fonts::drawStyledText(g, "Export successful", 0, 25, getWidth(), 40, findColour(PlugDataColour::panelTextColourId), Bold, 32, Justification::centred);

Expand Down
2 changes: 1 addition & 1 deletion Source/Heavy/Toolchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class ToolchainInstaller final : public Component
}

if (isTimerRunning()) {
getLookAndFeel().drawSpinningWaitAnimation(g, findColour(PlugDataColour::panelTextColourId), getWidth() / 2 - 16, getHeight() / 2 + 135, 32, 32);
getLookAndFeel().drawSpinningWaitAnimation(g, findColour(PlugDataColour::panelTextColourId), getWidth() / 2 - 16, getHeight() / 2 + 118, 32, 32);
}
}

Expand Down
32 changes: 32 additions & 0 deletions Source/LookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,38 @@ void PlugDataLook::drawTextEditorOutline(Graphics& g, int const width, int const
}
}

void PlugDataLook::drawSpinningWaitAnimation(Graphics& g, const Colour& colour, int x, int y, int w, int h)
{
const float radius = (float) jmin(w, h) * 0.4f;
const float thickness = radius * 0.3f;
const float cx = (float)x + (float)w * 0.5f;
const float cy = (float)y + (float)h * 0.5f;

// Compute animation progress
const double animationTime = Time::getMillisecondCounterHiRes() / 1000.0;
const double progress = fmod(animationTime, 2.0); // Loops every 2 seconds

// Adwaita-style arc calculation
const float minArcLength = MathConstants<float>::pi * 0.2f; // Shortest segment
const float maxArcLength = MathConstants<float>::pi * 0.8f; // Longest segment
const float startAngle = MathConstants<float>::twoPi * progress; // Rotating angle
const float t = (sinf(progress * MathConstants<float>::pi) + 1.0f) / 2.0f; // Smooth curve
const float arcLength = minArcLength + t * (maxArcLength - minArcLength);
const float endAngle = startAngle + arcLength;

// Draw background circle
g.setColour(colour.withAlpha(0.1f));
g.drawEllipse(cx - radius, cy - radius, radius * 2.0f, radius * 2.0f, thickness);

Path p;
p.addCentredArc(cx, cy, radius, radius, 0.0f, startAngle, endAngle, true);

// Draw moving arc
g.setColour(colour);
g.strokePath(p, PathStrokeType(thickness, PathStrokeType::curved, PathStrokeType::rounded));

}

void PlugDataLook::drawCornerResizer(Graphics& g, int const w, int const h, bool const isMouseOver, bool isMouseDragging)
{
Path triangle;
Expand Down
2 changes: 2 additions & 0 deletions Source/LookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ struct PlugDataLook final : public LookAndFeel_V4 {

void drawTextEditorOutline(Graphics& g, int width, int height, TextEditor& textEditor) override;

void drawSpinningWaitAnimation(Graphics& g, const Colour& colour, int x, int y, int w, int h) override;

void drawCornerResizer(Graphics& g, int w, int h, bool isMouseOver, bool isMouseDragging) override;

void drawLasso(Graphics& g, Component& lassoComp) override;
Expand Down

0 comments on commit b038cc9

Please sign in to comment.