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.

154 lines
6.7KB

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