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/cocoa/CinderCocoaTouch.h"
00027 #include "cinder/app/TouchEvent.h"
00028 #include "cinder/app/AccelEvent.h"
00029
00030
00031 namespace cinder { namespace app {
00032
00033 struct AppCocoaTouchState;
00034
00035 class AppCocoaTouch : public App {
00036 public:
00037 class Settings : public App::Settings {
00038 public:
00039 Settings()
00040 : App::Settings(), mEnableMultiTouch( true ) {}
00041
00043 void enableMultiTouch( bool enable = true ) { mEnableMultiTouch = enable; }
00045 bool isMultiTouchEnabled() const { return mEnableMultiTouch; }
00046
00047 private:
00048 bool mEnableMultiTouch;
00049 };
00050
00051 AppCocoaTouch();
00052 virtual ~AppCocoaTouch() {}
00053
00054 virtual void prepareSettings( Settings *settings ) {}
00056 virtual void didBecomeActive() {}
00057 virtual void willResignActive() {}
00058
00060 virtual void touchesBegan( TouchEvent event ) {}
00062 virtual void touchesMoved( TouchEvent event ) {}
00064 virtual void touchesEnded( TouchEvent event ) {}
00066 const std::vector<TouchEvent::Touch>& getActiveTouches() const { return mActiveTouches; }
00068 virtual void accelerated( AccelEvent event ) {}
00069
00071 CallbackId registerTouchesBegan( std::function<bool (TouchEvent)> callback ) { return mCallbacksTouchesBegan.registerCb( callback ); }
00073 template<typename T>
00074 CallbackId registerTouchesBegan( T *obj, bool (T::*callback)(TouchEvent) ) { return mCallbacksTouchesBegan.registerCb( std::bind1st( std::mem_fun( callback ), obj ) ); }
00076 void unregisterTouchesBegan( CallbackId id ) { mCallbacksTouchesBegan.unregisterCb( id ); }
00077
00079 CallbackId registerTouchesMoved( std::function<bool (TouchEvent)> callback ) { return mCallbacksTouchesMoved.registerCb( callback ); }
00081 template<typename T>
00082 CallbackId registerTouchesMoved( T *obj, bool (T::*callback)(TouchEvent) ) { return mCallbacksTouchesMoved.registerCb( std::bind1st( std::mem_fun( callback ), obj ) ); }
00084 void unregisterTouchesMoved( CallbackId id ) { mCallbacksTouchesMoved.unregisterCb( id ); }
00085
00087 CallbackId registerTouchesEnded( std::function<bool (TouchEvent)> callback ) { return mCallbacksTouchesEnded.registerCb( callback ); }
00089 template<typename T>
00090 CallbackId registerTouchesEnded( T *obj, bool (T::*callback)(TouchEvent) ) { return mCallbacksTouchesEnded.registerCb( std::bind1st( std::mem_fun( callback ), obj ) ); }
00092 void unregisterTouchesEnded( CallbackId id ) { mCallbacksTouchesEnded.unregisterCb( id ); }
00093
00095 CallbackId registerAccelerated( std::function<bool (AccelEvent)> callback ) { return mCallbacksAccelerated.registerCb( callback ); }
00097 template<typename T>
00098 CallbackId registerAccelerated( T *obj, bool (T::*callback)(AccelEvent) ) { return mCallbacksAccelerated.registerCb( std::bind1st( std::mem_fun( callback ), obj ) ); }
00100 void unregisterAccelerated( CallbackId id ) { mCallbacksAccelerated.unregisterCb( id ); }
00101
00102
00104 virtual int getWindowWidth() const;
00106 virtual int getWindowHeight() const;
00108 virtual float getContentScaleFactor() const;
00110 void setWindowWidth( int windowWidth ) {}
00112 void setWindowHeight( int windowHeight ) {}
00114 void setWindowSize( int windowWidth, int windowHeight ) {}
00115
00117 void enableAccelerometer( float updateFrequency = 30.0f, float filterFactor = 0.1f );
00119 void disableAccelerometer();
00120
00122 virtual float getFrameRate() const;
00124 virtual void setFrameRate( float aFrameRate );
00126 virtual bool isFullScreen() const;
00128 virtual void setFullScreen( bool aFullScreen );
00129
00131 virtual double getElapsedSeconds() const;
00132
00134 virtual fs::path getAppPath();
00135
00137 virtual void quit();
00138
00140 static AppCocoaTouch* get() { return sInstance; }
00142 virtual const Settings& getSettings() const { return mSettings; }
00143
00144
00146
00147 static void prepareLaunch() { App::prepareLaunch(); }
00148 static void executeLaunch( AppCocoaTouch *app, class Renderer *renderer, const char *title, int argc, char * const argv[] ) { sInstance = app; App::executeLaunch( app, renderer, title, argc, argv ); }
00149 static void cleanupLaunch() { App::cleanupLaunch(); }
00150
00151 virtual void launch( const char *title, int argc, char * const argv[] );
00153
00154
00156
00157 void privatePrepareSettings__();
00158 void privateTouchesBegan__( const TouchEvent &event );
00159 void privateTouchesMoved__( const TouchEvent &event );
00160 void privateTouchesEnded__( const TouchEvent &event );
00161 void privateSetActiveTouches__( const std::vector<TouchEvent::Touch> &touches ) { mActiveTouches = touches; }
00162 void privateAccelerated__( const Vec3f &direction );
00164
00165
00166 std::shared_ptr<AppCocoaTouchState> mState;
00167
00168 private:
00169 friend void setupCocoaTouchWindow( AppCocoaTouch *app );
00170
00171
00172 static AppCocoaTouch *sInstance;
00173 Settings mSettings;
00174
00175 std::vector<TouchEvent::Touch> mActiveTouches;
00176
00177 CallbackMgr<bool (TouchEvent)> mCallbacksTouchesBegan, mCallbacksTouchesMoved, mCallbacksTouchesEnded;
00178 CallbackMgr<bool (AccelEvent)> mCallbacksAccelerated;
00179
00180 float mAccelFilterFactor;
00181 Vec3f mLastAccel, mLastRawAccel;
00182 };
00183
00184 } }
00185
00186 #define CINDER_APP_COCOA_TOUCH( APP, RENDERER ) \
00187 int main( int argc, char *argv[] ) { \
00188 cinder::app::AppCocoaTouch::prepareLaunch(); \
00189 cinder::app::AppCocoaTouch *app = new APP; \
00190 cinder::app::Renderer *ren = new RENDERER; \
00191 cinder::app::AppCocoaTouch::executeLaunch( app, ren, #APP, argc, argv );\
00192 cinder::app::AppCocoaTouch::cleanupLaunch(); \
00193 return 0; \
00194 }