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#ifdef SDL3PP_MAIN_HANDLED
5#define SDL_MAIN_HANDLED
6#endif // SDL3PP_MAIN_HANDLED
7
8#ifdef SDL3PP_MAIN_USE_CALLBACKS
9#define SDL_MAIN_USE_CALLBACKS
10#endif // SDL3PP_MAIN_USE_CALLBACKS
11
12#include <SDL3/SDL_main.h>
13#include "SDL3pp.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
102using main_func = int(SDLCALL*)(int argc, char* argv[]);
103
116inline void SetMainReady() { SDL_SetMainReady(); }
117
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
192#if defined(SDL_PLATFORM_WINDOWS)
193
218inline bool RegisterApp(StringParam name, Uint32 style, void* hInst)
219{
220 return SDL_RegisterApp(name, style, hInst);
221}
222
238inline void UnregisterApp() { SDL_UnregisterApp(); }
239
240#endif /* defined(SDL_PLATFORM_WINDOWS) */
241
250inline void GDKSuspendComplete() { SDL_GDKSuspendComplete(); }
251
256#define SDL3PP_DEFINE_CALLBACKS(CLASS) \
257 static_assert(SDL::HasIterateFunction<CLASS>, "Main class not compatible"); \
258 inline SDL::AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) \
259 { \
260 return SDL::InitClass(reinterpret_cast<CLASS**>(appstate), \
261 SDL::AppArgs{argv, size_t(argc)}); \
262 } \
263 inline SDL::AppResult SDL_AppIterate(void* appstate) \
264 { \
265 return SDL::IterateClass(static_cast<CLASS*>(appstate)); \
266 } \
267 inline SDL::AppResult SDL_AppEvent(void* appstate, SDL::Event* event) \
268 { \
269 return SDL::EventClass(static_cast<CLASS*>(appstate), *event); \
270 } \
271 inline void SDL_AppQuit(void* appstate, SDL::AppResult result) \
272 { \
273 SDL::QuitClass(static_cast<CLASS*>(appstate), result); \
274 }
275
277
278} // namespace SDL
279
280#endif /* SDL3PP_MAIN_H_ */
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
AppResult(SDLCALL *)(void **appstate, int argc, char *argv[]) AppInit_func
Function pointer typedef for SDL_AppInit.
Definition: SDL3pp_init.h:152
AppResult(SDLCALL *)(void *appstate, Event *event) AppEvent_func
Function pointer typedef for SDL_AppEvent.
Definition: SDL3pp_init.h:183
void(SDLCALL *)(void *appstate, AppResult result) AppQuit_func
Function pointer typedef for SDL_AppQuit.
Definition: SDL3pp_init.h:197
AppResult(SDLCALL *)(void *appstate) AppIterate_func
Function pointer typedef for SDL_AppIterate.
Definition: SDL3pp_init.h:167
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 Init() when not using SDL_main() as an entry point.
Definition: SDL3pp_main.h:116
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 SDL3PP_MAIN_USE_CALLBACKS.
Definition: SDL3pp_main.h:181
void UnregisterApp()
Deregister the win32 window class from an RegisterApp call.
Definition: SDL3pp_main.h:238
int(SDLCALL *)(int argc, char *argv[]) main_func
The prototype for the application's main() function.
Definition: SDL3pp_main.h:102
void GDKSuspendComplete()
Callback from the application to let the suspend continue.
Definition: SDL3pp_main.h:250
bool RegisterApp(StringParam name, Uint32 style, void *hInst)
Register a win32 window class for SDL's use.
Definition: SDL3pp_main.h:218
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:341
Main include header for the SDL3pp library.