include/cinder/app/AppScreenSaver.h
Go to the documentation of this file.
00001 /*
00002  Copyright (c) 2010, The Barbarian Group
00003  All rights reserved.
00004 
00005  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
00006  the following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and
00009     the following disclaimer.
00010     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
00011     the following disclaimer in the documentation and/or other materials provided with the distribution.
00012 
00013  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
00014  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00015  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00016  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00017  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00018  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00019  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00020  POSSIBILITY OF SUCH DAMAGE.
00021 */
00022 
00023 #pragma once
00024 
00025 #include "cinder/Cinder.h"
00026 #include "cinder/gl/gl.h"
00027 #include "cinder/app/App.h"
00028 
00029 #if defined( CINDER_MAC )
00030     #ifdef __OBJC__
00031         @class AppImplCocoaScreenSaver;
00032     #else
00033         class AppImplCocoaScreenSaver;
00034     #endif
00035 #elif defined( CINDER_MSW )
00036     #include "cinder/app/AppImplMswScreenSaver.h"
00037     #include <windows.h>
00038     #undef min
00039     #undef max
00040     #include <ScrnSave.h>
00041 #endif
00042 
00043 
00044 namespace cinder { namespace app {
00045 
00046 class AppScreenSaver : public App {
00047  public:
00048     class Settings : public App::Settings {
00049       public:
00050         Settings() : App::Settings() {}
00051     };
00052 
00053     void    launch( const char *title, int argc, char * const argv[] ) { /* do nothing - this gets handled a weirder way for screensavers */ }
00054 
00055     virtual void        prepareSettings( Settings *settings ) {}
00056     const Settings&     getSettings() const { return mSettings; }
00057 
00059     virtual int     getWindowWidth() const;
00061     void            setWindowWidth( int windowWidth ) {}
00063     virtual int     getWindowHeight() const;
00065     void            setWindowHeight( int windowHeight ) {}
00067     void            setWindowSize( int windowWidth, int windowHeight ) {}
00068 
00070     virtual float       getFrameRate() const;
00072     virtual void        setFrameRate( float frameRate );
00074     virtual bool        isFullScreen() const;
00076     virtual void        setFullScreen( bool fullScreen ) {}
00077 
00079     virtual void            quit() {}
00080 
00081     virtual fs::path        getAppPath();
00082 
00083 #if defined( CINDER_MAC )
00084     static void executeLaunch( AppScreenSaver *app, class Renderer *renderer, const char *title ) { sInstance = app; App::executeLaunch( app, renderer, title, 0, 0 ); }
00085 #elif defined( CINDER_MSW )
00086     static void executeLaunch( AppScreenSaver *app, class Renderer *renderer, const char *title, ::HWND hwnd );
00087 #endif
00088 
00089 #if defined( CINDER_MAC )
00090     void            privateSetImpl__( void *impl ) { mImpl = reinterpret_cast<AppImplCocoaScreenSaver*>( impl ); }
00091 #elif defined( CINDER_MSW )
00092     void                            launch( ::HWND hwnd );
00093     virtual bool                    getsWindowsPaintEvents() { return false; }
00094     class AppImplMswScreenSaver*    getImpl() { return mImpl; }
00095 #endif
00096 
00097     virtual bool        receivesEvents() const { return false; }
00098 
00099  private:
00100     static AppScreenSaver       *sInstance;
00101 #if defined( CINDER_MAC )
00102     AppImplCocoaScreenSaver     *mImpl;
00103 #elif defined( CINDER_MSW )
00104     class AppImplMswScreenSaver *mImpl;
00105 #endif
00106     Settings            mSettings;
00107 };
00108 
00109 } } // namespace cinder::app
00110 
00111 #if defined( CINDER_MAC )
00112     extern "C" cinder::app::AppScreenSaver* ScreenSaverFactoryMethod( void *impl );
00113     #define CINDER_APP_SCREENSAVER( APP, RENDERER ) \
00114         extern "C" { \
00115         cinder::app::AppScreenSaver* ScreenSaverFactoryMethod( void *impl ) { \
00116             cinder::app::AppScreenSaver *app = new APP; \
00117             app->privateSetImpl__( impl ); \
00118             cinder::app::AppScreenSaver::executeLaunch( app, new RENDERER, #APP );  \
00119             return app; \
00120             } \
00121         }
00122 #elif defined( CINDER_MSW )
00123     #define CINDER_APP_SCREENSAVER( APP, RENDERER ) \
00124         cinder::app::AppScreenSaver *sScreenSaverMswInstance; \
00125         extern "C" LRESULT WINAPI ScreenSaverProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { \
00126             switch( message ) { \
00127                 case WM_CREATE: \
00128                     sScreenSaverMswInstance = new APP; \
00129                     cinder::app::AppScreenSaver::executeLaunch( sScreenSaverMswInstance, new RENDERER, #APP, hWnd ); return 0; break; \
00130                 default: if( sScreenSaverMswInstance ) return sScreenSaverMswInstance->getImpl()->eventHandler( hWnd, message, wParam, lParam ); \
00131                 else return DefScreenSaverProc( hWnd, message, wParam, lParam ); \
00132             } \
00133         } \
00134         extern "C" BOOL WINAPI ScreenSaverConfigureDialog( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { return FALSE; } \
00135         extern "C" BOOL WINAPI RegisterDialogClasses(HANDLE hInst) { return TRUE; }
00136 #endif