Base class that all apps derive from.
Public Member Functions
-
~AppBase ()
-
voidsetup ()
Override to perform any application setup after the Renderer has been initialized.
-
voidupdate ()
Override to perform any once-per-loop computation.
-
voiddraw ()
Override to perform any rendering once-per-loop or in response to OS-prompted requests for refreshes.
-
voidmouseDown (MouseEvent event)
Override to receive mouse-down events.
-
voidmouseUp (MouseEvent event)
Override to receive mouse-up events.
-
voidmouseWheel (MouseEvent event)
Override to receive mouse-wheel events.
-
voidmouseMove (MouseEvent event)
Override to receive mouse-move events.
-
voidmouseDrag (MouseEvent event)
Override to receive mouse-drag events.
-
voidtouchesBegan (TouchEvent event)
Override to respond to the beginning of a multitouch sequence.
-
voidtouchesMoved (TouchEvent event)
Override to respond to movement (drags) during a multitouch sequence.
-
voidtouchesEnded (TouchEvent event)
Override to respond to the end of a multitouch sequence.
-
voidkeyDown (KeyEvent event)
Override to receive key-down events.
-
voidkeyUp (KeyEvent event)
Override to receive key-up events.
-
voidresize ()
Override to receive window resize events.
-
voidfileDrop (FileDropEvent event)
Override to receive file-drop events.
-
voidcleanup ()
Override to cleanup any resources before app destruction.
-
voidquit ()=0
Requests that the application exit gracefully upon completion of the current event loop. Use std::terminate() instead to end application immediately.
-
signals::Signal< void()> &getSignalUpdate ()
Emitted at the start of each application update cycle.
-
EventSignalShouldQuit &getSignalShouldQuit ()
Signal that emits before the app quit process begins. If any slots return false then the app quitting is canceled.
-
signals::Signal< void()> &getSignalCleanup ()
Emitted prior to the application shutting down.
-
voidemitCleanup ()
-
signals::Signal< void()> &getSignalWillResignActive ()
-
voidemitWillResignActive ()
-
signals::Signal< void()> &getSignalDidBecomeActive ()
-
voidemitDidBecomeActive ()
-
signals::Signal< void(const DisplayRef &display)> &getSignalDisplayConnected ()
Emitted when a new display is connected to the system.
-
voidemitDisplayConnected (const DisplayRef &display)
Emits a signal indicating a new display has connected to the system.
-
signals::Signal< void(const DisplayRef &display)> &getSignalDisplayDisconnected ()
Emitted when a display is removed from the system.
-
voidemitDisplayDisconnected (const DisplayRef &display)
Emits a signal indicating a display has disconnected from the system.
-
signals::Signal< void(const DisplayRef &display)> &getSignalDisplayChanged ()
Emitted when the resolution or some other property of a Display is changed.
-
voidemitDisplayChanged (const DisplayRef &display)
Emits a signal when the resolution or some other property of a Display has changed.
-
const std::vector< TouchEvent::Touch > &getActiveTouches () const
-
createWindow (const Window::Format &format=Window::Format())=0
Creates and returns a reference to a new Window , adhering to format .
-
getWindow () const =0
Returns the the currently active Window . Throws ExcInvalidWindow if called with no active window.
-
getForegroundWindow () const =0
Gets the foreground Window , which has keyboard and mouse focus.
-
size_tgetNumWindows () const =0
Returns the number of Windows the app has open.
-
getWindowIndex (size_t index) const =0
Gets a Window by index, in the range [0, getNumWindows() ). Throw ExcInvalidWindow if index is out of bounds.
-
ivec2getMousePos () const =0
Returns the current location of the mouse in screen coordinates measured in points. Can be called outside the normal event loop.
-
voidhideCursor ()=0
Hides the mouse cursor.
-
voidshowCursor ()=0
Shows the mouse cursor.
-
voidenablePowerManagement (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, andtrue
on mobile -
boolisPowerManagementEnabled () const
is power management enabled, allowing screensavers and the system's power management to hide the application
-
intgetWindowWidth () const
Returns the width of the App's current window measured in points.
-
intgetWindowHeight () const
Returns the height of the App's current window measured in points.
-
voidsetWindowSize (int windowWidth, int windowHeight)
Sets the size of the App's current window measured in points. Ignored in full-screen mode.
-
voidsetWindowSize (const ivec2 &size)
Sets the size of the App's window measured in points. Ignored in full-screen mode.
-
vec2getWindowCenter () const
Returns the center of the App's window measured in points.
Equivalent to
vec2( getWindowWidth() * 0.5, getWindowHeight() * 0.5 )
-
ivec2getWindowSize () const
Returns the size of the App's current window measured in points.
-
floatgetWindowAspectRatio () const
Returns the aspect ratio of the App's current window.
-
getWindowBounds () const
Returns the bounding area of the App's current window measured in points.
Equivalent to
Area ( 0, 0, getWindowWidth() , getWindowHeight() );
-
floatgetWindowContentScale () const
Returns the contentScale of the App's window, which is the multiplier that maps points to pixels.
-
ivec2getWindowPos () const
Returns tcoordinates of the top-left corner of the current window measured in points.
-
intgetWindowPosX () const
Returns the X coordinate of the top-left corner of the current window measured in points.
-
intgetWindowPosY () const
Returns the Y coordinate of the top-left corner of the current window contents measured in points.
-
voidsetWindowPos (int x, int y)
Sets the coordinates of the top-left corner of the current window measured in points.
-
voidsetWindowPos (const ivec2 &windowPos)
Sets the coordinates of the top-left corner of the current window measured points.
-
floatgetFrameRate () const =0
Returns the maximum frame-rate the App will attempt to maintain.
-
voidsetFrameRate (float frameRate)=0
Sets the maximum frame-rate the App will attempt to maintain.
-
voiddisableFrameRate ()=0
Disables frameRate limiting.
-
boolisFrameRateEnabled () const =0
Returns whether frameRate limiting is enabled.
-
floatgetAverageFps () const
Returns the average frame-rate attained by the App as measured in frames-per-second.
-
doublegetFpsSampleInterval () const
Returns the sampling rate in seconds for measuring the average frame-per-second as returned by getAverageFps()
-
voidsetFpsSampleInterval (double sampleInterval)
Sets the sampling rate in seconds for measuring the average frame-per-second as returned by getAverageFps()
-
boolisFullScreen () const
Returns whether the App is in full-screen mode or not.
-
voidsetFullScreen (bool fullScreen, const FullScreenOptions &options=FullScreenOptions())
Sets whether the active App is in full-screen mode based on fullScreen .
-
doublegetElapsedSeconds () const
Returns the number of seconds which have elapsed since application launch.
-
uint32_tgetElapsedFrames () const
Returns the number of animation frames which have elapsed since application launch.
-
boolisMultiTouchEnabled () const
Returns whether the app is registered to receive multiTouch events from the operating system, configurable via Settings at startup. Disabled by default on desktop platforms, enabled on mobile.
-
bool
-
loadResource (const fs::path &resourcePath) const
-
loadAsset (const fs::path &relativePath)
Returns a DataSourceRef to an application asset. Throws a AssetLoadExc on failure.
-
fs::pathgetAssetPath (const fs::path &relativePath) const
Returns a fs::path to an application asset. Returns an empty path on failure.
-
voidaddAssetDirectory (const fs::path &dirPath)
Adds an absolute path 'dirPath' to the list of directories which are searched for assets.
-
fs::pathgetAppPath () const
Returns the path to the application on disk.
-
fs::pathgetOpenFilePath (const fs::path &initialPath=fs::path(), const std::vector< std::string > &extensions=std::vector< std::string >())
Presents the user with an open-file dialog and returns the selected file path.
The dialog optionally begins at the path initialPath and can be limited to allow selection of files ending in the extensions enumerated in extensions .
the selected file path, or an empty fs::path if the user cancelled or this operation isn't supported on the current platform.
-
fs::pathgetFolderPath (const fs::path &initialPath=fs::path())
Presents the user with an open-folder dialog.
the selected file path, or an empty fs::path if the user cancelled or this operation isn't supported on the current platform.
-
fs::pathgetSaveFilePath (const fs::path &initialPath=fs::path(), const std::vector< std::string > &extensions=std::vector< std::string >())
Presents the user with a save-file dialog and returns the selected file path.
The dialog optionally begins at the path initialPath and can be limited to allow selection of files ending in the extensions enumerated in extensions .
the selected file path, or an empty fs::path if the user cancelled or this operation isn't supported on the current platform.
-
std::ostream &console ()
Returns a reference to an output console, which is by default an alias to std::cout. Other platforms may override to use other necessary console mechanisms.
-
const std::vector< std::string > &getCommandLineArgs () const
Returns a vector of the command line arguments passed to the app when intantiated.
-
Timeline &timeline ()
Returns a reference to the App's Timeline .
-
asio::io_context &io_context ()
Returns a reference to the App's boost::asio::io_service()
-
voiddispatchAsync (const std::function< void()> &fn)
Executes a std::function on the App's primary thread ahead of the next update()
-
decltype(std::declval< T >()())dispatchSync (T fn)
-
copyWindowSurface ()
a copy of the current window's contents as a Surface8u
-
copyWindowSurface (const Area &area)
a copy of the Area area (measured in pixels) from the current window's contents as a Surface8u
-
voidrestoreWindowContext ()
Restores the current rendering context to be the App's window or the screen in full-screen mode. Generally this is only necessary if the app has displayed a dialog box or some other external window.
-
boolreceivesEvents () const
Static Public Member Functions
-
boolisMainThread ()
Returns
true
if the calling thread is the Application's main thread (the thread running the main function), false otherwise. -
AppBase *get ()
Returns a pointer to the active App.