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.

107 lines
3.5KB

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