Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #pragma once
00025
00026 #include "cinder/Cinder.h"
00027 #include "cinder/gl/gl.h"
00028 #include "cinder/app/App.h"
00029
00030 #if defined( CINDER_MAC )
00031 #ifdef __OBJC__
00032 @class AppImplCocoaScreenSaver;
00033 @class NSWindow;
00034 #else
00035 class AppImplCocoaScreenSaver;
00036 class NSWindow;
00037 #endif
00038 #elif defined( CINDER_MSW )
00039 #include "cinder/app/AppImplMswScreenSaver.h"
00040 #include <windows.h>
00041 #undef min
00042 #undef max
00043 #include <ScrnSave.h>
00044 #endif
00045
00046
00047 namespace cinder { namespace app {
00048
00049 class AppScreenSaver : public App {
00050 public:
00051 class Settings : public App::Settings {
00052 public:
00053 Settings()
00054 : App::Settings(),
00055 #if defined( CINDER_MAC )
00056 mEnableSecondaryDisplayBlanking( false ),
00057 mProvidesMacConfigDialog( false ),
00058 #elif defined( CINDER_MSW )
00059 mEnableSecondaryDisplayBlanking( true ),
00060 #endif
00061 mEnableDebug( false )
00062 {}
00063
00065 void enableSecondaryDisplayBlanking( bool enable = true ) { mEnableSecondaryDisplayBlanking = enable; }
00067 bool isSecondaryDisplayBlankingEnabled() const { return mEnableSecondaryDisplayBlanking; }
00068
00069 #if defined( CINDER_MAC )
00070
00071 void setProvidesMacConfigDialog( bool provides = true ) { mProvidesMacConfigDialog = provides; }
00073 bool getProvidesMacConfigDialog() const { return mProvidesMacConfigDialog; }
00074 #endif
00075
00077 void enableDebug( bool enable = true ) { mEnableDebug = true; }
00078 bool isDebugEnabled() const { return mEnableDebug; }
00079
00080 protected:
00081 bool mEnableSecondaryDisplayBlanking;
00082 #if defined( CINDER_MAC )
00083 bool mProvidesMacConfigDialog;
00084 #endif
00085 bool mEnableDebug;
00086 };
00087
00088 void launch( const char *title, int argc, char * const argv[] ) { }
00089
00090 virtual void prepareSettings( Settings *settings ) {}
00091 const Settings& getSettings() const { return mSettings; }
00092
00094 virtual float getFrameRate() const;
00096 virtual void setFrameRate( float frameRate );
00097
00099 bool isPreview() const;
00100
00102 virtual void quit() {}
00103
00104 #if defined( CINDER_MAC )
00105
00106 virtual NSWindow* createMacConfigDialog() { return NULL; }
00107 #elif defined( CINDER_MSW )
00108
00109 static BOOL doConfigureDialog( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) {
00110 return FALSE;
00111 }
00112 #endif
00113
00114 virtual fs::path getAppPath() const;
00115 #if defined( CINDER_COCOA )
00116 virtual NSBundle* getBundle() const;
00117 #endif
00118
00119 virtual void launch( RendererRef defaultRenderer, const char *title, int argc, char * const argv[] ) {}
00120
00121 virtual size_t getNumWindows() const override;
00122 virtual WindowRef getWindow() const override;
00123 virtual WindowRef getWindowIndex( size_t index ) const override;
00124
00125 #if defined( CINDER_MAC )
00126 static void executeLaunch( AppScreenSaver *app, RendererRef renderer, const char *title );
00127 #elif defined( CINDER_MSW )
00128 static void executeLaunch( AppScreenSaver *app, RendererRef renderer, const char *title, ::HWND hwnd );
00129 #endif
00130
00131 #if defined( CINDER_MAC )
00132 void privateSetImpl__( void *impl ) { mImpl = reinterpret_cast<AppImplCocoaScreenSaver*>( impl ); }
00133 #elif defined( CINDER_MSW )
00134 void launch( ::HWND hwnd );
00135 virtual bool getsWindowsPaintEvents() { return false; }
00136 class AppImplMswScreenSaver* getImpl() { return mImpl; }
00137 #endif
00138
00139 virtual bool receivesEvents() const { return false; }
00140
00141 private:
00142 static AppScreenSaver *sInstance;
00143 #if defined( CINDER_MAC )
00144 AppImplCocoaScreenSaver *mImpl;
00145 #elif defined( CINDER_MSW )
00146 class AppImplMswScreenSaver *mImpl;
00147 #endif
00148 Settings mSettings;
00149 };
00150
00151 } }
00152
00153 #if defined( CINDER_MAC )
00154 extern "C" cinder::app::AppScreenSaver* ScreenSaverFactoryMethod( void *impl );
00155 #define CINDER_APP_SCREENSAVER( APP, RENDERER ) \
00156 extern "C" { \
00157 cinder::app::AppScreenSaver* ScreenSaverFactoryMethod( void *impl ) { \
00158 cinder::app::AppScreenSaver *app = new APP; \
00159 app->privateSetImpl__( impl ); \
00160 cinder::app::AppScreenSaver::executeLaunch( app, RendererRef( new RENDERER ), #APP ); \
00161 return app; \
00162 } \
00163 }
00164 #elif defined( CINDER_MSW )
00165 #define CINDER_APP_SCREENSAVER( APP, RENDERER ) \
00166 cinder::app::AppScreenSaver *sScreenSaverMswInstance = 0; \
00167 LRESULT CALLBACK ScreenSaverProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { \
00168 switch( message ) { \
00169 case WM_CREATE: \
00170 sScreenSaverMswInstance = new APP; \
00171 cinder::app::AppScreenSaver::executeLaunch( sScreenSaverMswInstance, RendererRef( new RENDERER ), #APP, hWnd ); return 0; break; \
00172 default: if( sScreenSaverMswInstance && sScreenSaverMswInstance->getImpl() ) return sScreenSaverMswInstance->getImpl()->eventHandler( hWnd, message, wParam, lParam ); \
00173 else return ::DefScreenSaverProc( hWnd, message, wParam, lParam ); \
00174 } \
00175 } \
00176 extern "C" BOOL CALLBACK ScreenSaverConfigureDialog( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { return APP::doConfigureDialog( hDlg, message, wParam, lParam ); } \
00177 extern "C" BOOL CALLBACK RegisterDialogClasses(HANDLE hInst) { return TRUE; }
00178 #endif