Banjo API 0.0.1
C99 game development API
Loading...
Searching...
No Matches
Windows

Enumerations

enum  bj_window_flag { BJ_WINDOW_FLAG_NONE = 0x00 , BJ_WINDOW_FLAG_CLOSE = 0x01 , BJ_WINDOW_FLAG_KEY_REPEAT = 0x02 , BJ_WINDOW_FLAG_ALL = 0xFF }

Functions

struct bj_windowbj_bind_window (const char *title, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t flags)
void bj_unbind_window (struct bj_window *window)
void bj_set_window_should_close (struct bj_window *window)
bj_bool bj_should_close_window (struct bj_window *window)
uint8_t bj_get_window_flags (struct bj_window *window, uint8_t flags)
int bj_get_key (const struct bj_window *window, int key)
int bj_get_window_size (const struct bj_window *window, int *width, int *height)

Detailed Description

Window creation and management API.

This module provides functions to create, destroy, and control application windows. It handles window properties such as position, size, flags, and attached framebuffers. It also provides input queries such as key state inspection.

Typical usage:

Banjo supports windows manipulation for Windows, GNU/Linux and WebAssembly.

Todo

Add support for windows on macOS

Add support for windows on Wayland

Enumeration Type Documentation

◆ bj_window_flag

A set of flags describing some properties of a bj_window.

These flags can be provided at window creation with bj_bind_window. The may also change during the window lifetime. You can use bj_get_window_flags to query the status of any flag on an active window instance.

Enumerator
BJ_WINDOW_FLAG_NONE 

No Flag.

BJ_WINDOW_FLAG_CLOSE 

Window should be closed by the application.

BJ_WINDOW_FLAG_KEY_REPEAT 

Key repeat event is enabled (see bj_set_key_callback).

BJ_WINDOW_FLAG_ALL 

All flags set.

Function Documentation

◆ bj_bind_window()

struct bj_window * bj_bind_window ( const char * title,
uint16_t x,
uint16_t y,
uint16_t width,
uint16_t height,
uint8_t flags )

Create a new struct bj_window with the specified attributes.

Parameters
titleTitle of the window
xHorizontal position of the window on-screen, expressed in pixels
yVertical position of the window on-screen, expressed in pixels
widthWidth of the window.
heightHeight of the window.
flagsA set of options flags.
Returns
A pointer to the newly created struct bj_window object.
Memory Management

The caller is responsible for releasing the returned bj_window object with bj_unbind_window.

◆ bj_get_key()

int bj_get_key ( const struct bj_window * window,
int key )

Query the current state of a key for a given window.

Returns the state of the specified key as either BJ_RELEASE or BJ_PRESS. If window is NULL or if key is outside the valid range [0, 0xFE], the function returns BJ_RELEASE.

Parameters
windowPointer to the target window, or NULL
keyKey code in [0, 0xFE]
Returns
BJ_PRESS if the key is currently pressed, BJ_RELEASE otherwise

◆ bj_get_window_flags()

uint8_t bj_get_window_flags ( struct bj_window * window,
uint8_t flags )

Get window flags.

This function returns all the flag sets for window. flags is a filter to only get the flag you are interested into. It can be a single flag, an OR'd combination of multiple flags or even BJ_WINDOW_FLAG_ALL if you want to retrieve them all.

Parameters
windowThe window handler.
flagsFilter flag set.
Returns
An OR'd combination of bj_window_flag filtered by flags.

◆ bj_get_window_size()

int bj_get_window_size ( const struct bj_window * window,
int * width,
int * height )

Retrieve the size of the window.

Parameters
windowThe window handler
widthA location to the destination width
heightA location to the destination height
Returns
1 on success, 0 on error.
Behaviour

The function performs nothing if window is 0.

width and height can be 0 if you are only interested in retrieving one of the values.

Memory Management

You are responsible for the memory of width and height.

◆ bj_set_window_should_close()

void bj_set_window_should_close ( struct bj_window * window)

Flag a given window to be closed.

Once, flagged, the window is not automatically closed. Instead, call bj_unbind_window.

Note that it is not possible to remove a closed flag once set.

Parameters
windowPointer to the window object to flag.
Remarks

This function effectively returns bj_get_window_flags(window, BJ_WINDOW_FLAG_CLOSE) > 0.

See also
bj_should_close_window

◆ bj_should_close_window()

bj_bool bj_should_close_window ( struct bj_window * window)

Get the close flag state of a window.

Parameters
windowPointer to the window object to flag.
Returns
true if the close flag is set, false otherwise.

If window is 0, the function returns BJ_TRUE.

See also
bj_set_window_should_close

◆ bj_unbind_window()

void bj_unbind_window ( struct bj_window * window)

Deletes a struct bj_window object and releases associated memory.

Parameters
windowPointer to the window object to delete.