OpenEnroth 73e68f7
|
#include <Platform.h>
Public Member Functions | |
virtual | ~Platform ()=default |
virtual std::unique_ptr< PlatformWindow > | createWindow ()=0 |
virtual std::unique_ptr< PlatformEventLoop > | createEventLoop ()=0 |
virtual std::vector< PlatformGamepad * > | gamepads ()=0 |
virtual void | setCursorShown (bool cursorShown)=0 |
virtual bool | isCursorShown () const =0 |
virtual std::vector< Recti > | displayGeometries () const =0 |
virtual void | showMessageBox (const std::string &title, const std::string &message) const =0 |
virtual int64_t | tickCount () const =0 |
Static Public Member Functions | |
static std::unique_ptr< Platform > | createStandardPlatform () |
Platform abstraction layer.
Platform classes can be broadly divided into three categories:
API handles exposed by the platform are:
Platform
, which also works as a factory for other API handles.PlatformWindow
, an API handle for a GUI window.PlatformEventLoop
, an API handle for running an event loop.PlatformOpenGLContext
, an API handle for accessing OpenGL API for a window.Then there are the following extension points:
PlatformEventHandler
, which should be subclassed in user code to handle platform events. An instance is passed to PlatformEventLoop
methods, so this is where the calls back into the user code happen.That's it, there is only one extension point. If you want fancy event handler chains, you can use FilteringEventHandler
.
And then there are value types:
PlatformEvent
and subclasses for delivering events to PlatformEventHandler
.All platform classes don't throw but write errors to log instead. See per-method docs for details on how errors are reported by each method.
Also platform declares its own main
function, so you cannot declare main
in your code. Platform expects you to define platformMain
instead.
Some guidelines on adding new functionality to platform classes:
position
+ setPosition
+ framePosition
+ setFramePosition
for a window class, vs position
+ setPosition
+ frameMargins
. The latter set of methods is orthogonal, the former is not.SetFrameMargins
method because this is not how window frames work.
|
virtualdefault |
|
pure virtual |
Creates a new event loop.
nullptr
on error. Implemented in ApplicationProxy, NullPlatform, ProxyPlatform, and SdlPlatform.
|
static |
Creates a standard platform.
Platform
. This method is guaranteed to succeed.
|
pure virtual |
Creates a new platform window.
nullptr
on error. Implemented in ApplicationProxy, NullPlatform, ProxyPlatform, and SdlPlatform.
|
pure virtual |
Implemented in NullPlatform, ProxyPlatform, and SdlPlatform.
|
pure virtual |
This function lists the gamepads currently connected to the system. The gamepad objects themselves are owned by the platform and are destroyed automatically when disconnected. If you're caching them in your code, then make sure to subscribe to EVENT_GAMEPAD_DISCONNECTED
, it is guaranteed to fire before the gamepad object is destroyed.
Implemented in NullPlatform, ProxyPlatform, and SdlPlatform.
|
pure virtual |
Getter for setCursorShown
.
Implemented in NullPlatform, ProxyPlatform, and SdlPlatform.
|
pure virtual |
Shows / hides system cursor (on top of all windows created by this platform).
cursorShown | Whether to show the system cursor. |
Implemented in NullPlatform, ProxyPlatform, and SdlPlatform.
|
pure virtual |
Shows a modal message box.
title | Title of the message box window. |
message | Message to display. |
Implemented in NullPlatform, ProxyPlatform, and SdlPlatform.
|
pure virtual |
Implemented in EngineDeterministicComponent, NullPlatform, ProxyPlatform, and SdlPlatform.