Cinder

  • Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

include/cinder/app/AppCocoaTouch.h

Go to the documentation of this file.
00001 /*
00002  Copyright (c) 2010, The Barbarian Group
00003  All rights reserved.
00004 
00005  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
00006  the following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and
00009     the following disclaimer.
00010     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
00011     the following disclaimer in the documentation and/or other materials provided with the distribution.
00012 
00013  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
00014  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00015  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00016  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00017  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00018  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00019  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00020  POSSIBILITY OF SUCH DAMAGE.
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 
00029 namespace cinder { namespace app {
00030 
00031 struct AppCocoaTouchState;
00032 
00033 class AppCocoaTouch : public App {
00034   public:
00035     class Settings : public App::Settings {
00036       public:
00037         Settings()
00038             : App::Settings(), mEnableMultiTouch( true ) {}
00039 
00041         void        enableMultiTouch( bool enable = true ) { mEnableMultiTouch = enable; }
00043         bool        isMultiTouchEnabled() const { return mEnableMultiTouch; }
00044         
00045       private:
00046         bool        mEnableMultiTouch;
00047     };
00048 
00049     AppCocoaTouch();
00050     virtual ~AppCocoaTouch() {}
00051 
00053     virtual void        touchesBegan( TouchEvent event ) {}
00055     virtual void        touchesMoved( TouchEvent event ) {}
00057     virtual void        touchesEnded( TouchEvent event ) {}
00059     const std::vector<TouchEvent::Touch>&   getActiveTouches() const { return mActiveTouches; }
00060     
00062     virtual int     getWindowWidth() const;
00064     virtual int     getWindowHeight() const;
00066     void            setWindowWidth( int windowWidth ) {}
00068     void            setWindowHeight( int windowHeight ) {}
00070     void            setWindowSize( int windowWidth, int windowHeight ) {}
00071 
00073     virtual float       getFrameRate() const;
00075     virtual void        setFrameRate( float aFrameRate );
00077     virtual bool        isFullScreen() const;
00079     virtual void        setFullScreen( bool aFullScreen );
00080 
00082     virtual double      getElapsedSeconds() const;
00083 
00085     virtual std::string         getAppPath();
00086 
00088     virtual void    quit();
00089 
00091     static AppCocoaTouch*   get() { return sInstance; }
00093     virtual const Settings& getSettings() const { return mSettings; }
00094 
00096     // These are called by application instantation macros and are only used in the launch process
00097     static void     prepareLaunch() { App::prepareLaunch(); }
00098     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 ); }
00099     static void     cleanupLaunch() { App::cleanupLaunch(); }
00100     
00101     virtual void    launch( const char *title, int argc, char * const argv[] );
00103 
00104     // DO NOT CALL - should be private but aren't for esoteric reasons
00106     // Internal handlers - these are called into by AppImpl's. If you are calling one of these, you have likely strayed far off the path.
00107     void        privateTouchesBegan__( const TouchEvent &event );
00108     void        privateTouchesMoved__( const TouchEvent &event );
00109     void        privateTouchesEnded__( const TouchEvent &event );
00110     void        privateSetActiveTouches__( const std::vector<TouchEvent::Touch> &touches ) { mActiveTouches = touches; }
00112 
00113   private:
00114     friend void     setupCocoaTouchWindow( AppCocoaTouch *app );
00115     
00116     // The state is contained in a struct in order to avoid this .h needing to be compiled as Objective-C++
00117     shared_ptr<AppCocoaTouchState>      mState;
00118     
00119     static AppCocoaTouch    *sInstance; 
00120     Settings                mSettings;
00121     std::vector<TouchEvent::Touch>  mActiveTouches;
00122 };
00123 
00124 } } // namespace cinder::app
00125 
00126 #define CINDER_APP_COCOA_TOUCH( APP, RENDERER )                             \
00127 int main( int argc, char *argv[] ) {                                        \
00128     cinder::app::AppCocoaTouch::prepareLaunch();                            \
00129     cinder::app::AppCocoaTouch *app = new APP;                              \
00130     cinder::app::Renderer *ren = new RENDERER;                              \
00131     cinder::app::AppCocoaTouch::executeLaunch( app, ren, #APP, argc, argv );\
00132     cinder::app::AppCocoaTouch::cleanupLaunch();                            \
00133     return 0;                                                               \
00134 }