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.

150 lines
6.4KB

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