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 #endif 00036 00037 00038 namespace cinder { namespace app { 00039 00040 class AppBasic : public App { 00041 public: 00042 class Settings : public App::Settings { 00043 public: 00044 Settings(); 00045 00046 void setShouldQuit ( bool aShouldQuit = true ); 00047 void setFullScreenSize( int aFullScreenSizeX, int aFullScreenSizeY ); 00048 void setFullScreen( bool aFullScreen = true ); 00049 void setResizable( bool aResizable = true ); 00050 00051 int getFullScreenWidth() const { return mFullScreenSizeX; } 00052 int getFullScreenHeight() const { return mFullScreenSizeY; } 00053 00055 Display* getDisplay() const { return mDisplay; } 00056 void setDisplay( shared_ptr<Display> aDisplay ); 00057 private: 00058 int mFullScreenSizeX, mFullScreenSizeY; 00059 Display *mDisplay; 00060 }; 00061 00062 public: 00063 AppBasic(); 00064 virtual ~AppBasic(); 00065 00066 virtual void prepareSettings( Settings *settings ) {} 00067 00069 virtual int getWindowWidth() const; 00071 void setWindowWidth( int windowWidth ); 00073 virtual int getWindowHeight() const; 00075 void setWindowHeight( int windowHeight ); 00077 void setWindowSize( int windowWidth, int windowHeight ); 00078 00080 virtual float getFrameRate() const; 00082 virtual void setFrameRate( float frameRate ); 00084 virtual bool isFullScreen() const; 00086 virtual void setFullScreen( bool fullScreen ); 00087 00089 Vec2i getMousePos() const; 00091 void hideCursor(); 00093 void showCursor(); 00094 00095 const Settings& getSettings() const { return mSettings; } 00096 const Display& getDisplay(); 00097 00099 virtual void quit(); 00100 00102 virtual std::string getAppPath(); 00103 00104 #if defined( CINDER_MAC ) 00105 void privateSetImpl__( AppImplCocoaBasic *aImpl ); 00106 #elif defined( CINDER_MSW ) 00107 virtual bool getsWindowsPaintEvents() { return true; } 00108 #endif 00109 00111 static AppBasic* get() { return sInstance; } 00112 00114 // These are called by application instantation macros and are only used in the launch process 00115 static void prepareLaunch() { App::prepareLaunch(); } 00116 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 ); } 00117 static void cleanupLaunch() { App::cleanupLaunch(); } 00118 00119 virtual void launch( const char *title, int argc, char * const argv[] ); 00121 00123 virtual void privateResize__( int width, int height ); 00125 00126 private: 00127 00128 static AppBasic* sInstance; 00129 00130 #if defined( CINDER_MAC ) 00131 AppImplCocoaBasic *mImpl; 00132 #elif defined( CINDER_MSW ) 00133 class AppImplMswBasic *mImpl; 00134 friend class AppImplMswBasic; 00135 #endif 00136 00137 Settings mSettings; 00138 }; 00139 00140 } } // namespace cinder::app 00141 00142 // App-instantiation macros 00143 00144 #if defined( CINDER_MAC ) 00145 #define CINDER_APP_BASIC( APP, RENDERER ) \ 00146 int main( int argc, char * const argv[] ) { \ 00147 cinder::app::AppBasic::prepareLaunch(); \ 00148 cinder::app::AppBasic *app = new APP; \ 00149 cinder::app::Renderer *ren = new RENDERER; \ 00150 cinder::app::AppBasic::executeLaunch( app, ren, #APP, argc, argv ); \ 00151 cinder::app::AppBasic::cleanupLaunch(); \ 00152 return 0; \ 00153 } 00154 #elif defined( CINDER_MSW ) 00155 #define CINDER_APP_BASIC( APP, RENDERER ) \ 00156 int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { \ 00157 cinder::app::AppBasic::prepareLaunch(); \ 00158 cinder::app::AppBasic *app = new APP; \ 00159 cinder::app::Renderer *ren = new RENDERER; \ 00160 cinder::app::AppBasic::executeLaunch( app, ren, #APP, -1, 0 ); \ 00161 cinder::app::AppBasic::cleanupLaunch(); \ 00162 return 0; \ 00163 } 00164 #endif