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/app/App.h"
00028 #include "cinder/Display.h"
00029 #include "cinder/Function.h"
00030
00031 #if defined( CINDER_MAC )
00032 #include <OpenGL/CGLTypes.h>
00033 #ifdef __OBJC__
00034 @class AppImplCocoaBasic;
00035 @class WindowImplBasicCocoa;
00036 #else
00037 class AppImplCocoaBasic;
00038 class WindowImplBasicCocoa;
00039 #endif
00040 #endif
00041
00042 #include "cinder/app/TouchEvent.h"
00043
00044 namespace cinder { namespace app {
00045
00046 typedef signals::signal<bool (),BooleanAndEventCombiner> EventSignalShouldQuit;
00047
00048 class AppBasic : public App {
00049 public:
00050 class Settings : public App::Settings {
00051 public:
00052 Settings();
00053
00054 void setShouldQuit ( bool aShouldQuit = true );
00055 bool isFullScreen() { return mDefaultWindowFormat.isFullScreen(); }
00056
00058 bool isResizable() const { return mDefaultWindowFormat.isResizable(); }
00060 void setResizable( bool resizable = true ) { mDefaultWindowFormat.setResizable( resizable ); }
00062 bool isBorderless() const { return mDefaultWindowFormat.isBorderless(); }
00064 void setBorderless( bool borderless = true ) { mDefaultWindowFormat.setBorderless( borderless ); }
00066 bool isAlwaysOnTop() const { return mDefaultWindowFormat.isAlwaysOnTop(); }
00068 void setAlwaysOnTop( bool alwaysOnTop = true ) { mDefaultWindowFormat.setAlwaysOnTop( alwaysOnTop ); }
00069
00071 DisplayRef getDisplay() const { return mDefaultWindowFormat.getDisplay(); }
00073 void setDisplay( DisplayRef display ) { mDefaultWindowFormat.setDisplay( display ); }
00074
00075 #if defined( CINDER_MSW )
00076
00077 void enableConsoleWindow( bool enable = true ) { mEnableMswConsole = enable; }
00079 bool isConsoleWindowEnabled() const { return mEnableMswConsole; }
00080 #endif
00081
00083 void enableQuitOnLastWindowClose( bool enable = true ) { mQuitOnLastWindowClose = enable; }
00085 bool isQuitOnLastWindowCloseEnabled() const { return mQuitOnLastWindowClose; }
00086
00087 private:
00088 bool mQuitOnLastWindowClose;
00089 #if defined( CINDER_MSW )
00090 bool mEnableMswConsole;
00091 #endif
00092 };
00093
00094
00095 typedef std::shared_ptr<Window> WindowRef;
00096
00097 public:
00098 AppBasic();
00099 virtual ~AppBasic();
00100
00101 virtual void prepareSettings( Settings *settings ) {}
00102
00104 EventSignalShouldQuit& getSignalShouldQuit() { return mSignalShouldQuit; }
00105
00107 WindowRef createWindow( const Window::Format &format = Window::Format() );
00108
00110 virtual float getFrameRate() const;
00112 virtual void setFrameRate( float frameRate );
00114 virtual void disableFrameRate();
00116 virtual bool isFrameRateEnabled() const;
00117
00119 void hideCursor();
00121 void showCursor();
00122
00123 const Settings& getSettings() const { return mSettings; }
00124
00125
00127 virtual void quit();
00128
00130 const std::vector<std::string>& getArgs() const { return mCommandLineArgs; }
00131
00133 virtual fs::path getAppPath() const;
00134
00136 virtual app::WindowRef getWindow() const;
00138 virtual size_t getNumWindows() const;
00140 virtual WindowRef getWindowIndex( size_t index ) const;
00142 virtual WindowRef getForegroundWindow() const;
00143
00144
00146
00147 #if defined( CINDER_MAC )
00148 void privateSetImpl__( AppImplCocoaBasic *aImpl );
00149 #endif
00150 bool privateShouldQuit();
00151
00152 #if defined( CINDER_MSW )
00153 virtual bool getsWindowsPaintEvents() { return true; }
00154 #endif
00155
00156
00158 static AppBasic* get() { return sInstance; }
00159
00161
00162 static void prepareLaunch() { App::prepareLaunch(); }
00163 #if defined( CINDER_MSW )
00164 static void executeLaunch( AppBasic *app, RendererRef renderer, const char *title );
00165 #elif defined( CINDER_MAC )
00166 static void executeLaunch( AppBasic *app, RendererRef renderer, const char *title, int argc, char * const argv[] ) { App::sInstance = sInstance = app; App::executeLaunch( app, renderer, title, argc, argv ); }
00167 #endif
00168 static void cleanupLaunch() { App::cleanupLaunch(); }
00169
00170 virtual void launch( const char *title, int argc, char * const argv[] );
00172
00173 protected:
00174 static AppBasic* sInstance;
00175
00176 EventSignalShouldQuit mSignalShouldQuit;
00177
00178 #if defined( CINDER_MAC )
00179 AppImplCocoaBasic *mImpl;
00180 #elif defined( CINDER_MSW )
00181 class AppImplMswBasic *mImpl;
00182 friend class AppImplMswBasic;
00183 #endif
00184
00185 std::vector<std::string> mCommandLineArgs;
00186
00187 Settings mSettings;
00188 };
00189
00190 } }
00191
00192
00193
00194 #if defined( CINDER_MAC )
00195 #define CINDER_APP_BASIC( APP, RENDERER ) \
00196 int main( int argc, char * const argv[] ) { \
00197 cinder::app::AppBasic::prepareLaunch(); \
00198 cinder::app::AppBasic *app = new APP; \
00199 cinder::app::RendererRef ren( new RENDERER ); \
00200 cinder::app::AppBasic::executeLaunch( app, ren, #APP, argc, argv ); \
00201 cinder::app::AppBasic::cleanupLaunch(); \
00202 return 0; \
00203 }
00204 #elif defined( CINDER_MSW )
00205 #define CINDER_APP_BASIC( APP, RENDERER ) \
00206 int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { \
00207 cinder::app::AppBasic::prepareLaunch(); \
00208 cinder::app::AppBasic *app = new APP; \
00209 cinder::app::RendererRef ren( new RENDERER ); \
00210 cinder::app::AppBasic::executeLaunch( app, ren, #APP ); \
00211 cinder::app::AppBasic::cleanupLaunch(); \
00212 return 0; \
00213 }
00214 #endif