include/GUI/FadingSplashScreen.hpp

Go to the documentation of this file.
00001 #ifndef hpp_FadingSplashScreen_hpp
00002 #define hpp_FadingSplashScreen_hpp
00003 
00004 // We need base stuff
00005 #include "UZIBase.hpp"
00006 
00012 class FadingSplashScreen : public juce::ResizableWindow, public juce::Timer
00013 {
00014     // Members
00015 private:
00017     juce::Image*            splashImage;
00019     juce::Time              fadeOutStart;
00021     juce::Time              fadeOutStop;
00023     juce::DocumentWindow *  mainWindow;
00024 
00025     // Construction
00026 public:
00028     FadingSplashScreen(juce::DocumentWindow * main) : juce::ResizableWindow(JUCE_T("Splash"), juce::Colours::white, false), mainWindow(main)
00029     {
00030         setDropShadowEnabled(false);
00031         setOpaque(true);
00032         setBackgroundColour(juce::Colours::white.withAlpha(0.f));
00033         addToDesktop(0);
00034     }
00036     ~FadingSplashScreen()
00037     {
00038         if(splashImage)
00039             juce::ImageCache::release(splashImage);
00040         if (mainWindow)
00041             mainWindow->setVisible(true);
00042     }
00043 
00044     // Interface
00045 public:
00047     inline int getDesktopWindowStyleFlags() const { return 0; }
00048 
00050     void showSplash(int startMillis, int stopMillis, juce::Image * image)
00051     {
00052         splashImage = image;
00053         if (splashImage)
00054         {
00055             setAlwaysOnTop(true);
00056             setVisible(true);
00057             centreWithSize(splashImage->getWidth(), splashImage->getHeight());
00058             setOpaque (!image->hasAlphaChannel());
00059             addToDesktop (0);
00060             toFront (false);
00061             //juce::MessageManager::getInstance()->dispatchPendingMessages();
00062             repaint();
00063             
00064             if (startMillis < stopMillis)
00065             {
00066                 fadeOutStart = juce::Time::getCurrentTime() + juce::RelativeTime(startMillis/1000.f);
00067                 fadeOutStop = juce::Time::getCurrentTime() + juce::RelativeTime(stopMillis/1000.f);
00068                 startTimer((stopMillis - startMillis) / 10);
00069             }
00070 
00071         }
00072     }
00073 
00075     void timerCallback()
00076     {
00077         if (juce::Time::getCurrentTime() > fadeOutStart)
00078         {
00079             if (splashImage)
00080             {
00081                 splashImage->multiplyAllAlphas(.9f);
00082                 repaint();         
00083             }
00084         }
00085         if (juce::Time::getCurrentTime() > fadeOutStop)
00086         {
00087             stopTimer();
00088             delete this;
00089         }
00090     }
00091 
00093     void paint(juce::Graphics& g)
00094     {
00095         if (splashImage)
00096         {
00097             g.drawImageAt(splashImage, 0, 0);
00098         }
00099     }
00100 };
00101 
00102 #endif

(C) An X-Ryl669 project 2007

This document describes Unlimited Zooming Interface source code. UZI stands for Unlimited Zooming Interface, and source code license is