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.

156 lines
6.8KB

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