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.

juce_SplashScreen.cpp 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. SplashScreen::SplashScreen (const String& title, const Image& image, bool useDropShadow)
  18. : Component (title),
  19. backgroundImage (image),
  20. clickCountToDelete (0)
  21. {
  22. // You must supply a valid image here!
  23. jassert (backgroundImage.isValid());
  24. setOpaque (! backgroundImage.hasAlphaChannel());
  25. makeVisible (image.getWidth(), image.getHeight(), useDropShadow);
  26. }
  27. SplashScreen::SplashScreen (const String& title, int width, int height, bool useDropShadow)
  28. : Component (title),
  29. clickCountToDelete (0)
  30. {
  31. makeVisible (width, height, useDropShadow);
  32. }
  33. void SplashScreen::makeVisible (int w, int h, bool useDropShadow)
  34. {
  35. clickCountToDelete = Desktop::getInstance().getMouseButtonClickCounter();
  36. creationTime = Time::getCurrentTime();
  37. setAlwaysOnTop (true);
  38. setVisible (true);
  39. centreWithSize (w, h);
  40. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  41. toFront (false);
  42. }
  43. SplashScreen::~SplashScreen() {}
  44. void SplashScreen::deleteAfterDelay (RelativeTime timeout, bool removeOnMouseClick)
  45. {
  46. // Note that this method must be safe to call from non-GUI threads
  47. if (! removeOnMouseClick)
  48. clickCountToDelete = std::numeric_limits<int>::max();
  49. minimumVisibleTime = timeout;
  50. startTimer (50);
  51. }
  52. void SplashScreen::paint (Graphics& g)
  53. {
  54. g.setOpacity (1.0f);
  55. g.drawImage (backgroundImage,
  56. 0, 0, getWidth(), getHeight(),
  57. 0, 0, backgroundImage.getWidth(), backgroundImage.getHeight());
  58. }
  59. void SplashScreen::timerCallback()
  60. {
  61. if (Time::getCurrentTime() > creationTime + minimumVisibleTime
  62. || Desktop::getInstance().getMouseButtonClickCounter() > clickCountToDelete)
  63. delete this;
  64. }