![]() |
RGFW
A multi-platform single-header very simple-to-use framework library for creating GUI Libraries or simple GUI programs.
|
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
Classes | |
struct | RGFW_point |
struct | RGFW_rect |
struct | RGFW_area |
struct | RGFW_monitorMode |
struct | RGFW_monitor |
struct | RGFW_event |
struct | RGFW_window |
struct | RGFW_debugContext |
struct | RGFW_info |
Macros | |
#define | RGFW_USERPTR NULL |
#define | RGFW_UNUSED(x) (void)(x) |
#define | RGFW_ROUND(x) (i32)((x) >= 0 ? (x) + 0.5f : (x) - 0.5f) |
#define | RGFW_ALLOC malloc |
#define | RGFW_FREE free |
#define | RGFW_ASSERT assert |
#define | RGFW_MEMSET(ptr, value, num) memset(ptr, value, num) |
#define | RGFW_MEMCPY(dist, src, len) memcpy(dist, src, len) |
#define | RGFW_STRNCMP(s1, s2, max) strncmp(s1, s2, max) |
#define | RGFW_STRNCPY(dist, src, len) strncpy(dist, src, len) |
#define | RGFW_STRSTR(str, substr) strstr(str, substr) |
#define | RGFW_STRTOL(str, endptr, base) strtol(str, endptr, base) |
#define | RGFW_ATOF(num) atof(num) |
#define | RGFWDEF inline |
#define | RGFW_ENUM(type, name) type name; enum |
#define | RGFW_HEADER |
#define | RGFW_INT_DEFINED |
#define | RGFW_BOOL_DEFINED |
#define | RGFW_BOOL(x) (RGFW_bool)((x) ? RGFW_TRUE : RGFW_FALSE) /* force an value to be 0 or 1 */ |
#define | RGFW_TRUE (RGFW_bool)1 |
#define | RGFW_FALSE (RGFW_bool)0 |
#define | RGFW_OPENGL |
#define | RGFW_COCOA_FRAME_NAME NULL |
#define | RGFW_key u8 |
#define | RGFW_MAX_PATH 260 /* max length of a path (for dnd) */ |
#define | RGFW_MAX_DROPS 260 /* max items you can drop at once */ |
#define | RGFW_BIT(x) (1 << x) |
#define | RGFW_POINT(x, y) (RGFW_point){(i32)(x), (i32)(y)} |
#define | RGFW_RECT(x, y, w, h) (RGFW_rect){(i32)(x), (i32)(y), (i32)(w), (i32)(h)} |
#define | RGFW_AREA(w, h) (RGFW_area){(u32)(w), (u32)(h)} |
#define | RGFW_DEBUG_CTX(win, err) (RGFW_debugContext){win, NULL, err} |
#define | RGFW_DEBUG_CTX_MON(monitor) (RGFW_debugContext){_RGFW->root, &monitor, 0} |
#define | RGFW_MAX_EVENTS 32 |
#define | RGFW_eventQueuePushEx(eventInit) { RGFW_event e; eventInit; RGFW_eventQueuePush(e); } |
Typedefs | |
typedef uint8_t | u8 |
typedef int8_t | i8 |
typedef uint16_t | u16 |
typedef int16_t | i16 |
typedef uint32_t | u32 |
typedef int32_t | i32 |
typedef uint64_t | u64 |
typedef int64_t | i64 |
typedef u8 | RGFW_bool |
typedef struct RGFW_point | RGFW_point |
typedef struct RGFW_rect | RGFW_rect |
typedef struct RGFW_area | RGFW_area |
typedef struct RGFW_monitorMode | RGFW_monitorMode |
typedef struct RGFW_monitor | RGFW_monitor |
typedef void | RGFW_mouse |
typedef struct RGFW_event | RGFW_event |
typedef struct RGFW_window | RGFW_window |
typedef ptrdiff_t | RGFW_ssize_t |
typedef struct RGFW_debugContext | RGFW_debugContext |
typedef void(* | RGFW_debugfunc) (RGFW_debugType type, RGFW_errorCode err, RGFW_debugContext ctx, const char *msg) |
typedef void(* | RGFW_windowMovedfunc) (RGFW_window *win, RGFW_rect r) |
typedef void(* | RGFW_windowResizedfunc) (RGFW_window *win, RGFW_rect r) |
typedef void(* | RGFW_windowRestoredfunc) (RGFW_window *win, RGFW_rect r) |
typedef void(* | RGFW_windowMaximizedfunc) (RGFW_window *win, RGFW_rect r) |
typedef void(* | RGFW_windowMinimizedfunc) (RGFW_window *win, RGFW_rect r) |
typedef void(* | RGFW_windowQuitfunc) (RGFW_window *win) |
typedef void(* | RGFW_focusfunc) (RGFW_window *win, RGFW_bool inFocus) |
typedef void(* | RGFW_mouseNotifyfunc) (RGFW_window *win, RGFW_point point, RGFW_bool status) |
typedef void(* | RGFW_mousePosfunc) (RGFW_window *win, RGFW_point point, RGFW_point vector) |
typedef void(* | RGFW_dndInitfunc) (RGFW_window *win, RGFW_point point) |
typedef void(* | RGFW_windowRefreshfunc) (RGFW_window *win) |
typedef void(* | RGFW_keyfunc) (RGFW_window *win, u8 key, u8 keyChar, RGFW_keymod keyMod, RGFW_bool pressed) |
typedef void(* | RGFW_mouseButtonfunc) (RGFW_window *win, RGFW_mouseButton button, double scroll, RGFW_bool pressed) |
typedef void(* | RGFW_gamepadButtonfunc) (RGFW_window *win, u16 gamepad, u8 button, RGFW_bool pressed) |
typedef void(* | RGFW_gamepadAxisfunc) (RGFW_window *win, u16 gamepad, RGFW_point axis[2], u8 axisesCount, u8 whichAxis) |
typedef void(* | RGFW_gamepadfunc) (RGFW_window *win, u16 gamepad, RGFW_bool connected) |
typedef void(* | RGFW_dndfunc) (RGFW_window *win, char **droppedFiles, size_t droppedFilesCount) |
typedef void(* | RGFW_scaleUpdatedfunc) (RGFW_window *win, float scaleX, float scaleY) |
typedef void(* | RGFW_proc) (void) |
typedef struct RGFW_info | RGFW_info |
#define RGFW_ALLOC malloc |
#define RGFW_ASSERT assert |
#define RGFW_ATOF | ( | num | ) | atof(num) |
#define RGFW_BIT | ( | x | ) | (1 << x) |
#define RGFW_BOOL | ( | x | ) | (RGFW_bool)((x) ? RGFW_TRUE : RGFW_FALSE) /* force an value to be 0 or 1 */ |
#define RGFW_BOOL_DEFINED |
#define RGFW_COCOA_FRAME_NAME NULL |
#define RGFW_ENUM | ( | type, | |
name | |||
) | type name; enum |
#define RGFW_FALSE (RGFW_bool)0 |
#define RGFW_FREE free |
#define RGFW_HEADER |
#define RGFW_INT_DEFINED |
#define RGFW_key u8 |
#define RGFW_MAX_DROPS 260 /* max items you can drop at once */ |
#define RGFW_MAX_PATH 260 /* max length of a path (for dnd) */ |
#define RGFW_MEMCPY | ( | dist, | |
src, | |||
len | |||
) | memcpy(dist, src, len) |
#define RGFW_MEMSET | ( | ptr, | |
value, | |||
num | |||
) | memset(ptr, value, num) |
#define RGFW_OPENGL |
#define RGFW_POINT | ( | x, | |
y | |||
) | (RGFW_point){(i32)(x), (i32)(y)} |
#define RGFW_ROUND | ( | x | ) | (i32)((x) >= 0 ? (x) + 0.5f : (x) - 0.5f) |
#define RGFW_STRNCMP | ( | s1, | |
s2, | |||
max | |||
) | strncmp(s1, s2, max) |
#define RGFW_STRNCPY | ( | dist, | |
src, | |||
len | |||
) | strncpy(dist, src, len) |
#define RGFW_STRSTR | ( | str, | |
substr | |||
) | strstr(str, substr) |
#define RGFW_STRTOL | ( | str, | |
endptr, | |||
base | |||
) | strtol(str, endptr, base) |
#define RGFW_TRUE (RGFW_bool)1 |
#define RGFW_UNUSED | ( | x | ) | (void)(x) |
#define RGFW_USERPTR NULL |
#define RGFWDEF inline |
typedef int16_t i16 |
typedef int32_t i32 |
typedef int64_t i64 |
typedef int8_t i8 |
typedef struct RGFW_event RGFW_event |
Event structure for checking/getting events
typedef struct RGFW_monitor RGFW_monitor |
structure for monitor data
typedef struct RGFW_monitorMode RGFW_monitorMode |
typedef void RGFW_mouse |
loads mouse icon from bitmap (similar to RGFW_window_setIcon). Icon NOT resized by default
typedef struct RGFW_point RGFW_point |
basic vector type, if there's not already a point/vector type of choice
typedef struct RGFW_window RGFW_window |
window structure for managing the window
typedef uint16_t u16 |
typedef uint32_t u32 |
typedef uint64_t u64 |
typedef uint8_t u8 |
RGFWDEF void RGFW_deinit | ( | void | ) |
is called by default when the last open window is closed
RGFWDEF void RGFW_deinit_heap | ( | void | ) |
deinits the heap instance
typedef RGFW_ENUM | ( | u32 | , |
RGFW_windowFlags | |||
) |
source data for the window (used by the APIs)
Optional arguments for making a windows
< the window doesn't have a border
< the window cannot be resized by the user
< the window supports drag and drop
the window should hide the mouse (can be toggled later on using RGFW_window_mouseShow
)
< the window is fullscreen by default
< the window is transparent (only properly works on X11 and MacOS, although it's meant for for windows)
center the window on the screen
use OpenGL software rendering
(cocoa only), change directory to resource folder
scale the window to the screen
the window is hidden
< create a floating window
< free (RGFW_window_close) the RGFW_window struct when the window is closed (by the end user)
< focus the window when it's shown
< focus the window when it's shown
< if the window is in focus
typedef RGFW_ENUM | ( | u8 | , |
RGFW_eventType | |||
) |
event codes
< no event has been sent
< a key has been released
key event note the code of the key pressed is stored in RGFW_event.key !!Keycodes defined at the bottom of the RGFW_HEADER part of this file!!
while a string version is stored in RGFW_event.KeyString
RGFW_event.keyMod holds the current keyMod this means if CapsLock, NumLock are active or not
< a mouse button has been pressed (left,middle,right)
< a mouse button has been released (left,middle,right)
< the position of the mouse has been changed
mouse event note the x and y of the mouse can be found in the vector, RGFW_event.point
RGFW_event.button holds which mouse button was pressed
< a gamepad was connected
< a gamepad was disconnected
< a gamepad button was pressed
< a gamepad button was released
< an axis of a gamepad was moved
gamepad event note RGFW_event.gamepad holds which gamepad was altered, if any RGFW_event.button holds which gamepad button was pressed
RGFW_event.axis holds the data of all the axises RGFW_event.axisesCount says how many axises there are
< the window was moved (by the user)
< the window was resized (by the user), [on WASM this means the browser was resized]
< window is in focus now
< window is out of focus now
< the user clicked the quit button
< a file has been dropped into the window
< the start of a dnd event, when the place where the file drop is known
< the window was maximized
< the window was minimized
< the window was restored
< content scale factor changed
typedef RGFW_ENUM | ( | u8 | , |
RGFW_gamepadCodes | |||
) |
gamepad button codes (based on xbox/playstation), you may need to change these values per controller
< or PS X button
< or PS X button
< or PS circle button
< or PS triangle button
< or PS square button
< start button
< select button
< home button
< dpad up
< dpad down
< dpad left
< dpad right
< left bump
< left trigger
< right bumper
< right trigger
< right thumb stick
typedef RGFW_ENUM | ( | u8 | , |
RGFW_keymod | |||
) |
typedef RGFW_ENUM | ( | u8 | , |
RGFW_modeRequest | |||
) |
< scale the monitor size
< change the refresh rate
< change the monitor RGB bits size
typedef RGFW_ENUM | ( | u8 | , |
RGFW_mouseButton | |||
) |
mouse button codes (RGFW_event.button)
< left mouse button is pressed
< mouse-wheel-button is pressed
< right mouse button is pressed
< mouse wheel is scrolling up
< mouse wheel is scrolling down
RGFWDEF void RGFW_freeMouse | ( | RGFW_mouse * | mouse | ) |
RGFWDEF RGFW_monitor * RGFW_getMonitors | ( | size_t * | len | ) |
get an array of all the monitors (max 6)
RGFWDEF RGFW_monitor RGFW_getPrimaryMonitor | ( | void | ) |
get the primary monitor
optional init/deinit function is called by default when the first window is created by default
RGFWDEF void * RGFW_init_heap | ( | void | ) |
inits RGFW on the heap instead of in a global var
RGFWDEF RGFW_mouse * RGFW_loadMouse | ( | u8 * | icon, |
RGFW_area | a, | ||
i32 | channels | ||
) |
frees RGFW_mouse data
RGFWDEF RGFW_bool RGFW_monitor_requestMode | ( | RGFW_monitor | mon, |
RGFW_monitorMode | mode, | ||
RGFW_modeRequest | request | ||
) |
request a specific mode
RGFWDEF RGFW_bool RGFW_monitor_scaleToWindow | ( | RGFW_monitor | mon, |
RGFW_window * | win | ||
) |
scale monitor to window size
RGFWDEF RGFW_bool RGFW_monitorModeCompare | ( | RGFW_monitorMode | mon, |
RGFW_monitorMode | mon2, | ||
RGFW_modeRequest | request | ||
) |
check if 2 monitor modes are the same
(unix) Toggle use of wayland. This will be on by default if you use RGFW_WAYLAND
(if you don't use RGFW_WAYLAND, you don't expose WAYLAND functions) this is mostly used to allow you to force the use of XWayland