Cinder

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

include/cinder/app/AppBasic.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/Display.h"
00027 
00028 #if defined( CINDER_MAC )
00029     #include <OpenGL/CGLTypes.h>
00030     #ifdef __OBJC__
00031         @class AppImplCocoaBasic;
00032     #else
00033         class AppImplCocoaBasic;
00034     #endif
00035 #elif defined( CINDER_MSW )
00036     #include "cinder/app/TouchEvent.h"
00037 #endif
00038 
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    setFullScreenSize( int aFullScreenSizeX, int aFullScreenSizeY );
00050         void    setFullScreen( bool aFullScreen = true );
00051         void    setResizable( bool aResizable = true );
00052 
00053         int     getFullScreenWidth() const { return mFullScreenSizeX; }
00054         int     getFullScreenHeight() const { return mFullScreenSizeY; }
00055 
00057         Display*    getDisplay() const { return mDisplay; }
00058         void        setDisplay( shared_ptr<Display> aDisplay );
00059 
00060 #if defined( CINDER_MAC )
00061 
00062         void    enableSecondaryDisplayBlanking( bool enable = false ) { mEnableSecondaryDisplayBlanking = enable; }
00064         bool    isSecondaryDisplayBlankingEnabled() const { return mEnableSecondaryDisplayBlanking; }   
00065 #endif
00066         
00067 #if defined( CINDER_MSW )
00068 
00069         void        enableMultiTouch( bool enable = true ) { mEnableMultiTouch = enable; }
00071         bool        isMultiTouchEnabled() const { return mEnableMultiTouch; }
00072 #endif
00073      private:
00074 #if defined( CINDER_MSW )
00075         bool        mEnableMultiTouch;
00076 #endif
00077 #if defined( CINDER_MAC )
00078         bool        mEnableSecondaryDisplayBlanking;
00079 #endif
00080         int         mFullScreenSizeX, mFullScreenSizeY;
00081         Display     *mDisplay;
00082     };
00083 
00084  public:
00085     AppBasic();
00086     virtual ~AppBasic();
00087 
00088     virtual void        prepareSettings( Settings *settings ) {}
00089 
00090 #if defined( CINDER_MSW )
00091 
00092     virtual void        touchesBegan( TouchEvent event ) {}
00094     virtual void        touchesMoved( TouchEvent event ) {}
00096     virtual void        touchesEnded( TouchEvent event ) {}
00098     const std::vector<TouchEvent::Touch>&   getActiveTouches() const { return mActiveTouches; }
00099 #endif
00100 
00102     virtual int     getWindowWidth() const;
00104     void            setWindowWidth( int windowWidth );
00106     virtual int     getWindowHeight() const;
00108     void            setWindowHeight( int windowHeight );
00110     void            setWindowSize( int windowWidth, int windowHeight );
00111 
00113     virtual float       getFrameRate() const;
00115     virtual void        setFrameRate( float frameRate );
00117     virtual bool        isFullScreen() const;
00119     virtual void        setFullScreen( bool fullScreen );
00120 
00122     Vec2i               getMousePos() const;
00124     void                hideCursor();
00126     void                showCursor();
00127 
00128     const Settings&     getSettings() const { return mSettings; }
00129     const Display&      getDisplay();
00130 
00132     virtual void        quit();
00133 
00135     virtual std::string         getAppPath();
00136 
00137     // DO NOT CALL - should be private but aren't for esoteric reasons
00139     // Internal handlers - these are called into by AppImpl's. If you are calling one of these, you have likely strayed far off the path.
00140 #if defined( CINDER_MAC )
00141     void        privateSetImpl__( AppImplCocoaBasic *aImpl );   
00142 #elif defined( CINDER_MSW )
00143     void        privateTouchesBegan__( const TouchEvent &event );
00144     void        privateTouchesMoved__( const TouchEvent &event );
00145     void        privateTouchesEnded__( const TouchEvent &event );
00146     void        privateSetActiveTouches__( const std::vector<TouchEvent::Touch> &touches ) { mActiveTouches = touches; }
00147 
00148     virtual bool        getsWindowsPaintEvents() { return true; }
00149 #endif
00150 
00151     
00153     static AppBasic*    get()   { return sInstance; }
00154 
00156     // These are called by application instantation macros and are only used in the launch process
00157     static void     prepareLaunch() { App::prepareLaunch(); }
00158     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 ); }
00159     static void     cleanupLaunch() { App::cleanupLaunch(); }
00160     
00161     virtual void    launch( const char *title, int argc, char * const argv[] );
00163 
00165     virtual void    privateResize__( int width, int height );
00167 
00168  private:
00169  
00170     static AppBasic*    sInstance;
00171 
00172 #if defined( CINDER_MAC )
00173     AppImplCocoaBasic       *mImpl;
00174 #elif defined( CINDER_MSW )
00175     class AppImplMswBasic   *mImpl;
00176     friend class AppImplMswBasic;
00177     std::vector<TouchEvent::Touch>      mActiveTouches; // list of currently active touches
00178     
00179 #endif
00180 
00181     Settings        mSettings;
00182 };
00183 
00184 } } // namespace cinder::app
00185 
00186 // App-instantiation macros
00187 
00188 #if defined( CINDER_MAC )
00189     #define CINDER_APP_BASIC( APP, RENDERER )                               \
00190     int main( int argc, char * const argv[] ) {                             \
00191         cinder::app::AppBasic::prepareLaunch();                             \
00192         cinder::app::AppBasic *app = new APP;                               \
00193         cinder::app::Renderer *ren = new RENDERER;                          \
00194         cinder::app::AppBasic::executeLaunch( app, ren, #APP, argc, argv ); \
00195         cinder::app::AppBasic::cleanupLaunch();                             \
00196         return 0;                                                           \
00197     }
00198 #elif defined( CINDER_MSW )
00199     #define CINDER_APP_BASIC( APP, RENDERER )                                                       \
00200     int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) {  \
00201         cinder::app::AppBasic::prepareLaunch();                                                     \
00202         cinder::app::AppBasic *app = new APP;                                                       \
00203         cinder::app::Renderer *ren = new RENDERER;                                                  \
00204         cinder::app::AppBasic::executeLaunch( app, ren, #APP, -1, 0 );                              \
00205         cinder::app::AppBasic::cleanupLaunch();                                                     \
00206         return 0;                                                                                   \
00207     }
00208 #endif