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.

148 lines
5.4KB

  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. TooltipWindow tooltipWindow;
  54. //==============================================================================
  55. struct LogoDrawComponent : public Component,
  56. private Timer
  57. {
  58. LogoDrawComponent() : logoPath (MainAppWindow::getJUCELogoPath())
  59. {
  60. setBounds (logoPath.getBounds().withPosition (Point<float>()).getSmallestIntegerContainer());
  61. startTimer (1000 / 60); // try to repaint at 60 fps
  62. }
  63. void paint (Graphics& g) override
  64. {
  65. g.setGradientFill (getGradient());
  66. g.fillPath (logoPath, RectanglePlacement (RectanglePlacement::stretchToFit)
  67. .getTransformToFit (logoPath.getBounds(), getLocalBounds().toFloat()));
  68. }
  69. ColourGradient getGradient() const
  70. {
  71. Colour c1 = Colour::fromHSV (hues[0].getValue(), 0.3f, 0.9f, 1.0f);
  72. Colour c2 = Colour::fromHSV (hues[1].getValue(), 0.3f, 0.9f, 1.0f);
  73. Colour c3 = Colour::fromHSV (hues[2].getValue(), 0.3f, 0.9f, 1.0f);
  74. float x1 = getWidth() * gradientPos[0].getValue();
  75. float x2 = getWidth() * gradientPos[1].getValue();
  76. float y1 = getHeight() * gradientPos[2].getValue();
  77. float y2 = getHeight() * gradientPos[3].getValue();
  78. ColourGradient gradient (c1, x1, y1,
  79. c2, x2, y2, false);
  80. gradient.addColour (0.5, c3);
  81. return gradient;
  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.reduced (50.0f, 50.0f));
  91. float scaleFactor = 1.0f + size.getValue() * 0.2f;
  92. float rotationAngle = (angle.getValue() - 0.5f) * 0.1f;
  93. transform = transform.scaled (scaleFactor, scaleFactor, parentArea.getCentreX(), parentArea.getCentreY())
  94. .rotated (rotationAngle, parentArea.getCentreX(), parentArea.getCentreY());
  95. setTransform (transform);
  96. }
  97. repaint();
  98. }
  99. private:
  100. void timerCallback() override
  101. {
  102. updateTransform();
  103. }
  104. Path logoPath;
  105. BouncingNumber gradientPos[4], hues[3], size, angle;
  106. };
  107. LogoDrawComponent logo;
  108. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (IntroScreen)
  109. };
  110. // This static object will register this demo type in a global list of demos..
  111. static JuceDemoType<IntroScreen> demo ("00 Welcome!");