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.

102 lines
3.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. SplashScreen::SplashScreen (const String& title, const Image& image, bool useDropShadow)
  21. : Component (title),
  22. backgroundImage (image),
  23. clickCountToDelete (0)
  24. {
  25. // You must supply a valid image here!
  26. jassert (backgroundImage.isValid());
  27. setOpaque (! backgroundImage.hasAlphaChannel());
  28. #if JUCE_IOS || JUCE_ANDROID
  29. const bool useFullScreen = true;
  30. #else
  31. const bool useFullScreen = false;
  32. #endif
  33. makeVisible (image.getWidth(), image.getHeight(), useDropShadow, useFullScreen);
  34. }
  35. SplashScreen::SplashScreen (const String& title, int width, int height, bool useDropShadow)
  36. : Component (title),
  37. clickCountToDelete (0)
  38. {
  39. makeVisible (width, height, useDropShadow, false);
  40. }
  41. void SplashScreen::makeVisible (int w, int h, bool useDropShadow, bool fullscreen)
  42. {
  43. clickCountToDelete = Desktop::getInstance().getMouseButtonClickCounter();
  44. creationTime = Time::getCurrentTime();
  45. const Rectangle<int> screenSize = Desktop::getInstance().getDisplays().getMainDisplay().userArea;
  46. const int width = (fullscreen ? screenSize.getWidth() : w);
  47. const int height = (fullscreen ? screenSize.getHeight() : h);
  48. setAlwaysOnTop (true);
  49. setVisible (true);
  50. centreWithSize (width, height);
  51. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  52. if (fullscreen)
  53. getPeer()->setFullScreen (true);
  54. toFront (false);
  55. }
  56. SplashScreen::~SplashScreen() {}
  57. void SplashScreen::deleteAfterDelay (RelativeTime timeout, bool removeOnMouseClick)
  58. {
  59. // Note that this method must be safe to call from non-GUI threads
  60. if (! removeOnMouseClick)
  61. clickCountToDelete = std::numeric_limits<int>::max();
  62. minimumVisibleTime = timeout;
  63. startTimer (50);
  64. }
  65. void SplashScreen::paint (Graphics& g)
  66. {
  67. g.setOpacity (1.0f);
  68. g.drawImage (backgroundImage, getLocalBounds().toFloat(), RectanglePlacement (RectanglePlacement::fillDestination));
  69. }
  70. void SplashScreen::timerCallback()
  71. {
  72. if (Time::getCurrentTime() > creationTime + minimumVisibleTime
  73. || Desktop::getInstance().getMouseButtonClickCounter() > clickCountToDelete)
  74. delete this;
  75. }
  76. } // namespace juce