The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  19. //==============================================================================
  20. class BuildStatusTabComp : public Component,
  21. private ChangeListener,
  22. private Timer
  23. {
  24. public:
  25. BuildStatusTabComp (ErrorList& el, ActivityList& al)
  26. : errorList (el), activityList (al)
  27. {
  28. setInterceptsMouseClicks (false, false);
  29. addAndMakeVisible (&spinner);
  30. activityList.addChangeListener (this);
  31. errorList.addChangeListener (this);
  32. }
  33. ~BuildStatusTabComp() override
  34. {
  35. activityList.removeChangeListener (this);
  36. errorList.removeChangeListener (this);
  37. }
  38. enum { size = 20 };
  39. void updateStatus()
  40. {
  41. State newState = nothing;
  42. if (activityList.getNumActivities() > 0) newState = busy;
  43. else if (errorList.getNumErrors() > 0) newState = errors;
  44. else if (errorList.getNumWarnings() > 0) newState = warnings;
  45. if (newState != state)
  46. {
  47. state = newState;
  48. setSize (state != nothing ? size : 0, size);
  49. spinner.setVisible (state == busy);
  50. repaint();
  51. }
  52. }
  53. void paint (Graphics& g) override
  54. {
  55. if (state == errors || state == warnings)
  56. {
  57. g.setColour (state == errors ? Colours::red : Colours::yellow);
  58. const Path& icon = (state == errors) ? getIcons().warning
  59. : getIcons().info;
  60. g.fillPath (icon, RectanglePlacement (RectanglePlacement::centred)
  61. .getTransformToFit (icon.getBounds(),
  62. getCentralArea().reduced (1, 1).toFloat()));
  63. }
  64. }
  65. void resized() override
  66. {
  67. spinner.setBounds (getCentralArea());
  68. }
  69. Rectangle<int> getCentralArea() const
  70. {
  71. return getLocalBounds().withTrimmedRight (4);
  72. }
  73. private:
  74. ErrorList& errorList;
  75. ActivityList& activityList;
  76. void changeListenerCallback (ChangeBroadcaster*) override { if (! isTimerRunning()) startTimer (150); }
  77. void timerCallback() override { stopTimer(); updateStatus(); }
  78. enum State
  79. {
  80. nothing,
  81. busy,
  82. errors,
  83. warnings
  84. };
  85. State state;
  86. //==============================================================================
  87. struct Spinner : public Component,
  88. private Timer
  89. {
  90. Spinner()
  91. {
  92. setInterceptsMouseClicks (false, false);
  93. }
  94. void paint (Graphics& g) override
  95. {
  96. if (findParentComponentOfClass<TabBarButton>() != nullptr)
  97. {
  98. getLookAndFeel().drawSpinningWaitAnimation (g, findColour (treeIconColourId),
  99. 0, 0, getWidth(), getHeight());
  100. startTimer (1000 / 20);
  101. }
  102. }
  103. void timerCallback() override
  104. {
  105. if (isVisible())
  106. repaint();
  107. else
  108. stopTimer();
  109. }
  110. };
  111. Spinner spinner;
  112. };