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.

106 lines
3.3KB

  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()
  18. {
  19. setOpaque (true);
  20. }
  21. SplashScreen::~SplashScreen()
  22. {
  23. }
  24. //==============================================================================
  25. void SplashScreen::show (const String& title,
  26. const Image& backgroundImage_,
  27. const int minimumTimeToDisplayFor,
  28. const bool useDropShadow,
  29. const bool removeOnMouseClick)
  30. {
  31. backgroundImage = backgroundImage_;
  32. jassert (backgroundImage_.isValid());
  33. if (backgroundImage_.isValid())
  34. {
  35. setOpaque (! backgroundImage_.hasAlphaChannel());
  36. show (title,
  37. backgroundImage_.getWidth(),
  38. backgroundImage_.getHeight(),
  39. minimumTimeToDisplayFor,
  40. useDropShadow,
  41. removeOnMouseClick);
  42. }
  43. }
  44. void SplashScreen::show (const String& title,
  45. const int width,
  46. const int height,
  47. const int minimumTimeToDisplayFor,
  48. const bool useDropShadow,
  49. const bool removeOnMouseClick)
  50. {
  51. setName (title);
  52. setAlwaysOnTop (true);
  53. setVisible (true);
  54. centreWithSize (width, height);
  55. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  56. toFront (false);
  57. #if JUCE_MODAL_LOOPS_PERMITTED
  58. MessageManager::getInstance()->runDispatchLoopUntil (300);
  59. #endif
  60. repaint();
  61. originalClickCounter = removeOnMouseClick
  62. ? Desktop::getInstance().getMouseButtonClickCounter()
  63. : std::numeric_limits<int>::max();
  64. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  65. startTimer (50);
  66. }
  67. //==============================================================================
  68. void SplashScreen::paint (Graphics& g)
  69. {
  70. g.setOpacity (1.0f);
  71. g.drawImage (backgroundImage,
  72. 0, 0, getWidth(), getHeight(),
  73. 0, 0, backgroundImage.getWidth(), backgroundImage.getHeight());
  74. }
  75. void SplashScreen::timerCallback()
  76. {
  77. if (Time::getCurrentTime() > earliestTimeToDelete
  78. || Desktop::getInstance().getMouseButtonClickCounter() != originalClickCounter)
  79. {
  80. delete this;
  81. }
  82. }