sdl

r_sdl_init

r_sdl_frontend* r_sdl_init(const char* title, int w, int h, int flags);

Creates the main window, the rcut context, a software renderer and the default theme, returns NULL on failure. Build the main window's UI into r_sdl_frontend.root. Sizes are in logical pixels, high DPI is handled automatically.

Parameter
flagsCombination of r_sdl_flags, 0 for a visible window of fixed size.
r_sdl_frontend* app = r_sdl_init("Hello", 320, 200, R_SDL_RESIZABLE);
while(!r_sdl_quit_requested(app, true))
{
	SDL_Event e;
	if(SDL_WaitEventTimeout(&e, 50))
		do r_sdl_process_event(app, &e); while(SDL_PollEvent(&e));
	if(app->root->resized)
	{
		r_list_clear(app->root);
		r_label(app->root, app->root->root_area, "Hello");
	}
	r_sdl_update(app);
	r_sdl_render_ui(app);
}
r_sdl_free(app);

A minimal main loop, rebuilding when the window size changes.

See also: r_sdl_free, r_sdl_update

Concepts: frontend, context

r_sdl_flags

enum r_sdl_flags
{
	R_SDL_RESIZABLE = 1 << 0,
	R_SDL_VSYNC     = 1 << 1,
	R_SDL_HIDDEN    = 1 << 2,
};

r_sdl_frontend

typedef struct r_sdl_frontend
{
	r_draw    draw;
	r_context context;
	r_draw_software software;

	r_sdl_window windows[RCUT_SDL_MAX_WINDOWS];
	r_ui_list* root;
	uint64_t last_tick_time;
	bool no_popup_windows;
	bool quit_requested;
	SDL_Window* text_input_window;
	bool vsync;
	char* clipboard;
	int   cursor;
	SDL_Cursor* cursors[8];
} r_sdl_frontend;

The remaining fields are internal.

r_sdl_process_event

bool r_sdl_process_event(r_sdl_frontend* c, SDL_Event* e);

Forwards an SDL event to rcut: mouse, keyboard, text input, resizes and close requests. Returns true if rcut used it. Pass all events, unrelated ones are ignored.

Right Alt is AltGr on many layouts, it doesn't enter accelerator mode.

Concepts: frontend, input

r_sdl_close_requested

bool r_sdl_close_requested(r_sdl_frontend* c, r_ui_list* dialog, bool clear);

Returns true if the user requested to close the dialog window, clear resets the request, popup windows are closed automatically instead.

See also: r_sdl_dialog, r_destroy_ui_list

Concepts: frontend, target

r_sdl_update

void r_sdl_update(r_sdl_frontend* c);

Advances timers (hover delay, key repeat, caret blinking), removes expired ephemerals, updates the mouse cursor and starts or stops SDL text input. Call it once per loop iteration after processing events.

Concepts: frontend, rebuild

r_sdl_render_ui

void r_sdl_render_ui(r_sdl_frontend* c);

Draws all windows. Only damaged areas are redrawn, calling it every iteration is cheap if nothing changed.

Concepts: frontend, draw-context

r_sdl_screenshot

bool r_sdl_screenshot(r_sdl_frontend* c, const char* path);

Renders the main window and saves it to path as PNG (BMP before SDL 3.4), returns false on failure.

See also: r_sdl_render_ui

Concepts: frontend, draw-context

r_sdl_free

void r_sdl_free(r_sdl_frontend* c);

Frees the frontend and closes all its windows.

See also: r_sdl_init

Concepts: frontend

r_sdl_quit_requested

bool r_sdl_quit_requested(r_sdl_frontend* c, bool clear);

Returns true if the user requested to quit, clear resets the request.

See also: r_sdl_process_event, r_sdl_close_requested

Concepts: frontend

r_sdl_dialog

r_ui_list* r_sdl_dialog(r_sdl_frontend* c, uint64_t root_id, int w, int h, const char* title);

Opens a new window and returns its root list, root_id being the ID of its root area. The list is modal. Build into it like into r_sdl_frontend.root and close it with r_destroy_ui_list, e.g. once r_sdl_close_requested returns true. If no window is available it is shown centered in the main window instead.

Concepts: frontend, target, ui_list

RCUT_SDL_MAX_WINDOWS

#define RCUT_SDL_MAX_WINDOWS 128

Maximum number of windows, including popup windows.

See also: r_sdl_dialog

RCUT_SDL_CACHE_PIXELS

#define RCUT_SDL_CACHE_PIXELS (2048 * 2048) // Software cache shared by all windows, it must hold everything a frame uses.

Size in pixels of the software cache shared by all windows, it must hold everything a frame uses.

See also: r_draw_software_init