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.

133 lines
3.9KB

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