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 #pragma once
00024
00025 #include "cinder/app/App.h"
00026 #include "cinder/Display.h"
00027 #include "cinder/Function.h"
00028
00029 #if defined( CINDER_MAC )
00030 #include <OpenGL/CGLTypes.h>
00031 #ifdef __OBJC__
00032 @class AppImplCocoaBasic;
00033 #else
00034 class AppImplCocoaBasic;
00035 #endif
00036 #endif
00037
00038 #include "cinder/app/TouchEvent.h"
00039
00040 namespace cinder { namespace app {
00041
00042 class AppBasic : public App {
00043 public:
00044 class Settings : public App::Settings {
00045 public:
00046 Settings();
00047
00048 void setShouldQuit ( bool aShouldQuit = true );
00049 void setFullScreen( bool aFullScreen = true );
00050 void setResizable( bool aResizable = true );
00051
00053 Display* getDisplay() const { return mDisplay; }
00054 void setDisplay( std::shared_ptr<Display> aDisplay );
00055
00056 #if defined( CINDER_MAC )
00057
00058 void enableSecondaryDisplayBlanking( bool enable = false ) { mEnableSecondaryDisplayBlanking = enable; }
00060 bool isSecondaryDisplayBlankingEnabled() const { return mEnableSecondaryDisplayBlanking; }
00061 #endif
00062
00064 void enableMultiTouch( bool enable = true ) { mEnableMultiTouch = enable; }
00066 bool isMultiTouchEnabled() const { return mEnableMultiTouch; }
00067
00068 private:
00069 bool mEnableMultiTouch;
00070 #if defined( CINDER_MAC )
00071 bool mEnableSecondaryDisplayBlanking;
00072 #endif
00073 Display *mDisplay;
00074 };
00075
00076 public:
00077 AppBasic();
00078 virtual ~AppBasic();
00079
00080 virtual void prepareSettings( Settings *settings ) {}
00081
00083 virtual void touchesBegan( TouchEvent event ) {}
00085 virtual void touchesMoved( TouchEvent event ) {}
00087 virtual void touchesEnded( TouchEvent event ) {}
00089 const std::vector<TouchEvent::Touch>& getActiveTouches() const { return mActiveTouches; }
00090
00092 CallbackId registerTouchesBegan( std::function<bool (TouchEvent)> callback ) { return mCallbacksTouchesBegan.registerCb( callback ); }
00094 template<typename T>
00095 CallbackId registerTouchesBegan( T *obj, bool (T::*callback)(TouchEvent) ) { return mCallbacksTouchesBegan.registerCb( std::bind1st( std::mem_fun( callback ), obj ) ); }
00097 void unregisterTouchesBegan( CallbackId id ) { mCallbacksTouchesBegan.unregisterCb( id ); }
00098
00100 CallbackId registerTouchesMoved( std::function<bool (TouchEvent)> callback ) { return mCallbacksTouchesMoved.registerCb( callback ); }
00102 template<typename T>
00103 CallbackId registerTouchesMoved( T *obj, bool (T::*callback)(TouchEvent) ) { return mCallbacksTouchesMoved.registerCb( std::bind1st( std::mem_fun( callback ), obj ) ); }
00105 void unregisterTouchesMoved( CallbackId id ) { mCallbacksTouchesMoved.unregisterCb( id ); }
00106
00108 CallbackId registerTouchesEnded( std::function<bool (TouchEvent)> callback ) { return mCallbacksTouchesEnded.registerCb( callback ); }
00110 template<typename T>
00111 CallbackId registerTouchesEnded( T *obj, bool (T::*callback)(TouchEvent) ) { return mCallbacksTouchesEnded.registerCb( std::bind1st( std::mem_fun( callback ), obj ) ); }
00113 void unregisterTouchesEnded( CallbackId id ) { mCallbacksTouchesEnded.unregisterCb( id ); }
00114
00115
00117 virtual int getWindowWidth() const;
00119 void setWindowWidth( int windowWidth );
00121 virtual int getWindowHeight() const;
00123 void setWindowHeight( int windowHeight );
00125 void setWindowSize( int windowWidth, int windowHeight );
00126
00128 virtual Vec2i getWindowPos() const;
00129
00130 using App::setWindowPos;
00132 virtual void setWindowPos( const Vec2i &windowPos );
00133
00135 virtual float getFrameRate() const;
00137 virtual void setFrameRate( float frameRate );
00139 virtual bool isFullScreen() const;
00141 virtual void setFullScreen( bool fullScreen );
00142
00144 virtual bool isBorderless() const;
00146 virtual void setBorderless( bool borderless = true );
00148 virtual bool isAlwaysOnTop() const;
00150 virtual void setAlwaysOnTop( bool alwaysOnTop = true );
00151
00152
00154 Vec2i getMousePos() const;
00156 void hideCursor();
00158 void showCursor();
00159
00160 const Settings& getSettings() const { return mSettings; }
00161 const Display& getDisplay();
00162
00164 virtual void quit();
00165
00167 const std::vector<std::string>& getArgs() const { return mCommandLineArgs; }
00168
00170 virtual fs::path getAppPath();
00171
00172
00174
00175 #if defined( CINDER_MAC )
00176 void privateSetImpl__( AppImplCocoaBasic *aImpl );
00177 #endif
00178 void privateTouchesBegan__( const TouchEvent &event );
00179 void privateTouchesMoved__( const TouchEvent &event );
00180 void privateTouchesEnded__( const TouchEvent &event );
00181 void privateSetActiveTouches__( const std::vector<TouchEvent::Touch> &touches ) { mActiveTouches = touches; }
00182
00183 #if defined( CINDER_MSW )
00184 virtual bool getsWindowsPaintEvents() { return true; }
00185 #endif
00186
00187
00189 static AppBasic* get() { return sInstance; }
00190
00192
00193 static void prepareLaunch() { App::prepareLaunch(); }
00194 #if defined( CINDER_MSW )
00195 static void executeLaunch( AppBasic *app, class Renderer *renderer, const char *title );
00196 #elif defined( CINDER_MAC )
00197 static void executeLaunch( AppBasic *app, class Renderer *renderer, const char *title, int argc, char * const argv[] ) { sInstance = app; App::executeLaunch( app, renderer, title, argc, argv ); }
00198 #endif
00199 static void cleanupLaunch() { App::cleanupLaunch(); }
00200
00201 virtual void launch( const char *title, int argc, char * const argv[] );
00203
00205 virtual void privateResize__( const ResizeEvent &event );
00207
00208 private:
00209
00210 static AppBasic* sInstance;
00211
00212 CallbackMgr<bool (TouchEvent)> mCallbacksTouchesBegan, mCallbacksTouchesMoved, mCallbacksTouchesEnded;
00213
00214 #if defined( CINDER_MAC )
00215 AppImplCocoaBasic *mImpl;
00216 #elif defined( CINDER_MSW )
00217 class AppImplMswBasic *mImpl;
00218 friend class AppImplMswBasic;
00219 #endif
00220
00221 std::vector<std::string> mCommandLineArgs;
00222
00223 std::vector<TouchEvent::Touch> mActiveTouches;
00224
00225 Settings mSettings;
00226 };
00227
00228 } }
00229
00230
00231
00232 #if defined( CINDER_MAC )
00233 #define CINDER_APP_BASIC( APP, RENDERER ) \
00234 int main( int argc, char * const argv[] ) { \
00235 cinder::app::AppBasic::prepareLaunch(); \
00236 cinder::app::AppBasic *app = new APP; \
00237 cinder::app::Renderer *ren = new RENDERER; \
00238 cinder::app::AppBasic::executeLaunch( app, ren, #APP, argc, argv ); \
00239 cinder::app::AppBasic::cleanupLaunch(); \
00240 return 0; \
00241 }
00242 #elif defined( CINDER_MSW )
00243 #define CINDER_APP_BASIC( APP, RENDERER ) \
00244 int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { \
00245 cinder::app::AppBasic::prepareLaunch(); \
00246 cinder::app::AppBasic *app = new APP; \
00247 cinder::app::Renderer *ren = new RENDERER; \
00248 cinder::app::AppBasic::executeLaunch( app, ren, #APP ); \
00249 cinder::app::AppBasic::cleanupLaunch(); \
00250 return 0; \
00251 }
00252 #endif