Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AppScreenSaver.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012, The Cinder Project, All rights reserved.
3 
4  This code is intended for use with the Cinder C++ library: http://libcinder.org
5 
6  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
7  the following conditions are met:
8 
9  * Redistributions of source code must retain the above copyright notice, this list of conditions and
10  the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12  the following disclaimer in the documentation and/or other materials provided with the distribution.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
15  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
16  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
17  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
18  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21  POSSIBILITY OF SUCH DAMAGE.
22 */
23 
24 #pragma once
25 
26 #include "cinder/Cinder.h"
27 #include "cinder/gl/gl.h"
28 #include "cinder/app/App.h"
29 
30 #if defined( CINDER_MAC )
31  #ifdef __OBJC__
33  @class NSWindow;
34  #else
36  class NSWindow;
37  #endif
38 #elif defined( CINDER_MSW )
40  #include <windows.h>
41  #undef min
42  #undef max
43  #include <ScrnSave.h>
44 #endif
45 
46 
47 namespace cinder { namespace app {
48 
49 class AppScreenSaver : public App {
50  public:
51  class Settings : public App::Settings {
52  public:
54  : App::Settings(),
55 #if defined( CINDER_MAC )
57  mProvidesMacConfigDialog( false ),
58 #elif defined( CINDER_MSW )
60 #endif
61  mEnableDebug( false )
62  {}
63 
68 
69 #if defined( CINDER_MAC )
70  void setProvidesMacConfigDialog( bool provides = true ) { mProvidesMacConfigDialog = provides; }
73  bool getProvidesMacConfigDialog() const { return mProvidesMacConfigDialog; }
74 #endif
75 
77  void enableDebug( bool enable = true ) { mEnableDebug = true; }
78  bool isDebugEnabled() const { return mEnableDebug; }
79 
80  protected:
82 #if defined( CINDER_MAC )
83  bool mProvidesMacConfigDialog;
84 #endif
86  };
87 
88  void launch( const char *title, int argc, char * const argv[] ) { /* do nothing - this gets handled a weirder way for screensavers */ }
89 
90  virtual void prepareSettings( Settings *settings ) {}
91  const Settings& getSettings() const { return mSettings; }
92 
94  virtual float getFrameRate() const;
96  virtual void setFrameRate( float frameRate );
97 
99  bool isPreview() const;
100 
102  virtual void quit() {}
103 
104 #if defined( CINDER_MAC )
105  virtual NSWindow* createMacConfigDialog() { return NULL; }
107 #elif defined( CINDER_MSW )
108  static BOOL doConfigureDialog( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) {
110  return FALSE;
111  }
112 #endif
113 
114  virtual fs::path getAppPath() const;
115 #if defined( CINDER_COCOA )
116  virtual NSBundle* getBundle() const;
117 #endif
118 
119  virtual void launch( RendererRef defaultRenderer, const char *title, int argc, char * const argv[] ) {}
120 
121  virtual size_t getNumWindows() const override;
122  virtual WindowRef getWindow() const override;
123  virtual WindowRef getWindowIndex( size_t index ) const override;
124 
125 #if defined( CINDER_MAC )
126  static void executeLaunch( AppScreenSaver *app, RendererRef renderer, const char *title );
127 #elif defined( CINDER_MSW )
128  static void executeLaunch( AppScreenSaver *app, RendererRef renderer, const char *title, ::HWND hwnd );
129 #endif
130 
131 #if defined( CINDER_MAC )
132  void privateSetImpl__( void *impl ) { mImpl = reinterpret_cast<AppImplCocoaScreenSaver*>( impl ); }
133 #elif defined( CINDER_MSW )
134  void launch( ::HWND hwnd );
135  virtual bool getsWindowsPaintEvents() { return false; }
136  class AppImplMswScreenSaver* getImpl() { return mImpl; }
137 #endif
138 
139  virtual bool receivesEvents() const { return false; }
140 
141  private:
142  static AppScreenSaver *sInstance;
143 #if defined( CINDER_MAC )
145 #elif defined( CINDER_MSW )
146  class AppImplMswScreenSaver *mImpl;
147 #endif
148  Settings mSettings;
149 };
150 
151 } } // namespace cinder::app
152 
153 #if defined( CINDER_MAC )
154  extern "C" cinder::app::AppScreenSaver* ScreenSaverFactoryMethod( void *impl );
155  #define CINDER_APP_SCREENSAVER( APP, RENDERER ) \
156  extern "C" { \
157  cinder::app::AppScreenSaver* ScreenSaverFactoryMethod( void *impl ) { \
158  cinder::app::AppScreenSaver *app = new APP; \
159  app->privateSetImpl__( impl ); \
160  cinder::app::AppScreenSaver::executeLaunch( app, RendererRef( new RENDERER ), #APP ); \
161  return app; \
162  } \
163  }
164 #elif defined( CINDER_MSW )
165  #define CINDER_APP_SCREENSAVER( APP, RENDERER ) \
166  cinder::app::AppScreenSaver *sScreenSaverMswInstance = 0; \
167  LRESULT CALLBACK ScreenSaverProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { \
168  switch( message ) { \
169  case WM_CREATE: \
170  sScreenSaverMswInstance = new APP; \
171  cinder::app::AppScreenSaver::executeLaunch( sScreenSaverMswInstance, RendererRef( new RENDERER ), #APP, hWnd ); return 0; break; \
172  default: if( sScreenSaverMswInstance && sScreenSaverMswInstance->getImpl() ) return sScreenSaverMswInstance->getImpl()->eventHandler( hWnd, message, wParam, lParam ); \
173  else return ::DefScreenSaverProc( hWnd, message, wParam, lParam ); \
174  } \
175  } \
176  extern "C" BOOL CALLBACK ScreenSaverConfigureDialog( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { return APP::doConfigureDialog( hDlg, message, wParam, lParam ); } \
177  extern "C" BOOL CALLBACK RegisterDialogClasses(HANDLE hInst) { return TRUE; }
178 #endif
Definition: AppImplMswScreenSaver.h:37
Settings()
Definition: AppScreenSaver.h:53
void enable(GLenum state)
Enables the OpenGL State state. Equivalent to calling to glEnable( state );.
Definition: dx.h:198
bool mEnableSecondaryDisplayBlanking
Definition: AppScreenSaver.h:81
const Settings & getSettings() const
Definition: AppScreenSaver.h:91
bool isSecondaryDisplayBlankingEnabled() const
Returns whether secondary displays will be blanked (rendered as black) rather than issued draw() call...
Definition: AppScreenSaver.h:67
Definition: AppScreenSaver.h:51
Definition: App.h:129
GLuint index
Definition: GLee.h:2259
Definition: AppImplCocoaScreenSaver.h:37
void enableDebug(bool enable=true)
Prevents the screensaver from quitting in response to anything but clicks in its window, and from being the top-most window. Currenty ignored on Mac.
Definition: AppScreenSaver.h:77
std::shared_ptr< Window > WindowRef
Definition: Event.h:49
virtual size_t getNumWindows() const override
Returns the number of Windows the app has open.
Definition: AppScreenSaver.cpp:113
bool mEnableDebug
Definition: AppScreenSaver.h:85
bool isDebugEnabled() const
Definition: AppScreenSaver.h:78
Definition: App.h:127
void enableSecondaryDisplayBlanking(bool enable=true)
When enabled, secondary displays are blanked (rendered as black) rather than issued draw() calls...
Definition: AppScreenSaver.h:65
virtual WindowRef getWindowIndex(size_t index) const override
Gets a Window by index, in the range [0, getNumWindows()). Throw ExcInvalidWindow if index is out of ...
Definition: AppScreenSaver.cpp:131
virtual void setFrameRate(float frameRate)
Sets the maximum frame-rate the App will attempt to maintain.
Definition: AppScreenSaver.cpp:79
virtual bool receivesEvents() const
Definition: AppScreenSaver.h:139
virtual void prepareSettings(Settings *settings)
Definition: AppScreenSaver.h:90
std::shared_ptr< class Renderer > RendererRef
Definition: Renderer.h:85
virtual float getFrameRate() const
Returns the maximum frame-rate the App will attempt to maintain.
Definition: AppScreenSaver.cpp:70
bool isPreview() const
Returns whether the ScreenSaver is running in preview mode or not.
Definition: AppScreenSaver.cpp:88
virtual void launch(RendererRef defaultRenderer, const char *title, int argc, char *const argv[])
Definition: AppScreenSaver.h:119
virtual WindowRef getWindow() const override
Returns the the currently active Window. Throws ExcInvalidWindow if called with no active window...
Definition: AppScreenSaver.cpp:122
Definition: AppScreenSaver.h:49
virtual fs::path getAppPath() const
Returns the path to the application on disk.
Definition: AppScreenSaver.cpp:97
void launch(const char *title, int argc, char *const argv[])
Definition: AppScreenSaver.h:88
virtual void quit()
Ignored for ScreenSavers.
Definition: AppScreenSaver.h:102