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.

144 lines
5.1KB

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