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.

98 lines
3.1KB

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