window.md 2.7 KB

Window

Initializing

int ui_init(ui_t *ctx, int txtc, char **txtv, int w, int h, ui_image_t *icon);

Initializes the UI context and opens a window. The very first string in the txtv[] string array must be the window's title, the rest is up to you.

Parameter Description
ctx Pointer to UI context
txtc Number of strings
txtv Strings array for [localization]
w Window width
h Window height
icon Window icon image

Returns 0 on success, an error code otherwise.

Releasing

int ui_free(ui_t *ctx);

Closes the window and frees internal buffers.

Parameter Description
ctx Pointer to UI context

Returns 0 on success, an error code otherwise.

Fullscreen

int ui_fullscreen(ui_t *ctx);

Toggle context between fullscreen and windowed mode (after initialization it's windowed).

Parameter Description
ctx Pointer to UI context

Returns 0 on success, an error code otherwise.

Backend Window

void *ui_getwindow(ui_t *ctx);

In case there's a need, you can query the underlying backend's window handle with this function.

Parameter Description
ctx Pointer to UI context

Returns an implementation specific handle.

General Structure

General structure of your program should look like this:

/* UI context, one per window */
ui_t ctx;

/* provide a localization strings array */
enum { WINDOW_TITLE, HELLO_WORLD };
char *english[] = { "Window title", "Hello World!" };

/* open a window and initialize the context */
ui_init(&ctx, 2, english, 640, 480, NULL);

/* your main game loop */
do {
    /* do your thing, draw what you want to draw */
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    /* ... */

    /* get events and add an UI layer with your desired form on top */
    /* if this returns NULL, you should exit */
    if(!(evt = ui_event(&ctx, form))) break;

    /* parse the events */
    switch(evt->type) {
        case UI_EVT_KEY: /* key press */ break;
        case UI_EVT_MOUSE: /* mouse button event */ break;
        case UI_EVT_GAMEPAD: /* gamepad event */ break;
        /* ... */
    }
} while(1);

/* close the window */
ui_free(&ctx);