Audio plugin host https://kx.studio/carla
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.

96 lines
3.1KB

  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. SplashScreen::SplashScreen (const String& title, const Image& image, bool useDropShadow)
  18. : Component (title),
  19. backgroundImage (image),
  20. clickCountToDelete (0)
  21. {
  22. // You must supply a valid image here!
  23. jassert (backgroundImage.isValid());
  24. setOpaque (! backgroundImage.hasAlphaChannel());
  25. #if JUCE_IOS || JUCE_ANDROID
  26. const bool useFullScreen = true;
  27. #else
  28. const bool useFullScreen = false;
  29. #endif
  30. makeVisible (image.getWidth(), image.getHeight(), useDropShadow, useFullScreen);
  31. }
  32. SplashScreen::SplashScreen (const String& title, int width, int height, bool useDropShadow)
  33. : Component (title),
  34. clickCountToDelete (0)
  35. {
  36. makeVisible (width, height, useDropShadow, false);
  37. }
  38. void SplashScreen::makeVisible (int w, int h, bool useDropShadow, bool fullscreen)
  39. {
  40. clickCountToDelete = Desktop::getInstance().getMouseButtonClickCounter();
  41. creationTime = Time::getCurrentTime();
  42. const Rectangle<int> screenSize = Desktop::getInstance().getDisplays().getMainDisplay().userArea;
  43. const int width = (fullscreen ? screenSize.getWidth() : w);
  44. const int height = (fullscreen ? screenSize.getHeight() : h);
  45. setAlwaysOnTop (true);
  46. setVisible (true);
  47. centreWithSize (width, height);
  48. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  49. if (fullscreen)
  50. getPeer()->setFullScreen (true);
  51. toFront (false);
  52. }
  53. SplashScreen::~SplashScreen() {}
  54. void SplashScreen::deleteAfterDelay (RelativeTime timeout, bool removeOnMouseClick)
  55. {
  56. // Note that this method must be safe to call from non-GUI threads
  57. if (! removeOnMouseClick)
  58. clickCountToDelete = std::numeric_limits<int>::max();
  59. minimumVisibleTime = timeout;
  60. startTimer (50);
  61. }
  62. void SplashScreen::paint (Graphics& g)
  63. {
  64. g.setOpacity (1.0f);
  65. g.drawImage (backgroundImage, getLocalBounds().toFloat(), RectanglePlacement (RectanglePlacement::fillDestination));
  66. }
  67. void SplashScreen::timerCallback()
  68. {
  69. if (Time::getCurrentTime() > creationTime + minimumVisibleTime
  70. || Desktop::getInstance().getMouseButtonClickCounter() > clickCountToDelete)
  71. delete this;
  72. }