Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
App.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/Renderer.h"
29 #include "cinder/app/Window.h"
30 #include "cinder/Vector.h"
31 #include "cinder/app/MouseEvent.h"
32 #include "cinder/app/KeyEvent.h"
34 
35 #include "cinder/Display.h"
36 #include "cinder/DataSource.h"
37 #include "cinder/Timer.h"
38 #include "cinder/Function.h"
39 #include "cinder/Thread.h"
40 
41 #if defined( CINDER_COCOA )
42  #if defined( CINDER_COCOA_TOUCH )
43  #if defined( __OBJC__ )
44  #import <UIKit/UIKit.h>
45  #import <CoreFoundation/CoreFoundation.h>
46  #endif
47  #else
48  #include <ApplicationServices/ApplicationServices.h>
49  #endif
50  #if defined __OBJC__
51  @class CinderView;
52  @class NSBundle;
53  #else
54  class NSBundle;
55  #endif
56 // class CinderView;
57 #elif defined( CINDER_MSW )
58  #include "cinder/msw/OutputDebugStringStream.h"
59 #elif defined( CINDER_WINRT)
60  #include "cinder/msw/OutputDebugStringStream.h"
61 #endif
62 
63 #include <vector>
64 #include <algorithm>
65 
66 namespace cinder {
67 class Timeline;
68 } // namespace cinder
69 
70 #if !defined( CINDER_WINRT )
71 namespace boost { namespace asio {
72 class io_service;
73 } } // namespace boost::asio
74 #endif
75 
76 namespace cinder { namespace app {
77 
78 
81  typedef bool result_type;
82 
83  template<typename InputIterator>
84  bool operator()( InputIterator first, InputIterator last ) const
85  {
86  bool handled = ( first == last ) ? true : false;
87  while( first != last )
88  handled = *first++ || handled;
89 
90  return handled;
91  }
92 };
93 
96  typedef bool result_type;
97 
98  template<typename InputIterator>
99  bool operator()( InputIterator first, InputIterator last ) const
100  {
101  bool result = true;
102  while( first != last )
103  result = *first++ && result;
104 
105  return result;
106  }
107 };
108 
110 template<typename T>
112  typedef T result_type;
113 
114  template<typename InputIterator>
115  T operator()( InputIterator first, InputIterator last ) const
116  {
117  if( first == last )
118  return 0;
119  T mask = *first++;
120  while( first != last )
121  mask &= *first++;
122 
123  return mask;
124  }
125 };
126 
127 class App {
128  public:
129  class Settings {
130  public:
131  // whether or not the app should terminate prior to launching
132  bool isPrepared() const { return ! mShouldQuit; }
133 
135  void setWindowSize( int windowSizeX, int windowSizeY ) { mDefaultWindowFormat.setSize( Vec2i( windowSizeX, windowSizeY ) ); }
140 
144  void setWindowPos( int windowPosX, int windowPosY ) { mDefaultWindowFormat.setPos( Vec2i( windowPosX, windowPosY ) ); }
146  void setWindowPos( const Vec2i &windowPos ) { mDefaultWindowFormat.setPos( windowPos ); }
151 
155  void setFullScreen( bool fullScreen = true, const FullScreenOptions &options = FullScreenOptions() ) { mDefaultWindowFormat.setFullScreen( fullScreen, options ); }
156 
158  bool isResizable() const { return mDefaultWindowFormat.isResizable(); }
160  void setResizable( bool resizable = true ) { mDefaultWindowFormat.setResizable( resizable ); }
162  bool isBorderless() const { return mDefaultWindowFormat.isBorderless(); }
164  void setBorderless( bool borderless = true ) { mDefaultWindowFormat.setBorderless( borderless ); }
168  void setAlwaysOnTop( bool alwaysOnTop = true ) { mDefaultWindowFormat.setAlwaysOnTop( alwaysOnTop ); }
169 
173  void setDisplay( DisplayRef display ) { mDefaultWindowFormat.setDisplay( display ); }
174 
175  void prepareWindow( const Window::Format &format );
176  std::vector<Window::Format>& getWindowFormats() { return mWindowFormats; }
177  const std::vector<Window::Format>& getWindowFormats() const { return mWindowFormats; }\
178 
183 
188 
190  void enableMultiTouch( bool enable = true ) { mEnableMultiTouch = enable; }
192  bool isMultiTouchEnabled() const { return mEnableMultiTouch; }
193 
195  void enablePowerManagement( bool aPowerManagement = true );
198 
200  const std::string& getTitle() const { return mTitle; }
202  void setTitle( const std::string &title ) { mTitle = title; }
203 
205  void setFrameRate( float frameRate );
207  void disableFrameRate();
209  bool isFrameRateEnabled() const { return mFrameRateEnabled; }
211  float getFrameRate() const { return mFrameRate; }
212 
213  Settings();
214  virtual ~Settings() {}
215 
216  protected:
217  bool mShouldQuit; // defaults to false, facilitates early termination
218 
219  // A vector of Windows which have been requested using prepareWindow. An empty vector implies defaults.
220  std::vector<Window::Format> mWindowFormats;
221  // The Window format which will be used if prepareWindow is not called
223 
225  float mFrameRate;
226  bool mPowerManagement; // allow screensavers or power management to hide app. default: false
230 
231  friend class App;
232  };
233 
234 
235  public:
236  // interface
237  App();
238  virtual ~App();
239 
241  virtual void setup() {}
243  virtual void shutdown() {}
244 
246  virtual void update() {}
248  virtual void draw() {}
249 
251  virtual void mouseDown( MouseEvent event ) {}
253  virtual void mouseUp( MouseEvent event ) {}
255  virtual void mouseWheel( MouseEvent event ) {}
257  virtual void mouseMove( MouseEvent event ) {}
259  virtual void mouseDrag( MouseEvent event ) {}
260 
262  virtual void touchesBegan( TouchEvent event ) {}
264  virtual void touchesMoved( TouchEvent event ) {}
266  virtual void touchesEnded( TouchEvent event ) {}
267 
269  virtual void keyDown( KeyEvent event ) {}
271  virtual void keyUp( KeyEvent event ) {}
273  virtual void resize() {}
275  virtual void fileDrop( FileDropEvent event ) {}
276 
278  virtual void quit() = 0;
279 
281  signals::signal<void()>& getSignalUpdate() { return mSignalUpdate; }
282 
284  signals::signal<void()>& getSignalShutdown() { return mSignalShutdown; }
285  void emitShutdown();
286 
287 #if ! defined( CINDER_WINRT )
288  signals::signal<void()>& getSignalWillResignActive() { return mSignalWillResignActive; }
289  void emitWillResignActive();
290  signals::signal<void()>& getSignalDidBecomeActive() { return mSignalDidBecomeActive; }
291  void emitDidBecomeActive();
292 #endif
293 
294  const std::vector<TouchEvent::Touch>& getActiveTouches() const { return getWindow()->getActiveTouches(); }
295 
296  // Accessors
297  virtual const Settings& getSettings() const = 0;
299  RendererRef getRenderer() const { return getWindow()->getRenderer(); }
301  DisplayRef getDisplay() const { return getWindow()->getDisplay(); }
302 
304  virtual WindowRef getWindow() const = 0;
306  virtual size_t getNumWindows() const = 0;
308  virtual WindowRef getWindowIndex( size_t index ) const = 0;
309 
311  virtual void enablePowerManagement( bool powerManagement = true ) { mPowerManagement = powerManagement; }
313  virtual bool isPowerManagementEnabled() const { return mPowerManagement; }
314 
316  int getWindowWidth() const { return getWindow()->getWidth(); }
318  int getWindowHeight() const { return getWindow()->getHeight(); }
320  void setWindowSize( int windowWidth, int windowHeight ) { setWindowSize( Vec2i( windowWidth, windowHeight ) ); }
322  void setWindowSize( const Vec2i &size ) { getWindow()->setSize( size ); }
324 
325  Vec2f getWindowCenter() const { return Vec2f( (float)getWindowWidth(), (float)getWindowHeight() ) * 0.5f; }
329  float getWindowAspectRatio() const { return getWindowWidth() / (float)getWindowHeight(); }
331 
332  Area getWindowBounds() const { return Area( 0, 0, getWindowWidth(), getWindowHeight() ); }
334  float getWindowContentScale() const { return getWindow()->getContentScale(); }
335 
337  Vec2i getWindowPos() const { return getWindow()->getPos(); }
339  int getWindowPosX() const { return getWindow()->getPos().x; }
341  int getWindowPosY() const { return getWindow()->getPos().y; }
343  void setWindowPos( int x, int y ) { setWindowPos( Vec2i( x, y ) ); }
345  virtual void setWindowPos( const Vec2i &windowPos ) { getWindow()->setPos( windowPos ); }
346 
348  virtual float getFrameRate() const = 0;
350  virtual void setFrameRate( float frameRate ) = 0;
352  float getAverageFps() const { return mAverageFps; }
354  double getFpsSampleInterval() const { return mFpsSampleInterval; }
356  void setFpsSampleInterval( double sampleInterval ) { mFpsSampleInterval = sampleInterval; }
357 
359  bool isFullScreen() const { return getWindow()->isFullScreen(); }
361  void setFullScreen( bool aFullScreen, const FullScreenOptions &options = FullScreenOptions() ) { getWindow()->setFullScreen( aFullScreen, options ); }
362 
364  double getElapsedSeconds() const { return mTimer.getSeconds(); }
366  uint32_t getElapsedFrames() const { return mFrameCount; }
367 
369  static Vec2i getMousePos();
370 
371  // utilities
373  static DataSourceRef loadResource( const std::string &macPath, int mswID, const std::string &mswType );
374 #if defined( CINDER_COCOA )
375  static DataSourceRef loadResource( const std::string &macPath );
378  static fs::path getResourcePath( const fs::path &rsrcRelativePath );
380  static fs::path getResourcePath();
381 #elif defined( CINDER_WINRT )
382  static DataSourceRef loadResource( const std::string &assetPath ) { return App::get()->loadAsset( assetPath ); }
384 
385 #elif defined( CINDER_MSW )
386  static DataSourceRef loadResource( int mswID, const std::string &mswType );
388 #endif
389 
391  DataSourceRef loadAsset( const fs::path &relativePath );
393  fs::path getAssetPath( const fs::path &relativePath );
395  void addAssetDirectory( const fs::path &dirPath );
396 
398  virtual fs::path getAppPath() const = 0;
399 #if defined( CINDER_COCOA )
400  virtual NSBundle* getBundle() const;
402 #endif\
403 
404 #if defined( CINDER_WINRT )
405 
410  void getOpenFilePath( const fs::path &initialPath = "", std::vector<std::string> extensions = std::vector<std::string>(), std::function<void (fs::path)> f = nullptr );
411 #else
412 
417  fs::path getOpenFilePath( const fs::path &initialPath = "", std::vector<std::string> extensions = std::vector<std::string>() );
418 #endif
419 
420 #if defined( CINDER_WINRT )
421 
426  void getFolderPath( const fs::path &initialPath = "", std::vector<std::string> extensions = std::vector<std::string>(), std::function<void (fs::path)> f = nullptr );
427 #else
428  fs::path getFolderPath(const fs::path &initialPath="");
430 #endif
431 
432 #if defined( CINDER_WINRT )
433 
438  void getSaveFilePath( const fs::path &initialPath = "", std::vector<std::string> extensions = std::vector<std::string>(), std::function<void (fs::path)> f = nullptr );
439 #else
440 
444  fs::path getSaveFilePath( const fs::path &initialPath = "", std::vector<std::string> extensions = std::vector<std::string>() );
445 #endif
446  std::ostream& console();
448 
450  Timeline& timeline() { return *mTimeline; }
451 
453  static bool isPrimaryThread();
454 
455 #if !defined( CINDER_WINRT )
456  boost::asio::io_service& io_service() { return *mIo; }
458 #endif
459 
460 
461 
463  void dispatchAsync( const std::function<void()> &fn );
464 
465  template<typename T>
467  {
468  if( isPrimaryThread() )
469  return fn();
470  else {
471  typedef typename std::result_of<T()>::type result_type;
472 #if defined( _MSC_VER ) && ( _MSC_VER <= 1600 ) // slightly different signature with Boost.Thread
473  std::packaged_task<result_type> task( std::move(fn) );
474 #else
475  std::packaged_task<result_type()> task( std::move(fn) );
476 #endif
477  auto fute = task.get_future();
478  dispatchAsync( [&task]() { task(); } );
479  return fute.get();
480  }
481  }
482 
488  Surface copyWindowSurface( const Area &area );
490  void restoreWindowContext();
491 
493  RendererRef findSharedRenderer( RendererRef searchRenderer ) const;
494 
495  // DO NOT CALL - should be private but aren't for esoteric reasons
497  // Internal handlers - these are called into by AppImpl's. If you are calling one of these, you have likely strayed far off the path.
498  virtual void privateSetup__();
499  virtual void privateUpdate__();
501 
502 #if defined( CINDER_MSW )
503  // Not all Windows target types receive paint events, and the AppImplMswRenderer* needs to know that.
504  virtual bool getsWindowsPaintEvents() = 0;
505 #endif
506 
507  virtual bool receivesEvents() const { return true; }
508 
510  static App* get() { return sInstance; }
511 
512  protected:
514  // These are called by application instantation macros and are only used in the launch process
515  static void prepareLaunch();
516  static void executeLaunch( App *app, RendererRef defaultRenderer, const char *title, int argc, char * const argv[] );
517  static void cleanupLaunch();
518 
519  virtual void launch( const char *title, int argc, char * const argv[] ) = 0;
520 
522 
523 #if defined( CINDER_MSW )
524  friend class AppImplMsw;
525  std::shared_ptr<std::ostream> mOutputStream;
526 #elif defined( CINDER_WINRT )
527  friend class AppImplWinRT;
528  std::shared_ptr<std::ostream> mOutputStream;
529 #endif
530 
531  private:
532  void prepareAssetLoading();
533  fs::path findAssetPath( const fs::path &relativePath );
534 
535 #if defined( CINDER_COCOA )
536  static void *sAutoReleasePool;
537 #endif
538 
539  Timer mTimer;
540  uint32_t mFrameCount;
541  float mAverageFps;
542  uint32_t mFpsLastSampleFrame;
543  double mFpsLastSampleTime;
544  double mFpsSampleInterval;
545 
546  std::shared_ptr<Timeline> mTimeline;
547 
548  signals::signal<void()> mSignalUpdate, mSignalShutdown, mSignalWillResignActive, mSignalDidBecomeActive;
549 
550 #if !defined( CINDER_WINRT )
551  std::shared_ptr<boost::asio::io_service> mIo;
552  std::shared_ptr<void> mIoWork; // boost::asio::io_service::work, but can't fwd declare member class
553 #endif // !defined( CINDER_WINRT )
554 
555  // have we already setup the default path to assets?
556  bool mAssetDirectoriesInitialized;
557  // Path to directories which contain assets
558  std::vector<fs::path> mAssetDirectories;
559 
560  protected:
561  static App* sInstance;
564 };
565 
570 inline WindowRef getWindow() { return App::get()->getWindow(); }
572 inline size_t getNumWindows() { return App::get()->getNumWindows(); }
574 inline WindowRef getWindowIndex( size_t index ) { return App::get()->getWindowIndex( index ); }
575 
577 inline int getWindowWidth() { return App::get()->getWindowWidth(); }
579 inline void setWindowPos( const Vec2i &windowPos ) { App::get()->setWindowPos( windowPos); }
581 inline void setWindowPos( int x, int y ) { setWindowPos( Vec2i( x, y ) ); }
583 inline int getWindowHeight() { return App::get()->getWindowHeight(); }
585 inline void setWindowSize( int windowWidth, int windowHeight ) { App::get()->setWindowSize( windowWidth, windowHeight ); }
587 
590 inline Vec2i getWindowSize() { return App::get()->getWindowSize(); }
592 inline Vec2i getWindowPos() { return App::get()->getWindowPos(); }
594 inline float getWindowAspectRatio() { return App::get()->getWindowAspectRatio(); }
596 
597 inline Area getWindowBounds() { return App::get()->getWindowBounds(); }
599 inline float getWindowContentScale() { return App::get()->getWindowContentScale(); }
601 inline float getFrameRate() { return App::get()->getFrameRate(); }
603 inline void setFrameRate( float frameRate ) { App::get()->setFrameRate( frameRate ); }
605 inline bool isFullScreen() { return App::get()->isFullScreen(); }
607 inline void setFullScreen( bool fullScreen = true ) { App::get()->setFullScreen( fullScreen ); }
608 
610 inline float toPixels( float s ) { return getWindow()->toPixels( s ); }
612 inline Vec2f toPixels( Vec2f s ) { return getWindow()->toPixels( s ); }
614 inline Vec2i toPixels( Vec2i s ) { return app::getWindow()->toPixels( s ); }
616 inline Area toPixels( const Area &a ) { return getWindow()->toPixels( a ); }
618 inline Rectf toPixels( const Rectf &a ) { return getWindow()->toPixels( a ); }
620 inline float toPoints( float s ) { return getWindow()->toPoints( s ); }
622 inline Vec2f toPoints( Vec2f s ) { return getWindow()->toPoints( s ); }
624 inline Vec2i toPoints( Vec2i s ) { return getWindow()->toPoints( s ); }
626 inline Area toPoints( const Area &a ) { return getWindow()->toPoints( a ); }
628 inline Rectf toPoints( const Rectf &a ) { return getWindow()->toPoints( a ); }
629 
631 inline double getElapsedSeconds() { return App::get()->getElapsedSeconds(); }
633 inline uint32_t getElapsedFrames() { return App::get()->getElapsedFrames(); }
634 
636 inline DataSourceRef loadResource( const std::string &macPath, int mswID, const std::string &mswType ) { return App::loadResource( macPath, mswID, mswType ); }
637 #if defined( CINDER_COCOA )
638  inline DataSourceRef loadResource( const std::string &macPath ) { return App::loadResource( macPath ); }
640 #elif defined( CINDER_WINRT )
641  inline DataSourceRef loadResource( const std::string &assetPath ) { return App::get()->loadAsset( assetPath ); }
643 #elif defined( CINDER_MSW )
644  inline DataSourceRef loadResource( int mswID, const std::string &mswType ) { return App::loadResource( mswID, mswType ); }
646 #endif
647 
649 inline DataSourceRef loadAsset( const fs::path &relativePath ) { return App::get()->loadAsset( relativePath ); }
651 inline fs::path getAssetPath( const fs::path &relativePath ) { return App::get()->getAssetPath( relativePath ); }
653 inline void addAssetDirectory( const fs::path &dirPath ) { App::get()->addAssetDirectory( dirPath ); }
654 
656 inline fs::path getAppPath() { return App::get()->getAppPath(); }
658 
662 #if defined( CINDER_WINRT )
663 inline void getOpenFilePath( const fs::path &initialPath = "", std::vector<std::string> extensions = std::vector<std::string>(), std::function<void (fs::path)> f = nullptr ) { return App::get()->getOpenFilePath( initialPath, extensions, f ); }
664 #else
665 inline fs::path getOpenFilePath( const fs::path &initialPath = "", std::vector<std::string> extensions = std::vector<std::string>() ) { return App::get()->getOpenFilePath( initialPath, extensions ); }
666 #endif
667 
669 
672 #if defined( CINDER_WINRT )
673 inline fs::path getSaveFilePath( const fs::path &initialPath = "", std::vector<std::string> extensions = std::vector<std::string>(), std::function<void (fs::path)> f = nullptr) { App::get()->getSaveFilePath( initialPath, extensions, f ); }
674 #else
675 inline fs::path getSaveFilePath( const fs::path &initialPath = "", std::vector<std::string> extensions = std::vector<std::string>() ) { return App::get()->getSaveFilePath( initialPath, extensions ); }
676 #endif
677 
679 
682 inline std::ostream& console() { return App::get()->console(); }
683 
685 inline Timeline& timeline() { return App::get()->timeline(); }
686 
690 inline Surface copyWindowSurface( const Area &area ) { return App::get()->copyWindowSurface( area ); }
692 inline void restoreWindowContext() { return App::get()->restoreWindowContext(); }
693 
694 #if defined( CINDER_COCOA )
695 inline ::CGContextRef createWindowCgContext() { return (std::dynamic_pointer_cast<Renderer2d>(App::get()->getRenderer()))->getCgContext(); }
697 #endif
698 
700 
702 class ResourceLoadExc : public Exception {
703  public:
704 #if defined( CINDER_COCOA )
705  ResourceLoadExc( const std::string &macPath );
706 #elif defined( CINDER_MSW )
707  ResourceLoadExc( int mswID, const std::string &mswType );
708  ResourceLoadExc( const std::string &macPath, int mswID, const std::string &mswType );
709 #endif
710 
711  virtual const char * what() const throw() { return mMessage; }
712 
713  char mMessage[4096];
714 };
715 
717 class AssetLoadExc : public Exception {
718  public:
719  AssetLoadExc( const fs::path &relativePath );
720 
721  virtual const char * what() const throw() { return mMessage; }
722 
723  char mMessage[4096];
724 };
725 
726 } } // namespace cinder::app
void setFullScreen(bool fullScreen=true, const FullScreenOptions &options=FullScreenOptions())
Sets whether the Window will be created full-screen with FullScreenOptions options. Default is false. If true, FullScreenOptions mode defaults to kiosk.
Definition: Window.h:163
static bool isPrimaryThread()
Return true if the calling thread is the Application's primary thread.
Definition: App.cpp:491
void emitWillResignActive()
Definition: App.cpp:169
fs::path getOpenFilePath(const fs::path &initialPath="", std::vector< std::string > extensions=std::vector< std::string >())
Presents the user with a folder-open dialog and returns the selected folder path in the spcified call...
Definition: App.cpp:338
void setWindowPos(int x, int y)
Sets the coordinates of the top-left corner of the current window measured in points.
Definition: App.h:343
void enableMultiTouch(bool enable=true)
Registers the app to receive multiTouch events from the operating system. Disabled by default on desk...
Definition: App.h:190
void prepareWindow(const Window::Format &format)
Definition: App.cpp:96
float getFrameRate() const
maximum frameRate of the application specified in frames per second
Definition: App.h:211
GLenum GLint GLint y
Definition: GLee.h:987
virtual void mouseMove(MouseEvent event)
Override to receive mouse-move events.
Definition: App.h:257
signals::signal< void()> & getSignalShutdown()
Emitted prior to the application shutting down.
Definition: App.h:284
void enableHighDensityDisplay(bool enable=true)
Sets whether Windows created on a high-density (Retina) display will have their resolution doubled...
Definition: App.h:180
std::vector< Window::Format > mWindowFormats
Definition: App.h:220
fs::path getFolderPath(const fs::path &initialPath="")
Presents the user with a folder-open dialog and returns the selected folder.
Definition: App.cpp:386
virtual void update()
Override to perform any once-per-loop computation.
Definition: App.h:246
virtual const Settings & getSettings() const =0
void setWindowSize(const Vec2i &size)
Sets the size of the App's window measured in points. Ignored in full-screen mode.
Definition: App.h:322
void enable(GLenum state)
Enables the OpenGL State state. Equivalent to calling to glEnable( state );.
Definition: dx.h:198
fs::path getSaveFilePath(const fs::path &initialPath="", std::vector< std::string > extensions=std::vector< std::string >())
Presents the user with a file-save dialog and returns the selected file path.
Definition: App.h:675
Represents a mouse event.
Definition: MouseEvent.h:34
void setDefaultWindowFormat(const Window::Format &format)
Sets the Window::Format which will be used if no calls are made to Settings::prepareWindow() ...
Definition: App.h:187
Exception for failed asset loading.
Definition: App.h:717
float getWindowAspectRatio() const
Returns the aspect ratio of the App's current window.
Definition: App.h:329
Vec2< float > Vec2f
Definition: Vector.h:1314
virtual ~App()
Definition: App.cpp:122
Definition: Area.h:37
static App * sInstance
Definition: App.h:561
bool isFullScreen()
Returns whether the active App is in full-screen mode or not.
Definition: App.h:605
Returns true if all slots return true, else false. Does not short-circuit. Returns true if there are ...
Definition: App.h:95
bool mFrameRateEnabled
Definition: App.h:224
uint32_t getElapsedFrames() const
Returns the number of animation frames which have elapsed since application launch.
Definition: App.h:366
GLsizei const GLchar ** string
Definition: GLee.h:2427
virtual void keyUp(KeyEvent event)
Override to receive key-up events.
Definition: App.h:271
virtual fs::path getAppPath() const =0
Returns the path to the application on disk.
void dispatchAsync(const std::function< void()> &fn)
defined( CINDER_WINRT )
Definition: App.cpp:497
Options passed when entering fullscreen.
Definition: Window.h:110
Vec2i getPos() const
Returns the position in points measured relative to the system's primary display's upper-left corner ...
Definition: Window.h:178
Window::Format getDefaultWindowFormat() const
Returns the Window::Format which will be used if no calls are made to Settings::prepareWindow() ...
Definition: App.h:185
void enablePowerManagement(bool aPowerManagement=true)
a value of true allows screensavers or the system's power management to hide the app. Default value is false on desktop, and true on mobile
Definition: App.cpp:91
static DataSourceRef loadResource(const std::string &macPath, int mswID, const std::string &mswType)
Returns a DataSourceRef to an application resource. On Mac OS X, macPath is a path relative to the bu...
Definition: App.cpp:180
virtual void resize()
Override to receive window resize events.
Definition: App.h:273
int getWindowWidth()
Returns the width of the active App's window measured in points, or of the screen when in full-screen...
Definition: App.h:577
std::ostream & console()
Returns a reference to an output console, which is an alias to std::cout on the mac, and a wrapper around OutputDebugString on MSW.
Definition: App.cpp:480
void setDisplay(DisplayRef display)
Sets the Display the Window will be created on. Defaults to the primary display.
Definition: Window.h:155
virtual void draw()
Override to perform any rendering once-per-loop or in response to OS-prompted requests for refreshes...
Definition: App.h:248
Surface copyWindowSurface()
Returns a copy of the current window's contents as a Surface8u.
Definition: App.h:688
T operator()(InputIterator first, InputIterator last) const
Definition: App.h:115
Definition: App.h:129
virtual void setWindowPos(const Vec2i &windowPos)
Sets the coordinates of the top-left corner of the current window measured points.
Definition: App.h:345
void setAlwaysOnTop(bool alwaysOnTop=true)
Sets whether the Window created will always be above all other windows, including other applications'...
Definition: Window.h:223
void setFrameRate(float frameRate)
Sets maximum frameRate the update/draw loop will execute at, specified in frames per second...
Definition: App.cpp:86
GLuint index
Definition: GLee.h:2259
fs::path getAssetPath(const fs::path &relativePath)
Returns a fs::path to the active App's asset. Returns an empty path on failure.
Definition: App.h:651
bool isBorderless() const
Returns whether the default window will be created without a border (chrome/frame) ...
Definition: App.h:162
Timeline & timeline()
Returns a reference to the App's Timeline.
Definition: App.h:450
bool isPrepared() const
Definition: App.h:132
virtual void keyDown(KeyEvent event)
Override to receive key-down events.
Definition: App.h:269
float toPixels(float s)
Returns a scalar mapped from points to pixels for the current Window.
Definition: App.h:610
void disableFrameRate()
Disables the frameRate limiting, which is on by default. Restore using setFrameRate(). See also enableVerticalSync().
Definition: App.cpp:81
float mFrameRate
Definition: App.h:225
bool isBorderless() const
Returns whether the Window created will have no border. Defaults to false.
Definition: Window.h:215
bool isMultiTouchEnabled() const
Returns whether the app is registered to receive multiTouch events from the operating system...
Definition: App.h:192
char mMessage[4096]
Definition: App.h:713
int getWindowPosX() const
Returns the X coordinate of the top-left corner of the current window measured in points...
Definition: App.h:339
virtual float getFrameRate() const =0
Returns the maximum frame-rate the App will attempt to maintain.
void setFullScreen(bool fullScreen=true, const FullScreenOptions &options=FullScreenOptions())
Sets whether the default window is fullscreen at startup with FullScreenOptions options. Kiosk Mode is enabled by default.
Definition: App.h:155
virtual WindowRef getWindow() const =0
Returns the the currently active Window. Throws ExcInvalidWindow if called with no active window...
virtual void mouseDrag(MouseEvent event)
Override to receive mouse-drag events.
Definition: App.h:259
Exception for failed resource loading.
Definition: App.h:702
Area getWindowBounds() const
Returns the bounding area of the App's current window measured in points.
Definition: App.h:332
boost::asio::io_service & io_service()
Returns a reference to the App's boost::asio::io_service()
Definition: App.h:457
virtual void mouseDown(MouseEvent event)
Override to receive mouse-down events.
Definition: App.h:251
void addAssetDirectory(const fs::path &dirPath)
Adds an absolute path 'dirPath' to the list of directories which are searched for assets...
Definition: App.cpp:291
void setWindowSize(int windowWidth, int windowHeight)
Sets the size of the active App's window in points. Ignored in full-screen mode.
Definition: App.h:585
float getWindowAspectRatio()
Returns the aspect ratio of the active App's window or the screen in full-screen mode.
Definition: App.h:594
Surface copyWindowSurface()
Definition: App.cpp:510
void emitDidBecomeActive()
Definition: App.cpp:174
virtual void enablePowerManagement(bool powerManagement=true)
a value of true allows screensavers or the system's power management to hide the app. Default value is false on desktop, and true on mobile
Definition: App.h:311
double getSeconds() const
Returns the elapsed seconds if the timer is running, or the total time between calls to start() and s...
Definition: Timer.cpp:75
std::shared_ptr< Window > WindowRef
Definition: Event.h:49
virtual void quit()=0
Quits the application gracefully.
int getWindowWidth() const
Returns the width of the App's current window measured in points.
Definition: App.h:316
float getWindowContentScale() const
Returns the contentScale of the App's window, which is the multiplier that maps points to pixels...
Definition: App.h:334
AssetLoadExc(const fs::path &relativePath)
Definition: App.cpp:597
float toPoints(float s)
Returns a scalar mapped from pixels to points for the current Window.
Definition: App.h:620
char mMessage[4096]
Definition: App.h:723
void setWindowPos(const Vec2i &windowPos)
Sets the position of the active App's window measured in points. Ignored in full-screen mode...
Definition: App.h:579
float getWindowContentScale()
Returns the contentScale of the active App's window, which is the multiplier that maps points to pixe...
Definition: App.h:599
virtual void touchesMoved(TouchEvent event)
Override to respond to movement (drags) during a multitouch sequence.
Definition: App.h:264
bool isFullScreen() const
Returns whether the Window will be created full-screen. Default is false.
Definition: Window.h:159
void setBorderless(bool borderless=true)
Sets the default window to be created without a border (chrome/frame)
Definition: App.h:164
bool mPowerManagement
Definition: App.h:226
Vec2f getWindowCenter()
Returns the center of the active App's window in pixels or of the screen in full-screen mode...
Definition: App.h:588
Definition: App.h:127
RendererRef getRenderer() const
Returns the Renderer of the active Window.
Definition: App.h:299
const std::vector< Window::Format > & getWindowFormats() const
Definition: App.h:177
GLint * first
Definition: GLee.h:1725
virtual void mouseUp(MouseEvent event)
Override to receive mouse-up events.
Definition: App.h:253
std::vector< Window::Format > & getWindowFormats()
Definition: App.h:176
DataSourceRef loadAsset(const fs::path &relativePath)
Returns a DataSourceRef to the active App's's asset. Throws a AssetLoadExc on failure.
Definition: App.h:649
fs::path getAppPath()
Returns the path to the active App on disk.
Definition: App.h:656
void setWindowSize(const Vec2i &size)
Sets the size of the default window measured in pixels.
Definition: App.h:137
App()
Definition: App.cpp:103
float getAverageFps() const
Returns the average frame-rate attained by the App as measured in frames-per-second.
Definition: App.h:352
void unspecifyWindowPos()
Marks the window position setting as unspecified, effectively requesting the default.
Definition: App.h:150
int getWindowHeight()
Returns the height of the active App's window measured in points, or the screen when in full-screen m...
Definition: App.h:583
bool result_type
Definition: App.h:81
bool operator()(InputIterator first, InputIterator last) const
Definition: App.h:84
virtual size_t getNumWindows() const =0
Returns the number of Windows the app has open.
signals::signal< void()> & getSignalWillResignActive()
Definition: App.h:288
Vec2i getWindowSize()
Returns the size of the active App's window or the screen in full-screen mode measured in points...
Definition: App.h:590
DisplayRef getDisplay() const
Returns the Display of the active Window.
Definition: App.h:301
bool isFullScreen() const
Returns whether the App is in full-screen mode or not.
Definition: App.h:359
virtual WindowRef getWindowIndex(size_t index) const =0
Gets a Window by index, in the range [0, getNumWindows()). Throw ExcInvalidWindow if index is out of ...
bool isFullScreen()
Returns whether the default window is fullscreen.
Definition: App.h:153
bool isResizable() const
Returns whether the default window is resizable.
Definition: App.h:158
std::string mTitle
Definition: App.h:229
int getWindowHeight() const
Returns the height of the App's current window measured in points.
Definition: App.h:318
static App * get()
Returns a pointer to the active App.
Definition: App.h:510
GLenum GLint x
Definition: GLee.h:987
bool result_type
Definition: App.h:96
virtual ~Settings()
Definition: App.h:214
virtual bool isPowerManagementEnabled() const
is power management enabled, allowing screensavers and the system's power management to hide the appl...
Definition: App.h:313
std::shared_ptr< class Renderer > RendererRef
Definition: Renderer.h:85
Returns true if any slots return true, else false. Does not short-circuit. Returns true if there are ...
Definition: App.h:80
bool isResizable() const
Returns whether the Window created will be resizable. Defaults to true.
Definition: Window.h:209
WindowRef getWindow()
Returns the number of Windows the app has open.
Definition: App.h:570
void setSize(const Vec2i &size)
Sets the size in points at which the Window will be created. Default is 640 x 480.
Definition: Window.h:169
void setFrameRate(float frameRate)
Sets the maximum frame-rate the active App will attempt to maintain.
Definition: App.h:603
void emitShutdown()
Definition: App.cpp:162
virtual void mouseWheel(MouseEvent event)
Override to receive mouse-wheel events.
Definition: App.h:255
virtual void shutdown()
Override to perform any application cleanup before exiting.
Definition: App.h:243
void setTitle(const std::string &title)
the title of the app reflected in ways particular to the app type and platform (such as its Window or...
Definition: App.h:202
virtual void setFrameRate(float frameRate)=0
Sets the maximum frame-rate the App will attempt to maintain.
bool isPowerManagementEnabled() const
is power management enabled, allowing screensavers and the system's power management to hide the appl...
Definition: App.h:197
Vec2f getWindowCenter() const
Returns the center of the App's window measured in points.
Definition: App.h:325
void setAlwaysOnTop(bool alwaysOnTop=true)
Sets whether the default window always remains above all other windows.
Definition: App.h:168
bool isWindowPosSpecified() const
Returns whether a non-default window position has been requested.
Definition: App.h:148
bool isAlwaysOnTop() const
Returns whether the default window always remains above all other windows.
Definition: App.h:166
void setFullScreen(bool aFullScreen, const FullScreenOptions &options=FullScreenOptions())
Sets whether the active App is in full-screen mode based on fullScreen.
Definition: App.h:361
Returns a bitmask where in order for the bit in type T to be be 1, it has to be 1 from all slot...
Definition: App.h:111
Area getWindowBounds()
Returns the bounding area of the active App's window or the screen in full-screen mode measured in po...
Definition: App.h:597
RendererRef findSharedRenderer(RendererRef searchRenderer) const
Finds any Renderer of the same type as searchRenderer among existing windows. This is generally not n...
Definition: App.cpp:528
std::shared_ptr< class Display > DisplayRef
Definition: Display.h:53
T result_type
Definition: App.h:112
virtual const char * what() const
Definition: App.h:721
double getElapsedSeconds()
Returns the number seconds which have elapsed since the active App launched.
Definition: App.h:631
virtual bool receivesEvents() const
Definition: App.h:507
virtual const char * what() const
Definition: App.h:711
virtual void touchesEnded(TouchEvent event)
Override to respond to the end of a multitouch sequence.
Definition: App.h:266
void setBorderless(bool borderless=true)
Sets whether the Window created will have no border. Defaults to false.
Definition: Window.h:217
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:963
Definition: AppImplWinRT.h:49
Vec2i getSize() const
Returns the size in points at which the Window will be created. Default is 640 x 480.
Definition: Window.h:167
bool isAlwaysOnTop() const
Returns whether the Window created will always be above all other windows, including other applicatio...
Definition: Window.h:221
bool isFrameRateEnabled() const
Returns whether frameRate limiting is enabled. On by default, at 60 FPS.
Definition: App.h:209
Vec2i getWindowSize() const
Returns the size of the App's current window measured in points.
Definition: App.h:327
size_t getNumWindows()
Returns the number of Windows the app has open.
Definition: App.h:572
virtual void touchesBegan(TouchEvent event)
Override to respond to the beginning of a multitouch sequence.
Definition: App.h:262
Timeline & timeline()
Returns a reference to the active App's Timeline.
Definition: App.h:685
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
fs::path getOpenFilePath(const fs::path &initialPath="", std::vector< std::string > extensions=std::vector< std::string >())
Presents the user with a file-open dialog and returns the selected file path.
Definition: App.h:665
Represents a file-drop event, typically received from Windows Explorer or Mac OS X Finder...
Definition: FileDropEvent.h:36
bool isPosSpecified() const
Returns whether a non-default position has been requested for the Window.
Definition: Window.h:188
void setPos(const Vec2i &pos)
Sets the position in points measured relative to the system's primary display's upper-left corner at ...
Definition: Window.h:180
bool operator()(InputIterator first, InputIterator last) const
Definition: App.h:99
GLboolean GLboolean GLboolean GLboolean a
Definition: GLee.h:2964
uint32_t getElapsedFrames()
Returns the number of animation frames which have elapsed since the active App launched.
Definition: App.h:633
RendererRef mDefaultRenderer
Definition: App.h:562
Definition: Window.h:140
void setWindowPos(int windowPosX, int windowPosY)
Sets the position of the default window in screen coordinates measured in pixels. ...
Definition: App.h:144
void unspecifyPos()
Unspecifies a non-default position for the window, effectively requestion the default position...
Definition: Window.h:190
int getWindowPosY() const
Returns the Y coordinate of the top-left corner of the current window contents measured in points...
Definition: App.h:341
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
GLenum GLsizei GLenum format
Definition: GLee.h:969
void setWindowSize(int windowSizeX, int windowSizeY)
Sets the size of the default window measured in pixels.
Definition: App.h:135
double getElapsedSeconds() const
Returns the number of seconds which have elapsed since application launch.
Definition: App.h:364
bool mShouldQuit
Definition: App.h:217
double getFpsSampleInterval() const
Returns the sampling rate in seconds for measuring the average frame-per-second as returned by getAve...
Definition: App.h:354
DataSourceRef loadResource(const std::string &macPath, int mswID, const std::string &mswType)
Returns a DataSource to an application resource. On Mac OS X, macPath is a path relative to the bundl...
Definition: App.h:636
static Vec2i getMousePos()
Returns the current location of the mouse in screen coordinates measured in points. Can be called outside the normal event loop.
Definition: App.cpp:564
void setFpsSampleInterval(double sampleInterval)
Sets the sampling rate in seconds for measuring the average frame-per-second as returned by getAverag...
Definition: App.h:356
Vec2i getWindowPos()
Returns the position of the active App's window measured in points.
Definition: App.h:592
void addAssetDirectory(const fs::path &dirPath)
Adds an absolute path dirPath to the active App's list of directories which are searched for assets...
Definition: App.h:653
Definition: Exception.h:32
void restoreWindowContext()
Restores the current rendering context to be the App's window or the screen in full-screen mode...
Definition: App.cpp:521
A high-resolution timer class.
Definition: Timer.h:36
std::ostream & console()
Returns a reference to an output console, which is an alias to std::cout on the mac, and a wrapper around OutputDebugString on MSW.
Definition: App.h:682
virtual void setup()
Override to perform any application setup after the Renderer has been initialized.
Definition: App.h:241
void restoreWindowContext()
Restores the current rendering context to be the App's window or the screen in full-screen mode...
Definition: App.h:692
void setWindowSize(int windowWidth, int windowHeight)
Sets the size of the App's current window measured in points. Ignored in full-screen mode...
Definition: App.h:320
cinder::app::RendererRef getRenderer()
Definition: AppCocoaTouch.mm:1046
signals::signal< void()> & getSignalUpdate()
Emitted at the start of each application update cycle.
Definition: App.h:281
Vec2i getWindowPos() const
Returns tcoordinates of the top-left corner of the current window measured in points.
Definition: App.h:337
DisplayRef getDisplay() const
Returns the display for the default window.
Definition: App.h:171
bool mPowerManagement
Definition: App.h:563
std::result_of< T()>::type dispatchSync(T fn)
Definition: App.h:466
Vec2i getWindowPos() const
Returns the position of the default window in screen coordinates measured in pixels.
Definition: App.h:142
Represents a touch event.
Definition: TouchEvent.h:34
WindowRef getWindowIndex(size_t index)
Gets a Window by index, in the range [0, getNumWindows()).
Definition: App.h:574
const std::string & getTitle() const
the title of the app reflected in ways particular to the app type and platform (such as its Window or...
Definition: App.h:200
std::shared_ptr< class DataSource > DataSourceRef
Definition: DataSource.h:35
GLdouble s
Definition: GLee.h:1378
bool isHighDensityDisplayEnabled() const
Returns whether Windows created on a high-density (Retina) display will have their resolution doubled...
Definition: App.h:182
Definition: Timeline.h:42
bool mEnableHighDensityDisplay
Definition: App.h:227
GLenum GLint GLuint mask
Definition: GLee.h:2241
float getFrameRate()
Returns the maximum frame-rate the active App will attempt to maintain.
Definition: App.h:601
fs::path getSaveFilePath(const fs::path &initialPath="", std::vector< std::string > extensions=std::vector< std::string >())
Presents the user with a file-save dialog and returns the selected file path.
Definition: App.cpp:426
DataSourceRef loadAsset(const fs::path &relativePath)
Returns a DataSourceRef to an application asset. Throws a AssetLoadExc on failure.
Definition: App.cpp:277
Definition: AppImplMsw.h:63
void setResizable(bool resizable=true)
Sets the default window to be resizable or not.
Definition: App.h:160
GLclampf f
Definition: GLee.h:15307
RendererRef getDefaultRenderer() const
Returns the default Renderer which will be used when creating a new Window. Set by the app instantiat...
Definition: App.h:484
Represents a keyboard event.
Definition: KeyEvent.h:32
fs::path getAssetPath(const fs::path &relativePath)
Returns a fs::path to an application asset. Returns an empty path on failure.
Definition: App.cpp:286
signals::signal< void()> & getSignalDidBecomeActive()
Definition: App.h:290
Settings()
Definition: App.cpp:66
Definition: CinderView.h:54
GLsizeiptr size
Definition: GLee.h:2089
void setWindowPos(const Vec2i &windowPos)
Sets the position of the default window in screen coordinates measured in pixels. ...
Definition: App.h:146
const std::vector< TouchEvent::Touch > & getActiveTouches() const
Definition: App.h:294
Vec2i getWindowSize() const
Gets the size of the default window measured in pixels.
Definition: App.h:139
void setDisplay(DisplayRef display)
Sets the display for the default window.
Definition: App.h:173
Vec2< int > Vec2i
Definition: Vector.h:1313
void setFullScreen(bool fullScreen=true)
Sets whether the active App is in full-screen mode based on fullScreen.
Definition: App.h:607
virtual void fileDrop(FileDropEvent event)
Override to receive file-drop events.
Definition: App.h:275