SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_main.h
1#ifndef SDL3PP_MAIN_H_
2#define SDL3PP_MAIN_H_
3
4#include "SDL3pp.h"
5#ifdef SDL3PP_MAIN_HANDLED
6#define SDL_MAIN_HANDLED
7#endif // SDL3PP_MAIN_HANDLED
8
9#ifdef SDL3PP_MAIN_USE_CALLBACKS
10#define SDL_MAIN_USE_CALLBACKS
11#endif // SDL3PP_MAIN_USE_CALLBACKS
12
13#include <SDL3/SDL_main.h>
14
15namespace SDL {
16
50#ifdef SDL3PP_DOC
51
66#define SDL3PP_MAIN_HANDLED SDL_MAIN_HANDLED
67
88#define SDL3PP_MAIN_USE_CALLBACKS SDL_MAIN_USE_CALLBACKS
89
90#endif // SDL3PP_DOC
91
103using main_func = SDL_main_func;
104
118inline void SetMainReady() { return SDL_SetMainReady(); }
119
148inline int RunApp(int argc,
149 char* argv[],
150 main_func mainFunction,
151 void* reserved)
152{
153 return SDL_RunApp(argc, argv, mainFunction, reserved);
154}
155
181inline int EnterAppMainCallbacks(int argc,
182 char* argv[],
183 AppInit_func appinit,
184 AppIterate_func appiter,
185 AppEvent_func appevent,
186 AppQuit_func appquit)
187{
188 return SDL_EnterAppMainCallbacks(
189 argc, argv, appinit, appiter, appevent, appquit);
190}
191
200inline void GDKSuspendComplete() { return SDL_GDKSuspendComplete(); }
201
210#define SDL3PP_DEFINE_CALLBACKS(CLASS, APPNAME, APPVERSION, APPID) \
211 static_assert(SDL::HasIterateFunction<CLASS>, "Main class not compatible"); \
212 inline SDL::AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) \
213 { \
214 if (APPNAME) { \
215 SDL::SetAppMetadata(APPNAME, APPVERSION ?: "1.0", APPID ?: APPNAME); \
216 } \
217 return SDL::InitClass(reinterpret_cast<CLASS**>(appstate), \
218 SDL::AppArgs{argv, size_t(argc)}); \
219 } \
220 inline SDL::AppResult SDL_AppIterate(void* appstate) \
221 { \
222 return SDL::IterateClass(static_cast<CLASS*>(appstate)); \
223 } \
224 inline SDL::AppResult SDL_AppEvent(void* appstate, SDL::Event* event) \
225 { \
226 return SDL::EventClass(static_cast<CLASS*>(appstate), *event); \
227 } \
228 inline void SDL_AppQuit(void* appstate, SDL::AppResult result) \
229 { \
230 SDL::QuitClass(static_cast<CLASS*>(appstate), result); \
231 }
232
234
235} // namespace SDL
236
237#endif /* SDL3PP_MAIN_H_ */
SDL_AppIterate_func AppIterate_func
Function pointer typedef for SDL_AppIterate.
Definition SDL3pp_init.h:195
SDL_AppInit_func AppInit_func
Function pointer typedef for SDL_AppInit.
Definition SDL3pp_init.h:180
SDL_AppEvent_func AppEvent_func
Function pointer typedef for SDL_AppEvent.
Definition SDL3pp_init.h:211
SDL_AppQuit_func AppQuit_func
Function pointer typedef for SDL_AppQuit.
Definition SDL3pp_init.h:225
int RunApp(int argc, char *argv[], main_func mainFunction, void *reserved)
Initializes and launches an SDL application, by doing platform-specific initialization before calling...
Definition SDL3pp_main.h:148
void SetMainReady()
Circumvent failure of SDL_Init() when not using SDL_main() as an entry point.
Definition SDL3pp_main.h:118
int EnterAppMainCallbacks(int argc, char *argv[], AppInit_func appinit, AppIterate_func appiter, AppEvent_func appevent, AppQuit_func appquit)
An entry point for SDL's use in SDL_MAIN_USE_CALLBACKS.
Definition SDL3pp_main.h:181
SDL_main_func main_func
The prototype for the application's main() function.
Definition SDL3pp_main.h:103
void GDKSuspendComplete()
Callback from the application to let the suspend continue.
Definition SDL3pp_main.h:200
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7