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.

143 lines
4.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "JuceDemoHeader.h"
  18. //==============================================================================
  19. /**
  20. */
  21. class IntroScreen : public Component
  22. {
  23. public:
  24. IntroScreen()
  25. : linkButton ("www.juce.com", URL ("http://www.juce.com"))
  26. {
  27. setOpaque (true);
  28. addAndMakeVisible (versionLabel);
  29. addAndMakeVisible (linkButton);
  30. addAndMakeVisible (logo);
  31. versionLabel.setColour (Label::textColourId, Colours::white);
  32. versionLabel.setText (String ("{version} built on {date}")
  33. .replace ("{version}", SystemStats::getJUCEVersion())
  34. .replace ("{date}", String (__DATE__).replace (" ", " ")),
  35. dontSendNotification);
  36. linkButton.setColour (HyperlinkButton::textColourId, Colours::lightblue);
  37. }
  38. void paint (Graphics& g) override
  39. {
  40. g.fillAll (Colour::greyLevel (0.16f));
  41. }
  42. void resized() override
  43. {
  44. Rectangle<int> area (getLocalBounds().reduced (10).removeFromBottom (24));
  45. linkButton.setBounds (area.removeFromRight (getWidth() / 4));
  46. versionLabel.setBounds (area);
  47. logo.updateTransform();
  48. }
  49. private:
  50. Label versionLabel;
  51. HyperlinkButton linkButton;
  52. //==============================================================================
  53. struct LogoDrawComponent : public Component,
  54. private Timer
  55. {
  56. LogoDrawComponent() : logoPath (MainAppWindow::getJUCELogoPath()), elapsed (0.0f)
  57. {
  58. setBounds (logoPath.getBounds().withPosition (Point<float>()).getSmallestIntegerContainer());
  59. startTimerHz (60); // try to repaint at 60 fps
  60. }
  61. void paint (Graphics& g) override
  62. {
  63. Path wavePath;
  64. const float waveStep = 10.0f;
  65. int i = 0;
  66. for (float x = waveStep * 0.5f; x < getWidth(); x += waveStep)
  67. {
  68. const float y1 = getHeight() * 0.5f + getHeight() * 0.05f * std::sin (i * 0.38f + elapsed);
  69. const float y2 = getHeight() * 0.5f + getHeight() * 0.10f * std::sin (i * 0.20f + elapsed * 2.0f);
  70. wavePath.addLineSegment (Line<float> (x, y1, x, y2), 2.0f);
  71. wavePath.addEllipse (x - waveStep * 0.3f, y1 - waveStep * 0.3f, waveStep * 0.6f, waveStep * 0.6f);
  72. wavePath.addEllipse (x - waveStep * 0.3f, y2 - waveStep * 0.3f, waveStep * 0.6f, waveStep * 0.6f);
  73. ++i;
  74. }
  75. g.setColour (Colour::greyLevel (0.3f));
  76. g.fillPath (wavePath);
  77. g.setColour (Colours::orange);
  78. g.fillPath (logoPath, RectanglePlacement (RectanglePlacement::stretchToFit)
  79. .getTransformToFit (logoPath.getBounds(),
  80. getLocalBounds().toFloat().reduced (30, 30)));
  81. }
  82. void updateTransform()
  83. {
  84. if (Component* parent = getParentComponent())
  85. {
  86. const Rectangle<float> parentArea (parent->getLocalBounds().toFloat());
  87. AffineTransform transform = RectanglePlacement (RectanglePlacement::centred)
  88. .getTransformToFit (getLocalBounds().toFloat(),
  89. parentArea);
  90. setTransform (transform);
  91. }
  92. repaint();
  93. }
  94. private:
  95. void timerCallback() override
  96. {
  97. repaint();
  98. elapsed += 0.01f;
  99. }
  100. Path logoPath;
  101. float elapsed;
  102. };
  103. LogoDrawComponent logo;
  104. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (IntroScreen)
  105. };
  106. // This static object will register this demo type in a global list of demos..
  107. static JuceDemoType<IntroScreen> demo ("00 Welcome!");