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.

112 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. BEGIN_JUCE_NAMESPACE
  19. //==============================================================================
  20. SplashScreen::SplashScreen()
  21. {
  22. setOpaque (true);
  23. }
  24. SplashScreen::~SplashScreen()
  25. {
  26. }
  27. //==============================================================================
  28. void SplashScreen::show (const String& title,
  29. const Image& backgroundImage_,
  30. const int minimumTimeToDisplayFor,
  31. const bool useDropShadow,
  32. const bool removeOnMouseClick)
  33. {
  34. backgroundImage = backgroundImage_;
  35. jassert (backgroundImage_.isValid());
  36. if (backgroundImage_.isValid())
  37. {
  38. setOpaque (! backgroundImage_.hasAlphaChannel());
  39. show (title,
  40. backgroundImage_.getWidth(),
  41. backgroundImage_.getHeight(),
  42. minimumTimeToDisplayFor,
  43. useDropShadow,
  44. removeOnMouseClick);
  45. }
  46. }
  47. void SplashScreen::show (const String& title,
  48. const int width,
  49. const int height,
  50. const int minimumTimeToDisplayFor,
  51. const bool useDropShadow,
  52. const bool removeOnMouseClick)
  53. {
  54. setName (title);
  55. setAlwaysOnTop (true);
  56. setVisible (true);
  57. centreWithSize (width, height);
  58. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  59. toFront (false);
  60. #if JUCE_MODAL_LOOPS_PERMITTED
  61. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62. #endif
  63. repaint();
  64. originalClickCounter = removeOnMouseClick
  65. ? Desktop::getMouseButtonClickCounter()
  66. : std::numeric_limits<int>::max();
  67. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  68. startTimer (50);
  69. }
  70. //==============================================================================
  71. void SplashScreen::paint (Graphics& g)
  72. {
  73. g.setOpacity (1.0f);
  74. g.drawImage (backgroundImage,
  75. 0, 0, getWidth(), getHeight(),
  76. 0, 0, backgroundImage.getWidth(), backgroundImage.getHeight());
  77. }
  78. void SplashScreen::timerCallback()
  79. {
  80. if (Time::getCurrentTime() > earliestTimeToDelete
  81. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  82. {
  83. delete this;
  84. }
  85. }
  86. END_JUCE_NAMESPACE