Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AppBasic.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012, The Cinder Project, All rights reserved.
3  Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
4 
5  This code is intended for use with the Cinder C++ library: http://libcinder.org
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
8  the following conditions are met:
9 
10  * Redistributions of source code must retain the above copyright notice, this list of conditions and
11  the following disclaimer.
12  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
13  the following disclaimer in the documentation and/or other materials provided with the distribution.
14 
15  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22  POSSIBILITY OF SUCH DAMAGE.
23 */
24 
25 #pragma once
26 
27 #include "cinder/Cinder.h"
28 #include "cinder/app/App.h"
29 #include "cinder/Display.h"
30 #include "cinder/Function.h"
31 
32 #if defined( CINDER_MAC )
33  #include <OpenGL/CGLTypes.h>
34  #ifdef __OBJC__
35  @class AppImplCocoaBasic;
36  @class WindowImplBasicCocoa;
37  #else
38  class AppImplCocoaBasic;
40  #endif
41 #endif
42 
43 #include "cinder/app/TouchEvent.h"
44 
45 namespace cinder { namespace app {
46 
47 typedef signals::signal<bool (),BooleanAndEventCombiner> EventSignalShouldQuit;
48 
49 class AppBasic : public App {
50  public:
51  class Settings : public App::Settings {
52  public:
53  Settings();
54 
55  void setShouldQuit ( bool aShouldQuit = true );
57 
59  bool isResizable() const { return mDefaultWindowFormat.isResizable(); }
61  void setResizable( bool resizable = true ) { mDefaultWindowFormat.setResizable( resizable ); }
63  bool isBorderless() const { return mDefaultWindowFormat.isBorderless(); }
65  void setBorderless( bool borderless = true ) { mDefaultWindowFormat.setBorderless( borderless ); }
69  void setAlwaysOnTop( bool alwaysOnTop = true ) { mDefaultWindowFormat.setAlwaysOnTop( alwaysOnTop ); }
70 
74  void setDisplay( DisplayRef display ) { mDefaultWindowFormat.setDisplay( display ); }
75 
76 #if defined( CINDER_MSW )
77  void enableConsoleWindow( bool enable = true ) { mEnableMswConsole = enable; }
80  bool isConsoleWindowEnabled() const { return mEnableMswConsole; }
81 #endif
82 
84  void enableMultiTouch( bool enable = true ) { mEnableMultiTouch = enable; }
86  bool isMultiTouchEnabled() const { return mEnableMultiTouch; }
87 
89  void enableQuitOnLastWindowClose( bool enable = true ) { mQuitOnLastWindowClose = enable; }
91  bool isQuitOnLastWindowCloseEnabled() const { return mQuitOnLastWindowClose; }
92 
93  private:
94  bool mQuitOnLastWindowClose;
95 #if defined( CINDER_MSW )
96  bool mEnableMswConsole;
97 #endif
98  };
99 
100  // This is really just here to disambiguate app::WindowRef from the WindowRef found in QuickDraw (so that client code doesn't have to invoke cinder::app::WindowRef explicitly)
101  typedef std::shared_ptr<Window> WindowRef;
102 
103  public:
104  AppBasic();
105  virtual ~AppBasic();
106 
107  virtual void prepareSettings( Settings *settings ) {}
108 
111 
114 
116  virtual float getFrameRate() const;
118  virtual void setFrameRate( float frameRate );
120  virtual void disableFrameRate();
122  virtual bool isFrameRateEnabled() const;
123 
125  void hideCursor();
127  void showCursor();
128 
129  const Settings& getSettings() const { return mSettings; }
130 
131 
133  virtual void quit();
134 
136  const std::vector<std::string>& getArgs() const { return mCommandLineArgs; }
137 
139  virtual fs::path getAppPath() const;
140 
142  virtual app::WindowRef getWindow() const;
144  virtual size_t getNumWindows() const;
146  virtual WindowRef getWindowIndex( size_t index ) const;
148  virtual WindowRef getForegroundWindow() const;
149 
150 #if defined( CINDER_WINRT)
151  class AppImplWinRTBasic* getImpl() {return mImpl;};
152 #endif
153 
154  // DO NOT CALL - should be private but aren't for esoteric reasons
156  // Internal handlers - these are called into by AppImpl's. If you are calling one of these, you have likely strayed far off the path.
157 #if defined( CINDER_MAC )
158  void privateSetImpl__( AppImplCocoaBasic *aImpl );
159 #endif
160  bool privateShouldQuit();
161 
162 #if defined( CINDER_MSW )
163  virtual bool getsWindowsPaintEvents() { return true; }
164 #endif
165 
168  static AppBasic* get() { return sInstance; }
169 
171  // These are called by application instantation macros and are only used in the launch process
172  static void prepareLaunch() { App::prepareLaunch(); }
173 #if defined( CINDER_MSW )
174  static void executeLaunch( AppBasic *app, RendererRef renderer, const char *title );
175 #elif defined( CINDER_WINRT )
176  static void executeLaunch( AppBasic *app, RendererRef renderer, const char *title );
177 #elif defined( CINDER_MAC )
178  static void executeLaunch( AppBasic *app, RendererRef renderer, const char *title, int argc, char * const argv[] ) { App::sInstance = sInstance = app; App::executeLaunch( app, renderer, title, argc, argv ); }
179 #endif
180  static void cleanupLaunch() { App::cleanupLaunch(); }
181 
182  virtual void launch( const char *title, int argc, char * const argv[] );
184 
185  protected:
187 
189 
190 #if defined( CINDER_MAC )
191  AppImplCocoaBasic *mImpl;
192 #elif defined( CINDER_MSW )
193  class AppImplMswBasic *mImpl;
194  friend class AppImplMswBasic;
195 #elif defined ( CINDER_WINRT )
196  class AppImplWinRTBasic *mImpl;
197  friend class AppImplWinRTBasic;
198 #endif
199 
200  std::vector<std::string> mCommandLineArgs;
201 
203 };
204 
205 } } // namespace cinder::app
206 
207 // App-instantiation macros
208 
209 #if defined( CINDER_MAC )
210  #define CINDER_APP_BASIC( APP, RENDERER ) \
211  int main( int argc, char * const argv[] ) { \
212  cinder::app::AppBasic::prepareLaunch(); \
213  cinder::app::AppBasic *app = new APP; \
214  cinder::app::RendererRef ren( new RENDERER ); \
215  cinder::app::AppBasic::executeLaunch( app, ren, #APP, argc, argv ); \
216  cinder::app::AppBasic::cleanupLaunch(); \
217  return 0; \
218  }
219 #elif defined( CINDER_MSW )
220  #define CINDER_APP_BASIC( APP, RENDERER ) \
221  int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { \
222  cinder::app::AppBasic::prepareLaunch(); \
223  cinder::app::AppBasic *app = new APP; \
224  cinder::app::RendererRef ren( new RENDERER ); \
225  cinder::app::AppBasic::executeLaunch( app, ren, #APP ); \
226  cinder::app::AppBasic::cleanupLaunch(); \
227  return 0; \
228  }
229 #elif defined( CINDER_WINRT )
230  #define CINDER_APP_BASIC( APP, RENDERER ) \
231  [Platform::MTAThread] \
232  int main(Platform::Array<Platform::String^>^) { \
233  cinder::app::AppBasic::prepareLaunch(); \
234  cinder::app::AppBasic *app = new APP; \
235  cinder::app::RendererRef ren( new RENDERER ); \
236  cinder::app::AppBasic::executeLaunch( app, ren, #APP ); \
237  cinder::app::AppBasic::cleanupLaunch(); \
238  return 0; \
239  }
240 #endif
BooleanAndEventCombiner EventSignalShouldQuit
Definition: AppBasic.h:47
virtual void quit()
Ceases execution of the application.
Definition: AppBasic.cpp:271
void enable(GLenum state)
Enables the OpenGL State state. Equivalent to calling to glEnable( state );.
Definition: dx.h:198
virtual float getFrameRate() const
Returns the maximum frame-rate the App will attempt to maintain measured in frames-per-second.
Definition: AppBasic.cpp:160
virtual void setFrameRate(float frameRate)
Sets the maximum frame-rate the App will attempt to maintain \ a frameRate frames-per-second.
Definition: AppBasic.cpp:169
EventSignalShouldQuit & getSignalShouldQuit()
This is fired before the app is quit. If any slots return false then the app quitting is canceled...
Definition: AppBasic.h:110
static App * sInstance
Definition: App.h:561
Definition: AppImplWinRTBasic.h:45
bool isQuitOnLastWindowCloseEnabled() const
Returns whether the app quits automatically when its last window is closed. Enabled by default...
Definition: AppBasic.h:91
virtual bool isFrameRateEnabled() const
Returns whether frameRate limiting is enabled.
Definition: AppBasic.cpp:187
void showCursor()
Shows the mouse cursor.
Definition: AppBasic.cpp:260
void setDisplay(DisplayRef display)
Sets the Display the Window will be created on. Defaults to the primary display.
Definition: Window.h:155
Definition: AppBasic.h:51
WindowRef createWindow(const Window::Format &format=Window::Format())
Creates a new Window.
Definition: AppBasic.cpp:149
Definition: App.h:129
void setAlwaysOnTop(bool alwaysOnTop=true)
Sets whether the Window created will always be above all other windows, including other applications'...
Definition: Window.h:223
GLuint index
Definition: GLee.h:2259
bool isBorderless() const
Returns whether the Window created will have no border. Defaults to false.
Definition: Window.h:215
void setDisplay(DisplayRef display)
Sets the display for the default window.
Definition: AppBasic.h:74
Definition: AppImplCocoaBasic.h:84
void enableMultiTouch(bool enable=true)
Registers the app to receive multiTouch events from the operating system. Disabled by default...
Definition: AppBasic.h:84
AppBasic()
Definition: AppBasic.cpp:45
bool isMultiTouchEnabled() const
Returns whether the app is registered to receive multiTouch events from the operating system...
Definition: AppBasic.h:86
DisplayRef getDisplay() const
Returns the display for the default window.
Definition: AppBasic.h:72
std::shared_ptr< Window > WindowRef
Definition: Event.h:49
virtual void disableFrameRate()
Disables frameRate limiting.
Definition: AppBasic.cpp:178
virtual void prepareSettings(Settings *settings)
Definition: AppBasic.h:107
void enableQuitOnLastWindowClose(bool enable=true)
Sets whether the app quits automatically when its last window is closed. Enabled by default...
Definition: AppBasic.h:89
bool isFullScreen() const
Returns whether the Window will be created full-screen. Default is false.
Definition: Window.h:159
bool isBorderless() const
Returns whether the default window will be created without a border (chrome/frame) ...
Definition: AppBasic.h:63
virtual app::WindowRef getWindow() const
Gets the currently active Window.
Definition: AppBasic.cpp:229
Definition: App.h:127
virtual size_t getNumWindows() const
Returns the number of Windows the app has open.
Definition: AppBasic.cpp:207
void setResizable(bool resizable=true)
Sets the default window to be resizable or not.
Definition: AppBasic.h:61
std::shared_ptr< class Renderer > RendererRef
Definition: Renderer.h:85
bool isResizable() const
Returns whether the Window created will be resizable. Defaults to true.
Definition: Window.h:209
Definition: AppBasic.h:49
const Settings & getSettings() const
Definition: AppBasic.h:129
void setAlwaysOnTop(bool alwaysOnTop=true)
Sets whether the default window always remains above all other windows.
Definition: AppBasic.h:69
static AppBasic * sInstance
Definition: AppBasic.h:186
bool isAlwaysOnTop() const
Returns whether the default window always remains above all other windows.
Definition: AppBasic.h:67
std::shared_ptr< class Display > DisplayRef
Definition: Display.h:53
void setBorderless(bool borderless=true)
Sets whether the Window created will have no border. Defaults to false.
Definition: Window.h:217
bool isAlwaysOnTop() const
Returns whether the Window created will always be above all other windows, including other applicatio...
Definition: Window.h:221
Definition: AppImplCocoaBasic.h:40
void hideCursor()
Hides the mouse cursor.
Definition: AppBasic.cpp:249
Window::Format mDefaultWindowFormat
Definition: App.h:222
void setResizable(bool resizable=true)
Sets whether the Window created will be resizable. Defaults to true.
Definition: Window.h:211
Definition: AppImplMswBasic.h:39
bool isResizable() const
Returns whether the default window is resizable.
Definition: AppBasic.h:59
EventSignalShouldQuit mSignalShouldQuit
Definition: AppBasic.h:188
std::shared_ptr< Window > WindowRef
Definition: AppBasic.h:101
std::vector< std::string > mCommandLineArgs
Definition: AppBasic.h:200
void setShouldQuit(bool aShouldQuit=true)
Definition: AppBasic.cpp:295
Definition: Window.h:140
bool mEnableMultiTouch
Definition: App.h:228
DisplayRef getDisplay() const
Returns the Display the Window will be created on. Defaults to the primary display.
Definition: Window.h:153
bool isFullScreen()
Definition: AppBasic.h:56
GLenum GLsizei GLenum format
Definition: GLee.h:969
void setBorderless(bool borderless=true)
Sets the default window to be created without a border (chrome/frame)
Definition: AppBasic.h:65
virtual WindowRef getForegroundWindow() const
Gets the foreground Window, which has keyboard and mouse focus.
Definition: AppBasic.cpp:238
virtual WindowRef getWindowIndex(size_t index) const
Gets a Window by index, in the range [0, getNumWindows()).
Definition: AppBasic.cpp:218
virtual fs::path getAppPath() const
Returns the path to the application on disk.
Definition: AppBasic.cpp:196
virtual ~AppBasic()
Definition: AppBasic.cpp:51
Settings()
Definition: AppBasic.cpp:287
Settings mSettings
Definition: AppBasic.h:202
const std::vector< std::string > & getArgs() const
Returns a vector of the command line arguments passed to the app.
Definition: AppBasic.h:136