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 2.9KB

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