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.

160 lines
5.8KB

  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())
  58. {
  59. setBounds (logoPath.getBounds().withPosition (Point<float>()).getSmallestIntegerContainer());
  60. startTimer (1000 / 60); // try to repaint at 60 fps
  61. elapsed = 0.0f;
  62. }
  63. void paint (Graphics& g) override
  64. {
  65. //g.setGradientFill (getGradient());
  66. g.setColour (Colour::greyLevel (0.3f));
  67. float waveStep = 10.0f;
  68. for (int i = 0; i < getWidth()/waveStep; ++i)
  69. {
  70. float x = waveStep*0.5f + waveStep * i;
  71. float y1 = getHeight() * 0.5f + getHeight() * 0.05f * sin (i * 0.38f + elapsed);
  72. float y2 = getHeight() * 0.5 + getHeight() * 0.1f * sin (i * 0.2f + elapsed * 2.0f);
  73. g.drawLine (x, y1, x, y2, 2.0f);
  74. g.fillEllipse (x - waveStep * 0.3f, y1 - waveStep * 0.3f, waveStep*0.6f, waveStep*0.6f);
  75. g.fillEllipse (x - waveStep * 0.3f, y2 - waveStep * 0.3f, waveStep*0.6f, waveStep*0.6f);
  76. }
  77. g.setColour (Colours::orange);
  78. g.fillPath (logoPath, RectanglePlacement (RectanglePlacement::stretchToFit)
  79. .getTransformToFit (logoPath.getBounds(), getLocalBounds().toFloat().reduced (30, 30)));
  80. }
  81. ColourGradient getGradient() const
  82. {
  83. Colour c1 = Colour::fromHSV (hues[0].getValue(), 0.9f, 0.9f, 1.0f);
  84. Colour c2 = Colour::fromHSV (hues[1].getValue(), 0.9f, 0.9f, 1.0f);
  85. Colour c3 = Colour::fromHSV (hues[2].getValue(), 0.9f, 0.9f, 1.0f);
  86. float x1 = getWidth() * gradientPos[0].getValue();
  87. float x2 = getWidth() * gradientPos[1].getValue();
  88. float y1 = getHeight() * gradientPos[2].getValue();
  89. float y2 = getHeight() * gradientPos[3].getValue();
  90. ColourGradient gradient (c1, x1, y1,
  91. c2, x2, y2, false);
  92. gradient.addColour (0.5, c3);
  93. return gradient;
  94. }
  95. void updateTransform()
  96. {
  97. if (Component* parent = getParentComponent())
  98. {
  99. const Rectangle<float> parentArea (parent->getLocalBounds().toFloat());
  100. AffineTransform transform = RectanglePlacement (RectanglePlacement::centred)
  101. .getTransformToFit (getLocalBounds().toFloat(),
  102. parentArea);
  103. setTransform (transform);
  104. }
  105. repaint();
  106. }
  107. private:
  108. void timerCallback() override
  109. {
  110. //updateTransform();
  111. repaint();
  112. elapsed += 0.01f;
  113. }
  114. Path logoPath;
  115. BouncingNumber gradientPos[4], hues[3], size, angle;
  116. float elapsed;
  117. };
  118. LogoDrawComponent logo;
  119. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (IntroScreen)
  120. };
  121. // This static object will register this demo type in a global list of demos..
  122. static JuceDemoType<IntroScreen> demo ("00 Welcome!");