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.

juce_SplashScreen.cpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - 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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-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().getPrimaryDisplay()->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