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.

152 lines
6.7KB

  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. #pragma once
  18. //==============================================================================
  19. /** A component for showing a splash screen while your app starts up.
  20. This will automatically position itself, and can be told to delete itself after
  21. being on-screen for a minimum length of time.
  22. To use it, just create one of these in your JUCEApplicationBase::initialise() method,
  23. and when your initialisation tasks have finished running, call its deleteAfterDelay()
  24. method to make it automatically get rid of itself.
  25. Note that although you could call deleteAfterDelay() as soon as you create the
  26. SplashScreen object, if you've got a long initialisation procedure, you probably
  27. don't want the splash to time-out and disappear before the initialisation has
  28. finished, which is why it makes sense to not call this method until the end of
  29. your init tasks.
  30. E.g. @code
  31. void MyApp::initialise (const String& commandLine)
  32. {
  33. splash = new SplashScreen ("Welcome to my app!",
  34. ImageFileFormat::loadFrom (File ("/foobar/splash.jpg")),
  35. true);
  36. // now kick off your initialisation work on some kind of thread or task, and
  37. launchBackgroundInitialisationThread();
  38. }
  39. void MyApp::myInitialisationWorkFinished()
  40. {
  41. // ..assuming this is some kind of callback method that is triggered when
  42. // your background initialisation threads have finished, and it's time to open
  43. // your main window, etc..
  44. splash->deleteAfterDelay (RelativeTime::seconds (4), false);
  45. ...etc...
  46. }
  47. @endcode
  48. */
  49. class JUCE_API SplashScreen : public Component,
  50. private Timer,
  51. private DeletedAtShutdown
  52. {
  53. public:
  54. //==============================================================================
  55. /** Creates a SplashScreen object.
  56. When called, the constructor will position the SplashScreen in the centre of the
  57. display, and after the time specified, it will automatically delete itself.
  58. Bear in mind that if you call this during your JUCEApplicationBase::initialise()
  59. method and then block the message thread by performing some kind of task, then
  60. obviously neither your splash screen nor any other GUI will appear until you
  61. allow the message thread to resume and do its work. So if you have time-consuming
  62. tasks to do during startup, use a background thread for them.
  63. After creating one of these (or your subclass of it), you should do your app's
  64. initialisation work, and then call the deleteAfterDelay() method to tell this object
  65. to delete itself after the user has had chance to get a good look at it.
  66. If you're writing a custom splash screen class, there's another protected constructor
  67. that your subclass can call, which doesn't take an image.
  68. @param title the name to give the component
  69. @param backgroundImage an image to draw on the component. The component's size
  70. will be set to the size of this image, and if the image is
  71. semi-transparent, the component will be made non-opaque
  72. @param useDropShadow if true, the window will have a drop shadow
  73. */
  74. SplashScreen (const String& title,
  75. const Image& backgroundImage,
  76. bool useDropShadow);
  77. /** Destructor. */
  78. ~SplashScreen();
  79. /** Tells the component to auto-delete itself after a timeout period, or when the
  80. mouse is clicked.
  81. You should call this after finishing your app's initialisation work.
  82. Note that although you could call deleteAfterDelay() as soon as you create the
  83. SplashScreen object, if you've got a long initialisation procedure, you probably
  84. don't want the splash to time-out and disappear before your initialisation has
  85. finished, which is why it makes sense to not call this method and start the
  86. self-delete timer until you're ready.
  87. It's safe to call this method from a non-GUI thread as long as there's no danger that
  88. the object may be being deleted at the same time.
  89. @param minimumTotalTimeToDisplayFor how long the splash screen should stay visible for.
  90. Note that this time is measured from the construction-time of this
  91. object, not from the time that the deleteAfterDelay() method is
  92. called, so if you call this method after a long initialisation
  93. period, it may be deleted without any further delay.
  94. @param removeOnMouseClick if true, the window will be deleted as soon as the user clicks
  95. the mouse (anywhere)
  96. */
  97. void deleteAfterDelay (RelativeTime minimumTotalTimeToDisplayFor,
  98. bool removeOnMouseClick);
  99. protected:
  100. //==============================================================================
  101. /** This constructor is for use by custom sub-classes that don't want to provide an image. */
  102. SplashScreen (const String& title, int width, int height, bool useDropShadow);
  103. /** @internal */
  104. void paint (Graphics&) override;
  105. private:
  106. //==============================================================================
  107. Image backgroundImage;
  108. Time creationTime;
  109. RelativeTime minimumVisibleTime;
  110. int clickCountToDelete;
  111. void timerCallback() override;
  112. void makeVisible (int w, int h, bool shadow, bool fullscreen);
  113. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SplashScreen)
  114. };