5#include <SDL3/SDL_init.h>
6#include "SDL3pp_callbackWrapper.h"
7#include "SDL3pp_error.h"
8#include "SDL3pp_events.h"
10#include "SDL3pp_strings.h"
319inline void Quit() { SDL_Quit(); }
399 CheckError(SDL_RunOnMainThread(callback, userdata, wait_complete));
430 void* wrapped = Wrapper::Wrap(std::move(callback));
471 CheckError(SDL_SetAppMetadata(appname, appversion, appidentifier));
535 CheckError(SDL_SetAppMetadataProperty(name, value));
538namespace prop::appMetaData {
540constexpr auto NAME_STRING = SDL_PROP_APP_METADATA_NAME_STRING;
542constexpr auto VERSION_STRING = SDL_PROP_APP_METADATA_VERSION_STRING;
544constexpr auto IDENTIFIER_STRING = SDL_PROP_APP_METADATA_IDENTIFIER_STRING;
546constexpr auto CREATOR_STRING = SDL_PROP_APP_METADATA_CREATOR_STRING;
548constexpr auto COPYRIGHT_STRING = SDL_PROP_APP_METADATA_COPYRIGHT_STRING;
550constexpr auto URL_STRING = SDL_PROP_APP_METADATA_URL_STRING;
552constexpr auto TYPE_STRING = SDL_PROP_APP_METADATA_TYPE_STRING;
579 return SDL_GetAppMetadataProperty(name);
582#ifndef SDL3PP_APPCLASS_LOG_PRIORITY
586#define SDL3PP_APPCLASS_LOG_PRIORITY LOG_PRIORITY_CRITICAL
609 static_assert(std::is_default_constructible_v<T>);
615 requires std::convertible_to<AppArgs, T>
618 *state =
new T{args};
625concept HasInitFunction =
requires(T** state) {
626 { T::Init(state,
AppArgs{}) } -> std::convertible_to<AppResult>;
647 }
catch (std::exception& e) {
655template<HasInitFunction T>
663 }
catch (std::exception& e) {
674concept HasIterateFunction =
requires(T* state) { state->Iterate(); };
683template<HasIterateFunction T>
687 return state->Iterate();
688 }
catch (std::exception& e) {
698concept HasEventFunction =
699 requires(T* state,
const SDL_Event& event) { state->Event(event); };
712 if (event.type == SDL_EVENT_QUIT)
return APP_SUCCESS;
730 }
catch (std::exception& e) {
738template<HasEventFunction T>
742 return state->Event(event);
743 }
catch (std::exception& e) {
767concept HasQuitFunction =
768 requires(T* state,
AppResult result) { T::Quit(state, result); };
788template<HasQuitFunction T>
791 T::Quit(state, result);
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:197
SDL_Event Event
The structure for all events in SDL.
Definition: SDL3pp_events.h:798
void Init(InitFlags flags)
Initialize the SDL library.
Definition: SDL3pp_init.h:253
void SetAppMetadata(StringParam appname, StringParam appversion, StringParam appidentifier)
Specify basic metadata about your app.
Definition: SDL3pp_init.h:467
void QuitClass(T *state, AppResult result)
Destroy state with given result.
Definition: SDL3pp_init.h:783
AppResult(SDLCALL *)(void **appstate, int argc, char *argv[]) AppInit_func
Function pointer typedef for SDL_AppInit.
Definition: SDL3pp_init.h:152
AppResult IterateClass(T *state)
Iterate the state.
Definition: SDL3pp_init.h:684
InitFlags WasInit(InitFlags flags)
Get a mask of the specified subsystems which are currently initialized.
Definition: SDL3pp_init.h:301
std::function< void()> MainThreadCB
Callback run on the main thread.
Definition: SDL3pp_init.h:368
void InitSubSystem(InitFlags flags)
Compatibility function to initialize the SDL library.
Definition: SDL3pp_init.h:269
AppResult DefaultCreateClass(T **state, AppArgs args)
Allocate and initialize state with new.
Definition: SDL3pp_init.h:607
constexpr AppResult APP_FAILURE
Value that requests termination with error from the main callbacks.
Definition: SDL3pp_init.h:124
std::span< char const *const > AppArgs
Represents application parameters.
Definition: SDL3pp_init.h:592
constexpr AppResult APP_CONTINUE
Value that requests that the app continue from the main callbacks.
Definition: SDL3pp_init.h:118
const char * GetAppMetadataProperty(StringParam name)
Get metadata about your app.
Definition: SDL3pp_init.h:577
SDL_AppResult AppResult
Return values for optional main callbacks.
Definition: SDL3pp_init.h:115
void(SDLCALL *)(void *userdata) MainThreadCallback
Callback run on the main thread.
Definition: SDL3pp_init.h:354
void RunOnMainThread(MainThreadCallback callback, void *userdata, bool wait_complete)
Call a function on the main thread during event processing.
Definition: SDL3pp_init.h:395
AppResult DefaultEventClass(T *state, const SDL_Event &event)
Default handle by finishing if QUIT is requested.
Definition: SDL3pp_init.h:710
void DefaultClassDestroy(T *state)
Destroy state with delete;.
Definition: SDL3pp_init.h:760
AppResult(SDLCALL *)(void *appstate, Event *event) AppEvent_func
Function pointer typedef for SDL_AppEvent.
Definition: SDL3pp_init.h:183
void SetAppMetadataProperty(StringParam name, StringParam value)
Specify metadata about your app through a set of properties.
Definition: SDL3pp_init.h:533
#define SDL3PP_APPCLASS_LOG_PRIORITY
The default log priority for app class.
Definition: SDL3pp_init.h:586
AppResult EventClass(T *state, const SDL_Event &event)
Iterate the state.
Definition: SDL3pp_init.h:726
void Quit()
Clean up all initialized subsystems.
Definition: SDL3pp_init.h:319
void QuitSubSystem(InitFlags flags)
Shut down specific SDL subsystems.
Definition: SDL3pp_init.h:287
AppResult InitClass(T **state, AppArgs args)
Init state with arguments.
Definition: SDL3pp_init.h:643
void(SDLCALL *)(void *appstate, AppResult result) AppQuit_func
Function pointer typedef for SDL_AppQuit.
Definition: SDL3pp_init.h:197
bool IsMainThread()
Return whether this is the main thread.
Definition: SDL3pp_init.h:338
constexpr AppResult APP_SUCCESS
Value that requests termination with success from the main callbacks.
Definition: SDL3pp_init.h:121
AppResult(SDLCALL *)(void *appstate) AppIterate_func
Function pointer typedef for SDL_AppIterate.
Definition: SDL3pp_init.h:167
void LogUnformatted(LogPriority priority, StringParam message) const
Log an unformatted message with the specified priority.
Definition: SDL3pp_log.h:208
constexpr LogCategory LOG_CATEGORY_APPLICATION
APPLICATION.
Definition: SDL3pp_log.h:433
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:341
constexpr InitFlags INIT_SENSOR
INIT_SENSOR implies INIT_EVENTS
Definition: SDL3pp_init.h:83
Uint32 InitFlags
Initialization flags for Init and/or InitSubSystem.
Definition: SDL3pp_init.h:63
constexpr InitFlags INIT_JOYSTICK
INIT_JOYSTICK implies INIT_EVENTS
Definition: SDL3pp_init.h:73
constexpr InitFlags INIT_VIDEO
INIT_VIDEO implies INIT_EVENTS, should be initialized on the main thread
Definition: SDL3pp_init.h:71
constexpr InitFlags INIT_AUDIO
INIT_AUDIO implies INIT_EVENTS
Definition: SDL3pp_init.h:65
constexpr InitFlags INIT_EVENTS
EVENTS.
Definition: SDL3pp_init.h:81
constexpr InitFlags INIT_GAMEPAD
INIT_GAMEPAD implies INIT_JOYSTICK
Definition: SDL3pp_init.h:78
constexpr InitFlags INIT_HAPTIC
HAPTIC.
Definition: SDL3pp_init.h:76
constexpr InitFlags INIT_CAMERA
INIT_CAMERA implies INIT_EVENTS
Definition: SDL3pp_init.h:86
Main include header for the SDL3pp library.
Definition: SDL3pp_callbackWrapper.h:20