Banjo API 0.0.1
Multi-purpose C99 API
Loading...
Searching...
No Matches
Windows
Collaboration diagram for Windows:

Detailed Description

Typedefs

typedef struct bj_window_t bj_window
 Opaque typedef for the window type.
 
typedef enum bj_window_flag_t bj_window_flag
 A set of flags describing some properties of a bj_window.
 
typedef void(* bj_window_enter_event_t) (bj_window *p_window, bj_bool enter, int x, int y)
 Callback type for functions called when the mouse cursor enters a window.
 
typedef void(* bj_window_cursor_event_t) (bj_window *p_window, int x, int y)
 Callback type for functions called when the mouse cursor position changes.
 
typedef void(* bj_window_button_event_t) (bj_window *p_window, int, bj_event_action action, int x, int y)
 Callback type for functions called when a mouse button is pressed or released.
 
typedef void(* bj_window_key_event_t) (bj_window *p_window, bj_event_action action, bj_key key, int scancode)
 Callback type for functions called when a keyboard key is pressed or released.
 

Enumerations

enum  bj_window_flag_t { BJ_WINDOW_FLAG_NONE = 0x00 , BJ_WINDOW_FLAG_CLOSE = 0x01 , BJ_WINDOW_FLAG_KEY_REPEAT = 0x02 , BJ_WINDOW_FLAG_ALL = 0xFF }
 A set of flags describing some properties of a bj_window. More...
 

Functions

bj_windowbj_window_new (const char *p_title, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t flags)
 Create a new bj_window with the specified attributes.
 
void bj_window_del (bj_window *p_window)
 Deletes a bj_window object and releases associated memory.
 
void bj_window_set_should_close (bj_window *p_window)
 Flag a given window to be closed.
 
bj_bool bj_window_should_close (bj_window *p_window)
 Get the close flag state of a window.
 
bj_window_cursor_event_t bj_window_set_cursor_event (bj_window *p_window, bj_window_cursor_event_t p_callback)
 Set the callback for cursor events.
 
bj_window_button_event_t bj_window_set_button_event (bj_window *p_window, bj_window_button_event_t p_callback)
 Set the callback for button events.
 
bj_window_key_event_t bj_window_set_key_event (bj_window *p_window, bj_window_key_event_t p_callback)
 Set the callback for key events.
 
void bj_close_on_escape (bj_window *, bj_event_action, bj_key, int)
 An event call back for closing the window when escape key is pressed.
 
bj_window_enter_event_t bj_window_set_enter_event (bj_window *p_window, bj_window_enter_event_t p_callback)
 Set the callback for enter events.
 
uint8_t bj_window_get_flags (bj_window *p_window, uint8_t flags)
 Get window flags.
 
void bj_poll_events (void)
 Polls all pending events and dispatch them to callbacks.
 
bj_bitmapbj_window_get_framebuffer (bj_window *p_window, bj_error **p_error)
 Return the framebuffer attached to the window.
 
int bj_window_get_size (const bj_window *p_window, int *width, int *height)
 Retrieve the size of the window.
 
void bj_window_update_framebuffer (bj_window *p_window)
 Copy window's framebuffer onto screen.
 

Typedef Documentation

◆ bj_window_button_event_t

typedef void(* bj_window_button_event_t) (bj_window *p_window, int, bj_event_action action, int x, int y)
Parameters
p_windowWindow handle
actionSets if the button is pressed or released
xThe horizontal position of the cursor
yThe vertical position of the cursor
See also
bj_window_set_button_event

◆ bj_window_cursor_event_t

typedef void(* bj_window_cursor_event_t) (bj_window *p_window, int x, int y)
Parameters
p_windowWindow handle
xThe horizontal position of the cursor
yThe vertical position of the cursor
See also
bj_window_set_cursor_event

◆ bj_window_enter_event_t

typedef void(* bj_window_enter_event_t) (bj_window *p_window, bj_bool enter, int x, int y)
Parameters
p_windowWindow handle
entertrue if the cursor enters the window, false otherwise.
xThe horizontal position of the cursor
yThe vertical position of the cursor
See also
bj_window_set_enter_event

◆ bj_window_flag

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

◆ bj_window_key_event_t

typedef void(* bj_window_key_event_t) (bj_window *p_window, bj_event_action action, bj_key key, int scancode)
Parameters
p_windowWindow handle
actionSets if the button is pressed or released
keyLayout-dependent representation of the pressed key
scancodeImplementation-dependent / Layout-independent representation of the key that has been pressed or released.
See also
bj_window_set_key_event

Enumeration Type Documentation

◆ bj_window_flag_t

These flags can be provided at window creation with bj_window_new. The may also change during the window lifetime. You can use bj_window_get_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_window_set_key_event).

BJ_WINDOW_FLAG_ALL 

All flags set.

Function Documentation

◆ bj_close_on_escape()

void bj_close_on_escape ( bj_window * ,
bj_event_action ,
bj_key ,
int  )

This utility function is a pre-made bj_window_key_event_t you can directly use to provide a window the behaviour of closing when ESC key is pressed by the user (BJ_KEY_ESCAPE).

Call it using bj_window_set_key_event(p_window, bj_close_on_escape).

See also
bj_window_key_event_t and bj_window_set_key_event

◆ bj_poll_events()

void bj_poll_events ( void )

All events received by the system will be processed and sent to the event callbacks.

Examples
bitmap_blit.c, drawing_2d.c, events.c, load_bmp.c, shaders.c, sprite_animation.c, and window.c.

◆ bj_window_del()

void bj_window_del ( bj_window * p_window)
Parameters
p_windowPointer to the window object to delete.
Examples
bitmap_blit.c, drawing_2d.c, events.c, load_bmp.c, shaders.c, sprite_animation.c, and window.c.

◆ bj_window_get_flags()

uint8_t bj_window_get_flags ( bj_window * p_window,
uint8_t flags )

This function returns all the flag sets for p_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
p_windowThe window handler.
flagsFilter flag set.
Returns
An OR'd combination of bj_window_flag_t filtered by flags.
See also
bj_window_enter_event_t

◆ bj_window_get_framebuffer()

bj_bitmap * bj_window_get_framebuffer ( bj_window * p_window,
bj_error ** p_error )

The framebuffer is an instance of bj_bitmap attached (and owned) by the window. If necessary, bj_window_get_flags will create (or recreate) the framebuffer object upon calling this function. This can happen when the window is resize, minimized or any even that invalidate the window drawing area.

TODO: The instance should stay the same and the framebuffer only change internally.

Parameters
p_windowThe window handler
p_errorOptional error location
Returns
A pointer to a bj_bitmap attached to the window or 0 in case of failure.
Behaviour

The function performs nothing if p_window is 0.

Memory Management

The library is responsible for the return bj_bitmap object.

Examples
bitmap_blit.c, drawing_2d.c, load_bmp.c, shaders.c, and sprite_animation.c.

◆ bj_window_get_size()

int bj_window_get_size ( const bj_window * p_window,
int * width,
int * height )
Parameters
p_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 p_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_window_new()

bj_window * bj_window_new ( const char * p_title,
uint16_t x,
uint16_t y,
uint16_t width,
uint16_t height,
uint8_t flags )
Parameters
p_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 bj_window object.
Memory Management

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

Examples
bitmap_blit.c, drawing_2d.c, events.c, load_bmp.c, shaders.c, sprite_animation.c, and window.c.

◆ bj_window_set_button_event()

bj_window_button_event_t bj_window_set_button_event ( bj_window * p_window,
bj_window_button_event_t p_callback )

The providded callback is called each time a button event is raised by the system. If an event was already set previously, it is returned to the caller. The vent set is user until a new callback function is set.

Parameters
p_windowThe window handler
p_callbackThe callback function
Returns
0 or the previously set callback function if any.
See also
bj_window_button_event_t
Examples
events.c.

◆ bj_window_set_cursor_event()

bj_window_cursor_event_t bj_window_set_cursor_event ( bj_window * p_window,
bj_window_cursor_event_t p_callback )

The provided callback is called each time a cursor event is raised by the system. If an event was already set previously, it is returned to the caller. The event set is used until a new callback function is set.

Parameters
p_windowThe window handler
p_callbackThe callback function
Returns
0 or the previously set callback function if any.
See also
bj_window_cursor_event_t
Examples
events.c.

◆ bj_window_set_enter_event()

bj_window_enter_event_t bj_window_set_enter_event ( bj_window * p_window,
bj_window_enter_event_t p_callback )

The providded callback is called each time an enter event is raised by the system. If an event was already set previously, it is returned to the caller. The vent set is user until a new callback function is set.

Parameters
p_windowThe window handler
p_callbackThe callback function
Returns
0 or the previously set callback function if any.
See also
bj_window_enter_event_t
Examples
events.c.

◆ bj_window_set_key_event()

bj_window_key_event_t bj_window_set_key_event ( bj_window * p_window,
bj_window_key_event_t p_callback )

The providded callback is called each time a key event is raised by the system. If an event was already set previously, it is returned to the caller. The vent set is user until a new callback function is set.

Parameters
p_windowThe window handler
p_callbackThe callback function
Returns
0 or the previously set callback function if any.
Behaviour

Pressing a key on the keyboard will generate a single call event with BJ_PRESS action. Releasing the key generates a single call with BJ_RELEASE. If the BJ_WINDOW_FLAG_KEY_REPEAT flag is set for a window, holding down the key will continuously call the event function with a BJ_REPEAT action.

See also
bj_window_key_event_t
Examples
bitmap_blit.c, drawing_2d.c, events.c, load_bmp.c, shaders.c, sprite_animation.c, and window.c.

◆ bj_window_set_should_close()

void bj_window_set_should_close ( bj_window * p_window)

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

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

Parameters
p_windowPointer to the window object to flag.
Remarks

This function effectively returns bj_window_get_flags(p_window, BJ_WINDOW_FLAG_CLOSE) > 0.

See also
bj_window_should_close
Examples
events.c, and window.c.

◆ bj_window_should_close()

bj_bool bj_window_should_close ( bj_window * p_window)
Parameters
p_windowPointer to the window object to flag.
Returns
true if the close flag is set, false otherwise.

If p_window is 0, the function returns BJ_TRUE.

See also
bj_window_set_should_close
Examples
bitmap_blit.c, drawing_2d.c, events.c, load_bmp.c, shaders.c, sprite_animation.c, and window.c.

◆ bj_window_update_framebuffer()

void bj_window_update_framebuffer ( bj_window * p_window)
Parameters
p_windowThe window handler

Use this function to apply any change made to the framebuffer on the window.

Behaviour

The function performs nothing if p_window is 0 or does not contain any framebuffer.

See also
bj_window_get_framebuffer
Examples
bitmap_blit.c, drawing_2d.c, load_bmp.c, shaders.c, and sprite_animation.c.