# Cinder

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

# 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     #include <ScrnSave.h>
    00039 #endif
    00040
    00041
    00042 namespace cinder { namespace app {
    00043
    00044 class AppScreenSaver : public App {
    00045  public:
    00046     class Settings : public App::Settings {
    00047       public:
    00048         Settings() : App::Settings() {}
    00049     };
    00050
    00051     void    launch( const char *title, int argc, char * const argv[] ) { /* do nothing - this gets handled a weirder way for screensavers */ }
    00052
    00053     virtual void        prepareSettings( Settings *settings ) {}
    00054     const Settings&     getSettings() const { return mSettings; }
    00055
    00057     virtual int     getWindowWidth() const;
    00059     void            setWindowWidth( int windowWidth ) {}
    00061     virtual int     getWindowHeight() const;
    00063     void            setWindowHeight( int windowHeight ) {}
    00065     void            setWindowSize( int windowWidth, int windowHeight ) {}
    00066
    00068     virtual float       getFrameRate() const;
    00070     virtual void        setFrameRate( float frameRate );
    00072     virtual bool        isFullScreen() const;
    00074     virtual void        setFullScreen( bool fullScreen ) {}
    00075
    00077     virtual void            quit() {}
    00078
    00079     virtual std::string     getAppPath();
    00080
    00081 #if defined( CINDER_MAC )
    00082     static void executeLaunch( AppScreenSaver *app, class Renderer *renderer, const char *title ) { sInstance = app; App::executeLaunch( app, renderer, title, 0, 0 ); }
    00083 #elif defined( CINDER_MSW )
    00084     static void executeLaunch( AppScreenSaver *app, class Renderer *renderer, const char *title, ::HWND hwnd );
    00085 #endif
    00086
    00087 #if defined( CINDER_MAC )
    00088     void            privateSetImpl__( void *impl ) { mImpl = reinterpret_cast<AppImplCocoaScreenSaver*>( impl ); }
    00089 #elif defined( CINDER_MSW )
    00090     void                            launch( ::HWND hwnd );
    00091     virtual bool                    getsWindowsPaintEvents() { return false; }
    00092     class AppImplMswScreenSaver*    getImpl() { return mImpl; }
    00093 #endif
    00094
    00095     virtual bool        receivesEvents() const { return false; }
    00096
    00097  private:
    00098     static AppScreenSaver       *sInstance;
    00099 #if defined( CINDER_MAC )
    00100     AppImplCocoaScreenSaver     *mImpl;
    00101 #elif defined( CINDER_MSW )
    00102     class AppImplMswScreenSaver *mImpl;
    00103 #endif
    00104     Settings            mSettings;
    00105 };
    00106
    00107 } } // namespace cinder::app
    00108
    00109 #if defined( CINDER_MAC )
    00110     extern "C" cinder::app::AppScreenSaver* ScreenSaverFactoryMethod( void *impl );
    00111     #define CINDER_APP_SCREENSAVER( APP, RENDERER ) \
    00112         extern "C" { \
    00113         cinder::app::AppScreenSaver* ScreenSaverFactoryMethod( void *impl ) { \
    00114             cinder::app::AppScreenSaver *app = new APP; \
    00115             app->privateSetImpl__( impl ); \
    00116             cinder::app::AppScreenSaver::executeLaunch( app, new RENDERER, #APP );  \
    00117             return app; \
    00118             } \
    00119         }
    00120 #elif defined( CINDER_MSW )
    00121     #define CINDER_APP_SCREENSAVER( APP, RENDERER ) \
    00122         cinder::app::AppScreenSaver *sScreenSaverMswInstance; \
    00123         extern "C" LRESULT WINAPI ScreenSaverProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { \
    00124             switch( message ) { \
    00125                 case WM_CREATE: \
    00126                     sScreenSaverMswInstance = new APP; \
    00127                     cinder::app::AppScreenSaver::executeLaunch( sScreenSaverMswInstance, new RENDERER, #APP, hWnd ); return 0; break; \
    00128                 default: if( sScreenSaverMswInstance ) return sScreenSaverMswInstance->getImpl()->eventHandler( hWnd, message, wParam, lParam ); \
    00129                 else return DefScreenSaverProc( hWnd, message, wParam, lParam ); \
    00130             } \
    00131         } \
    00132         extern "C" BOOL WINAPI ScreenSaverConfigureDialog( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { return FALSE; } \
    00133         extern "C" BOOL WINAPI RegisterDialogClasses(HANDLE hInst) { return TRUE; }
    00134 #endif