Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/DREssedAlarm184/LWXGL/llms.txt

Use this file to discover all available pages before exploring further.

LWXGL has a built-in modal dialog system that renders a centered dialog box over the window content, blocking all element interaction until the user dismisses it. While a modal is active, button onclick callbacks and keyboard input handlers are suppressed — only the modal’s own OK and Cancel controls respond to clicks.

Spawning a modal

void GSpawnModal(int type, const char* msg, void (*on_confirm)(void));
ParameterDescription
type0 — alert (OK button only); 1 — confirm (OK + Cancel buttons)
msgMessage text. Supports \n for line breaks. Lines longer than ~31 characters are truncated at the right edge of the dialog.
on_confirmCallback invoked when the user clicks OK. Pass NULL for informational alerts.
void do_delete(void) {
    // User confirmed — proceed with deletion
    delete_record(selected_id);
}

// Trigger a confirmation dialog:
GSpawnModal(1, "Delete this record?\nThis cannot be undone.", do_delete);
Clicking Cancel (type 1 only) dismisses the modal without invoking on_confirm. Clicking OK dismisses the modal and, if on_confirm is not NULL, calls it immediately.

Checking modal state

int GQueryModalOpen(void);
Returns 1 if a modal is currently displayed, 0 otherwise. You can use this to pause game logic or skip input processing while the dialog is open. The modal is rendered as a fixed-size centered box (306 × 156 pixels, positioned near the top-center of the window). The message text starts at the top-left of the dialog interior and wraps on \n characters, with each line 15 pixels tall. Button labels are positioned in the lower-right area of the dialog:
  • OK is rendered in palette color 10 (bright green by default).
  • Cancel (type 1 only) is rendered in palette color 12 (bright red by default).

Usage pattern in a game loop

When using GSimpleWindowLoop, integrate modal awareness into your per-frame callback to prevent game state from advancing while the dialog is visible:
void on_every(int tick, float dt) {
    if (!GQueryModalOpen()) {
        // Normal per-frame game logic — only runs when no modal is open
        update_game(dt);
        handle_player_input();
    }
    // Per-frame rendering (GRenderWindow) runs unconditionally;
    // the modal is drawn on top of the scene automatically.
}
Only one modal can be active at a time. Calling GSpawnModal while a modal is already open immediately replaces it — the previous message and callback are discarded.
For purely informational messages that require no action beyond acknowledgment, pass NULL as on_confirm and use type = 0:
GSpawnModal(0, "Settings saved successfully.", NULL);

Build docs developers (and LLMs) love