2015-03-03 19:24:02 +03:00
|
|
|
/*
|
|
|
|
Copyright (c) 2015
|
|
|
|
vurtun <polygone@gmx.net>
|
|
|
|
MIT licence
|
2015-06-06 13:45:18 +03:00
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
Zahnrad
|
2015-06-06 13:45:18 +03:00
|
|
|
-----------------------
|
2015-09-18 00:09:49 +03:00
|
|
|
These two file provide both the interface and implementation for a bloat free
|
2015-06-06 13:45:18 +03:00
|
|
|
minimal state immediate mode graphical user interface toolkit. The Toolkit
|
|
|
|
does not have any library or runtine dependencies like libc but does not
|
2015-09-18 00:09:49 +03:00
|
|
|
handle os window/input management.
|
2015-03-03 19:24:02 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
#ifndef ZR_H_
|
|
|
|
#define ZR_H_
|
2015-03-20 12:58:11 +03:00
|
|
|
|
2015-04-10 19:35:17 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-08-27 20:25:13 +03:00
|
|
|
/*
|
|
|
|
* ==============================================================
|
|
|
|
*
|
|
|
|
* Constants
|
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
#define ZR_UTF_INVALID 0xFFFD
|
|
|
|
#define ZR_UTF_SIZE 4
|
2015-06-04 23:17:54 +03:00
|
|
|
/* describes the number of bytes a glyph consists of*/
|
2015-09-18 00:09:49 +03:00
|
|
|
#define ZR_INPUT_MAX 16
|
2015-06-06 13:45:18 +03:00
|
|
|
/* defines the max number of bytes to be added as text input in one frame */
|
2015-09-18 00:09:49 +03:00
|
|
|
#define ZR_MAX_COLOR_STACK 32
|
2015-06-04 23:17:54 +03:00
|
|
|
/* defines the number of temporary configuration color changes that can be stored */
|
2015-09-18 00:09:49 +03:00
|
|
|
#define ZR_MAX_ATTRIB_STACK 32
|
2015-06-04 23:17:54 +03:00
|
|
|
/* defines the number of temporary configuration attribute changes that can be stored */
|
2015-04-10 19:35:17 +03:00
|
|
|
|
2015-08-27 20:25:13 +03:00
|
|
|
/*
|
|
|
|
* ==============================================================
|
|
|
|
*
|
|
|
|
* Compiler switches
|
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
#define ZR_COMPILE_WITH_FIXED_TYPES 1
|
2015-08-27 20:25:13 +03:00
|
|
|
/* setting this define to 1 adds header <stdint.h> for fixed sized types
|
2015-08-15 13:00:01 +03:00
|
|
|
* if 0 each type has to be set to the correct size*/
|
2015-09-18 00:09:49 +03:00
|
|
|
#define ZR_COMPILE_WITH_ASSERT 1
|
2015-08-21 18:34:51 +03:00
|
|
|
/* setting this define to 1 adds the <assert.h> header for the assert macro
|
|
|
|
IMPORTANT: it also adds clib so only use it if wanted */
|
2015-09-18 00:09:49 +03:00
|
|
|
#define ZR_COMPILE_WITH_VERTEX_BUFFER 1
|
2015-09-06 20:13:07 +03:00
|
|
|
/* setting this define to 1 adds a vertex draw command list backend to this library,
|
|
|
|
which allows you to convert queue commands into vertex draw commands.
|
|
|
|
If you do not want or need a default backend you can set this flag to zero
|
|
|
|
and the module of the library will not be compiled */
|
2015-09-18 00:09:49 +03:00
|
|
|
#define ZR_COMPILE_WITH_FONT 1
|
2015-09-06 20:13:07 +03:00
|
|
|
/* setting this define to 1 adds the `stb_truetype` and `stb_rect_pack` header
|
2015-09-15 19:13:43 +03:00
|
|
|
to this library and provides a default font for font loading and rendering.
|
2015-09-08 11:57:27 +03:00
|
|
|
If you already have font handling or do not want to use this font handler
|
|
|
|
you can just set this define to zero and the font module will not be compiled
|
2015-09-15 19:13:43 +03:00
|
|
|
and the two headers will not be needed. */
|
2015-08-27 20:25:13 +03:00
|
|
|
/*
|
|
|
|
* ==============================================================
|
|
|
|
*
|
|
|
|
* Basic Types
|
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
#if ZR_COMPILE_WITH_FIXED_TYPES
|
2015-04-10 19:35:17 +03:00
|
|
|
#include <stdint.h>
|
2015-09-18 00:09:49 +03:00
|
|
|
typedef char zr_char;
|
|
|
|
typedef int32_t zr_int;
|
|
|
|
typedef int32_t zr_bool;
|
|
|
|
typedef int16_t zr_short;
|
|
|
|
typedef int64_t zr_long;
|
|
|
|
typedef float zr_float;
|
|
|
|
typedef double zr_double;
|
|
|
|
typedef uint16_t zr_ushort;
|
|
|
|
typedef uint32_t zr_uint;
|
|
|
|
typedef uint64_t zr_ulong;
|
|
|
|
typedef uint32_t zr_flags;
|
|
|
|
typedef zr_flags zr_state;
|
|
|
|
typedef uint8_t zr_byte;
|
|
|
|
typedef uint32_t zr_flag;
|
|
|
|
typedef uint64_t zr_size;
|
|
|
|
typedef uintptr_t zr_ptr;
|
2015-04-10 19:35:17 +03:00
|
|
|
#else
|
2015-09-18 00:09:49 +03:00
|
|
|
typedef int zr_int;
|
|
|
|
typedef int zr_bool;
|
|
|
|
typedef char zr_char;
|
|
|
|
typedef short zr_short;
|
|
|
|
typedef long zr_long;
|
|
|
|
typedef float zr_float;
|
|
|
|
typedef double zr_double;
|
|
|
|
typedef unsigned short zr_ushort;
|
|
|
|
typedef unsigned int zr_uint;
|
|
|
|
typedef unsigned long zr_ulong;
|
|
|
|
typedef unsigned int zr_flags;
|
|
|
|
typedef zr_flags zr_state;
|
|
|
|
typedef unsigned char zr_byte;
|
|
|
|
typedef unsigned int zr_flag;
|
|
|
|
typedef unsigned long zr_size;
|
|
|
|
typedef unsigned long zr_ptr;
|
2015-04-10 19:35:17 +03:00
|
|
|
#endif
|
|
|
|
|
2015-08-31 16:23:49 +03:00
|
|
|
/* Basic types */
|
2015-09-18 00:09:49 +03:00
|
|
|
enum {zr_false, zr_true};
|
|
|
|
enum zr_heading {ZR_UP, ZR_RIGHT, ZR_DOWN, ZR_LEFT};
|
|
|
|
struct zr_color {zr_byte r,g,b,a;};
|
|
|
|
struct zr_vec2 {zr_float x,y;};
|
|
|
|
struct zr_vec2i {zr_short x, y;};
|
|
|
|
struct zr_rect {zr_float x,y,w,h;};
|
|
|
|
struct zr_recti {zr_ushort x,y,w,h;};
|
|
|
|
typedef zr_char zr_glyph[ZR_UTF_SIZE];
|
|
|
|
struct zr_key {zr_bool down; zr_uint clicked;};
|
|
|
|
typedef union {void *ptr; zr_int id;} zr_handle;
|
|
|
|
struct zr_image {zr_handle handle; zr_ushort w, h; zr_ushort region[4];};
|
|
|
|
enum zr_widget_states {ZR_INACTIVE = zr_false, ZR_ACTIVE = zr_true};
|
|
|
|
enum zr_collapse_states {ZR_MINIMIZED = zr_false, ZR_MAXIMIZED = zr_true};
|
2015-06-04 23:17:54 +03:00
|
|
|
|
|
|
|
/* Callbacks */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_user_font;
|
|
|
|
struct zr_edit_box;
|
|
|
|
struct zr_user_font_glyph;
|
2015-06-20 20:06:36 +03:00
|
|
|
/*
|
|
|
|
* ==============================================================
|
|
|
|
*
|
|
|
|
* Utility
|
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
*/
|
2015-07-05 00:36:01 +03:00
|
|
|
/* Utility
|
|
|
|
----------------------------
|
2015-08-27 20:25:13 +03:00
|
|
|
The utility API provides a number of object construction function
|
2015-07-05 00:36:01 +03:00
|
|
|
for some gui specific objects like image handle, vector, color and rectangle.
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
----------------------------
|
|
|
|
Utility function API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_get_null_rect -- returns a default clipping rectangle
|
|
|
|
zr_utf_decode -- decodes a utf-8 glyph into u32 unicode glyph and len
|
|
|
|
zr_utf_encode -- encodes a u32 unicode glyph into a utf-8 glyph
|
|
|
|
zr_image_ptr -- create a image handle from pointer
|
|
|
|
zr_image_id -- create a image handle from integer id
|
|
|
|
zr_subimage_ptr -- create a sub-image handle from pointer and region
|
|
|
|
zr_subimage_id -- create a sub-image handle from integer id and region
|
|
|
|
zr_rect_is_valid -- check if a rectangle inside the image command is valid
|
|
|
|
zr_rect -- creates a rectangle from x,y-Position and width and height
|
|
|
|
zr_vec2 -- creates a 2D floating point vector
|
|
|
|
zr_rgba -- create a gui color struct from rgba color code
|
|
|
|
zr_rgb -- create a gui color struct from rgb color code
|
|
|
|
*/
|
|
|
|
#if ZR_COMPILE_WITH_ASSERT
|
|
|
|
#ifndef ZR_ASSERT
|
2015-08-27 20:25:13 +03:00
|
|
|
#include <assert.h>
|
2015-09-18 00:09:49 +03:00
|
|
|
#define ZR_ASSERT(expr) assert(expr)
|
2015-08-27 20:25:13 +03:00
|
|
|
#endif
|
|
|
|
#else
|
2015-09-18 00:09:49 +03:00
|
|
|
#define ZR_ASSERT(expr)
|
2015-08-27 20:25:13 +03:00
|
|
|
#endif
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_rect zr_get_null_rect(void);
|
|
|
|
zr_size zr_utf_decode(const zr_char*, zr_long*, zr_size);
|
|
|
|
zr_size zr_utf_encode(zr_long, zr_char*, zr_size);
|
|
|
|
zr_size zr_utf_len(const zr_char*, zr_size len);
|
|
|
|
zr_handle zr_handle_ptr(void*);
|
|
|
|
zr_handle zr_handle_id(zr_int);
|
|
|
|
struct zr_image zr_image_ptr(void*);
|
|
|
|
struct zr_image zr_image_id(zr_int);
|
|
|
|
struct zr_image zr_subimage_ptr(void*, zr_ushort w, zr_ushort h, struct zr_rect);
|
|
|
|
struct zr_image zr_subimage_id(zr_int, zr_ushort w, zr_ushort h, struct zr_rect);
|
|
|
|
zr_bool zr_image_is_subimage(const struct zr_image* img);
|
|
|
|
struct zr_rect zr_rect(zr_float x, zr_float y, zr_float w, zr_float h);
|
|
|
|
struct zr_vec2 zr_vec2(zr_float x, zr_float y);
|
|
|
|
struct zr_color zr_rgba(zr_byte r, zr_byte g, zr_byte b, zr_byte a);
|
|
|
|
struct zr_color zr_rgb(zr_byte r, zr_byte g, zr_byte b);
|
|
|
|
#define zr_ptr_add(t, p, i) ((t*)((void*)((zr_byte*)(p) + (i))))
|
|
|
|
#define zr_ptr_sub(t, p, i) ((t*)((void*)((zr_byte*)(p) - (i))))
|
|
|
|
#define zr_ptr_add_const(t, p, i) ((const t*)((const void*)((const zr_byte*)(p) + (i))))
|
|
|
|
#define zr_ptr_sub_const(t, p, i) ((const t*)((const void*)((const zr_byte*)(p) - (i))))
|
2015-05-29 15:18:23 +03:00
|
|
|
/*
|
|
|
|
* ==============================================================
|
|
|
|
*
|
|
|
|
* Input
|
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
*/
|
2015-06-04 23:17:54 +03:00
|
|
|
/* INPUT
|
|
|
|
----------------------------
|
2015-06-16 00:46:13 +03:00
|
|
|
The input API is responsible for holding input by keeping track of
|
2015-06-04 23:17:54 +03:00
|
|
|
mouse, key and text input state. The core of the API is the persistent
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_input struct which holds the input state while running.
|
2015-06-04 23:17:54 +03:00
|
|
|
It is important to note that no direct os or window handling is done by the input
|
|
|
|
API, instead all the input state has to be provided from the user. This in one hand
|
|
|
|
expects more work from the user and complicates the usage but on the other hand
|
|
|
|
provides simple abstraction over a big number of platforms, libraries and other
|
|
|
|
already provided functionality.
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
----------------------------
|
2015-09-18 00:09:49 +03:00
|
|
|
To instantiate the Input API the zr_input structure has to be zeroed at
|
2015-06-04 23:17:54 +03:00
|
|
|
the beginning of the program by either using memset or setting it to {0},
|
|
|
|
since the internal state is persistent over all frames.
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
To modify the internal input state you have to first set the zr_input struct
|
|
|
|
into a modifiable state with zr_input_begin. After the zr_input struct is
|
2015-06-04 23:17:54 +03:00
|
|
|
now ready you can add input state changes until everything is up to date.
|
2015-09-18 00:09:49 +03:00
|
|
|
Finally to revert back into a read state you have to call zr_input_end.
|
2015-06-04 23:17:54 +03:00
|
|
|
|
|
|
|
Input function API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_input_begin -- begins the modification state
|
|
|
|
zr_input_motion -- notifies of a cursor motion update
|
|
|
|
zr_input_key -- notifies of a keyboard key update
|
|
|
|
zr_input_button -- notifies of a action event
|
|
|
|
zr_input_char -- adds a text glyph to zr_input
|
|
|
|
zr_input_end -- ends the modification state
|
2015-06-04 23:17:54 +03:00
|
|
|
|
2015-08-21 18:34:51 +03:00
|
|
|
Input query function API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_input_is_mouse_click_in_rect - checks for up/down click in a rectangle
|
|
|
|
zr_input_is_mouse_hovering_rect - checks if the mouse hovers over a rectangle
|
|
|
|
zr_input_mouse_clicked - checks if hover + down + clicked in rectangle
|
|
|
|
zr_input_is_mouse_down - checks if the current mouse button is down
|
|
|
|
zr_input_is_mouse_released - checks if mouse button previously released
|
|
|
|
zr_input_is_key_pressed - checks if key was up and now is down
|
|
|
|
zr_input_is_key_released - checks if key was down and is now up
|
|
|
|
zr_input_is_key_down - checks if key is currently down
|
2015-06-04 23:17:54 +03:00
|
|
|
*/
|
|
|
|
/* every key that is being used inside the library */
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_keys {
|
|
|
|
ZR_KEY_SHIFT,
|
|
|
|
ZR_KEY_DEL,
|
|
|
|
ZR_KEY_ENTER,
|
|
|
|
ZR_KEY_BACKSPACE,
|
|
|
|
ZR_KEY_SPACE,
|
|
|
|
ZR_KEY_COPY,
|
|
|
|
ZR_KEY_CUT,
|
|
|
|
ZR_KEY_PASTE,
|
|
|
|
ZR_KEY_LEFT,
|
|
|
|
ZR_KEY_RIGHT,
|
|
|
|
ZR_KEY_MAX
|
2015-03-23 19:18:18 +03:00
|
|
|
};
|
|
|
|
|
2015-08-31 16:23:49 +03:00
|
|
|
/* every used mouse button */
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_buttons {
|
|
|
|
ZR_BUTTON_LEFT,
|
|
|
|
ZR_BUTTON_MIDDLE,
|
|
|
|
ZR_BUTTON_RIGHT,
|
|
|
|
ZR_BUTTON_MAX
|
2015-08-31 16:23:49 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_mouse_button {
|
|
|
|
zr_bool down;
|
2015-08-31 16:23:49 +03:00
|
|
|
/* current button state */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_uint clicked;
|
2015-08-31 16:23:49 +03:00
|
|
|
/* button state change */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 clicked_pos;
|
2015-08-31 16:23:49 +03:00
|
|
|
/* mouse position of last state change */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_mouse {
|
|
|
|
struct zr_mouse_button buttons[ZR_BUTTON_MAX];
|
2015-08-31 16:23:49 +03:00
|
|
|
/* mouse button states */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 pos;
|
2015-08-31 16:23:49 +03:00
|
|
|
/* current mouse position */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 prev;
|
2015-08-31 16:23:49 +03:00
|
|
|
/* mouse position in the last frame */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 delta;
|
2015-08-31 16:23:49 +03:00
|
|
|
/* mouse travelling distance from last to current frame */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float scroll_delta;
|
2015-08-31 16:23:49 +03:00
|
|
|
/* number of steps in the up or down scroll direction */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_keyboard {
|
|
|
|
struct zr_key keys[ZR_KEY_MAX];
|
2015-06-04 23:17:54 +03:00
|
|
|
/* state of every used key */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_char text[ZR_INPUT_MAX];
|
2015-06-04 23:17:54 +03:00
|
|
|
/* utf8 text input frame buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size text_len;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* text input frame buffer length in bytes */
|
2015-08-31 16:23:49 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_input {
|
|
|
|
struct zr_keyboard keyboard;
|
2015-08-31 16:23:49 +03:00
|
|
|
/* current keyboard key + text input state */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_mouse mouse;
|
2015-08-31 16:23:49 +03:00
|
|
|
/* current mouse button and position state */
|
2015-03-23 19:18:18 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_input_begin(struct zr_input*);
|
2015-06-16 00:46:13 +03:00
|
|
|
/* this function sets the input state to writeable */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_input_motion(struct zr_input*, zr_int x, zr_int y);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function updates the current mouse position
|
|
|
|
Input:
|
2015-06-16 00:46:13 +03:00
|
|
|
- local os window X position
|
|
|
|
- local os window Y position
|
2015-06-04 23:17:54 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_input_key(struct zr_input*, enum zr_keys, zr_bool down);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function updates the current state of a key
|
|
|
|
Input:
|
2015-06-16 00:46:13 +03:00
|
|
|
- key identifier
|
2015-06-04 23:17:54 +03:00
|
|
|
- the new state of the key
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_input_button(struct zr_input*, enum zr_buttons, zr_int x, zr_int y, zr_bool down);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function updates the current state of the button
|
|
|
|
Input:
|
2015-08-31 16:23:49 +03:00
|
|
|
- mouse button identifier
|
2015-06-16 00:46:13 +03:00
|
|
|
- local os window X position
|
|
|
|
- local os window Y position
|
2015-06-04 23:17:54 +03:00
|
|
|
- the new state of the button
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_input_scroll(struct zr_input*, zr_float y);
|
2015-06-10 18:35:46 +03:00
|
|
|
/* this function updates the current page scroll delta
|
|
|
|
Input:
|
|
|
|
- vector with each direction (< 0 down > 0 up and scroll distance)
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_input_glyph(struct zr_input*, const zr_glyph);
|
2015-06-16 00:46:13 +03:00
|
|
|
/* this function adds a utf-8 glpyh into the internal text frame buffer
|
2015-06-04 23:17:54 +03:00
|
|
|
Input:
|
2015-06-16 00:46:13 +03:00
|
|
|
- utf8 glyph to add to the text buffer
|
2015-06-04 23:17:54 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_input_char(struct zr_input*, char);
|
2015-07-02 12:56:51 +03:00
|
|
|
/* this function adds char into the internal text frame buffer
|
|
|
|
Input:
|
|
|
|
- character to add to the text buffer
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_input_end(struct zr_input*);
|
2015-07-14 14:26:53 +03:00
|
|
|
/* this function sets the input state to readable */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_input_has_mouse_click_in_rect(const struct zr_input*,enum zr_buttons,
|
|
|
|
struct zr_rect);
|
2015-08-31 16:23:49 +03:00
|
|
|
/* this function returns true if a mouse click inside a rectangle occured in prev frames */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_input_has_mouse_click_down_in_rect(const struct zr_input*, enum zr_buttons,
|
|
|
|
struct zr_rect, zr_bool down);
|
2015-08-31 16:23:49 +03:00
|
|
|
/* this function returns true if a mouse down click inside a rectangle occured in prev frames */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_input_is_mouse_click_in_rect(const struct zr_input*, enum zr_buttons,
|
|
|
|
struct zr_rect);
|
2015-08-31 16:23:49 +03:00
|
|
|
/* this function returns true if a mouse click inside a rectangle occured and was just clicked */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_input_is_mouse_prev_hovering_rect(const struct zr_input*, struct zr_rect);
|
2015-08-31 16:23:49 +03:00
|
|
|
/* this function returns true if the mouse hovers over a rectangle */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_input_is_mouse_hovering_rect(const struct zr_input*, struct zr_rect);
|
2015-08-21 18:34:51 +03:00
|
|
|
/* this function returns true if the mouse hovers over a rectangle */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_input_mouse_clicked(const struct zr_input*, enum zr_buttons, struct zr_rect);
|
2015-08-21 18:34:51 +03:00
|
|
|
/* this function returns true if a mouse click inside a rectangle occured
|
|
|
|
and the mouse still hovers over the rectangle*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_input_is_mouse_down(const struct zr_input*, enum zr_buttons);
|
2015-08-21 18:34:51 +03:00
|
|
|
/* this function returns true if the current mouse button is down */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_input_is_mouse_pressed(const struct zr_input*, enum zr_buttons);
|
2015-08-31 16:23:49 +03:00
|
|
|
/* this function returns true if the current mouse button is down and state change*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_input_is_mouse_released(const struct zr_input*, enum zr_buttons);
|
2015-08-21 18:34:51 +03:00
|
|
|
/* this function returns true if the mouse button was previously pressed but
|
|
|
|
was now released */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_input_is_key_pressed(const struct zr_input*, enum zr_keys);
|
2015-08-21 18:34:51 +03:00
|
|
|
/* this function returns true if the given key was up and is now pressed */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_input_is_key_released(const struct zr_input*, enum zr_keys);
|
2015-08-21 18:34:51 +03:00
|
|
|
/* this function returns true if the given key was down and is now up */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_input_is_key_down(const struct zr_input*, enum zr_keys);
|
2015-08-21 18:34:51 +03:00
|
|
|
/* this function returns true if the given key was down and is now up */
|
2015-05-29 15:18:23 +03:00
|
|
|
/*
|
|
|
|
* ==============================================================
|
|
|
|
*
|
|
|
|
* Buffer
|
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
*/
|
2015-06-04 23:17:54 +03:00
|
|
|
/* BUFFER
|
|
|
|
----------------------------
|
2015-08-27 20:25:13 +03:00
|
|
|
A basic (double)-buffer API with linear allocation and resetting as only freeing.
|
2015-06-04 23:17:54 +03:00
|
|
|
The buffer main purpose is to control all memory management inside
|
|
|
|
the GUI toolkit and still leave memory control as much as possible in the hand
|
2015-06-16 00:46:13 +03:00
|
|
|
of the user. The memory is provided in three different ways.
|
2015-06-04 23:17:54 +03:00
|
|
|
The first way is to use a fixed size block of memory to be filled up.
|
2015-06-16 00:46:13 +03:00
|
|
|
Biggest advantage is a simple memory model. Downside is that if the buffer
|
|
|
|
is full there is no way to accesses more memory, which fits target application
|
|
|
|
with a GUI with roughly known memory consumptions.
|
2015-06-04 23:17:54 +03:00
|
|
|
The second way to mnamge memory is by extending the fixed size block by querying
|
2015-06-16 00:46:13 +03:00
|
|
|
information from the buffer about the used size and needed size and allocate new
|
2015-06-04 23:17:54 +03:00
|
|
|
memory if the buffer is full. While this approach is still better than just using
|
|
|
|
a fixed size memory block the reallocation still has one invalid frame as consquence
|
|
|
|
since the used memory information is only available at the end of the frame which leads
|
|
|
|
to the last way of handling memory.
|
|
|
|
The last and most complicated way of handling memory is by allocator callbacks.
|
2015-08-27 20:25:13 +03:00
|
|
|
The user hereby registers callbacks to be called to allocate, free and reallocate
|
2015-06-04 23:17:54 +03:00
|
|
|
memory if needed. While this solves most allocation problems it causes some
|
|
|
|
loss of flow control on the user side.
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
----------------------------
|
2015-06-06 13:45:18 +03:00
|
|
|
To instantiate the buffer you either have to call the fixed size or allocator
|
2015-06-04 23:17:54 +03:00
|
|
|
initialization function and provide a memory block in the first case and
|
|
|
|
an allocator in the second case.
|
2015-09-18 00:09:49 +03:00
|
|
|
To allocate memory from the buffer you would call zr_buffer_alloc with a request
|
2015-06-04 23:17:54 +03:00
|
|
|
memory block size aswell as an alignment for the block. Finally to reset the memory
|
|
|
|
at the end of the frame and when the memory buffer inside the buffer is no longer
|
2015-09-18 00:09:49 +03:00
|
|
|
needed you would call zr_buffer_reset. To free all memory that has been allocated
|
2015-08-27 20:25:13 +03:00
|
|
|
by an allocator if the buffer is no longer being used you have to call
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_buffer_clear.
|
2015-06-04 23:17:54 +03:00
|
|
|
|
|
|
|
Buffer function API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_buffer_init -- initializes a dynamic buffer
|
|
|
|
zr_buffer_init_fixed -- initializes a static buffer
|
|
|
|
zr_buffer_info -- provides buffer memory information
|
|
|
|
zr_buffer_alloc -- allocates a block of memory from the buffer
|
|
|
|
zr_buffer_clear -- resets the buffer back to an empty state
|
|
|
|
zr_buffer_free -- frees all memory if the buffer is dynamic
|
|
|
|
zr_buffer_mark -- marks the current buffer size for later resetting
|
|
|
|
zr_buffer_reset -- resets the buffer either back to zero or up to marker if set
|
|
|
|
zr_buffer_memory -- returns the internal memory
|
|
|
|
zr_buffer_total -- returns the current total size of the memory
|
|
|
|
*/
|
|
|
|
struct zr_memory_status {
|
2015-05-29 15:18:23 +03:00
|
|
|
void *memory;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* pointer to the currently used memory block inside the referenced buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_uint type;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* type of the buffer which is either fixed size or dynamic */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size size;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* total size of the memory block */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size allocated;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* allocated amount of memory */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size needed;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* memory size that would have been allocated if enough memory was present */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size calls;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* number of allocation calls referencing this buffer */
|
2015-05-29 15:18:23 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_allocator {
|
|
|
|
zr_handle userdata;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* handle to your own allocator */
|
2015-09-18 00:09:49 +03:00
|
|
|
void*(*alloc)(zr_handle, zr_size);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* allocation function pointer */
|
2015-09-18 00:09:49 +03:00
|
|
|
void*(*realloc)(zr_handle, void*, zr_size);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* reallocation pointer of a previously allocated memory block */
|
2015-09-18 00:09:49 +03:00
|
|
|
void(*free)(zr_handle, void*);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* callback function pointer to finally free all allocated memory */
|
2015-05-29 15:18:23 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_buffer_type {
|
|
|
|
ZR_BUFFER_FIXED,
|
2015-06-04 23:17:54 +03:00
|
|
|
/* fixed size memory buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_BUFFER_DYNAMIC
|
2015-06-05 23:32:44 +03:00
|
|
|
/* dynamically growing buffer */
|
2015-05-29 15:18:23 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_buffer_allocation_type {
|
|
|
|
ZR_BUFFER_FRONT,
|
2015-08-27 20:25:13 +03:00
|
|
|
/* allocate memory from the front of the buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_BUFFER_BACK,
|
2015-08-27 20:25:13 +03:00
|
|
|
/* allocate memory from the back of the buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_BUFFER_MAX
|
2015-08-27 20:25:13 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_buffer_marker {
|
|
|
|
zr_bool active;
|
2015-08-27 20:25:13 +03:00
|
|
|
/* flag indiciation if the marker was set */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size offset;
|
2015-08-27 20:25:13 +03:00
|
|
|
/* offset of the marker inside the buffer */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_memory {void *ptr;zr_size size;};
|
|
|
|
struct zr_buffer {
|
|
|
|
struct zr_buffer_marker marker[ZR_BUFFER_MAX];
|
2015-08-27 20:25:13 +03:00
|
|
|
/* buffer marker to free a buffer to a certain offset */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_allocator pool;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* allocator callback for dynamic buffers */
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_buffer_type type;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* memory type management type */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_memory memory;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* memory and size of the current memory block */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float grow_factor;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* growing factor for dynamic memory management */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size allocated;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* total amount of memory allocated */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size needed;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* total amount of memory allocated if enough memory would have been present */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size calls;
|
2015-07-17 18:06:56 +03:00
|
|
|
/* number of allocation calls */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size size;
|
2015-08-27 20:25:13 +03:00
|
|
|
/* current size of the buffer */
|
2015-05-29 15:18:23 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_buffer_init(struct zr_buffer*, const struct zr_allocator*,
|
|
|
|
zr_size initial_size, zr_float grow_factor);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function initializes a growing buffer
|
|
|
|
Input:
|
|
|
|
- allocator holding your own alloctator and memory allocation callbacks
|
|
|
|
- initial size of the buffer
|
2015-06-16 00:46:13 +03:00
|
|
|
- factor to grow the buffer by if the buffer is full
|
2015-06-04 23:17:54 +03:00
|
|
|
Output:
|
|
|
|
- dynamically growing buffer
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_buffer_init_fixed(struct zr_buffer*, void *memory, zr_size size);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function initializes a fixed sized buffer
|
2015-06-04 23:17:54 +03:00
|
|
|
Input:
|
|
|
|
- fixed size previously allocated memory block
|
|
|
|
- size of the memory block
|
|
|
|
Output:
|
|
|
|
- fixed size buffer
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_buffer_info(struct zr_memory_status*, struct zr_buffer*);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function requests memory information from a buffer
|
|
|
|
Input:
|
|
|
|
- buffer to get the inforamtion from
|
|
|
|
Output:
|
|
|
|
- buffer memory information
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void *zr_buffer_alloc(struct zr_buffer*, enum zr_buffer_allocation_type,
|
|
|
|
zr_size size, zr_size align);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this functions allocated a aligned memory block from a buffer
|
|
|
|
Input:
|
|
|
|
- buffer to allocate memory from
|
|
|
|
- size of the requested memory block
|
|
|
|
- alignment requirement for the memory block
|
|
|
|
Output:
|
|
|
|
- memory block with given size and alignment requirement
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_buffer_mark(struct zr_buffer*, enum zr_buffer_allocation_type);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* sets a marker either for the back or front buffer for later resetting */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_buffer_reset(struct zr_buffer*, enum zr_buffer_allocation_type);
|
2015-08-27 20:25:13 +03:00
|
|
|
/* resets the buffer back to the previously set marker or if not set the begining */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_buffer_clear(struct zr_buffer*);
|
2015-08-06 17:36:28 +03:00
|
|
|
/* this functions resets the buffer back into an empty state */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_buffer_free(struct zr_buffer*);
|
2015-06-16 00:46:13 +03:00
|
|
|
/* this functions frees all memory inside a dynamically growing buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
void *zr_buffer_memory(struct zr_buffer*);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* returns the memory inside the buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size zr_buffer_total(struct zr_buffer*);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* returns the total size of the buffer */
|
2015-05-29 15:18:23 +03:00
|
|
|
/*
|
|
|
|
* ==============================================================
|
|
|
|
*
|
2015-09-06 20:13:07 +03:00
|
|
|
* Command Buffer
|
2015-05-29 15:18:23 +03:00
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
*/
|
2015-08-06 17:36:28 +03:00
|
|
|
/* COMMAND BUFFER
|
2015-06-04 23:17:54 +03:00
|
|
|
----------------------------
|
2015-08-21 18:34:51 +03:00
|
|
|
The command buffer API queues draw calls as commands into a buffer and
|
2015-06-06 13:45:18 +03:00
|
|
|
therefore abstracts over drawing routines and enables defered drawing.
|
|
|
|
The API offers a number of drawing primitives like lines, rectangles, circles,
|
|
|
|
triangles, images, text and clipping rectangles, that have to be drawn by the user.
|
2015-08-27 20:25:13 +03:00
|
|
|
Therefore the command buffer is the main toolkit output besides the actual
|
|
|
|
widget output.
|
2015-06-04 23:17:54 +03:00
|
|
|
The actual draw command execution is done by the user and is build up in a
|
|
|
|
interpreter like fashion by iterating over all commands and executing each
|
2015-09-06 20:13:07 +03:00
|
|
|
command depending on the command type.
|
2015-06-04 23:17:54 +03:00
|
|
|
|
|
|
|
USAGE
|
|
|
|
----------------------------
|
2015-08-21 18:34:51 +03:00
|
|
|
To use the command buffer you first have to initiate the command buffer with a
|
2015-08-07 17:53:52 +03:00
|
|
|
buffer. After the initilization you can add primitives by
|
2015-09-18 00:09:49 +03:00
|
|
|
calling the appropriate zr_command_buffer_XXX for each primitive.
|
|
|
|
To iterate over each commands inside the buffer zr_foreach_buffer_command is
|
2015-06-04 23:17:54 +03:00
|
|
|
provided. Finally to reuse the buffer after the frame use the
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_command_buffer_reset function. If used without a command queue the command
|
2015-08-07 17:53:52 +03:00
|
|
|
buffer has be cleared after each frame to reset the buffer back into a
|
|
|
|
empty state.
|
2015-06-04 23:17:54 +03:00
|
|
|
|
|
|
|
command buffer function API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_command_buffer_init -- initializes a command buffer with a buffer
|
|
|
|
zr_command_buffer_clear -- resets the command buffer and internal buffer
|
|
|
|
zr_command_buffer_reset -- resets the command buffer but not the buffer
|
2015-06-04 23:17:54 +03:00
|
|
|
|
|
|
|
command queue function API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_command_buffer_push -- pushes and enqueues a command into the buffer
|
|
|
|
zr_command_buffer_push_scissor -- pushes a clipping rectangle into the command buffer
|
|
|
|
zr_command_buffer_push_line -- pushes a line into the command buffer
|
|
|
|
zr_command_buffer_push_rect -- pushes a rectange into the command buffer
|
|
|
|
zr_command_buffer_push_circle -- pushes a circle into the command buffer
|
|
|
|
zr_command_buffer_push_triangle-- pushes a triangle command into the buffer
|
|
|
|
zr_command_buffer_push_cruve -- pushes a bezier cruve command into the buffer
|
|
|
|
zr_command_buffer_push_image -- pushes a image draw command into the buffer
|
|
|
|
zr_command_buffer_push_text -- pushes a text draw command into the buffer
|
2015-06-04 23:17:54 +03:00
|
|
|
|
|
|
|
command iterator function API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_command_buffer_begin -- returns the first command in a buffer
|
|
|
|
zr_command_buffer_next -- returns the next command in a buffer
|
|
|
|
zr_foreach_buffer_command -- iterates over all commands in a buffer
|
2015-06-04 23:17:54 +03:00
|
|
|
*/
|
|
|
|
/* command type of every used drawing primitive */
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_command_type {
|
|
|
|
ZR_COMMAND_NOP,
|
|
|
|
ZR_COMMAND_SCISSOR,
|
|
|
|
ZR_COMMAND_LINE,
|
|
|
|
ZR_COMMAND_CURVE,
|
|
|
|
ZR_COMMAND_RECT,
|
|
|
|
ZR_COMMAND_CIRCLE,
|
|
|
|
ZR_COMMAND_TRIANGLE,
|
|
|
|
ZR_COMMAND_TEXT,
|
|
|
|
ZR_COMMAND_IMAGE,
|
|
|
|
ZR_COMMAND_MAX
|
2015-05-29 15:18:23 +03:00
|
|
|
};
|
|
|
|
|
2015-06-04 23:17:54 +03:00
|
|
|
/* command base and header of every comand inside the buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command {
|
|
|
|
enum zr_command_type type;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* the type of the current command */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size next;
|
2015-08-06 17:36:28 +03:00
|
|
|
/* absolute base pointer offset to the next command */
|
2015-05-29 15:18:23 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_scissor {
|
|
|
|
struct zr_command header;
|
|
|
|
zr_short x, y;
|
|
|
|
zr_ushort w, h;
|
2015-05-29 15:18:23 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_line {
|
|
|
|
struct zr_command header;
|
|
|
|
struct zr_vec2i begin;
|
|
|
|
struct zr_vec2i end;
|
|
|
|
struct zr_color color;
|
2015-05-29 15:18:23 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_curve {
|
|
|
|
struct zr_command header;
|
|
|
|
struct zr_vec2i begin;
|
|
|
|
struct zr_vec2i end;
|
|
|
|
struct zr_vec2i ctrl[2];
|
|
|
|
struct zr_color color;
|
2015-08-29 22:07:01 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_rect {
|
|
|
|
struct zr_command header;
|
|
|
|
zr_uint rounding;
|
|
|
|
zr_short x, y;
|
|
|
|
zr_ushort w, h;
|
|
|
|
struct zr_color color;
|
2015-05-29 15:18:23 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_circle {
|
|
|
|
struct zr_command header;
|
|
|
|
zr_short x, y;
|
|
|
|
zr_ushort w, h;
|
|
|
|
struct zr_color color;
|
2015-05-29 15:18:23 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_triangle {
|
|
|
|
struct zr_command header;
|
|
|
|
struct zr_vec2i a;
|
|
|
|
struct zr_vec2i b;
|
|
|
|
struct zr_vec2i c;
|
|
|
|
struct zr_color color;
|
2015-05-29 15:18:23 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_image {
|
|
|
|
struct zr_command header;
|
|
|
|
zr_short x, y;
|
|
|
|
zr_ushort w, h;
|
|
|
|
struct zr_image img;
|
2015-09-06 20:13:07 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_text {
|
|
|
|
struct zr_command header;
|
|
|
|
const struct zr_user_font *font;
|
|
|
|
struct zr_color background;
|
|
|
|
struct zr_color foreground;
|
|
|
|
zr_short x, y;
|
|
|
|
zr_ushort w, h;
|
|
|
|
zr_size length;
|
|
|
|
zr_char string[1];
|
2015-05-29 15:18:23 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_command_clipping {
|
|
|
|
ZR_NOCLIP = zr_false,
|
|
|
|
ZR_CLIP = zr_true
|
2015-06-03 01:58:57 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_buffer_stats {
|
|
|
|
zr_uint lines;
|
2015-08-27 20:25:13 +03:00
|
|
|
/* number of lines inside the buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_uint rectangles;
|
2015-08-27 20:25:13 +03:00
|
|
|
/* number of rectangles in the buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_uint circles;
|
2015-08-27 20:25:13 +03:00
|
|
|
/* number of circles in the buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_uint triangles;
|
2015-08-27 20:25:13 +03:00
|
|
|
/* number of triangles in the buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_uint images;
|
2015-08-27 20:25:13 +03:00
|
|
|
/* number of images in the buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_uint text;
|
2015-08-27 20:25:13 +03:00
|
|
|
/* number of text commands in the buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_uint glyphes;
|
2015-08-27 20:25:13 +03:00
|
|
|
/* number of text glyphes in the buffer */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_queue;
|
|
|
|
struct zr_command_buffer {
|
|
|
|
struct zr_buffer *base;
|
2015-08-06 17:36:28 +03:00
|
|
|
/* memory buffer to store the command */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_rect clip;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* current clipping rectangle */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool use_clipping;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* flag if the command buffer should clip commands */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_buffer_stats stats;
|
2015-08-27 20:25:13 +03:00
|
|
|
/* stats about the content of the buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_queue *queue;
|
|
|
|
struct zr_command_buffer *next;
|
|
|
|
struct zr_command_buffer *prev;
|
|
|
|
zr_size begin, end, last;
|
2015-08-27 20:25:13 +03:00
|
|
|
/* INTERNAL: references into a command queue */
|
2015-06-03 01:58:57 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_buffer_init(struct zr_command_buffer*, struct zr_buffer*,
|
|
|
|
enum zr_command_clipping);
|
2015-08-06 17:36:28 +03:00
|
|
|
/* this function intializes the command buffer
|
2015-07-12 17:51:56 +03:00
|
|
|
Input:
|
2015-08-21 18:34:51 +03:00
|
|
|
- memory buffer to store the commands into
|
2015-08-06 17:36:28 +03:00
|
|
|
- clipping flag for removing non-visible draw commands
|
2015-07-12 17:51:56 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_buffer_reset(struct zr_command_buffer*);
|
2015-08-07 17:53:52 +03:00
|
|
|
/* this function clears the command buffer but not the internal memory buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_buffer_clear(struct zr_command_buffer*);
|
2015-08-07 17:53:52 +03:00
|
|
|
/* this function clears the command buffer and internal memory buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
void *zr_command_buffer_push(struct zr_command_buffer*, zr_uint type, zr_size size);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function push enqueues a command into the buffer
|
|
|
|
Input:
|
|
|
|
- buffer to push the command into
|
|
|
|
- type of the command
|
|
|
|
- amount of memory that is needed for the specified command
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_buffer_push_scissor(struct zr_command_buffer*, struct zr_rect);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function push a clip rectangle command into the buffer
|
|
|
|
Input:
|
|
|
|
- buffer to push the clip rectangle command into
|
|
|
|
- x,y and width and height of the clip rectangle
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_buffer_push_line(struct zr_command_buffer*, zr_float, zr_float,
|
|
|
|
zr_float, zr_float, struct zr_color);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function pushes a line draw command into the buffer
|
|
|
|
Input:
|
|
|
|
- buffer to push the clip rectangle command into
|
2015-08-29 22:07:01 +03:00
|
|
|
- starting point of the line
|
|
|
|
- ending point of the line
|
|
|
|
- color of the line to draw
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_buffer_push_curve(struct zr_command_buffer*, zr_float, zr_float,
|
|
|
|
zr_float, zr_float, zr_float, zr_float,
|
|
|
|
zr_float, zr_float, struct zr_color);
|
2015-08-29 22:07:01 +03:00
|
|
|
/* this function pushes a quad bezier line draw command into the buffer
|
|
|
|
Input:
|
|
|
|
- buffer to push the clip rectangle command into
|
|
|
|
- starting point (x,y) of the line
|
|
|
|
- first control point (x,y) of the line
|
|
|
|
- second control point (x,y) of the line
|
2015-09-04 12:51:28 +03:00
|
|
|
- ending point (x,y) of the line
|
2015-06-04 23:17:54 +03:00
|
|
|
- color of the line to draw
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_buffer_push_rect(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
zr_float rounding, struct zr_color color);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function pushes a rectangle draw command into the buffer
|
|
|
|
Input:
|
|
|
|
- buffer to push the draw rectangle command into
|
2015-08-21 18:34:51 +03:00
|
|
|
- rectangle bounds
|
|
|
|
- rectangle edge rounding
|
2015-06-04 23:17:54 +03:00
|
|
|
- color of the rectangle to draw
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_buffer_push_circle(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
struct zr_color c);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function pushes a circle draw command into the buffer
|
|
|
|
Input:
|
|
|
|
- buffer to push the circle draw command into
|
2015-08-21 18:34:51 +03:00
|
|
|
- rectangle bounds of the circle
|
2015-06-04 23:17:54 +03:00
|
|
|
- color of the circle to draw
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_buffer_push_triangle(struct zr_command_buffer*, zr_float, zr_float,
|
|
|
|
zr_float, zr_float, zr_float, zr_float,
|
|
|
|
struct zr_color);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function pushes a triangle draw command into the buffer
|
|
|
|
Input:
|
|
|
|
- buffer to push the draw triangle command into
|
|
|
|
- (x,y) coordinates of all three points
|
|
|
|
- rectangle diameter of the circle
|
|
|
|
- color of the triangle to draw
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_buffer_push_image(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
struct zr_image*);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function pushes a image draw command into the buffer
|
|
|
|
Input:
|
|
|
|
- buffer to push the draw image command into
|
2015-08-21 18:34:51 +03:00
|
|
|
- bounds of the image to draw with position, width and height
|
2015-06-04 23:17:54 +03:00
|
|
|
- rectangle diameter of the circle
|
|
|
|
- color of the triangle to draw
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_buffer_push_text(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
const zr_char*, zr_size, const struct zr_user_font*,
|
|
|
|
struct zr_color, struct zr_color);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function pushes a text draw command into the buffer
|
|
|
|
Input:
|
|
|
|
- buffer to push the draw text command into
|
|
|
|
- top left position of the text with x,y position
|
|
|
|
- maixmal size of the text to draw with width and height
|
|
|
|
- color of the triangle to draw
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
#define zr_command(t, c) ((const struct zr_command_##t*)c)
|
2015-08-07 17:53:52 +03:00
|
|
|
/* this is a small helper makro to cast from a general to a specific command */
|
2015-09-18 00:09:49 +03:00
|
|
|
#define zr_foreach_buffer_command(i, b)\
|
|
|
|
for((i)=zr_command_buffer_begin(b); (i)!=NULL; (i)=zr_command_buffer_next(b,i))
|
2015-08-07 17:53:52 +03:00
|
|
|
/* this loop header allow to iterate over each command in a command buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
const struct zr_command *zr_command_buffer_begin(struct zr_command_buffer*);
|
2015-08-06 17:36:28 +03:00
|
|
|
/* this function returns the first command in the command buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
const struct zr_command *zr_command_buffer_next(struct zr_command_buffer*,
|
|
|
|
struct zr_command*);
|
2015-08-06 17:36:28 +03:00
|
|
|
/* this function returns the next command of a given command*/
|
|
|
|
/*
|
|
|
|
* ==============================================================
|
|
|
|
*
|
|
|
|
* Command Queue
|
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
*/
|
|
|
|
/* COMMAND QUEUE
|
|
|
|
----------------------------
|
2015-08-07 17:53:52 +03:00
|
|
|
The command queue extends the command buffer with the possiblity to use
|
|
|
|
more than one command buffer on one memory buffer and still only need
|
2015-09-06 20:13:07 +03:00
|
|
|
to iterate over one command list. Therefore it is possible to have multiple
|
2015-08-29 12:04:09 +03:00
|
|
|
windows without having to manage each windows individual memory. This greatly
|
2015-08-10 21:34:47 +03:00
|
|
|
simplifies and reduces the amount of code needed with just using command buffers.
|
|
|
|
|
|
|
|
Internally the command queue has a list of command buffers which can be
|
2015-09-18 00:09:49 +03:00
|
|
|
modified to create a certain sequence, for example the `zr_begin`
|
|
|
|
function changes the list to create overlapping windows, while `zr_begin_tiled`
|
2015-09-15 19:13:43 +03:00
|
|
|
always draws all its windows in the background by pushing its buffers to the
|
|
|
|
beginning of the list.
|
2015-08-06 17:36:28 +03:00
|
|
|
|
|
|
|
USAGE
|
|
|
|
----------------------------
|
2015-08-21 18:34:51 +03:00
|
|
|
The command queue owns a memory buffer internaly that needs to be initialized
|
2015-09-18 00:09:49 +03:00
|
|
|
either as a fixed size or dynamic buffer with functions `zr_commmand_queue_init'
|
|
|
|
or `zr_command_queue_init_fixed`. Windows are automaticall added to the command
|
|
|
|
queue in the `zr_window_init` with the `zr_command_queue_add` function
|
|
|
|
but removing a window requires a manual call of `zr_command_queue_remove`.
|
|
|
|
Internally the window calls the `zr_command_queue_start` and
|
|
|
|
`zr_commanmd_queue_finish` function that setup and finilize a command buffer for
|
2015-08-07 17:53:52 +03:00
|
|
|
command queuing. Finally to iterate over all commands in all command buffers
|
|
|
|
the iterator API is provided. It allows to iterate over each command in a
|
|
|
|
foreach loop.
|
2015-08-06 17:36:28 +03:00
|
|
|
|
|
|
|
command queue function API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_command_queue_init -- initializes a dynamic command queue
|
|
|
|
zr_command_queue_init_fixed -- initializes a static command queue
|
|
|
|
zr_command_queue_clear -- frees all memory if the command queue is dynamic
|
|
|
|
zr_command_queue_insert_font -- adds a command buffer in the front of the queue
|
|
|
|
zr_command_queue_insert_back -- adds a command buffer in the back of the queue
|
|
|
|
zr_command_queue_remove -- removes a command buffer from the queue
|
|
|
|
zr_command_queue_start -- begins the command buffer filling process
|
|
|
|
zr_command_queue_start_child -- begins the child command buffer filling process
|
|
|
|
zr_command_queue_finish_child -- ends the child command buffer filling process
|
|
|
|
zr_command_queue_finish -- ends the command buffer filling process
|
2015-08-06 17:36:28 +03:00
|
|
|
|
|
|
|
command iterator function API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_command_queue_begin -- returns the first command in a queue
|
|
|
|
zr_command_queue_next -- returns the next command in a queue or NULL
|
|
|
|
zr_foreach_command -- iterates over all commands in a queue
|
2015-08-06 17:36:28 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_buffer_list {
|
|
|
|
zr_size count;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* number of windows inside the stack */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_buffer *begin;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* first window inside the window which will be drawn first */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_buffer *end;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* currently active window which will be drawn last */
|
2015-08-06 17:36:28 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_sub_buffer {
|
|
|
|
zr_size begin;
|
2015-08-10 21:34:47 +03:00
|
|
|
/* begin of the subbuffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size parent_last;
|
2015-08-10 21:34:47 +03:00
|
|
|
/* last entry before the sub buffer*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size last;
|
2015-08-10 21:34:47 +03:00
|
|
|
/* last entry in the sub buffer*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size end;
|
2015-08-10 21:34:47 +03:00
|
|
|
/* end of the subbuffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size next;
|
2015-08-10 21:34:47 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_sub_buffer_stack {
|
|
|
|
zr_size count;
|
2015-08-10 21:34:47 +03:00
|
|
|
/* number of subbuffers */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size begin;
|
2015-08-10 21:34:47 +03:00
|
|
|
/* buffer offset of the first subbuffer*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size end;
|
2015-08-10 21:34:47 +03:00
|
|
|
/* buffer offset of the last subbuffer*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size size;
|
2015-08-10 21:34:47 +03:00
|
|
|
/* real size of the buffer */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_queue {
|
|
|
|
struct zr_buffer buffer;
|
2015-08-06 17:36:28 +03:00
|
|
|
/* memory buffer the hold all commands */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_buffer_list list;
|
2015-08-10 21:34:47 +03:00
|
|
|
/* list of each memory buffer inside the queue */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_sub_buffer_stack stack;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* subbuffer stack for overlapping popup windows in windows */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool build;
|
2015-08-07 17:53:52 +03:00
|
|
|
/* flag indicating if a complete command list was build inside the queue*/
|
2015-08-06 17:36:28 +03:00
|
|
|
};
|
2015-05-29 15:18:23 +03:00
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_queue_init(struct zr_command_queue*, const struct zr_allocator*,
|
|
|
|
zr_size initial_size, zr_float grow_factor);
|
2015-08-06 17:36:28 +03:00
|
|
|
/* this function initializes a growing command queue
|
|
|
|
Input:
|
|
|
|
- allocator holding your own alloctator and memory allocation callbacks
|
|
|
|
- initial size of the buffer
|
|
|
|
- factor to grow the buffer by if the buffer is full
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_queue_init_fixed(struct zr_command_queue*, void*, zr_size);
|
2015-08-06 17:36:28 +03:00
|
|
|
/* this function initializes a fixed size command queue
|
|
|
|
Input:
|
|
|
|
- fixed size previously allocated memory block
|
|
|
|
- size of the memory block
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_queue_insert_back(struct zr_command_queue*, struct zr_command_buffer*);
|
2015-08-07 17:53:52 +03:00
|
|
|
/* this function adds a command buffer into the back of the queue
|
|
|
|
Input:
|
|
|
|
- command buffer to add into the queue
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_queue_insert_front(struct zr_command_queue*, struct zr_command_buffer*);
|
2015-08-07 17:53:52 +03:00
|
|
|
/* this function adds a command buffer into the beginning of the queue
|
2015-08-06 17:36:28 +03:00
|
|
|
Input:
|
|
|
|
- command buffer to add into the queue
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_queue_remove(struct zr_command_queue*, struct zr_command_buffer*);
|
2015-08-06 17:36:28 +03:00
|
|
|
/* this function removes a command buffer from the queue
|
|
|
|
Input:
|
|
|
|
- command buffer to remove from the queue
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_queue_start(struct zr_command_queue*, struct zr_command_buffer*);
|
2015-08-06 17:36:28 +03:00
|
|
|
/* this function sets up the command buffer to be filled up
|
|
|
|
Input:
|
|
|
|
- command buffer to fill with commands
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_queue_finish(struct zr_command_queue*, struct zr_command_buffer*);
|
2015-08-06 17:36:28 +03:00
|
|
|
/* this function finishes the command buffer fill up process
|
|
|
|
Input:
|
|
|
|
- the now filled command buffer
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_command_queue_start_child(struct zr_command_queue*,
|
|
|
|
struct zr_command_buffer*);
|
2015-08-21 18:34:51 +03:00
|
|
|
/* this function sets up a child buffer inside a command buffer to be filled up
|
2015-08-10 21:34:47 +03:00
|
|
|
Input:
|
2015-08-21 18:34:51 +03:00
|
|
|
- command buffer to begin the child buffer in
|
2015-08-10 21:34:47 +03:00
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- zr_true if successful zr_false otherwise
|
2015-08-10 21:34:47 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_queue_finish_child(struct zr_command_queue*, struct zr_command_buffer*);
|
2015-08-21 18:34:51 +03:00
|
|
|
/* this function finishes the child buffer inside the command buffer fill up process
|
2015-08-10 21:34:47 +03:00
|
|
|
Input:
|
2015-08-21 18:34:51 +03:00
|
|
|
- the command buffer to create the child command buffer in
|
2015-08-10 21:34:47 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_queue_free(struct zr_command_queue*);
|
2015-08-06 17:36:28 +03:00
|
|
|
/* this function clears the internal buffer if it is a dynamic buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_queue_clear(struct zr_command_queue*);
|
2015-08-06 17:36:28 +03:00
|
|
|
/* this function reset the internal buffer and has to be called every frame */
|
2015-09-18 00:09:49 +03:00
|
|
|
#define zr_foreach_command(i, q)\
|
|
|
|
for((i)=zr_command_queue_begin(q); (i)!=0; (i)=zr_command_queue_next(q,i))
|
2015-08-06 17:36:28 +03:00
|
|
|
/* this function iterates over each command inside the command queue
|
|
|
|
Input:
|
2015-09-18 00:09:49 +03:00
|
|
|
- iterator zr_command pointer to iterate over all commands
|
2015-08-06 17:36:28 +03:00
|
|
|
- queue to iterate over
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_command_queue_build(struct zr_command_queue*);
|
2015-08-21 18:34:51 +03:00
|
|
|
/* this function builds the internal queue commmand list out of all buffers.
|
2015-09-18 00:09:49 +03:00
|
|
|
* Only needs be called if zr_command_queue_begin is called in parallel */
|
|
|
|
const struct zr_command *zr_command_queue_begin(struct zr_command_queue*);
|
2015-08-06 17:36:28 +03:00
|
|
|
/* this function returns the first command in the command queue */
|
2015-09-18 00:09:49 +03:00
|
|
|
const struct zr_command* zr_command_queue_next(struct zr_command_queue*,
|
|
|
|
const struct zr_command*);
|
2015-08-06 17:36:28 +03:00
|
|
|
/* this function returns the next command of a given command*/
|
2015-09-06 20:13:07 +03:00
|
|
|
/*
|
|
|
|
* ===============================================================
|
|
|
|
*
|
|
|
|
* Draw List
|
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
#if ZR_COMPILE_WITH_VERTEX_BUFFER
|
2015-09-06 20:13:07 +03:00
|
|
|
/* DRAW LIST
|
|
|
|
----------------------------
|
|
|
|
The optional draw list provides a way to convert the gui library
|
|
|
|
drawing command output into a hardware accessible format.
|
|
|
|
This consists of vertex, element and draw batch command buffer output which
|
|
|
|
can be interpreted by render frameworks (OpenGL, DirectX, ...).
|
|
|
|
In addition to just provide a way to convert commands the draw list has
|
|
|
|
a primitives and stateful path drawing API, which allows to draw into the
|
2015-09-07 19:37:30 +03:00
|
|
|
draw list even with anti-aliasing.
|
2015-09-06 20:13:07 +03:00
|
|
|
|
|
|
|
The draw list consist internaly of three user provided buffers that will be
|
|
|
|
filled with data. The first buffer is the the draw command and temporary
|
|
|
|
path buffer which permanetly stores all draw batch commands. The vertex and
|
|
|
|
element buffer are the same buffers as their hardware renderer counter-parts,
|
|
|
|
in fact it is even possible to directly map one of these buffers and fill
|
|
|
|
them with data.
|
|
|
|
|
|
|
|
The reason why the draw list is optional or is not the default library output
|
|
|
|
is that basic commands provide an easy way to abstract over other libraries
|
|
|
|
which already provide a drawing API and do not need or want the output the
|
2015-09-07 20:12:47 +03:00
|
|
|
draw list provides. In addition it is way easier and takes less memory
|
|
|
|
to serialize commands decribing primitives than vertex data.
|
2015-09-06 20:13:07 +03:00
|
|
|
|
|
|
|
USAGE
|
|
|
|
----------------------------
|
|
|
|
To actually use the draw list you first need the initialize the draw list
|
2015-09-07 20:12:47 +03:00
|
|
|
by providing three buffers to be filled while drawing. The reason
|
2015-09-06 20:13:07 +03:00
|
|
|
buffers need to be provided and not memory or an allocator is to provide
|
|
|
|
more fine grained control over the memory inside the draw list, which in term
|
|
|
|
requires more work from the user.
|
|
|
|
|
|
|
|
After the draw list has been initialized you can fill the draw list by
|
|
|
|
a.) converting the content of a command queue into the draw list format
|
|
|
|
b.) adding primtive filled shapes or only the outline of rectangles, circle, etc.
|
|
|
|
c.) using the stateful path API for fine grained drawing control
|
|
|
|
|
|
|
|
Finaly for the drawing process you have to iterate over each draw command
|
2015-09-18 00:09:49 +03:00
|
|
|
inside the `zr_draw_list` by using the function `zr_foreach_draw_command`
|
2015-09-07 20:12:47 +03:00
|
|
|
which contains drawing state like clip rectangle, current texture and a number
|
|
|
|
of elements to draw with the current state.
|
2015-09-06 20:13:07 +03:00
|
|
|
|
|
|
|
draw list buffer functions
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_draw_list_init - initializes a command buffer with memory
|
|
|
|
zr_draw_list_clear - clears and resets the buffer
|
|
|
|
zr_draw_list_load - load the draw buffer from a command queue
|
|
|
|
zr_draw_list_begin - returns the first command in the draw buffer
|
|
|
|
zr_draw_list_next - returns the next command in the draw buffer or NULL
|
|
|
|
zr_draw_list_is_empty - returns if the buffer has no vertexes or commands
|
|
|
|
zr_foreach_draw_command - iterates over all commands in the draw buffer
|
2015-09-06 20:13:07 +03:00
|
|
|
|
|
|
|
draw list primitives drawing functions
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_draw_list_add_line - pushes a line into the draw list
|
|
|
|
zr_draw_list_add_rect - pushes a rectangle into the draw list
|
|
|
|
zr_draw_list_add_rect_filled - pushes a filled rectangle into the draw list
|
|
|
|
zr_draw_list_add_triangle - pushes a triangle into the draw list
|
|
|
|
zr_draw_list_add_triangle_filled -pushes a filled triangle into the draw list
|
|
|
|
zr_draw_list_add_circle - pushes circle into the draw list
|
|
|
|
zr_draw_list_add_circle_filled - pushes a filled circle into the draw list
|
|
|
|
zr_draw_list_add_text - pushes text into the draw list
|
|
|
|
zr_draw_list_add_image - pushes an image into the draw list
|
2015-09-06 20:13:07 +03:00
|
|
|
|
|
|
|
stateful path functions
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_draw_list_path_clear - resets the current path
|
|
|
|
zr_draw_list_path_line_to - adds a point into the path
|
|
|
|
zr_draw_list_path_arc_to - adds a arc into the path
|
|
|
|
zr_draw_list_path_curve_to - adds a bezier curve into the path
|
|
|
|
zr_draw_list_path_rect_to - adds a rectangle into the path
|
|
|
|
zr_draw_list_path_fill - fills the path as a convex polygon
|
|
|
|
zr_draw_list_path_stroke - connects each point in the path
|
|
|
|
*/
|
|
|
|
typedef zr_ushort zr_draw_index;
|
|
|
|
typedef zr_uint zr_draw_vertex_color;
|
|
|
|
typedef zr_float(*zr_sin_f)(zr_float);
|
|
|
|
typedef zr_float(*zr_cos_f)(zr_float);
|
|
|
|
|
|
|
|
enum zr_anti_aliasing {
|
|
|
|
ZR_ANTI_ALIASING_OFF = zr_false,
|
2015-09-06 20:13:07 +03:00
|
|
|
/* renderes all primitives without anit-aliasing */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_ANTI_ALIASING_ON,
|
2015-09-06 20:13:07 +03:00
|
|
|
/* renderes all primitives with anit-aliasing */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_ANTI_ALIASING_MAX
|
2015-09-06 20:13:07 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_draw_vertex {
|
|
|
|
struct zr_vec2 position;
|
|
|
|
struct zr_vec2 uv;
|
|
|
|
zr_draw_vertex_color col;
|
2015-09-06 20:13:07 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_draw_list_stroke {
|
|
|
|
ZR_STROKE_OPEN = zr_false,
|
2015-09-15 19:13:43 +03:00
|
|
|
/* build up path has no connection back to the beginning */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_STROKE_CLOSED = zr_true
|
2015-09-15 19:13:43 +03:00
|
|
|
/* build up path has a connection back to the beginning */
|
2015-09-06 20:13:07 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_draw_command {
|
|
|
|
zr_uint elem_count;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* number of elements in the current draw batch */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_rect clip_rect;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* current screen clipping rectangle */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_handle texture;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* current texture to set */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_draw_null_texture {
|
|
|
|
zr_handle texture;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* texture handle to a texture with a white pixel */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 uv;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* coordinates to the white pixel in the texture */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_draw_list {
|
|
|
|
enum zr_anti_aliasing AA;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* flag indicating if anti-aliasing should be used to render primtives */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_draw_null_texture null;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* texture with white pixel for easy primitive drawing */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_rect clip_rect;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* current clipping rectangle */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_cos_f cos; zr_sin_f sin;
|
|
|
|
/* cosine/sine calculation callback since this library does not use libc */
|
|
|
|
struct zr_buffer *buffer;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* buffer to store draw commands and temporarily store path */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_buffer *vertexes;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* buffer to store each draw vertex */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_buffer *elements;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* buffer to store each draw element index */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_uint element_count;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* total number of elements inside the elements buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_uint vertex_count;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* total number of vertexes inside the vertex buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size cmd_offset;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* offset to the first command in the buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_uint cmd_count;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* number of commands inside the buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_uint path_count;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* current number of points inside the path */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_uint path_offset;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* offset to the first point in the buffer */
|
|
|
|
};
|
|
|
|
/* ---------------------------------------------------------------
|
|
|
|
* MAIN
|
|
|
|
* ---------------------------------------------------------------*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_init(struct zr_draw_list*, struct zr_buffer *cmds,
|
|
|
|
struct zr_buffer *vertexes, struct zr_buffer *elements,
|
|
|
|
zr_sin_f, zr_cos_f, struct zr_draw_null_texture,
|
|
|
|
enum zr_anti_aliasing AA);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function initializes the draw list
|
|
|
|
Input:
|
|
|
|
- command memory buffer to fill with commands and provided temporary memory for path
|
|
|
|
- vertex memory buffer to fill with draw vertexeses
|
|
|
|
- element memory buffer to fill with draw indexes
|
|
|
|
- sine function callback since this library does not use clib (default: just use sinf)
|
|
|
|
- cosine function callback since this library does not use clib (default: just use cosf)
|
|
|
|
- special null structure which holds a texture with a white pixel
|
|
|
|
- Anti-aliasing flag for turning on/off anti-aliased primitives drawing
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_load(struct zr_draw_list*, struct zr_command_queue *queue,
|
|
|
|
zr_float line_thickness, zr_uint curve_segments);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function loads the draw list from command queue commands
|
|
|
|
Input:
|
|
|
|
- queue with draw commands to fill the draw list with
|
|
|
|
- line thickness for all lines and non-filled primitives
|
|
|
|
- number of segments used for drawing circles and curves
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_clear(struct zr_draw_list *list);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function clears all buffers inside the draw list */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_draw_list_is_empty(struct zr_draw_list *list);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function returns if the draw list is empty */
|
2015-09-18 00:09:49 +03:00
|
|
|
#define zr_foreach_draw_command(i, q)\
|
|
|
|
for((i)=zr_draw_list_begin(q); (i)!=NULL; (i)=zr_draw_list_next(q,i))
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function iterates over each draw command inside the draw list
|
|
|
|
Input:
|
2015-09-18 00:09:49 +03:00
|
|
|
- iterator zr_draw_command pointer to iterate over all commands
|
2015-09-06 20:13:07 +03:00
|
|
|
- draw list to iterate over
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
const struct zr_draw_command *zr_draw_list_begin(const struct zr_draw_list *list);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function returns the first draw command in the draw list */
|
2015-09-18 00:09:49 +03:00
|
|
|
const struct zr_draw_command* zr_draw_list_next(const struct zr_draw_list *list,
|
|
|
|
const struct zr_draw_command*);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function returns the next draw command of a given draw command*/
|
|
|
|
/* ---------------------------------------------------------------
|
|
|
|
* PRIMITIVES
|
|
|
|
* ---------------------------------------------------------------*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_add_clip(struct zr_draw_list*, struct zr_rect);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function pushes a new clipping rectangle into the draw list
|
|
|
|
Input:
|
|
|
|
- new clipping rectangle
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_add_line(struct zr_draw_list*, struct zr_vec2 a,
|
|
|
|
struct zr_vec2 b, struct zr_color col,
|
|
|
|
zr_float thickness);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function pushes a new clipping rectangle into the draw list
|
|
|
|
Input:
|
|
|
|
- beginning point of the line
|
|
|
|
- end point of the line
|
|
|
|
- used line color
|
|
|
|
- line thickness in pixel
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_add_rect(struct zr_draw_list*, struct zr_rect rect,
|
|
|
|
struct zr_color col, zr_float rounding,
|
|
|
|
zr_float line_thickness);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function pushes a rectangle into the draw list
|
|
|
|
Input:
|
|
|
|
- rectangle to render into the draw list
|
|
|
|
- rectangle outline color
|
|
|
|
- rectangle edge rounding (0 == no edge rounding)
|
|
|
|
- rectangle outline thickness
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_add_rect_filled(struct zr_draw_list*, struct zr_rect rect,
|
|
|
|
struct zr_color col, zr_float rounding);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function pushes a filled rectangle into the draw list
|
|
|
|
Input:
|
|
|
|
- rectangle to render into the draw list
|
|
|
|
- color to fill the rectangle with
|
|
|
|
- rectangle edge rounding (0 == no edge rounding)
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_add_triangle(struct zr_draw_list*, struct zr_vec2 a,
|
|
|
|
struct zr_vec2 b, struct zr_vec2 c,
|
|
|
|
struct zr_color, zr_float line_thickness);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function pushes a triangle into the draw list
|
|
|
|
Input:
|
|
|
|
- first point of the triangle
|
|
|
|
- second point of the triangle
|
|
|
|
- third point of the triangle
|
|
|
|
- color of the triangle outline
|
|
|
|
- triangle outline line thickness
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_add_triangle_filled(struct zr_draw_list*, struct zr_vec2 a,
|
|
|
|
struct zr_vec2 b, struct zr_vec2 c,
|
|
|
|
struct zr_color col);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function pushes a filled triangle into the draw list
|
|
|
|
Input:
|
|
|
|
- first point of the triangle
|
|
|
|
- second point of the triangle
|
|
|
|
- third point of the triangle
|
|
|
|
- color to fill the triangle with
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_add_circle(struct zr_draw_list*, struct zr_vec2 center,
|
|
|
|
zr_float radius, struct zr_color col, zr_uint segs,
|
|
|
|
zr_float line_thickness);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function pushes a circle outline into the draw list
|
|
|
|
Input:
|
|
|
|
- center point of the circle
|
|
|
|
- circle radius
|
|
|
|
- circle outlone color
|
|
|
|
- number of segement that make up the circle
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_add_circle_filled(struct zr_draw_list*, struct zr_vec2 center,
|
|
|
|
zr_float radius, struct zr_color col, zr_uint);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function pushes a filled circle into the draw list
|
|
|
|
Input:
|
|
|
|
- center point of the circle
|
|
|
|
- circle radius
|
|
|
|
- color to fill the circle with
|
|
|
|
- number of segement that make up the circle
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_add_curve(struct zr_draw_list*, struct zr_vec2 p0,
|
|
|
|
struct zr_vec2 cp0, struct zr_vec2 cp1, struct zr_vec2 p1,
|
|
|
|
struct zr_color col, zr_uint segments, zr_float thickness);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function pushes a bezier curve into the draw list
|
|
|
|
Input:
|
|
|
|
- beginning point of the curve
|
|
|
|
- first curve control point
|
|
|
|
- second curve control point
|
|
|
|
- end point of the curve
|
|
|
|
- color of the curve
|
|
|
|
- number of segement that make up the circle
|
|
|
|
- line thickness of the curve
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_add_text(struct zr_draw_list*, const struct zr_user_font*,
|
|
|
|
struct zr_rect, const zr_char*, zr_size length,
|
|
|
|
struct zr_color bg, struct zr_color fg);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function renders text
|
|
|
|
Input:
|
|
|
|
- user font to draw the text with
|
|
|
|
- the rectangle the text will be drawn into
|
|
|
|
- string text to draw
|
|
|
|
- length of the string to draw
|
|
|
|
- text background color
|
|
|
|
- text color
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_add_image(struct zr_draw_list *list, struct zr_image texture,
|
|
|
|
struct zr_rect rect, struct zr_color color);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function renders an image
|
|
|
|
Input:
|
|
|
|
- image texture handle to draw
|
|
|
|
- rectangle with position and size of the image
|
|
|
|
- color to blend with the image
|
|
|
|
*/
|
|
|
|
/* ---------------------------------------------------------------
|
|
|
|
* PATH
|
|
|
|
* ---------------------------------------------------------------*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_path_clear(struct zr_draw_list*);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* clears the statefull drawing path previously build */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_path_line_to(struct zr_draw_list*, struct zr_vec2 pos);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* adds a point into the path that will make up a line or a convex polygon */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_path_arc_to(struct zr_draw_list*, struct zr_vec2 center,
|
|
|
|
zr_float radius, zr_float a_min, zr_float a_max,
|
|
|
|
zr_uint segments);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* adds an arc made up of a number of segments into the path */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_path_rect_to(struct zr_draw_list*, struct zr_vec2 a,
|
|
|
|
struct zr_vec2 b, zr_float rounding);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* adds a rectangle into the path */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_path_curve_to(struct zr_draw_list*, struct zr_vec2 p1,
|
|
|
|
struct zr_vec2 p2, struct zr_vec2 p3,
|
|
|
|
zr_uint num_segments);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* adds a bezier curve into the path where the first point has to be already in the path */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_path_fill(struct zr_draw_list*, struct zr_color);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* uses all points inside the path to draw a convex polygon */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_draw_list_path_stroke(struct zr_draw_list*, struct zr_color,
|
|
|
|
zr_bool closed, zr_float thickness);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* uses all points inside the path to draw a line/outline */
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* ==============================================================
|
|
|
|
*
|
|
|
|
* Font
|
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
*/
|
2015-09-15 19:13:43 +03:00
|
|
|
/* FONT
|
|
|
|
----------------------------
|
|
|
|
Font handling in this library can be achived in three different ways.
|
|
|
|
The first and simplest ways is by just using your font handling mechanism
|
|
|
|
and provide a simple callback for text string width calculation with
|
2015-09-18 00:09:49 +03:00
|
|
|
`zr_user_font`. This requires the default drawing output
|
2015-09-15 19:13:43 +03:00
|
|
|
and is not possible for the optional vertex buffer output.
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
The second way of font handling is by using the same `zr_user_font` struct
|
2015-09-15 19:13:43 +03:00
|
|
|
to reference a font as before but providing a second callback for
|
2015-09-18 00:09:49 +03:00
|
|
|
`zr_user_font_glyph` querying which is used for text drawing in the optional vertex
|
2015-09-15 19:13:43 +03:00
|
|
|
buffer output. In addition to the callback it is also required to provide
|
|
|
|
a texture atlas from the font to draw.
|
|
|
|
|
|
|
|
The final and most complex way is to use the optional font baker
|
|
|
|
and font handling function, which requires two additional headers for
|
|
|
|
TTF font baking. While the previous two methods did no need any functions
|
|
|
|
outside callbacks and are therefore rather simple to handle, the final
|
|
|
|
font handling method quite complex and you need to handle the complex
|
|
|
|
font baking API. The reason why it is complex is because there are multible
|
|
|
|
ways of using the API. For example it must be possible to use the font
|
|
|
|
for default command output as well as vertex buffer output. So for example
|
|
|
|
texture coordinates can either be UV for vertex buffer output or absolute pixel
|
|
|
|
for drawing function based on pixels. Furthermore it is possible to incoperate
|
|
|
|
custom user data into the resulting baked image (for example a white pixel for the
|
|
|
|
vertex buffer output). In addition and probably the most complex aspect of
|
|
|
|
the baking API was to incoperate baking of multible fonts into one image.
|
|
|
|
|
|
|
|
In general the font baking API can be understood as having a number of
|
|
|
|
loaded in memory TTF-fonts, font baking configuration and optional custom
|
|
|
|
render data as input, while the output is made of font specific data, a big
|
|
|
|
glyph array of all baked glyphes and the baked image. The API
|
|
|
|
was designed that way to have a typical file format and not
|
|
|
|
a perfectly ready in memory library instance of a font. The reason is more
|
|
|
|
control and seperates the font baking code from the in library used font format.
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
----------------------------
|
|
|
|
font baking functions
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_font_bake_memory -- calculates the needed font baking memory
|
|
|
|
zr_font_bake_pack -- packs all glyphes and calculates needed image memory
|
|
|
|
zr_font_bake -- renders all glyphes inside an image and setups glyphes
|
|
|
|
zr_font_bake_custom_data -- renders custom user data into the image
|
|
|
|
zr_font_bake_convert -- converts the baked image from alpha8 to rgba8
|
2015-09-15 19:13:43 +03:00
|
|
|
|
|
|
|
font functions
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_font_init -- initilizes the font
|
|
|
|
zr_font_ref -- create a user font out of the font
|
|
|
|
zr_font_find_glyph -- finds and returns a glyph from the font
|
2015-09-15 19:13:43 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
typedef zr_size(*zr_text_width_f)(zr_handle, const zr_char*, zr_size);
|
|
|
|
typedef void(*zr_query_font_glyph_f)(zr_handle, struct zr_user_font_glyph*,
|
|
|
|
zr_long codepoint, zr_long next_codepoint);
|
2015-09-15 19:13:43 +03:00
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
#if ZR_COMPILE_WITH_VERTEX_BUFFER
|
|
|
|
struct zr_user_font_glyph {
|
|
|
|
struct zr_vec2 uv[2];
|
2015-09-15 19:13:43 +03:00
|
|
|
/* texture coordinates */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 offset;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* offset between top left and glyph */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float width, height;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* size of the glyph */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float xadvance;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* offset to the next glyph */
|
2015-09-06 20:13:07 +03:00
|
|
|
};
|
2015-09-15 19:13:43 +03:00
|
|
|
#endif
|
2015-09-06 20:13:07 +03:00
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_user_font {
|
|
|
|
zr_handle userdata;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* user provided font handle */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float height;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* max height of the font */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_text_width_f width;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* font string width in pixel callback */
|
2015-09-18 00:09:49 +03:00
|
|
|
#if ZR_COMPILE_WITH_VERTEX_BUFFER
|
|
|
|
zr_query_font_glyph_f query;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* font glyph callback to query drawing info */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_handle texture;
|
2015-09-06 20:13:07 +03:00
|
|
|
/* texture handle to the used font atlas or texture */
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
#ifdef ZR_COMPILE_WITH_FONT
|
|
|
|
enum zr_font_coord_type {
|
|
|
|
ZR_COORD_UV,
|
2015-09-15 19:13:43 +03:00
|
|
|
/* texture coordinates inside font glyphes are clamped between 0.0f and 1.0f */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_COORD_PIXEL
|
2015-09-15 19:13:43 +03:00
|
|
|
/* texture coordinates inside font glyphes are in absolute pixel */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_baked_font {
|
|
|
|
zr_float height;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* height of the font */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float ascent, descent;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* font glyphes ascent and descent */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_long glyph_offset;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* glyph array offset inside the font glyph baking output array */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_long glyph_count;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* number of glyphes of this font inside the glyph baking array output */
|
2015-09-18 00:09:49 +03:00
|
|
|
const zr_long *ranges;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* font codepoint ranges as pairs of (from/to) and 0 as last element */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_font_config {
|
2015-09-15 19:13:43 +03:00
|
|
|
void *ttf_blob;
|
|
|
|
/* pointer to loaded TTF file memory block */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size ttf_size;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* size of the loaded TTF file memory block */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float size;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* bake pixel height of the font */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_uint oversample_h, oversample_v;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* rasterize at hight quality for sub-pixel position */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool pixel_snap;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* align very character to pixel boundry (if true set oversample (1,1)) */
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_font_coord_type coord_type;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* baked glyph texture coordinate format with either pixel or UV coordinates */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 spacing;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* extra pixel spacing between glyphs */
|
2015-09-18 00:09:49 +03:00
|
|
|
const zr_long *range;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* list of unicode ranges (2 values per range, zero terminated) */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_baked_font *font;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* font to setup in the baking process */
|
2015-09-06 20:13:07 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_font_glyph {
|
|
|
|
zr_long codepoint;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* unicode codepoint */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float xadvance;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* xoffset to the next character */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float x0, y0, x1, y1;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* glyph bounding points in pixel inside the glyph image with top left and bottom right */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float u0, v0, u1, v1;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* texture coordinates either in pixel or clamped (0.0 - 1.0) */
|
2015-09-06 20:13:07 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_font {
|
|
|
|
zr_float size;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* pixel height of the font */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float scale;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* scale factor for different font size */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float ascent, descent;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* font ascent and descent */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_font_glyph *glyphes;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* font glyph array */
|
2015-09-18 00:09:49 +03:00
|
|
|
const struct zr_font_glyph *fallback;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* fallback glyph */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_long fallback_codepoint;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* fallback glyph codepoint */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_long glyph_count;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* font glyph array size */
|
2015-09-18 00:09:49 +03:00
|
|
|
const zr_long *ranges;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* glyph unicode ranges in the font */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_handle atlas;
|
2015-09-15 19:13:43 +03:00
|
|
|
/* font image atlas handle */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* some language glyph codepoint ranges */
|
2015-09-18 00:09:49 +03:00
|
|
|
const zr_long *zr_font_default_glyph_ranges(void);
|
|
|
|
const zr_long *zr_font_chinese_glyph_ranges(void);
|
|
|
|
const zr_long *zr_font_cyrillic_glyph_ranges(void);
|
2015-09-15 19:13:43 +03:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------
|
|
|
|
* Baking
|
|
|
|
* ---------------------------------------------------------------*/
|
|
|
|
/* font baking functions (need to be called sequentially top to bottom) */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_font_bake_memory(zr_size *temporary_memory, zr_size *glyph_count,
|
|
|
|
struct zr_font_config*, zr_size count);
|
2015-09-15 19:13:43 +03:00
|
|
|
/* this function calculates the needed memory for the baking process
|
|
|
|
Input:
|
|
|
|
- array of configuration for every font that should be baked into one image
|
|
|
|
- number of configuration fonts in the array
|
|
|
|
Output:
|
|
|
|
- amount of memory needed in the baking process
|
|
|
|
- total number of glyphes that need to be allocated
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_font_bake_pack(zr_size *img_memory, zr_size *img_width, zr_size *img_height,
|
|
|
|
struct zr_recti *custom_space,
|
|
|
|
void *temporary_memory, zr_size temporary_size,
|
|
|
|
const struct zr_font_config*, zr_size font_count);
|
|
|
|
/* this function packs together all glyphes and optional space into one
|
2015-09-15 19:13:43 +03:00
|
|
|
total image space and returns the needed image width and height.
|
|
|
|
Input:
|
2015-09-18 00:09:49 +03:00
|
|
|
- NULL or custom space inside the image with width and height (will be updated!)
|
2015-09-15 19:13:43 +03:00
|
|
|
- temporary memory block that will be used in the baking process
|
|
|
|
- size of the temporary memory block
|
|
|
|
- array of configuration for every font that should be baked into one image
|
|
|
|
- number of configuration fonts in the array
|
|
|
|
Output:
|
|
|
|
- calculated resulting size of the image in bytes
|
|
|
|
- pixel width of the resulting image
|
|
|
|
- pixel height of the resulting image
|
|
|
|
- custom space bounds with position and size inside image which can be filled by the user
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_font_bake(void *image_memory, zr_size image_width, zr_size image_height,
|
|
|
|
void *temporary_memory, zr_size temporary_memory_size,
|
|
|
|
struct zr_font_glyph*, zr_size glyphes_count,
|
|
|
|
const struct zr_font_config*, zr_size font_count);
|
2015-09-15 19:13:43 +03:00
|
|
|
/* this function bakes all glyphes into the pre-allocated image and
|
|
|
|
fills a glyph array with information.
|
|
|
|
Input:
|
|
|
|
- image memory buffer to bake the glyph into
|
|
|
|
- pixel width/height of the image
|
|
|
|
- temporary memory block that will be used in the baking process
|
|
|
|
- size of the temporary memory block
|
|
|
|
Output:
|
|
|
|
- image filled with glyphes
|
|
|
|
- filled glyph array
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_font_bake_custom_data(void *img_memory, zr_size img_width, zr_size img_height,
|
|
|
|
struct zr_recti img_dst, const char *texture_data_mask,
|
|
|
|
zr_size tex_width, zr_size tex_height,
|
|
|
|
zr_char white, zr_char black);
|
2015-09-15 19:13:43 +03:00
|
|
|
/* this function bakes custom data in string format with white, black and zero
|
|
|
|
alpha pixels into the font image. The zero alpha pixel is represented as
|
|
|
|
any character beside the black and zero pixel character.
|
|
|
|
Input:
|
|
|
|
- image memory buffer to bake the custom data into
|
|
|
|
- image size (width/height) of the image in pixels
|
|
|
|
- custom texture data in string format
|
|
|
|
- texture size (width/height) of the custom image content
|
|
|
|
- character representing a white pixel in the texture data format
|
|
|
|
- character representing a black pixel in the texture data format
|
|
|
|
Output:
|
|
|
|
- image filled with custom texture data
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_font_bake_convert(void *out_memory, zr_ushort img_width, zr_ushort img_height,
|
2015-09-15 19:13:43 +03:00
|
|
|
const void *in_memory);
|
|
|
|
/* this function converts the alpha8 baking input image into a
|
|
|
|
preallocated rgba8 output image.
|
|
|
|
Input:
|
|
|
|
- image pixel size (width, height)
|
|
|
|
- memory block containing the alpha8 image
|
|
|
|
Output:
|
|
|
|
- rgba8 output image
|
|
|
|
*/
|
|
|
|
/* ---------------------------------------------------------------
|
|
|
|
* Font
|
|
|
|
* ---------------------------------------------------------------*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_font_init(struct zr_font*, zr_float pixel_height,
|
|
|
|
zr_long fallback_codepoint, struct zr_font_glyph*,
|
|
|
|
const struct zr_baked_font*, zr_handle atlas);
|
2015-09-15 19:13:43 +03:00
|
|
|
/* this function initializes a font. IMPORTANT: The font only references
|
|
|
|
* its glyphes since it allows to have multible font glyph in one big array.
|
|
|
|
Input:
|
|
|
|
- pixel height of the font can be different than the baked font height
|
|
|
|
- unicode fallback codepoint for a glyph that will be used if a glyph is requested
|
|
|
|
that does not exist in the font
|
|
|
|
- glyph array of all glyphes inside the font
|
|
|
|
- number of glyphes inside the glyph array
|
|
|
|
- font information for this font from the baking process
|
|
|
|
- handle to the baked font image atlas
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_user_font zr_font_ref(struct zr_font*);
|
2015-09-15 19:13:43 +03:00
|
|
|
/* this function
|
|
|
|
Output:
|
|
|
|
- gui font handle used in the library
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
const struct zr_font_glyph* zr_font_find_glyph(struct zr_font*, zr_long unicode);
|
2015-09-15 19:13:43 +03:00
|
|
|
/* this function
|
|
|
|
Input:
|
|
|
|
- unicode glyph codepoint of the glyph
|
|
|
|
Output:
|
|
|
|
- either the glyph with the given codepoint or a fallback glyph if does not exist
|
|
|
|
*/
|
2015-09-06 20:13:07 +03:00
|
|
|
#endif
|
2015-07-05 00:36:01 +03:00
|
|
|
/*
|
2015-07-17 18:06:56 +03:00
|
|
|
* ===============================================================
|
2015-07-05 00:36:01 +03:00
|
|
|
*
|
|
|
|
* Edit Box
|
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
*/
|
2015-07-08 13:05:20 +03:00
|
|
|
/* EDIT BOX
|
|
|
|
----------------------------
|
|
|
|
The Editbox is for text input with either a fixed or dynamically growing
|
2015-09-18 00:09:49 +03:00
|
|
|
buffer. It extends the basic functionality of basic input over `zr_edit`
|
|
|
|
and `zr_edit` with basic copy and paste functionality and the possiblity
|
2015-07-08 13:05:20 +03:00
|
|
|
to use a extending buffer.
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
----------------------------
|
|
|
|
The Editbox first needs to be initialized either with a fixed size
|
|
|
|
memory block or a allocator. After that it can be used by either the
|
2015-09-18 00:09:49 +03:00
|
|
|
`zr_editobx` or `zr_editbox` function. In addition symbols can be
|
|
|
|
added and removed with `zr_edit_box_add` and `zr_edit_box_remove`.
|
2015-07-08 13:05:20 +03:00
|
|
|
|
|
|
|
Widget function API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_edit_box_init -- initialize a dynamically growing edit box
|
|
|
|
zr_edit_box_init_fixed -- initialize a fixed size edit box
|
|
|
|
zr_edit_box_reset -- resets the edit box back to the beginning
|
|
|
|
zr_edit_box_clear -- frees all memory of a dynamic edit box
|
|
|
|
zr_edit_box_add -- adds a symbol to the editbox
|
|
|
|
zr_edit_box_remove -- removes a symbol from the editbox
|
|
|
|
zr_edit_box_get -- returns the string inside the editbox
|
|
|
|
zr_edit_box_get_const -- returns the const string inside the editbox
|
|
|
|
zr_edit_box_free -- frees all memory in a dynamic editbox
|
|
|
|
zr_edit_box_info -- fills a memory info struct with data
|
|
|
|
zr_edit_box_at -- returns the glyph at the given position
|
|
|
|
zr_edit_box_at_cursor -- returns the glyph at the cursor position
|
|
|
|
zr_edit_box_at_char -- returns the char at the given position
|
|
|
|
zr_edit_box_set_cursor -- sets the cursor to a given glyph
|
|
|
|
zr_edit_box_get_cursor -- returns the position of the cursor
|
|
|
|
zr_edit_box_len_char -- returns the length of the string in bytes
|
|
|
|
zr_edit_box_len -- returns the length of the string in glyphes
|
|
|
|
*/
|
|
|
|
typedef zr_bool(*zr_filter)(zr_long unicode);
|
|
|
|
typedef void(*zr_paste_f)(zr_handle, struct zr_edit_box*);
|
|
|
|
typedef void(*zr_copy_f)(zr_handle, const char*, zr_size size);
|
|
|
|
|
|
|
|
struct zr_clipboard {
|
|
|
|
zr_handle userdata;
|
2015-08-06 17:36:28 +03:00
|
|
|
/* user memory for callback */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_paste_f paste;
|
2015-08-06 17:36:28 +03:00
|
|
|
/* paste callback for the edit box */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_copy_f copy;
|
2015-08-06 17:36:28 +03:00
|
|
|
/* copy callback for the edit box */
|
2015-07-05 00:36:01 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_selection {
|
|
|
|
zr_bool active;
|
2015-08-06 17:36:28 +03:00
|
|
|
/* current selection state */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size begin;
|
2015-08-06 17:36:28 +03:00
|
|
|
/* text selection beginning glyph index */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size end;
|
2015-08-06 17:36:28 +03:00
|
|
|
/* text selection ending glyph index */
|
2015-08-02 14:49:51 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
typedef struct zr_buffer zr_edit_buffer;
|
|
|
|
struct zr_edit_box {
|
|
|
|
zr_edit_buffer buffer;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* glyph buffer to add text into */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_state active;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* flag indicating if the buffer is currently being modified */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size cursor;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* current glyph (not byte) cursor position */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size glyphes;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* number of glyphes inside the edit box */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_clipboard clip;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* copy paste callbacks */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_filter filter;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* input filter callback */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_selection sel;
|
2015-08-02 14:49:51 +03:00
|
|
|
/* text selection */
|
2015-07-05 00:36:01 +03:00
|
|
|
};
|
|
|
|
|
2015-07-08 13:05:20 +03:00
|
|
|
/* filter function */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_filter_default(zr_long unicode);
|
|
|
|
zr_bool zr_filter_ascii(zr_long unicode);
|
|
|
|
zr_bool zr_filter_float(zr_long unicode);
|
|
|
|
zr_bool zr_filter_decimal(zr_long unicode);
|
|
|
|
zr_bool zr_filter_hex(zr_long unicode);
|
|
|
|
zr_bool zr_filter_oct(zr_long unicode);
|
|
|
|
zr_bool zr_filter_binary(zr_long unicode);
|
2015-07-05 00:36:01 +03:00
|
|
|
|
2015-07-12 17:36:55 +03:00
|
|
|
/* editbox */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_edit_box_init(struct zr_edit_box*, struct zr_allocator*, zr_size initial,
|
|
|
|
zr_float grow_fac, const struct zr_clipboard*, zr_filter);
|
2015-07-18 16:54:05 +03:00
|
|
|
/* this function initializes the editbox a growing buffer
|
|
|
|
Input:
|
|
|
|
- allocator implementation
|
|
|
|
- initital buffer size
|
|
|
|
- buffer growing factor
|
|
|
|
- clipboard implementation for copy&paste or NULL of not needed
|
|
|
|
- character filtering callback to limit input or NULL of not needed
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_edit_box_init_fixed(struct zr_edit_box*, void *memory, zr_size size,
|
|
|
|
const struct zr_clipboard*, zr_filter);
|
2015-07-18 16:54:05 +03:00
|
|
|
/* this function initializes the editbox a static buffer
|
|
|
|
Input:
|
|
|
|
- memory block to fill
|
|
|
|
- sizeo of the memory block
|
|
|
|
- clipboard implementation for copy&paste or NULL of not needed
|
|
|
|
- character filtering callback to limit input or NULL of not needed
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_edit_box_clear(struct zr_edit_box*);
|
2015-07-18 16:54:05 +03:00
|
|
|
/* this function resets the buffer and sets everything back into a clean state */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_edit_box_free(struct zr_edit_box*);
|
2015-07-18 16:54:05 +03:00
|
|
|
/* this function frees all internal memory in a dynamically growing buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_edit_box_info(struct zr_memory_status*, struct zr_edit_box*);
|
2015-08-06 17:36:28 +03:00
|
|
|
/* this function returns information about the memory in use */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_edit_box_add(struct zr_edit_box*, const char*, zr_size);
|
2015-07-18 16:54:05 +03:00
|
|
|
/* this function adds text at the current cursor position
|
|
|
|
Input:
|
|
|
|
- string buffer or glyph to copy/add to the buffer
|
|
|
|
- length of the string buffer or glyph
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_edit_box_remove(struct zr_edit_box*);
|
2015-07-18 16:54:05 +03:00
|
|
|
/* removes the glyph at the current cursor position */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_char *zr_edit_box_get(struct zr_edit_box*);
|
2015-07-18 16:54:05 +03:00
|
|
|
/* returns the string buffer inside the edit box */
|
2015-09-18 00:09:49 +03:00
|
|
|
const zr_char *zr_edit_box_get_const(struct zr_edit_box*);
|
2015-07-18 16:54:05 +03:00
|
|
|
/* returns the constant string buffer inside the edit box */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_edit_box_at(struct zr_edit_box*, zr_size pos, zr_glyph, zr_size*);
|
2015-07-18 16:54:05 +03:00
|
|
|
/* this function returns the glyph at a given offset
|
|
|
|
Input:
|
|
|
|
- glyph offset inside the buffer
|
|
|
|
Output:
|
|
|
|
- utf8 glyph at the given position
|
|
|
|
- byte length of the glyph
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_edit_box_at_cursor(struct zr_edit_box*, zr_glyph, zr_size*);
|
2015-07-18 16:54:05 +03:00
|
|
|
/* this function returns the glyph at the cursor
|
|
|
|
Output:
|
|
|
|
- utf8 glyph at the cursor position
|
|
|
|
- byte length of the glyph
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_char zr_edit_box_at_char(struct zr_edit_box*, zr_size pos);
|
2015-07-18 16:54:05 +03:00
|
|
|
/* this function returns the character at a given byte position
|
|
|
|
Input:
|
|
|
|
- character offset inside the buffer
|
|
|
|
Output:
|
|
|
|
- character at the given position
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_edit_box_set_cursor(struct zr_edit_box*, zr_size pos);
|
2015-07-18 16:54:05 +03:00
|
|
|
/* this function sets the cursor at a given glyph position
|
|
|
|
Input:
|
|
|
|
- glyph offset inside the buffer
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size zr_edit_box_get_cursor(struct zr_edit_box *eb);
|
2015-07-18 16:54:05 +03:00
|
|
|
/* this function returns the cursor glyph position
|
|
|
|
Output:
|
|
|
|
- cursor glyph offset inside the buffer
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size zr_edit_box_len_char(struct zr_edit_box*);
|
2015-07-18 16:54:05 +03:00
|
|
|
/* this function returns length of the buffer in bytes
|
|
|
|
Output:
|
|
|
|
- string buffer byte length
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size zr_edit_box_len(struct zr_edit_box*);
|
2015-07-18 16:54:05 +03:00
|
|
|
/* this function returns length of the buffer in glyphes
|
|
|
|
Output:
|
|
|
|
- string buffer glyph length
|
|
|
|
*/
|
2015-05-29 15:18:23 +03:00
|
|
|
/*
|
|
|
|
* ==============================================================
|
|
|
|
*
|
|
|
|
* Widgets
|
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
*/
|
2015-06-04 23:17:54 +03:00
|
|
|
/* WIDGETS
|
|
|
|
----------------------------
|
|
|
|
The Widget API supports a number of basic widgets like buttons, sliders or
|
|
|
|
editboxes and stores no widget state. Instead the state of each widget has to
|
2015-08-29 12:04:09 +03:00
|
|
|
be managed by the user. It is the basis for the window API and implements
|
|
|
|
the functionality for almost all widgets in the window API. The widget API
|
|
|
|
hereby is more flexible than the window API in placing and styling but
|
2015-07-14 14:26:53 +03:00
|
|
|
requires more work for the user and has no concept for groups of widgets.
|
2015-06-04 23:17:54 +03:00
|
|
|
|
|
|
|
USAGE
|
|
|
|
----------------------------
|
2015-08-07 17:53:52 +03:00
|
|
|
Most widgets take an input struct, font and widget specific data and a command
|
2015-06-04 23:17:54 +03:00
|
|
|
buffer to push draw command into and return the updated widget state.
|
|
|
|
Important to note is that there is no actual state that is being stored inside
|
|
|
|
the toolkit so everything has to be stored byte the user.
|
|
|
|
|
|
|
|
Widget function API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_widget_text -- draws a string inside a box
|
|
|
|
zr_widget_button_text -- button widget with text content
|
|
|
|
zr_widget_button_image -- button widget with icon content
|
|
|
|
zr_widget_button_triangle -- button widget with triangle content
|
|
|
|
zr_widget_button_text_triangle -- button widget with triangle and text content
|
|
|
|
zr_widget_button_text_image -- button widget with image and text content
|
|
|
|
zr_widget_toggle -- either a checkbox or radiobutton widget
|
|
|
|
zr_widget_slider -- floating point slider widget
|
|
|
|
zr_progress -- unsigned integer progressbar widget
|
|
|
|
zr_editbox -- Editbox widget for complex user input
|
|
|
|
zr_edit -- Editbox wiget for basic user input
|
|
|
|
zr_edit_filtered -- Editbox with utf8 gylph filter capabilities
|
|
|
|
zr_spinner -- integer spinner widget
|
|
|
|
zr_selector -- string selector widget
|
|
|
|
zr_scrollbarv -- vertical scrollbar widget imeplementation
|
|
|
|
zr_scrollbarh -- horizontal scrollbar widget imeplementation
|
|
|
|
*/
|
|
|
|
enum zr_text_align {
|
|
|
|
ZR_TEXT_LEFT,
|
|
|
|
ZR_TEXT_CENTERED,
|
|
|
|
ZR_TEXT_RIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum zr_button_behavior {
|
|
|
|
ZR_BUTTON_DEFAULT,
|
2015-08-07 17:53:52 +03:00
|
|
|
/* button only returns on activation */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_BUTTON_REPEATER,
|
2015-08-07 17:53:52 +03:00
|
|
|
/* button returns as long as the button is pressed */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_BUTTON_BEHAVIOR_MAX
|
2015-08-07 17:53:52 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_text {
|
|
|
|
struct zr_vec2 padding;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* padding between bounds and text */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color background;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* text background color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color text;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* text color */
|
2015-03-13 22:01:31 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_button {
|
|
|
|
zr_float border_width;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* size of the border */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float rounding;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* buttong rectangle rounding */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 padding;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* padding between bounds and content */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color border;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* button border color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color normal;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* normal button background color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color hover;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* hover button background color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color active;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* hover button background color */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_button_text {
|
|
|
|
struct zr_button base;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* basic button style */
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_text_align alignment;
|
2015-08-13 16:57:28 +03:00
|
|
|
/* text alignment in the button */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color normal;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* normal text color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color hover;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* hovering text border color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color active;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* active text border color */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_symbol {
|
|
|
|
ZR_SYMBOL_X,
|
|
|
|
ZR_SYMBOL_UNDERSCORE,
|
|
|
|
ZR_SYMBOL_CIRCLE,
|
|
|
|
ZR_SYMBOL_CIRCLE_FILLED,
|
|
|
|
ZR_SYMBOL_RECT,
|
|
|
|
ZR_SYMBOL_RECT_FILLED,
|
|
|
|
ZR_SYMBOL_TRIANGLE_UP,
|
|
|
|
ZR_SYMBOL_TRIANGLE_DOWN,
|
|
|
|
ZR_SYMBOL_TRIANGLE_LEFT,
|
|
|
|
ZR_SYMBOL_TRIANGLE_RIGHT,
|
|
|
|
ZR_SYMBOL_PLUS,
|
|
|
|
ZR_SYMBOL_MINUS,
|
|
|
|
ZR_SYMBOL_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
struct zr_button_symbol {
|
|
|
|
struct zr_button base;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* basic button style */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color normal;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* normal triangle color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color hover;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* hovering triangle color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color active;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* active triangle color */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_button_icon {
|
|
|
|
struct zr_button base;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* basic button style */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 padding;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* additional image padding */
|
2015-03-20 12:58:11 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_toggle_type {
|
|
|
|
ZR_TOGGLE_CHECK,
|
2015-06-04 23:17:54 +03:00
|
|
|
/* checkbox toggle */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_TOGGLE_OPTION
|
2015-06-04 23:17:54 +03:00
|
|
|
/* radiobutton toggle */
|
2015-03-09 22:04:45 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_toggle {
|
|
|
|
zr_float rounding;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* checkbox rectangle rounding */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 padding;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* padding between bounds and content */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color font;
|
2015-09-07 19:37:30 +03:00
|
|
|
/* text background */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color background;
|
2015-09-07 19:37:30 +03:00
|
|
|
/* text color background */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color normal;
|
2015-09-07 19:37:30 +03:00
|
|
|
/* toggle cursor background normal color*/
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color hover;
|
2015-09-07 19:37:30 +03:00
|
|
|
/* toggle cursor background hove color*/
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color cursor;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* toggle cursor color*/
|
2015-03-09 22:04:45 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_progress {
|
|
|
|
zr_float rounding;
|
2015-06-16 00:46:13 +03:00
|
|
|
/* progressbar rectangle rounding */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 padding;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* padding between bounds and content */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color border;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* progressbar cursor color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color background;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* progressbar background color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color normal;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* progressbar normal cursor color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color hover;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* progressbar hovering cursor color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color active;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* progressbar active cursor color */
|
2015-03-09 22:04:45 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_slider {
|
|
|
|
struct zr_vec2 padding;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* padding between bounds and content */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color border;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* slider cursor border color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color bg;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* slider background color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color normal;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* slider cursor color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color hover;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* slider cursor color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color active;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* slider cursor color */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float rounding;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* slider rounding */
|
2015-05-23 01:11:58 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_scrollbar {
|
|
|
|
zr_float rounding;
|
2015-06-16 00:46:13 +03:00
|
|
|
/* scrollbar rectangle rounding */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color border;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* scrollbar border color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color background;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* scrollbar background color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color normal;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* scrollbar cursor color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color hover;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* scrollbar cursor color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color active;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* scrollbar cursor color */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool has_scrolling;
|
2015-06-23 20:23:25 +03:00
|
|
|
/* flag if the scrollbar can be updated by scrolling */
|
2015-03-09 22:04:45 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_input_filter {
|
|
|
|
ZR_INPUT_DEFAULT,
|
2015-06-16 00:46:13 +03:00
|
|
|
/* everything goes */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_INPUT_ASCII,
|
2015-06-16 00:46:13 +03:00
|
|
|
/* ASCII characters (0-127)*/
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_INPUT_FLOAT,
|
2015-06-16 00:46:13 +03:00
|
|
|
/* only float point numbers */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_INPUT_DEC,
|
2015-06-16 00:46:13 +03:00
|
|
|
/* only integer numbers */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_INPUT_HEX,
|
2015-06-16 00:46:13 +03:00
|
|
|
/* only hex numbers */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_INPUT_OCT,
|
2015-06-16 00:46:13 +03:00
|
|
|
/* only octal numbers */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_INPUT_BIN
|
2015-06-16 00:46:13 +03:00
|
|
|
/* only binary numbers */
|
2015-03-13 22:01:31 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_edit {
|
|
|
|
zr_float border_size;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* editbox border line size */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float rounding;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* editbox rectangle rounding */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 padding;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* padding between bounds and content*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool show_cursor;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* flag indication if the cursor should be drawn */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color background;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* editbox background */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color border;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* editbox border color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color cursor;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* editbox cursor color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color text;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* editbox text color */
|
2015-03-13 22:01:31 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_spinner {
|
|
|
|
struct zr_button_symbol button;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* button style */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color color;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* spinner background color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color border;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* spinner border color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color text;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* spinner text color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 padding;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* spinner padding between bounds and content*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool show_cursor;
|
2015-06-04 23:17:54 +03:00
|
|
|
/* flag indicating if the cursor should be drawn */
|
2015-03-09 22:04:45 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_widget_text(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
const char*, zr_size, const struct zr_text*,
|
|
|
|
enum zr_text_align, const struct zr_user_font*);
|
2015-06-16 00:46:13 +03:00
|
|
|
/* this function executes a text widget with text alignment
|
2015-06-04 23:17:54 +03:00
|
|
|
Input:
|
2015-06-16 00:46:13 +03:00
|
|
|
- output command buffer for drawing
|
2015-08-21 18:34:51 +03:00
|
|
|
- text bounds
|
2015-06-04 23:17:54 +03:00
|
|
|
- string to draw
|
|
|
|
- length of the string
|
|
|
|
- visual widget style structure describing the text
|
|
|
|
- text alignment with either left, center and right
|
|
|
|
- font structure for text drawing
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_widget_button_text(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
const char*, enum zr_button_behavior,
|
|
|
|
const struct zr_button_text*,
|
|
|
|
const struct zr_input*, const struct zr_user_font*);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function executes a text button widget
|
|
|
|
Input:
|
2015-06-16 00:46:13 +03:00
|
|
|
- output command buffer for drawing
|
2015-08-21 18:34:51 +03:00
|
|
|
- text button widget bounds
|
2015-06-04 23:17:54 +03:00
|
|
|
- button text
|
|
|
|
- button behavior with either repeating or transition state event
|
|
|
|
- visual widget style structure describing the button
|
|
|
|
- input structure to update the button with
|
|
|
|
- font structure for text drawing
|
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- returns zr_true if the button was pressed zr_false otherwise
|
2015-06-04 23:17:54 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_widget_button_image(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
struct zr_image, enum zr_button_behavior b,
|
|
|
|
const struct zr_button_icon*, const struct zr_input*);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function executes a image button widget
|
|
|
|
Input:
|
2015-06-16 00:46:13 +03:00
|
|
|
- output command buffer for drawing
|
|
|
|
- (x,y) position
|
|
|
|
- (width, height) size
|
2015-06-04 23:17:54 +03:00
|
|
|
- user provided image handle which is either a pointer or a id
|
|
|
|
- button behavior with either repeating or transition state event
|
|
|
|
- visual widget style structure describing the button
|
|
|
|
- input structure to update the button with
|
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- returns zr_true if the button was pressed zr_false otherwise
|
2015-06-04 23:17:54 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_widget_button_symbol(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
enum zr_symbol, enum zr_button_behavior,
|
|
|
|
const struct zr_button_symbol*, const struct zr_input*,
|
|
|
|
const struct zr_user_font*);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function executes a triangle button widget
|
|
|
|
Input:
|
2015-06-16 00:46:13 +03:00
|
|
|
- output command buffer for drawing
|
2015-08-21 18:34:51 +03:00
|
|
|
- triangle button bounds
|
2015-06-04 23:17:54 +03:00
|
|
|
- triangle direction with either left, top, right xor bottom
|
|
|
|
- button behavior with either repeating or transition state event
|
|
|
|
- visual widget style structure describing the button
|
|
|
|
- input structure to update the button with
|
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- returns zr_true if the button was pressed zr_false otherwise
|
2015-06-04 23:17:54 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_widget_button_text_symbol(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
enum zr_symbol, const char*, enum zr_text_align,
|
|
|
|
enum zr_button_behavior,
|
|
|
|
const struct zr_button_text*,
|
|
|
|
const struct zr_user_font*,
|
|
|
|
const struct zr_input*);
|
2015-06-06 21:13:28 +03:00
|
|
|
/* this function executes a button with text and a triangle widget
|
|
|
|
Input:
|
2015-06-16 00:46:13 +03:00
|
|
|
- output command buffer for drawing
|
2015-08-21 18:34:51 +03:00
|
|
|
- bounds of the text triangle widget
|
2015-06-06 21:13:28 +03:00
|
|
|
- triangle direction with either left, top, right xor bottom
|
|
|
|
- button text
|
|
|
|
- text alignment with either left, center and right
|
|
|
|
- button behavior with either repeating or transition state event
|
|
|
|
- visual widget style structure describing the button
|
|
|
|
- font structure for text drawing
|
|
|
|
- input structure to update the button with
|
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- returns zr_true if the button was pressed zr_false otherwise
|
2015-06-06 21:13:28 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_widget_button_text_image(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
struct zr_image, const char*, enum zr_text_align,
|
|
|
|
enum zr_button_behavior,
|
|
|
|
const struct zr_button_text*,
|
|
|
|
const struct zr_user_font*, const struct zr_input*);
|
2015-06-06 21:13:28 +03:00
|
|
|
/* this function executes a button widget with text and an icon
|
|
|
|
Input:
|
2015-06-16 00:46:13 +03:00
|
|
|
- output command buffer for drawing
|
2015-08-21 18:34:51 +03:00
|
|
|
- bounds of the text image widgets
|
2015-06-06 21:13:28 +03:00
|
|
|
- user provided image handle which is either a pointer or a id
|
|
|
|
- button text
|
|
|
|
- text alignment with either left, center and right
|
|
|
|
- button behavior with either repeating or transition state event
|
|
|
|
- visual widget style structure describing the button
|
|
|
|
- font structure for text drawing
|
|
|
|
- input structure to update the button with
|
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- returns zr_true if the button was pressed zr_false otherwise
|
2015-06-06 21:13:28 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_widget_toggle(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
zr_bool*, const char *string, enum zr_toggle_type,
|
|
|
|
const struct zr_toggle*, const struct zr_input*,
|
|
|
|
const struct zr_user_font*);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function executes a toggle (checkbox, radiobutton) widget
|
|
|
|
Input:
|
2015-06-16 00:46:13 +03:00
|
|
|
- output command buffer for drawing
|
2015-08-21 18:34:51 +03:00
|
|
|
- bounds of the toggle
|
2015-06-04 23:17:54 +03:00
|
|
|
- active or inactive flag describing the state of the toggle
|
|
|
|
- visual widget style structure describing the toggle
|
|
|
|
- input structure to update the toggle with
|
|
|
|
- font structure for text drawing
|
|
|
|
Output:
|
|
|
|
- returns the update state of the toggle
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float zr_widget_slider(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
zr_float min, zr_float val, zr_float max, zr_float step,
|
|
|
|
const struct zr_slider *s, const struct zr_input *in);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function executes a slider widget
|
|
|
|
Input:
|
2015-06-16 00:46:13 +03:00
|
|
|
- output command buffer for drawing
|
2015-08-21 18:34:51 +03:00
|
|
|
- bounds of the slider
|
2015-06-04 23:17:54 +03:00
|
|
|
- minimal slider value that will not be underflown
|
|
|
|
- slider value to be updated by the user
|
|
|
|
- maximal slider value that will not be overflown
|
|
|
|
- step interval the value will be updated with
|
|
|
|
- visual widget style structure describing the slider
|
|
|
|
- input structure to update the slider with
|
|
|
|
Output:
|
|
|
|
- returns the from the user input updated value
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size zr_widget_progress(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
zr_size value, zr_size max, zr_bool modifyable,
|
|
|
|
const struct zr_progress*, const struct zr_input*);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function executes a progressbar widget
|
|
|
|
Input:
|
2015-06-16 00:46:13 +03:00
|
|
|
- output command buffer for drawing
|
|
|
|
- (x,y) position
|
|
|
|
- (width, height) size
|
2015-06-04 23:17:54 +03:00
|
|
|
- progressbar value to be updated by the user
|
|
|
|
- maximal progressbar value that will not be overflown
|
|
|
|
- flag if the progressbar is modifyable by the user
|
|
|
|
- visual widget style structure describing the progressbar
|
|
|
|
- input structure to update the slider with
|
|
|
|
Output:
|
|
|
|
- returns the from the user input updated value
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_widget_editbox(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
struct zr_edit_box*, const struct zr_edit*,
|
|
|
|
const struct zr_input*, const struct zr_user_font*);
|
2015-07-05 00:36:01 +03:00
|
|
|
/* this function executes a editbox widget
|
|
|
|
Input:
|
|
|
|
- output command buffer for drawing
|
|
|
|
- (x,y) position
|
|
|
|
- (width, height) size
|
|
|
|
- edit box structure containing the state to update
|
|
|
|
- visual widget style structure describing the editbox
|
|
|
|
- input structure to update the editbox with
|
|
|
|
- font structure for text drawing
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size zr_widget_edit(struct zr_command_buffer*, struct zr_rect, zr_char*, zr_size,
|
|
|
|
zr_size max, zr_state*, zr_size *cursor, const struct zr_edit*,
|
|
|
|
enum zr_input_filter filter, const struct zr_input*,
|
|
|
|
const struct zr_user_font*);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function executes a editbox widget
|
|
|
|
Input:
|
2015-06-16 00:46:13 +03:00
|
|
|
- output command buffer for drawing
|
|
|
|
- (x,y) position
|
|
|
|
- (width, height) size
|
2015-06-04 23:17:54 +03:00
|
|
|
- char buffer to add or remove glyphes from/to
|
|
|
|
- buffer text length in bytes
|
|
|
|
- maximal buffer size
|
|
|
|
- current state of the editbox with either active or inactive
|
|
|
|
- visual widget style structure describing the editbox
|
|
|
|
- glyph input filter type to only let specified glyph through
|
|
|
|
- input structure to update the editbox with
|
|
|
|
- font structure for text drawing
|
|
|
|
Output:
|
|
|
|
- state of the editbox with either active or inactive
|
|
|
|
- returns the size of the buffer in bytes after the modification
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size zr_widget_edit_filtered(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
zr_char*, zr_size, zr_size max, zr_state*,
|
|
|
|
zr_size *cursor, const struct zr_edit*,
|
|
|
|
zr_filter filter, const struct zr_input*,
|
|
|
|
const struct zr_user_font*);
|
2015-06-04 23:17:54 +03:00
|
|
|
/* this function executes a editbox widget
|
|
|
|
Input:
|
2015-06-16 00:46:13 +03:00
|
|
|
- output command buffer for drawing
|
|
|
|
- (x,y) position
|
|
|
|
- (width, height) size
|
2015-06-04 23:17:54 +03:00
|
|
|
- char buffer to add or remove glyphes from/to
|
|
|
|
- buffer text length in bytes
|
|
|
|
- maximal buffer size
|
|
|
|
- current state of the editbox with either active or inactive
|
|
|
|
- visual widget style structure describing the editbox
|
|
|
|
- glyph input filter callback to only let specified glyph through
|
|
|
|
- input structure to update the editbox with
|
|
|
|
- font structure for text drawing
|
|
|
|
Output:
|
|
|
|
- state of the editbox with either active or inactive
|
|
|
|
- returns the size of the buffer in bytes after the modification
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_int zr_widget_spinner(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
const struct zr_spinner*, zr_int min, zr_int value,
|
|
|
|
zr_int max, zr_int step, zr_state *active,
|
|
|
|
const struct zr_input*, const struct zr_user_font*);
|
2015-08-21 18:34:51 +03:00
|
|
|
/* this function executes a integer spinner widget
|
|
|
|
Input:
|
|
|
|
- output command buffer for draw commands
|
|
|
|
- bounds of the spinner widget
|
|
|
|
- visual widget style structure describing the spinner
|
|
|
|
- minimal spinner value that will no be underflown
|
|
|
|
- spinner value that will be updated
|
|
|
|
- maximal spinner value that will no be overflown
|
|
|
|
- spinner input state with either active or inactive
|
|
|
|
- input structure to update the slider with
|
|
|
|
- font structure for text drawing
|
|
|
|
Output:
|
|
|
|
- returns the from the user input updated spinner value
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float zr_widget_scrollbarv(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
zr_float offset, zr_float target,
|
|
|
|
zr_float step, const struct zr_scrollbar*,
|
|
|
|
const struct zr_input*);
|
2015-08-02 14:49:51 +03:00
|
|
|
/* this function executes a vertical scrollbar widget
|
|
|
|
Input:
|
|
|
|
- output command buffer for draw commands
|
|
|
|
- (x,y) position
|
|
|
|
- (width, height) size
|
|
|
|
- scrollbar offset in source pixel
|
|
|
|
- destination pixel size
|
|
|
|
- step pixel size if the scrollbar up- or down button is pressed
|
|
|
|
- visual widget style structure describing the selector
|
|
|
|
- input structure to update the slider with
|
|
|
|
Output:
|
|
|
|
- returns the from the user input updated scrollbar offset in pixels
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float zr_widget_scrollbarh(struct zr_command_buffer*, struct zr_rect,
|
|
|
|
zr_float offset, zr_float target,
|
|
|
|
zr_float step, const struct zr_scrollbar*,
|
|
|
|
const struct zr_input*);
|
2015-08-02 14:49:51 +03:00
|
|
|
/* this function executes a horizontal scrollbar widget
|
2015-06-04 23:17:54 +03:00
|
|
|
Input:
|
|
|
|
- output command buffer for draw commands
|
2015-06-16 00:46:13 +03:00
|
|
|
- (x,y) position
|
|
|
|
- (width, height) size
|
2015-06-04 23:17:54 +03:00
|
|
|
- scrollbar offset in source pixel
|
|
|
|
- destination pixel size
|
|
|
|
- step pixel size if the scrollbar up- or down button is pressed
|
|
|
|
- visual widget style structure describing the selector
|
|
|
|
- input structure to update the slider with
|
|
|
|
Output:
|
2015-06-04 23:37:47 +03:00
|
|
|
- returns the from the user input updated scrollbar offset in pixels
|
2015-06-04 23:17:54 +03:00
|
|
|
*/
|
2015-05-29 15:18:23 +03:00
|
|
|
/*
|
|
|
|
* ==============================================================
|
|
|
|
*
|
2015-08-29 12:04:09 +03:00
|
|
|
* Style
|
2015-05-29 15:18:23 +03:00
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
*/
|
2015-08-29 12:04:09 +03:00
|
|
|
/* STYLE
|
2015-06-04 23:17:54 +03:00
|
|
|
----------------------------
|
2015-08-29 12:04:09 +03:00
|
|
|
The window style consists of properties, color and rectangle roundingo
|
|
|
|
information that is used for the general style and looks of window.
|
2015-06-16 00:46:13 +03:00
|
|
|
In addition for temporary modification the configuration structure consists
|
|
|
|
of a stack for pushing and pop either color or property values.
|
2015-06-04 23:17:54 +03:00
|
|
|
|
|
|
|
USAGE
|
|
|
|
----------------------------
|
2015-06-04 23:50:22 +03:00
|
|
|
To use the configuration file you either initialize every value yourself besides
|
2015-06-04 23:37:47 +03:00
|
|
|
the internal stack which needs to be initialized to zero or use the default
|
2015-09-18 00:09:49 +03:00
|
|
|
configuration by calling the function zr_config_default.
|
|
|
|
To add and remove temporary configuration states the zr_config_push_xxxx
|
|
|
|
for adding and zr_config_pop_xxxx for removing either color or property values
|
|
|
|
from the stack. To reset all previously modified values the zr_config_reset_xxx
|
2015-06-04 23:37:47 +03:00
|
|
|
were added.
|
|
|
|
|
2015-06-04 23:17:54 +03:00
|
|
|
Configuration function API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_style_default -- initializes a default style
|
|
|
|
zr_style_set_font -- changes the used font
|
|
|
|
zr_style_property -- returns the property value from an id
|
|
|
|
zr_style_color -- returns the color value from an id
|
|
|
|
zr_style_push_property -- push old property onto stack and sets a new value
|
|
|
|
zr_style_push_color -- push old color onto stack and sets a new value
|
|
|
|
zr_style_pop_color -- resets an old color value from the internal stack
|
|
|
|
zr_style_pop_property -- resets an old property value from the internal stack
|
|
|
|
zr_style_reset_colors -- reverts back all temporary color changes from the style
|
|
|
|
zr_style_reset_properties -- reverts back all temporary property changes
|
|
|
|
zr_style_reset -- reverts back all temporary all changes from the config
|
|
|
|
*/
|
|
|
|
enum zr_style_colors {
|
|
|
|
ZR_COLOR_TEXT,
|
|
|
|
ZR_COLOR_TEXT_HOVERING,
|
|
|
|
ZR_COLOR_TEXT_ACTIVE,
|
|
|
|
ZR_COLOR_WINDOW,
|
|
|
|
ZR_COLOR_HEADER,
|
|
|
|
ZR_COLOR_BORDER,
|
|
|
|
ZR_COLOR_BUTTON,
|
|
|
|
ZR_COLOR_BUTTON_HOVER,
|
|
|
|
ZR_COLOR_BUTTON_ACTIVE,
|
|
|
|
ZR_COLOR_TOGGLE,
|
|
|
|
ZR_COLOR_TOGGLE_HOVER,
|
|
|
|
ZR_COLOR_TOGGLE_CURSOR,
|
|
|
|
ZR_COLOR_SLIDER,
|
|
|
|
ZR_COLOR_SLIDER_CURSOR,
|
|
|
|
ZR_COLOR_SLIDER_CURSOR_HOVER,
|
|
|
|
ZR_COLOR_SLIDER_CURSOR_ACTIVE,
|
|
|
|
ZR_COLOR_PROGRESS,
|
|
|
|
ZR_COLOR_PROGRESS_CURSOR,
|
|
|
|
ZR_COLOR_PROGRESS_CURSOR_HOVER,
|
|
|
|
ZR_COLOR_PROGRESS_CURSOR_ACTIVE,
|
|
|
|
ZR_COLOR_INPUT,
|
|
|
|
ZR_COLOR_INPUT_CURSOR,
|
|
|
|
ZR_COLOR_INPUT_TEXT,
|
|
|
|
ZR_COLOR_SPINNER,
|
|
|
|
ZR_COLOR_SPINNER_TRIANGLE,
|
|
|
|
ZR_COLOR_HISTO,
|
|
|
|
ZR_COLOR_HISTO_BARS,
|
|
|
|
ZR_COLOR_HISTO_NEGATIVE,
|
|
|
|
ZR_COLOR_HISTO_HIGHLIGHT,
|
|
|
|
ZR_COLOR_PLOT,
|
|
|
|
ZR_COLOR_PLOT_LINES,
|
|
|
|
ZR_COLOR_PLOT_HIGHLIGHT,
|
|
|
|
ZR_COLOR_SCROLLBAR,
|
|
|
|
ZR_COLOR_SCROLLBAR_CURSOR,
|
|
|
|
ZR_COLOR_SCROLLBAR_CURSOR_HOVER,
|
|
|
|
ZR_COLOR_SCROLLBAR_CURSOR_ACTIVE,
|
|
|
|
ZR_COLOR_TABLE_LINES,
|
|
|
|
ZR_COLOR_TAB_HEADER,
|
|
|
|
ZR_COLOR_SHELF,
|
|
|
|
ZR_COLOR_SHELF_TEXT,
|
|
|
|
ZR_COLOR_SHELF_ACTIVE,
|
|
|
|
ZR_COLOR_SHELF_ACTIVE_TEXT,
|
|
|
|
ZR_COLOR_SCALER,
|
|
|
|
ZR_COLOR_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum zr_style_rounding {
|
|
|
|
ZR_ROUNDING_BUTTON,
|
|
|
|
ZR_ROUNDING_SLIDER,
|
|
|
|
ZR_ROUNDING_PROGRESS,
|
|
|
|
ZR_ROUNDING_CHECK,
|
|
|
|
ZR_ROUNDING_INPUT,
|
|
|
|
ZR_ROUNDING_GRAPH,
|
|
|
|
ZR_ROUNDING_SCROLLBAR,
|
|
|
|
ZR_ROUNDING_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum zr_style_properties {
|
|
|
|
ZR_PROPERTY_ITEM_SPACING,
|
|
|
|
ZR_PROPERTY_ITEM_PADDING,
|
|
|
|
ZR_PROPERTY_PADDING,
|
|
|
|
ZR_PROPERTY_SCALER_SIZE,
|
|
|
|
ZR_PROPERTY_SCROLLBAR_SIZE,
|
|
|
|
ZR_PROPERTY_SIZE,
|
|
|
|
ZR_PROPERTY_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
struct zr_saved_property {
|
|
|
|
enum zr_style_properties type;
|
2015-06-04 23:50:22 +03:00
|
|
|
/* identifier of the current modified property */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 value;
|
2015-06-04 23:50:22 +03:00
|
|
|
/* property value that has been saveed */
|
2015-05-20 18:05:28 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_saved_color {
|
|
|
|
enum zr_style_colors type;
|
2015-06-04 23:50:22 +03:00
|
|
|
/* identifier of the current modified color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color value;
|
2015-06-04 23:50:22 +03:00
|
|
|
/* color value that has been saveed */
|
2015-05-20 18:05:28 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_style_components {
|
|
|
|
ZR_DEFAULT_COLOR = 0x01,
|
2015-08-05 13:48:01 +03:00
|
|
|
/* default all colors inside the configuration struct */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_DEFAULT_PROPERTIES = 0x02,
|
2015-08-05 13:48:01 +03:00
|
|
|
/* default all properites inside the configuration struct */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_DEFAULT_ROUNDING = 0x04,
|
2015-08-05 13:48:01 +03:00
|
|
|
/* default all rounding values inside the configuration struct */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_DEFAULT_ALL = 0xFFFF
|
2015-08-05 13:48:01 +03:00
|
|
|
/* default the complete configuration struct */
|
2015-05-31 22:49:20 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_style_mod_stack {
|
|
|
|
zr_size property;
|
2015-06-04 23:50:22 +03:00
|
|
|
/* current property stack pushing index */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_saved_property properties[ZR_MAX_ATTRIB_STACK];
|
2015-06-04 23:50:22 +03:00
|
|
|
/* saved property stack */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_saved_color colors[ZR_MAX_COLOR_STACK];
|
2015-06-04 23:50:22 +03:00
|
|
|
/* saved color stack */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size color;
|
2015-06-04 23:50:22 +03:00
|
|
|
/* current color stack pushing index */
|
2015-06-04 23:17:54 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_style {
|
|
|
|
struct zr_user_font font;
|
2015-06-04 23:50:22 +03:00
|
|
|
/* the from the user provided font */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float rounding[ZR_ROUNDING_MAX];
|
2015-06-04 23:50:22 +03:00
|
|
|
/* rectangle widget rounding */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 properties[ZR_PROPERTY_MAX];
|
2015-08-29 12:04:09 +03:00
|
|
|
/* configuration properties to modify the style */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color colors[ZR_COLOR_COUNT];
|
2015-08-29 12:04:09 +03:00
|
|
|
/* configuration color to modify color */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_style_mod_stack stack;
|
2015-06-04 23:50:22 +03:00
|
|
|
/* modification stack */
|
2015-03-05 17:37:11 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_style_default(struct zr_style*, zr_flags, const struct zr_user_font*);
|
2015-08-29 12:04:09 +03:00
|
|
|
/* this function load the window configuration with default values
|
2015-06-05 16:01:15 +03:00
|
|
|
Input:
|
2015-08-27 20:25:13 +03:00
|
|
|
- config flags which part of the configuration should be loaded with default values
|
2015-08-29 12:04:09 +03:00
|
|
|
- user font reference structure describing the font used inside the window
|
2015-06-05 16:01:15 +03:00
|
|
|
Output:
|
2015-08-29 12:04:09 +03:00
|
|
|
- configuration structure holding the default window style
|
2015-06-05 16:01:15 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_style_set_font(struct zr_style*, const struct zr_user_font*);
|
2015-07-12 17:36:55 +03:00
|
|
|
/* this function changes the used font and can be used even inside a frame
|
2015-07-10 14:24:00 +03:00
|
|
|
Input:
|
2015-08-29 12:04:09 +03:00
|
|
|
- user font reference structure describing the font used inside the window
|
2015-07-10 14:24:00 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 zr_style_property(const struct zr_style*,
|
|
|
|
enum zr_style_properties);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function accesses a configuration property over an identifier
|
|
|
|
Input:
|
|
|
|
- Configuration the get the property from
|
|
|
|
- Configuration property idenfifier describing the property to get
|
|
|
|
Output:
|
|
|
|
- Property value that has been asked for
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_color zr_style_color(const struct zr_style*, enum zr_style_colors);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function accesses a configuration color over an identifier
|
|
|
|
Input:
|
|
|
|
- Configuration the get the color from
|
|
|
|
- Configuration color idenfifier describing the color to get
|
|
|
|
Output:
|
|
|
|
- color value that has been asked for
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_style_push_property(struct zr_style*, enum zr_style_properties,
|
|
|
|
struct zr_vec2);
|
2015-08-27 20:25:13 +03:00
|
|
|
/* this function temporarily changes a property in a stack to be reseted later
|
2015-06-05 16:01:15 +03:00
|
|
|
Input:
|
|
|
|
- Configuration structure to push the change to
|
|
|
|
- Property idenfifier to change
|
2015-08-10 21:34:47 +03:00
|
|
|
- new value of the property
|
2015-06-05 16:01:15 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_style_push_color(struct zr_style*, enum zr_style_colors,
|
|
|
|
struct zr_color);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function temporarily changes a color in a stack like fashion to be reseted later
|
|
|
|
Input:
|
|
|
|
- Configuration structure to push the change to
|
|
|
|
- color idenfifier to change
|
2015-08-10 21:34:47 +03:00
|
|
|
- new color
|
2015-06-05 16:01:15 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_style_pop_color(struct zr_style*);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function reverts back a previously pushed temporary color change
|
|
|
|
Input:
|
|
|
|
- Configuration structure to pop the change from and to
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_style_pop_property(struct zr_style*);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function reverts back a previously pushed temporary property change
|
|
|
|
Input:
|
|
|
|
- Configuration structure to pop the change from and to
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_style_reset_colors(struct zr_style*);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function reverts back all previously pushed temporary color changes
|
|
|
|
Input:
|
|
|
|
- Configuration structure to pop the change from and to
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_style_reset_properties(struct zr_style*);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function reverts back all previously pushed temporary color changes
|
|
|
|
Input:
|
|
|
|
- Configuration structure to pop the change from and to
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_style_reset(struct zr_style*);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function reverts back all previously pushed temporary color and
|
|
|
|
* property changes
|
|
|
|
Input:
|
|
|
|
- Configuration structure to pop the change from and to
|
|
|
|
*/
|
2015-09-09 14:54:20 +03:00
|
|
|
/*
|
|
|
|
* ==============================================================
|
|
|
|
*
|
|
|
|
* Tiling
|
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
TILING
|
2015-09-15 19:13:43 +03:00
|
|
|
----------------------------
|
|
|
|
Tiling provides a way to divide a space into fixed slots which again can be
|
|
|
|
divided into either horizontal or vertical spaces. The tiled layout consists
|
|
|
|
of five slots (Top, Left, Center, Right and Bottom) what is also known
|
|
|
|
as a Border layout. Since slots can either be filled or empty, horizontally or
|
|
|
|
vertically fillable, have either none, one or many subspaces and can even
|
|
|
|
have a tiled layout inside it is possible to achive a great number of layout.
|
|
|
|
|
|
|
|
In addition it is possible to define the space inside the tiled layout either
|
|
|
|
in pixel or as a ratio. Ratio based layout are great for scaling but
|
|
|
|
are less usefull in cases where scaling destroys the UI. Pixel based layouts
|
|
|
|
provided a layout which always look the same but are less flexible.
|
|
|
|
|
|
|
|
The tiled layout is used in the library inside windows as a widget layout
|
|
|
|
and for window placing inside the screen with each case having its own functions
|
|
|
|
to handle and use the tiled layout.
|
2015-09-09 14:54:20 +03:00
|
|
|
|
2015-09-15 19:13:43 +03:00
|
|
|
USAGE
|
2015-09-09 14:54:20 +03:00
|
|
|
----------------------------
|
2015-09-15 19:13:43 +03:00
|
|
|
To use the tiled layout you have to define which slot inside the layout
|
|
|
|
should be active, how the slot should be filled and how much space the
|
2015-09-18 00:09:49 +03:00
|
|
|
it takes. To define each slot you first have to call `zr_tiled_begin`
|
2015-09-15 19:13:43 +03:00
|
|
|
to start the layout slot definiton and to end the definition
|
2015-09-18 00:09:49 +03:00
|
|
|
the corresponding function `zr_tiled_end` has to be called.
|
|
|
|
Between both sequence points you can define each slot with `zr_tiled_slot`.
|
2015-09-15 19:13:43 +03:00
|
|
|
|
|
|
|
-----------------------------
|
|
|
|
| TOP |
|
|
|
|
-----------------------------
|
|
|
|
| | | |
|
|
|
|
| LEFT | CENTER | RIGHT |
|
|
|
|
| | | |
|
|
|
|
-----------------------------
|
|
|
|
| BOTTOM |
|
|
|
|
-----------------------------
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
Tiling API
|
|
|
|
zr_tiled_begin -- starts the definition of a tiled layout
|
|
|
|
zr_tiled_slot -- activates and setups a slot inside the tile layout
|
|
|
|
zr_tiled_end -- ends the definiition of the tiled layout slots
|
|
|
|
zr_tiled_slot_bounds -- returns the bounds of a slot in the tiled layout
|
|
|
|
zr_tiled_bounds -- returns the bounds of a widget in the tiled layout
|
2015-09-09 14:54:20 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_tiled_layout_slot_index {
|
|
|
|
ZR_SLOT_TOP,
|
|
|
|
ZR_SLOT_BOTTOM,
|
|
|
|
ZR_SLOT_LEFT,
|
|
|
|
ZR_SLOT_CENTER,
|
|
|
|
ZR_SLOT_RIGHT,
|
|
|
|
ZR_SLOT_MAX
|
2015-09-09 14:54:20 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_layout_format {
|
|
|
|
ZR_DYNAMIC, /* row layout which scales with the window */
|
|
|
|
ZR_STATIC /* row layout with fixed pixel width */
|
2015-09-09 14:54:20 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_tiled_slot_format {
|
|
|
|
ZR_SLOT_HORIZONTAL,
|
2015-09-09 14:54:20 +03:00
|
|
|
/* widgets in slots are added left to right */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_SLOT_VERTICAL
|
2015-09-09 14:54:20 +03:00
|
|
|
/* widgets in slots are added top to bottom */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_tiled_slot {
|
|
|
|
zr_uint capacity;
|
2015-09-09 14:54:20 +03:00
|
|
|
/* number of widget inside the slot */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float value;
|
2015-09-09 14:54:20 +03:00
|
|
|
/* temp value for layout build up */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 size;
|
2015-09-09 14:54:20 +03:00
|
|
|
/* horizontal and vertical window (ratio/width) */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 pos;
|
2015-09-09 14:54:20 +03:00
|
|
|
/* position of the slot in the window */
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_tiled_slot_format format;
|
2015-09-09 14:54:20 +03:00
|
|
|
/* layout filling format */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_tiled_layout {
|
|
|
|
struct zr_tiled_slot slots[ZR_SLOT_MAX];
|
2015-09-09 14:54:20 +03:00
|
|
|
/* tiled layout slots */
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_layout_format fmt;
|
2015-09-09 14:54:20 +03:00
|
|
|
/* row layout format */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float width, height;
|
2015-09-09 14:54:20 +03:00
|
|
|
/* width/height of the layout */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_tiled_begin(struct zr_tiled_layout*, enum zr_layout_format,
|
|
|
|
zr_float width, zr_float height);
|
2015-09-09 14:54:20 +03:00
|
|
|
/* this functions begins the definitions of a tiled layout
|
|
|
|
Input:
|
|
|
|
- layout format with either dynamic ratio based or fixed pixel based slots
|
|
|
|
- pixel width of the tiled layout space
|
|
|
|
- pixel height of the tiled layout space
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_tiled_slot(struct zr_tiled_layout *layout,
|
|
|
|
enum zr_tiled_layout_slot_index, zr_float ratio,
|
|
|
|
enum zr_tiled_slot_format, zr_uint widget_count);
|
2015-09-15 19:13:43 +03:00
|
|
|
/* this functions defines a slot in the tiled layout which then can be filled
|
|
|
|
* with widgets
|
|
|
|
Input:
|
|
|
|
- slot identifier
|
|
|
|
- either ratio or pixel size of the slot
|
|
|
|
- slot filling format with either horizontal or vertical filling
|
|
|
|
- number of widgets inside the slot
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_tiled_end(struct zr_tiled_layout*);
|
2015-09-15 19:13:43 +03:00
|
|
|
/* this functions ends the definitions of the tiled layout slots */
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_tiled_slot_bounds(struct zr_rect*, const struct zr_tiled_layout*,
|
|
|
|
enum zr_tiled_layout_slot_index);
|
2015-09-09 14:54:20 +03:00
|
|
|
/* this functions queries the bounds (position + size) of a tiled layout slot
|
|
|
|
Input:
|
|
|
|
- slot identifier
|
|
|
|
Output:
|
|
|
|
- rectangle with position and size of the slot
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_tiled_bounds(struct zr_rect*, const struct zr_tiled_layout*,
|
|
|
|
enum zr_tiled_layout_slot_index, zr_uint);
|
2015-09-09 14:54:20 +03:00
|
|
|
/* this functions queries the bounds (position + size) of a tiled layout slot entry
|
|
|
|
Input:
|
|
|
|
- slot identifier
|
|
|
|
- index of the widget inside the slot
|
|
|
|
Output:
|
|
|
|
- rectangle with position and size of the slot entry
|
|
|
|
*/
|
2015-05-29 15:18:23 +03:00
|
|
|
/*
|
|
|
|
* ==============================================================
|
|
|
|
*
|
2015-08-29 12:04:09 +03:00
|
|
|
* Window
|
2015-05-29 15:18:23 +03:00
|
|
|
*
|
|
|
|
* ===============================================================
|
2015-09-06 20:13:07 +03:00
|
|
|
WINDOW
|
|
|
|
The window groups widgets together and allows collective operation
|
|
|
|
on these widgets like movement, scrolling, window minimizing and closing.
|
|
|
|
Windows are divided into a persistent state window struct and a temporary
|
|
|
|
context which is used each frame to fill the window. All direct build up
|
|
|
|
function therefore work on the context and not on the actual window.
|
|
|
|
Each window is linked inside a queue which in term allows for an easy
|
|
|
|
way to buffer output commands but requires that the window is unlinked
|
|
|
|
from the queue if removed.
|
2015-06-04 23:17:54 +03:00
|
|
|
|
|
|
|
USAGE
|
2015-09-18 00:09:49 +03:00
|
|
|
The window needs to be initialized by `zr_window_init` and can be updated
|
|
|
|
by all the `zr_window_set_xxx` function. Important to note is that each
|
2015-09-06 20:13:07 +03:00
|
|
|
window is linked inside a queue by an internal memory buffer. So if you want
|
|
|
|
to remove the window you first have to remove the window from the queue
|
2015-09-18 00:09:49 +03:00
|
|
|
or if you want to change to queue use `zr_window_queue_set`.
|
2015-08-29 12:04:09 +03:00
|
|
|
|
|
|
|
window function API
|
2015-09-06 20:13:07 +03:00
|
|
|
------------------
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_window_init -- initializes the window with position, size and flags
|
|
|
|
zr_window_unlink -- remove the window from the command queue
|
|
|
|
zr_window_set_config -- updates the used window configuration
|
|
|
|
zr_window_add_flag -- adds a behavior flag to the window
|
|
|
|
zr_window_remove_flag -- removes a behavior flag from the window
|
|
|
|
zr_window_has_flag -- check if a given behavior flag is set in the window
|
|
|
|
zr_window_is_minimized -- return wether the window is minimized
|
2015-09-06 20:13:07 +03:00
|
|
|
|
|
|
|
APIs
|
|
|
|
-----------------
|
2015-09-16 16:04:26 +03:00
|
|
|
Window Context API -- The context is temporary state that is used every frame to build a window
|
|
|
|
Window Header API -- Responsible for creating a header at the top of a window
|
|
|
|
Window Layout API -- The window layout is responsible for placing widget in the window
|
|
|
|
Window Widget API -- Different widget that can be placed inside the window
|
|
|
|
Window Tree API -- Tree widget that allows to visualize and mofify a tree
|
|
|
|
Window Combobox API -- Combobox widget for collapsable popup content
|
|
|
|
Window Group API -- Create a subwindow inside a window which again can be filled with widgets
|
|
|
|
Window Shelf API -- Group window with tabs which can be filled with widget
|
|
|
|
Window Popup API -- Popup window with either non-blocking or blocking capabilities
|
|
|
|
Window Menu API -- Popup menus with currently one single depth
|
2015-08-29 12:04:09 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_window_flags {
|
|
|
|
ZR_WINDOW_HIDDEN = 0x01,
|
2015-08-29 12:04:09 +03:00
|
|
|
/* Hiddes the window and stops any window interaction and drawing can be set
|
|
|
|
* by user input or by closing the window */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_WINDOW_BORDER = 0x02,
|
2015-08-29 12:04:09 +03:00
|
|
|
/* Draws a border around the window to visually seperate the window from the
|
2015-06-05 16:01:15 +03:00
|
|
|
* background */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_WINDOW_BORDER_HEADER = 0x04,
|
2015-08-29 12:04:09 +03:00
|
|
|
/* Draws a border between window header and body */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_WINDOW_MOVEABLE = 0x08,
|
2015-08-29 12:04:09 +03:00
|
|
|
/* The moveable flag inidicates that a window can be move by user input by
|
|
|
|
* dragging the window header */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_WINDOW_SCALEABLE = 0x10,
|
2015-08-29 12:04:09 +03:00
|
|
|
/* The scaleable flag indicates that a window can be scaled by user input
|
|
|
|
* by dragging a scaler icon at the button of the window */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_WINDOW_MINIMIZED = 0x20,
|
2015-08-29 12:04:09 +03:00
|
|
|
/* marks the window as minimized */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_WINDOW_ROM = 0x40,
|
2015-08-29 12:04:09 +03:00
|
|
|
/* sets the window into a read only mode and does not allow input changes */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_WINDOW_DYNAMIC = 0x80,
|
2015-08-29 12:04:09 +03:00
|
|
|
/* special type of window which grows up in height while being filled to a
|
2015-08-11 15:44:53 +03:00
|
|
|
* certain maximum height. It is mainly used for combo boxes but can be
|
2015-08-29 12:04:09 +03:00
|
|
|
* used to create perfectly fitting windows as well */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_WINDOW_ACTIVE = 0x10000,
|
2015-08-29 12:04:09 +03:00
|
|
|
/* INTERNAL ONLY!: marks the window as active, used by the window stack */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_WINDOW_TAB = 0x20000,
|
2015-09-06 20:13:07 +03:00
|
|
|
/* INTERNAL ONLY!: Marks the window as subwindow of another window(Groups/Tabs/Shelf)*/
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_WINDOW_COMBO_MENU = 0x40000,
|
2015-08-29 12:04:09 +03:00
|
|
|
/* INTERNAL ONLY!: Marks the window as an combo box or menu */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_WINDOW_REMOVE_ROM = 0x80000,
|
2015-08-29 12:04:09 +03:00
|
|
|
/* INTERNAL ONLY!: removes the read only mode at the end of the window */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_WINDOW_NO_SCROLLBAR = 0x100000
|
2015-08-29 13:56:40 +03:00
|
|
|
/* INTERNAL ONLY!: removes the scrollbar from the window */
|
2015-08-29 12:04:09 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_window {
|
|
|
|
struct zr_rect bounds;
|
2015-08-31 01:14:41 +03:00
|
|
|
/* size with width and height and position of the window */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_flags flags;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* window flags modifing its behavior */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 offset;
|
|
|
|
/* scrollbar x- and y-offset */
|
|
|
|
const struct zr_style *style;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* configuration reference describing the window style */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_buffer buffer;
|
2015-06-05 16:01:15 +03:00
|
|
|
/* output command buffer queuing all drawing calls */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_queue *queue;
|
2015-08-06 17:36:28 +03:00
|
|
|
/* output command queue which hold the command buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
const struct zr_input *input;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* input state for updating the window and all its widgets */
|
2015-05-07 16:52:35 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_window_init(struct zr_window*, struct zr_rect bounds,
|
|
|
|
zr_flags flags, struct zr_command_queue*,
|
|
|
|
const struct zr_style*, const struct zr_input *in);
|
2015-08-29 12:04:09 +03:00
|
|
|
/* this function initilizes and setups the window
|
|
|
|
Input:
|
|
|
|
- bounds of the window with x,y position and width and height
|
|
|
|
- window flags for modified window behavior
|
|
|
|
- reference to a output command queue to push draw calls into
|
|
|
|
- configuration file containing the style, color and font for the window
|
|
|
|
Output:
|
|
|
|
- a newly initialized window
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_window_unlink(struct zr_window*);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function unlinks the window from its queue */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_window_add_flag(struct zr_window*, zr_flags);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function adds window flags to the window */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_window_remove_flag(struct zr_window*, zr_flags);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function removes window flags from the window */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_window_has_flag(struct zr_window*, zr_flags);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this function checks if a window has given flag(s) */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_window_is_minimized(struct zr_window*);
|
2015-08-29 12:04:09 +03:00
|
|
|
/* this function checks if the window is minimized */
|
2015-09-10 00:12:03 +03:00
|
|
|
/* --------------------------------------------------------------
|
2015-08-29 12:04:09 +03:00
|
|
|
* Context
|
2015-09-06 20:13:07 +03:00
|
|
|
* --------------------------------------------------------------
|
|
|
|
CONTEXT
|
|
|
|
The context is temporary window state that is used in the window drawing
|
|
|
|
and build up process. The reason the window and context are divided is that
|
|
|
|
the context has far more state which is not needed outside of the build up
|
|
|
|
phase. The context is not only useful for normal windows. It is used for
|
|
|
|
more complex widget or layout as well. This includes a window inside a window,
|
|
|
|
popup windows, menus, comboboxes, etc. In each case the context allows to
|
|
|
|
fill a space with widgets. Therefore the context provides the base
|
|
|
|
and key stone of the flexibility in the library. The context is used
|
|
|
|
for all APIs for the window.
|
|
|
|
|
|
|
|
USAGE
|
2015-09-18 00:09:49 +03:00
|
|
|
The context from a window is created by `zr_begin` and finilized by
|
|
|
|
`zr_end`. Between these two sequence points the context can be used
|
2015-09-06 20:13:07 +03:00
|
|
|
to setup the window with widgets. Other widgets which also use a context
|
2015-09-18 00:09:49 +03:00
|
|
|
have each their own `zr_xxx_begin` and `zr_xxx_end` function pair and act
|
2015-09-06 20:13:07 +03:00
|
|
|
the same as a window context.
|
|
|
|
|
|
|
|
context function API
|
|
|
|
------------------
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_begin -- starts the window build up process by filling a context with window state
|
|
|
|
zr_end -- ends the window build up process and update the window state
|
|
|
|
zr_canvas -- returns the currently used drawing command buffer
|
|
|
|
zr_input -- returns the from the context used input struct
|
|
|
|
zr_queue -- returns the queue of the window
|
|
|
|
zr_space -- returns the drawable space inside the window
|
|
|
|
*/
|
|
|
|
enum zr_widget_state {
|
|
|
|
ZR_WIDGET_INVALID,
|
2015-09-06 20:13:07 +03:00
|
|
|
/* The widget cannot be seen and is completly out of view */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_WIDGET_VALID,
|
2015-09-06 20:13:07 +03:00
|
|
|
/* The widget is completly inside the window can be updated */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_WIDGET_ROM
|
2015-09-06 20:13:07 +03:00
|
|
|
/* The widget is partially visible and cannot be updated */
|
2015-08-29 12:04:09 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_row_layout_type {
|
2015-09-06 20:13:07 +03:00
|
|
|
/* INTERNAL */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_LAYOUT_DYNAMIC_FIXED,
|
2015-08-29 12:04:09 +03:00
|
|
|
/* fixed widget ratio width window layout */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_LAYOUT_DYNAMIC_ROW,
|
2015-07-27 20:56:19 +03:00
|
|
|
/* immediate mode widget specific widget width ratio layout */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_LAYOUT_DYNAMIC_FREE,
|
2015-07-29 23:19:17 +03:00
|
|
|
/* free ratio based placing of widget in a local space */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_LAYOUT_DYNAMIC_TILED,
|
2015-09-09 14:54:20 +03:00
|
|
|
/* dynamic Border layout */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_LAYOUT_DYNAMIC,
|
2015-07-27 20:56:19 +03:00
|
|
|
/* retain mode widget specific widget ratio width*/
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_LAYOUT_STATIC_FIXED,
|
2015-08-29 12:04:09 +03:00
|
|
|
/* fixed widget pixel width window layout */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_LAYOUT_STATIC_ROW,
|
2015-07-29 23:19:17 +03:00
|
|
|
/* immediate mode widget specific widget pixel width layout */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_LAYOUT_STATIC_FREE,
|
2015-07-29 23:19:17 +03:00
|
|
|
/* free pixel based placing of widget in a local space */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_LAYOUT_STATIC_TILED,
|
2015-09-09 14:54:20 +03:00
|
|
|
/* static Border layout */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_LAYOUT_STATIC
|
2015-07-27 20:56:19 +03:00
|
|
|
/* retain mode widget specific widget pixel width layout */
|
2015-07-14 14:26:53 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
#define ZR_UNDEFINED (-1.0f)
|
|
|
|
struct zr_row_layout {
|
|
|
|
enum zr_row_layout_type type;
|
2015-07-14 14:26:53 +03:00
|
|
|
/* type of the row layout */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size index;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* index of the current widget in the current window row */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float height;
|
2015-06-09 18:05:05 +03:00
|
|
|
/* height of the current row */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size columns;
|
2015-06-09 18:05:05 +03:00
|
|
|
/* number of columns in the current row */
|
2015-09-18 00:09:49 +03:00
|
|
|
const zr_float *ratio;
|
2015-06-09 18:05:05 +03:00
|
|
|
/* row widget width ratio */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float item_width, item_height;
|
2015-07-29 23:19:17 +03:00
|
|
|
/* current width of very item */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float item_offset;
|
2015-07-14 14:26:53 +03:00
|
|
|
/* x positon offset of the current item */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float filled;
|
2015-07-14 14:26:53 +03:00
|
|
|
/* total fill ratio */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_rect item;
|
2015-07-29 23:19:17 +03:00
|
|
|
/* item bounds */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_rect clip;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* temporary clipping rect */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_tiled_layout *tiled;
|
2015-09-09 14:54:20 +03:00
|
|
|
/* tiled border layout */
|
2015-07-29 23:19:17 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_header {
|
|
|
|
zr_float x, y, w, h;
|
2015-07-29 23:19:17 +03:00
|
|
|
/* header bounds */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float front, back;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* visual header filling deque */
|
2015-07-29 23:19:17 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_menu {
|
|
|
|
zr_float x, y, w, h;
|
2015-07-29 23:19:17 +03:00
|
|
|
/* menu bounds */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 offset;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* saved window scrollbar offset */
|
2015-06-09 18:05:05 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_context {
|
|
|
|
zr_flags flags;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* window flags modifing its behavior */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_rect bounds;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* position and size of the window in the os window */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 offset;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* window scrollbar offset */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool valid;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* flag inidicating if the window is visible */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float at_x, at_y, max_x;
|
2015-06-05 16:01:15 +03:00
|
|
|
/* index position of the current widget row and column */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float width, height;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* size of the actual useable space inside the window */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float footer_h;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* height of the window footer space */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_rect clip;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* window clipping rect */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_header header;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* window header bounds */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_menu menu;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* window menubar bounds */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_row_layout row;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* currently used window row layout */
|
2015-09-18 00:09:49 +03:00
|
|
|
const struct zr_style *style;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* configuration data describing the visual style of the window */
|
2015-09-18 00:09:49 +03:00
|
|
|
const struct zr_input *input;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* current input state for updating the window and all its widgets */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_buffer *buffer;
|
2015-06-05 16:01:15 +03:00
|
|
|
/* command draw call output command buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_queue *queue;
|
2015-08-10 21:34:47 +03:00
|
|
|
/* command draw call output command buffer */
|
2015-05-16 13:26:39 +03:00
|
|
|
};
|
2015-07-29 23:19:17 +03:00
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_begin(struct zr_context*, struct zr_window*);
|
2015-09-09 14:54:20 +03:00
|
|
|
/* this function begins the window build up process by creating a context to fill
|
|
|
|
Input:
|
|
|
|
- input structure holding all user generated state changes
|
|
|
|
Output:
|
|
|
|
- window context to fill up with widgets
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_begin_tiled(struct zr_context*, struct zr_window*, struct zr_tiled_layout*,
|
|
|
|
enum zr_tiled_layout_slot_index slot, zr_uint index);
|
2015-09-09 14:54:20 +03:00
|
|
|
/* this function begins the window build up process by creating a context to fill
|
|
|
|
and placing the window inside a tiled layout on the screen.
|
2015-08-21 18:34:51 +03:00
|
|
|
Input:
|
|
|
|
- input structure holding all user generated state changes
|
|
|
|
Output:
|
2015-08-29 12:04:09 +03:00
|
|
|
- window context to fill up with widgets
|
2015-07-02 14:08:44 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_end(struct zr_context*, struct zr_window*);
|
2015-08-29 12:04:09 +03:00
|
|
|
/* this function ends the window layout build up process and updates the window */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_rect zr_space(struct zr_context*);
|
|
|
|
/* this function returns the drawable space inside the window */
|
|
|
|
struct zr_command_buffer* zr_canvas(struct zr_context*);
|
2015-08-27 20:25:13 +03:00
|
|
|
/* this functions returns the currently used draw command buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
const struct zr_input *zr_input(struct zr_context*);
|
2015-08-30 20:33:10 +03:00
|
|
|
/* this functions returns the currently used input */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_command_queue *zr_queue(struct zr_context*);
|
2015-09-06 20:13:07 +03:00
|
|
|
/* this functions returns the currently used queue */
|
2015-09-10 00:12:03 +03:00
|
|
|
/* --------------------------------------------------------------
|
2015-07-29 23:19:17 +03:00
|
|
|
* HEADER
|
|
|
|
* --------------------------------------------------------------
|
|
|
|
HEADER
|
2015-08-29 12:04:09 +03:00
|
|
|
The header API is for adding a window space at the top of the window for
|
|
|
|
buttons, icons and window title. It is useful for toggling the visiblity
|
|
|
|
aswell as minmized state of the window. The header can be filled with buttons
|
2015-07-29 23:19:17 +03:00
|
|
|
and icons from the left and as well as the right side and allows therefore
|
|
|
|
a wide range of header layouts.
|
|
|
|
|
|
|
|
USAGE
|
2015-08-29 12:04:09 +03:00
|
|
|
To create a header you have to call one of two API after the window layout
|
2015-09-18 00:09:49 +03:00
|
|
|
has been created with `zr_begin`. The first and easiest way is to
|
|
|
|
just call `zr_header` which provides a basic header with
|
2015-08-27 20:25:13 +03:00
|
|
|
with title and button and buton pressed notification if a button was pressed.
|
2015-07-29 23:19:17 +03:00
|
|
|
The layout supported is hereby limited and custom button and icons cannot be
|
|
|
|
added. To achieve that you have to use the more extensive header API.
|
2015-09-18 00:09:49 +03:00
|
|
|
You start by calling `zr_header_begin` after `zr_begin` and
|
|
|
|
call the different `zr_header_xxx` functions to add icons or the title
|
2015-08-29 12:04:09 +03:00
|
|
|
either at the left or right side of the window. Each function returns if the
|
2015-08-11 15:44:53 +03:00
|
|
|
icon or button has been pressed or in the case of the toggle the current state.
|
2015-07-29 23:19:17 +03:00
|
|
|
Finally if all button/icons/toggles have been added the process is finished
|
2015-09-18 00:09:49 +03:00
|
|
|
by calling `zr_header_end`.
|
2015-08-29 12:04:09 +03:00
|
|
|
|
|
|
|
window header function API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_header_begin -- begins the header build up process
|
|
|
|
zr_header_button -- adds a button into the header
|
|
|
|
zr_header_button_icon -- adds a image button into the header
|
|
|
|
zr_header_toggle -- adds a toggle button into the header
|
|
|
|
zr_header_flag -- adds a window flag toggle button
|
|
|
|
zr_header_title -- adds the title of the window into the header
|
|
|
|
zr_header_end -- finishes the header build up process
|
|
|
|
zr_header -- short cut version of the header build up process
|
|
|
|
zr_menubar_begin -- marks the beginning of the menubar building process
|
|
|
|
zr_menubar_end -- marks the end the menubar build up process
|
|
|
|
*/
|
|
|
|
enum zr_header_flags {
|
|
|
|
ZR_CLOSEABLE = 0x01,
|
2015-07-30 23:19:06 +03:00
|
|
|
/* adds a closeable icon into the header */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_MINIMIZABLE = 0x02,
|
2015-07-30 23:19:06 +03:00
|
|
|
/* adds a minimize icon into the header */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_SCALEABLE = 0x04,
|
2015-07-30 23:19:06 +03:00
|
|
|
/* adds a scaleable flag icon into the header */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_MOVEABLE = 0x08
|
2015-07-30 23:19:06 +03:00
|
|
|
/* adds a moveable flag icon into the header */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_header_align {
|
|
|
|
ZR_HEADER_LEFT,
|
2015-07-30 23:19:06 +03:00
|
|
|
/* header elements are added at the left side of the header */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_HEADER_RIGHT
|
2015-07-30 23:19:06 +03:00
|
|
|
/* header elements are added at the right side of the header */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_flags zr_header(struct zr_context*, const char *title,
|
|
|
|
zr_flags show, zr_flags notify, enum zr_header_align);
|
2015-08-21 18:34:51 +03:00
|
|
|
/* this function is a shorthand for the header build up process
|
|
|
|
flag by the user
|
|
|
|
Input:
|
|
|
|
- title of the header or NULL if not needed
|
|
|
|
- flags indicating which icons should be drawn to the header
|
|
|
|
- flags indicating which icons should notify if clicked
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_header_begin(struct zr_context*);
|
2015-08-29 12:04:09 +03:00
|
|
|
/* this function begins the window header build up process */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_header_button(struct zr_context *layout, enum zr_symbol symbol,
|
|
|
|
enum zr_header_align);
|
2015-07-29 23:19:17 +03:00
|
|
|
/* this function adds a header button icon
|
2015-07-20 12:18:05 +03:00
|
|
|
Input:
|
2015-07-27 20:56:19 +03:00
|
|
|
-
|
2015-07-20 12:18:05 +03:00
|
|
|
- symbol that shall be shown in the header as a icon
|
2015-07-20 15:06:52 +03:00
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- zr_true if the button was pressed zr_false otherwise
|
2015-07-26 23:18:31 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_header_button_icon(struct zr_context*, struct zr_image,
|
|
|
|
enum zr_header_align);
|
2015-07-29 23:19:17 +03:00
|
|
|
/* this function adds a header image button icon
|
2015-07-26 23:18:31 +03:00
|
|
|
Input:
|
|
|
|
- symbol that shall be shown in the header as a icon
|
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- zr_true if the button was pressed zr_false otherwise
|
2015-07-26 23:18:31 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_header_toggle(struct zr_context*, enum zr_symbol inactive,
|
|
|
|
enum zr_symbol active, enum zr_header_align,
|
|
|
|
zr_bool state);
|
2015-07-26 23:18:31 +03:00
|
|
|
/* this function adds a header toggle button
|
|
|
|
Input:
|
|
|
|
- symbol that will be drawn if the toggle is inactive
|
|
|
|
- symbol that will be drawn if the toggle is active
|
|
|
|
- state of the toggle with either active or inactive
|
|
|
|
Output:
|
|
|
|
- updated state of the toggle
|
2015-07-20 12:18:05 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_header_flag(struct zr_context *layout, enum zr_symbol inactive,
|
|
|
|
enum zr_symbol active, enum zr_header_align,
|
|
|
|
enum zr_window_flags flag);
|
2015-08-29 12:04:09 +03:00
|
|
|
/* this function adds a header toggle button for modifing a certain window flag
|
2015-07-27 20:56:19 +03:00
|
|
|
Input:
|
|
|
|
- symbol that will be drawn if the flag is inactive
|
|
|
|
- symbol that will be drawn if the flag is active
|
2015-08-29 12:04:09 +03:00
|
|
|
- window flag whose state will be display by the toggle button
|
2015-07-27 20:56:19 +03:00
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- zr_true if the button was pressed zr_false otherwise
|
2015-07-27 20:56:19 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_header_title(struct zr_context*, const char*, enum zr_header_align);
|
2015-08-29 12:04:09 +03:00
|
|
|
/* this function adds a title to the window header
|
2015-07-20 12:18:05 +03:00
|
|
|
Input:
|
|
|
|
- title of the header
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_header_end(struct zr_context*);
|
2015-08-29 12:04:09 +03:00
|
|
|
/* this function ends the window header build up process */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_menubar_begin(struct zr_context*);
|
2015-08-29 12:04:09 +03:00
|
|
|
/* this function begins the window menubar build up process */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_menubar_end(struct zr_context*);
|
2015-08-29 12:04:09 +03:00
|
|
|
/* this function ends the window menubar build up process */
|
2015-09-09 14:54:20 +03:00
|
|
|
|
2015-09-10 00:12:03 +03:00
|
|
|
/* --------------------------------------------------------------
|
2015-09-09 14:54:20 +03:00
|
|
|
* Layout
|
2015-07-29 23:19:17 +03:00
|
|
|
* --------------------------------------------------------------
|
2015-08-06 17:36:28 +03:00
|
|
|
LAYOUT
|
2015-08-29 12:04:09 +03:00
|
|
|
The layout API is for positioning of widget inside a window context. In general there
|
2015-09-09 14:54:20 +03:00
|
|
|
are four different ways to position widget. The first one is a table with
|
2015-07-29 23:19:17 +03:00
|
|
|
fixed size columns. This like the other three comes in two flavors. First
|
2015-08-29 12:04:09 +03:00
|
|
|
the scaleable width as a ratio of the window width and the other is a
|
|
|
|
non-scaleable fixed pixel value for static windows.
|
2015-08-13 16:57:28 +03:00
|
|
|
Since sometimes widgets with different sizes in a row is needed another set
|
2015-08-05 13:48:01 +03:00
|
|
|
of row layout has been added. The first set is for dynamically size widgets
|
|
|
|
in an immediate mode API which sets each size of a widget directly before
|
2015-07-29 23:19:17 +03:00
|
|
|
it is called or a retain mode API which stores the size of every widget as
|
|
|
|
an array.
|
2015-09-09 14:54:20 +03:00
|
|
|
The third way to position widgets is by allocating a fixed space from
|
2015-08-29 12:04:09 +03:00
|
|
|
the window and directly positioning each widget with position and size.
|
2015-07-29 23:19:17 +03:00
|
|
|
This requires the least amount of work for the API and the most for the user,
|
|
|
|
but offers the most positioning freedom.
|
2015-09-09 14:54:20 +03:00
|
|
|
The final row layout is a tiled layout which divides a space in the panel
|
|
|
|
into a Top, Left, Center, Right and Bottom slot. Each slot can be filled
|
|
|
|
with widgets either horizontally or vertically.
|
2015-07-29 23:19:17 +03:00
|
|
|
|
2015-09-09 14:54:20 +03:00
|
|
|
fixed width widget layout API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_layout_row_dynamic -- scaling fixed column row layout
|
|
|
|
zr_layout_row_static -- fixed width fixed column row layout
|
2015-09-09 14:54:20 +03:00
|
|
|
|
|
|
|
custom width widget layout API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_layout_row -- user defined widget row layout
|
|
|
|
zr_layout_row_begin -- begins the row build up process
|
|
|
|
zr_layout_row_push -- pushes the next widget width
|
|
|
|
zr_layout_row_end -- ends the row build up process
|
2015-09-09 14:54:20 +03:00
|
|
|
|
|
|
|
custom widget placing layout API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_layout_row_space_begin -- creates a free placing space in the window
|
|
|
|
zr_layout_row_space_push -- pushes a widget into the space
|
|
|
|
zr_layout_row_space_end -- finishes the free drawingp process
|
|
|
|
zr_layout_row_space_bounds -- totally allocated space in window
|
|
|
|
zr_layout_row_space_to_screen -- converts from local space to screen
|
|
|
|
zr_layout_row_space_to_local -- converts from screen to local space
|
|
|
|
zr_layout_row_space_rect_to_screen -- converts rect from local space to screen
|
|
|
|
zr_layout_row_space_rect_to_local -- converts rect from screen to local space
|
2015-07-30 23:19:06 +03:00
|
|
|
|
2015-09-09 14:54:20 +03:00
|
|
|
tiled widget placing layout API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_layout_row_tiled_begin -- begins tiled layout based placing of widgets
|
|
|
|
zr_layout_row_tiled_slot_bounds -- returns the bounds of a slot in the tiled layout
|
|
|
|
zr_layout_row_tiled_bounds -- returns the bounds of a widget in the tiled layout
|
|
|
|
zr_layout_row_tiled_push -- pushes a widget into a slot in the tiled layout
|
|
|
|
zr_layout_row_tiled_end -- ends tiled layout based placing of widgets
|
2015-07-30 23:19:06 +03:00
|
|
|
|
2015-09-09 14:54:20 +03:00
|
|
|
window tree layout function API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_layout_push -- pushes a new node/collapseable header/tab
|
|
|
|
zr_layout_pop -- pops the the previously added node
|
2015-07-30 23:19:06 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_layout_node_type {
|
|
|
|
ZR_LAYOUT_NODE,
|
2015-09-09 14:54:20 +03:00
|
|
|
/* a node is a space which can be minimized or maximized */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_LAYOUT_TAB
|
2015-09-09 14:54:20 +03:00
|
|
|
/* a tab is a node with a header */
|
2015-08-05 13:48:01 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_layout_row_dynamic(struct zr_context*, zr_float height, zr_size cols);
|
2015-08-05 13:48:01 +03:00
|
|
|
/* this function sets the row layout to dynamically fixed size widget
|
2015-07-30 23:19:06 +03:00
|
|
|
Input:
|
2015-08-05 13:48:01 +03:00
|
|
|
- height of the row that will be filled
|
|
|
|
- number of widget inside the row that will divide the space
|
2015-07-29 23:19:17 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_layout_row_static(struct zr_context*, zr_float row_height,
|
|
|
|
zr_size item_width, zr_size cols);
|
2015-08-05 13:48:01 +03:00
|
|
|
/* this function sets the row layout to static fixed size widget
|
2015-07-29 23:19:17 +03:00
|
|
|
Input:
|
|
|
|
- height of the row that will be filled
|
2015-08-05 13:48:01 +03:00
|
|
|
- width in pixel measurement of each widget in the row
|
2015-07-29 23:19:17 +03:00
|
|
|
- number of widget inside the row that will divide the space
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_layout_row_begin(struct zr_context*,
|
|
|
|
enum zr_layout_format,
|
|
|
|
zr_float row_height, zr_size cols);
|
2015-07-29 23:19:17 +03:00
|
|
|
/* this function start a new scaleable row that can be filled with different
|
|
|
|
sized widget
|
|
|
|
Input:
|
2015-08-05 13:48:01 +03:00
|
|
|
- scaleable or fixed row format
|
2015-07-29 23:19:17 +03:00
|
|
|
- height of the row that will be filled
|
|
|
|
- number of widget inside the row that will divide the space
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_layout_row_push(struct zr_context*, zr_float value);
|
2015-07-29 23:19:17 +03:00
|
|
|
/* this function pushes a widget into the previously start row with the given
|
2015-08-29 12:04:09 +03:00
|
|
|
window width ratio or pixel width
|
2015-07-29 23:19:17 +03:00
|
|
|
Input:
|
2015-09-18 00:09:49 +03:00
|
|
|
- value with either a ratio for ZR_DYNAMIC or a pixel width for ZR_STATIC layout
|
2015-07-29 23:19:17 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_layout_row_end(struct zr_context*);
|
2015-07-29 23:19:17 +03:00
|
|
|
/* this function ends the previously started scaleable row */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_layout_row(struct zr_context*, enum zr_layout_format,
|
|
|
|
zr_float height, zr_size cols, const zr_float *ratio);
|
2015-08-05 13:48:01 +03:00
|
|
|
/* this function sets the row layout as an array of ratios/width for
|
2015-07-29 23:19:17 +03:00
|
|
|
every widget that will be inserted into that row
|
|
|
|
Input:
|
2015-08-05 13:48:01 +03:00
|
|
|
- scaleable or fixed row format
|
2015-07-29 23:19:17 +03:00
|
|
|
- height of the row and there each widget inside
|
|
|
|
- number of widget inside the row
|
2015-08-29 12:04:09 +03:00
|
|
|
- window ratio/pixel width array for each widget
|
2015-07-29 23:19:17 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_layout_row_space_begin(struct zr_context*,
|
|
|
|
enum zr_layout_format,
|
|
|
|
zr_float height, zr_size widget_count);
|
2015-08-05 13:48:01 +03:00
|
|
|
/* this functions starts a space where widgets can be added
|
2015-07-29 23:19:17 +03:00
|
|
|
at any given position and the user has to make sure no overlap occures
|
|
|
|
Input:
|
|
|
|
- height of the row and therefore each widget inside
|
|
|
|
- number of widget that will be added into that space
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_rect zr_layout_row_space_bounds(struct zr_context*);
|
2015-08-31 18:35:37 +03:00
|
|
|
/* this functions returns the complete bounds of the space in the panel */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_layout_row_space_push(struct zr_context*, struct zr_rect);
|
2015-07-29 23:19:17 +03:00
|
|
|
/* this functions pushes the position and size of the next widget that will
|
2015-08-29 12:04:09 +03:00
|
|
|
be added into the previously allocated window space
|
2015-07-29 23:19:17 +03:00
|
|
|
Input:
|
|
|
|
- rectangle with position and size as a ratio of the next widget to add
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 zr_layout_row_space_to_screen(struct zr_context*, struct zr_vec2);
|
2015-08-31 01:14:41 +03:00
|
|
|
/* this functions calculates a position from local space to screen space
|
|
|
|
Input:
|
|
|
|
- position in local layout space
|
|
|
|
Output:
|
|
|
|
- position in screen space
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 zr_layout_row_space_to_local(struct zr_context*, struct zr_vec2);
|
2015-08-31 01:14:41 +03:00
|
|
|
/* this functions calculates a position from screen space to local space
|
|
|
|
Input:
|
|
|
|
- position in screen layout space
|
|
|
|
Output:
|
|
|
|
- position in local layout space
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_rect zr_layout_row_space_rect_to_screen(struct zr_context*, struct zr_rect);
|
2015-08-31 01:14:41 +03:00
|
|
|
/* this functions calculates a rectange from local space to screen space
|
|
|
|
Input:
|
|
|
|
- rectangle in local layout space
|
|
|
|
Output:
|
|
|
|
- rectangle in screen space
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_rect zr_layout_row_space_rect_to_local(struct zr_context*, struct zr_rect);
|
2015-08-31 01:14:41 +03:00
|
|
|
/* this functions calculates a rectangle from screen space to local space
|
|
|
|
Input:
|
|
|
|
- rectangle in screen space
|
|
|
|
Output:
|
|
|
|
- rectangle in local space
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_layout_row_space_end(struct zr_context*);
|
2015-07-29 23:19:17 +03:00
|
|
|
/* this functions finishes the scaleable space filling process */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_layout_row_tiled_begin(struct zr_context*, struct zr_tiled_layout*);
|
2015-09-09 14:54:20 +03:00
|
|
|
/* this functions begins the tiled layout
|
|
|
|
Input:
|
|
|
|
- row height of the complete layout to allocate from the window
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_layout_row_tiled_push(struct zr_context*, enum zr_tiled_layout_slot_index,
|
|
|
|
zr_uint index);
|
2015-09-09 14:54:20 +03:00
|
|
|
/* this functions pushes a widget into a tiled layout slot
|
|
|
|
Input:
|
|
|
|
- slot identifier
|
|
|
|
- widget index in the slot
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_layout_row_tiled_end(struct zr_context*);
|
2015-09-09 14:54:20 +03:00
|
|
|
/* this functions ends the tiled layout */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_layout_push(struct zr_context*, enum zr_layout_node_type,
|
|
|
|
const char *title, zr_state*);
|
2015-08-29 12:04:09 +03:00
|
|
|
/* this functions pushes either a tree node or collapseable header into
|
|
|
|
* the current window layout
|
2015-07-29 23:19:17 +03:00
|
|
|
Input:
|
2015-08-29 12:04:09 +03:00
|
|
|
- title of the node to push into the window
|
2015-08-05 13:48:01 +03:00
|
|
|
- type of then node with either default node, collapseable header or tab
|
2015-09-18 00:09:49 +03:00
|
|
|
- state of the node with either ZR_MINIMIZED or ZR_MAXIMIZED
|
2015-08-05 13:48:01 +03:00
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- returns the updated state as either zr_true if open and zr_false otherwise
|
2015-08-05 13:48:01 +03:00
|
|
|
- updates the state of the node pointer to the updated state
|
2015-06-09 18:05:05 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_layout_pop(struct zr_context*);
|
2015-08-05 13:48:01 +03:00
|
|
|
/* this functions ends the previously added node */
|
2015-09-10 00:12:03 +03:00
|
|
|
/* --------------------------------------------------------------
|
2015-07-29 23:19:17 +03:00
|
|
|
* WIDGETS
|
|
|
|
* --------------------------------------------------------------
|
|
|
|
WIDGET
|
2015-08-29 12:04:09 +03:00
|
|
|
The layout API uses the layout API to provide and add widget to the window.
|
2015-07-29 23:19:17 +03:00
|
|
|
IMPORTANT: the widget API does NOT work without a layout so if you have
|
2015-08-07 17:53:52 +03:00
|
|
|
visual glitches then the problem probably stems from not using the layout
|
2015-08-29 12:04:09 +03:00
|
|
|
correctly. The window widget API does not implement any widget itself, instead
|
2015-07-29 23:19:17 +03:00
|
|
|
it uses the general Widget API under the hood and is only responsible for
|
|
|
|
calling the correct widget API function with correct position, size and style.
|
|
|
|
All widgets do NOT store any state instead everything has to be managed by
|
|
|
|
the user.
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
To use the Widget API you first have to call one of the layout API funtions
|
|
|
|
to setup the widget. After that you can just call one of the widget functions
|
|
|
|
at it will automaticall update the widget state as well as `draw` the widget
|
2015-08-29 12:04:09 +03:00
|
|
|
by adding draw command into the window command buffer.
|
|
|
|
|
|
|
|
window widget API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_widget -- base function for all widgets to allocate space
|
|
|
|
zr_spacing -- column seperator and is basically an empty widget
|
|
|
|
zr_seperator -- adds either a horizontal or vertical seperator
|
|
|
|
zr_text -- text widget for printing text with length
|
|
|
|
zr_text_colored -- colored text widget for printing string by length
|
|
|
|
zr_label -- text widget for printing zero terminated strings
|
|
|
|
zr_label_colored -- widget for printing colored zero terminiated strings
|
|
|
|
zr_button_text -- button widget with text content
|
|
|
|
zr_button_toggle -- button toggle widget with text content
|
|
|
|
zr_button_color -- colored button widget without content
|
|
|
|
zr_button_symbol -- button with triangle either up-/down-/left- or right
|
|
|
|
zr_button_image -- button widget width icon content
|
|
|
|
zr_button_text_image -- button widget with text and icon
|
|
|
|
zr_button_text_symbol -- button widget with text and a triangle
|
|
|
|
zr_button_fitting -- button widget without border and fitting space
|
|
|
|
zr_button_toggle_fitting -- toggle widget without border and fitting space
|
|
|
|
zr_image -- image widget for outputing a image to a window
|
|
|
|
zr_check -- add a checkbox widget
|
|
|
|
zr_option -- radiobutton widget
|
|
|
|
zr_option_group -- radiobutton group for automatic single selection
|
|
|
|
zr_slider -- slider widget with min,max,step value
|
|
|
|
zr_progress -- progressbar widget
|
|
|
|
zr_edit -- edit textbox widget for text input
|
|
|
|
zr_edit_filtered -- edit textbox widget for text input with filter input
|
|
|
|
zr_editbox -- edit textbox with cursor, clipboard and filter
|
|
|
|
zr_spinner -- spinner widget with keyboard or mouse modification
|
|
|
|
*/
|
|
|
|
enum zr_widget_state zr_widget(struct zr_rect*, struct zr_context*);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function represents the base of every widget and calculates the bounds
|
2015-08-29 12:04:09 +03:00
|
|
|
* and allocated space for a widget inside a window.
|
2015-06-05 16:01:15 +03:00
|
|
|
Output:
|
|
|
|
- allocated space for a widget to draw into
|
2015-09-18 00:09:49 +03:00
|
|
|
- zr_true if the widget is visible and should be updated zr_false if not
|
2015-06-05 16:01:15 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_spacing(struct zr_context*, zr_size cols);
|
2015-06-16 00:46:13 +03:00
|
|
|
/* this function creates a seperator to fill space
|
2015-06-05 16:01:15 +03:00
|
|
|
Input:
|
|
|
|
- number of columns or widget to jump over
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_seperator(struct zr_context*);
|
2015-09-09 15:31:19 +03:00
|
|
|
/* this function creates a seperator line */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_text(struct zr_context*, const char*, zr_size,
|
|
|
|
enum zr_text_align);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function creates a bounded non terminated text widget with either
|
|
|
|
left, centered or right alignment
|
|
|
|
Input:
|
|
|
|
- string pointer to text that should be drawn
|
|
|
|
- number of bytes the text is long
|
|
|
|
- text alignment with either left, centered or right alignment
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_text_colored(struct zr_context*, const char*, zr_size,
|
|
|
|
enum zr_text_align, struct zr_color);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function creates a bounded non terminated color text widget with either
|
|
|
|
left, centered or right alignment
|
|
|
|
Input:
|
|
|
|
- string pointer to text that should be drawn
|
|
|
|
- number of bytes the text is long
|
|
|
|
- text alignment with either left, centered or right alignment
|
|
|
|
- color the text should be drawn
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_label(struct zr_context*, const char*, enum zr_text_align);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function creates a zero terminated text widget with either
|
|
|
|
left, centered or right alignment
|
|
|
|
Input:
|
|
|
|
- string pointer to text that should be drawn
|
|
|
|
- text alignment with either left, centered or right alignment
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_label_colored(struct zr_context*, const char*,
|
|
|
|
enum zr_text_align, struct zr_color);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function creates a zero terminated colored text widget with either
|
|
|
|
left, centered or right alignment
|
|
|
|
Input:
|
|
|
|
- string pointer to text that should be drawn
|
|
|
|
- text alignment with either left, centered or right alignment
|
|
|
|
- color the label should be drawn
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_image(struct zr_context*, struct zr_image);
|
2015-07-18 19:25:26 +03:00
|
|
|
/* this function creates an image widget
|
|
|
|
Input:
|
|
|
|
- string pointer to text that should be drawn
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_check(struct zr_context*, const char*, zr_bool active);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function creates a checkbox widget with either active or inactive state
|
|
|
|
Input:
|
|
|
|
- checkbox label describing the content
|
|
|
|
- state of the checkbox with either active or inactive
|
|
|
|
Output:
|
|
|
|
- from user input updated state of the checkbox
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_option(struct zr_context*, const char*, zr_bool active);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function creates a radiobutton widget with either active or inactive state
|
|
|
|
Input:
|
|
|
|
- radiobutton label describing the content
|
|
|
|
- state of the radiobutton with either active or inactive
|
|
|
|
Output:
|
|
|
|
- from user input updated state of the radiobutton
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size zr_option_group(struct zr_context*, const char**,
|
|
|
|
zr_size cnt, zr_size cur);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function creates a radiobutton group widget with only one active radiobutton
|
|
|
|
Input:
|
|
|
|
- radiobutton label array describing the content of each radiobutton
|
|
|
|
- number of radiobuttons
|
|
|
|
- index of the current active radiobutton
|
|
|
|
Output:
|
|
|
|
- the from user input updated index of the active radiobutton
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_button_text(struct zr_context*, const char*,
|
|
|
|
enum zr_button_behavior);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function creates a text button
|
|
|
|
Input:
|
|
|
|
- button label describing the button
|
2015-08-13 16:57:28 +03:00
|
|
|
- string label
|
|
|
|
- button behavior with either default or repeater behavior
|
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- zr_true if the button was transistioned from unpressed to pressed with
|
2015-08-13 16:57:28 +03:00
|
|
|
default button behavior or pressed if repeater behavior.
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_button_color(struct zr_context*, struct zr_color,
|
|
|
|
enum zr_button_behavior);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function creates a colored button without content
|
|
|
|
Input:
|
|
|
|
- color the button should be drawn with
|
|
|
|
- button behavior with either default or repeater behavior
|
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- zr_true if the button was transistioned from unpressed to pressed with
|
2015-06-05 16:01:15 +03:00
|
|
|
default button behavior or pressed if repeater behavior.
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_button_symbol(struct zr_context*, enum zr_symbol, enum zr_button_behavior);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function creates a button with a triangle pointing in one of four directions
|
|
|
|
Input:
|
|
|
|
- triangle direction with either up, down, left or right direction
|
|
|
|
- button behavior with either default or repeater behavior
|
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- zr_true if the button was transistioned from unpressed to pressed with
|
2015-06-05 16:01:15 +03:00
|
|
|
default button behavior or pressed if repeater behavior.
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_button_image(struct zr_context*, struct zr_image img,
|
|
|
|
enum zr_button_behavior);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function creates a button with an icon as content
|
|
|
|
Input:
|
|
|
|
- icon image handle to draw into the button
|
|
|
|
- button behavior with either default or repeater behavior
|
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- zr_true if the button was transistioned from unpressed to pressed with
|
2015-06-05 16:01:15 +03:00
|
|
|
default button behavior or pressed if repeater behavior.
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_button_text_symbol(struct zr_context*, enum zr_symbol,
|
|
|
|
const char*, enum zr_text_align,
|
|
|
|
enum zr_button_behavior);
|
2015-08-27 20:25:13 +03:00
|
|
|
/* this function creates a button with a triangle and text
|
2015-06-06 21:13:28 +03:00
|
|
|
Input:
|
2015-08-29 12:04:09 +03:00
|
|
|
- symbol to draw with the text
|
2015-06-06 21:13:28 +03:00
|
|
|
- button label describing the button
|
|
|
|
- text alignment with either left, centered or right alignment
|
|
|
|
- button behavior with either default or repeater behavior
|
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- zr_true if the button was transistioned from unpressed to pressed with
|
2015-06-06 21:13:28 +03:00
|
|
|
default button behavior or pressed if repeater behavior.
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_button_text_image(struct zr_context *layout, struct zr_image img,
|
|
|
|
const char *text, enum zr_text_align align,
|
|
|
|
enum zr_button_behavior behavior);
|
2015-07-01 15:01:53 +03:00
|
|
|
/* this function creates a button with an icon and text
|
|
|
|
Input:
|
|
|
|
- image or subimage to use as an icon
|
|
|
|
- button label describing the button
|
|
|
|
- text alignment with either left, centered or right alignment
|
|
|
|
- button behavior with either default or repeater behavior
|
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- zr_true if the button was transistioned from unpressed to pressed with
|
2015-07-01 15:01:53 +03:00
|
|
|
default button behavior or pressed if repeater behavior.
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_button_fitting(struct zr_context *layout, const char *text,
|
|
|
|
enum zr_text_align align, enum zr_button_behavior behavior);
|
2015-08-29 13:56:40 +03:00
|
|
|
/* this function creates a fitting button without border
|
|
|
|
Input:
|
|
|
|
- button label describing the button
|
|
|
|
- text alignment with either left, centered or right alignment
|
|
|
|
- button behavior with either default or repeater behavior
|
|
|
|
Output:
|
2015-09-18 00:09:49 +03:00
|
|
|
- zr_true if the button was transistioned from unpressed to pressed with
|
2015-08-29 13:56:40 +03:00
|
|
|
default button behavior or pressed if repeater behavior.
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_button_toggle(struct zr_context*, const char*,zr_bool value);
|
2015-09-08 11:57:27 +03:00
|
|
|
/* this function creates a toggle button which is either active or inactive
|
|
|
|
Input:
|
|
|
|
- label describing the toggle button
|
|
|
|
- current state of the toggle
|
|
|
|
Output:
|
|
|
|
- from user input updated toggle state
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_button_toggle_fitting(struct zr_context*, const char*,zr_bool value);
|
|
|
|
/* this function creates a fitting toggle button which is either active or inactive
|
|
|
|
Input:
|
|
|
|
- label describing the toggle button
|
|
|
|
- current state of the toggle
|
|
|
|
Output:
|
|
|
|
- from user input updated toggle state
|
|
|
|
*/
|
|
|
|
zr_float zr_slider(struct zr_context*, zr_float min, zr_float val,
|
|
|
|
zr_float max, zr_float step);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function creates a slider for value manipulation
|
|
|
|
Input:
|
|
|
|
- minimal slider value that will not be underflown
|
|
|
|
- slider value which shall be updated
|
|
|
|
- maximal slider value that will not be overflown
|
|
|
|
- step intervall to change the slider with
|
|
|
|
Output:
|
|
|
|
- the from user input updated slider value
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size zr_progress(struct zr_context*, zr_size cur, zr_size max,
|
|
|
|
zr_bool modifyable);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function creates an either user or program controlled progressbar
|
|
|
|
Input:
|
|
|
|
- current progressbar value
|
|
|
|
- maximal progressbar value that will not be overflown
|
|
|
|
- flag indicating if the progressbar should be changeable by user input
|
|
|
|
Output:
|
|
|
|
- the from user input updated progressbar value if modifyable progressbar
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_editbox(struct zr_context*, struct zr_edit_box*);
|
2015-07-05 00:36:01 +03:00
|
|
|
/* this function creates an editbox with copy & paste functionality and text buffering */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size zr_edit(struct zr_context*, zr_char *buffer, zr_size len,
|
|
|
|
zr_size max, zr_state *active, zr_size *cursor,
|
|
|
|
enum zr_input_filter);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function creates an editbox to updated/insert user text input
|
|
|
|
Input:
|
|
|
|
- buffer to fill with user input
|
|
|
|
- current length of the buffer in bytes
|
|
|
|
- maximal number of bytes the buffer can be filled with
|
|
|
|
- state of the editbox with active as currently modified by the user
|
|
|
|
- filter type to limit the glyph the user can input into the editbox
|
|
|
|
Output:
|
|
|
|
- length of the buffer after user input update
|
2015-09-18 00:09:49 +03:00
|
|
|
- current state of the editbox with active(zr_true) or inactive(zr_false)
|
2015-06-05 16:01:15 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size zr_edit_filtered(struct zr_context*, zr_char *buffer,
|
|
|
|
zr_size len, zr_size max, zr_state *active,
|
|
|
|
zr_size *cursor, zr_filter);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function creates an editbox to updated/insert filtered user text input
|
|
|
|
Input:
|
|
|
|
- buffer to fill with user input
|
|
|
|
- current length of the buffer in bytes
|
|
|
|
- maximal number of bytes the buffer can be filled with
|
|
|
|
- state of the editbox with active as currently modified by the user
|
|
|
|
- filter callback to limit the glyphes the user can input into the editbox
|
|
|
|
Output:
|
|
|
|
- length of the buffer after user input update
|
2015-09-18 00:09:49 +03:00
|
|
|
- current state of the editbox with active(zr_true) or inactive(zr_false)
|
2015-06-05 16:01:15 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_int zr_spinner(struct zr_context*, zr_int min, zr_int value,
|
|
|
|
zr_int max, zr_int step, zr_state *active);
|
2015-08-05 13:48:01 +03:00
|
|
|
/* this function creates a integer spinner widget
|
|
|
|
Input:
|
|
|
|
- min value that will not be underflown
|
|
|
|
- current spinner value to be updated by user input
|
|
|
|
- max value that will not be overflown
|
|
|
|
- spinner value modificaton stepping intervall
|
|
|
|
- current state of the spinner with active as currently modfied by user input
|
|
|
|
Output:
|
|
|
|
- the from user input updated spinner value
|
2015-09-18 00:09:49 +03:00
|
|
|
- current state of the editbox with active(zr_true) or inactive(zr_false)
|
2015-08-05 13:48:01 +03:00
|
|
|
*/
|
2015-09-10 00:12:03 +03:00
|
|
|
/* --------------------------------------------------------------
|
2015-08-29 13:56:40 +03:00
|
|
|
* Group
|
2015-07-29 23:19:17 +03:00
|
|
|
* --------------------------------------------------------------
|
2015-08-11 15:44:53 +03:00
|
|
|
*
|
2015-08-29 13:56:40 +03:00
|
|
|
GROUP
|
|
|
|
A group window represents a window inside a window. The group thereby has a fixed height
|
2015-08-29 12:04:09 +03:00
|
|
|
but just like a normal window has a scrollbar. It main promise is to group together
|
|
|
|
a group of widgets into a small space inside a window and to provide a scrollable
|
|
|
|
space inside a window.
|
2015-08-07 17:53:52 +03:00
|
|
|
|
|
|
|
USAGE
|
2015-08-29 12:04:09 +03:00
|
|
|
To create a group you first have to allocate space in a window. This is done
|
2015-08-29 13:56:40 +03:00
|
|
|
by the group row layout API and works the same as widgets. After that the
|
2015-09-18 00:09:49 +03:00
|
|
|
`zr_group_begin` has to be called with the parent layout to create
|
2015-08-29 12:04:09 +03:00
|
|
|
the group in and a group layout to create a new window inside the window.
|
|
|
|
Just like a window layout structures the group layout only has a lifetime
|
2015-09-18 00:09:49 +03:00
|
|
|
between the `zr_group_begin` and `zr_group_end` and does
|
2015-08-12 16:18:44 +03:00
|
|
|
not have to be persistent.
|
2015-08-11 15:44:53 +03:00
|
|
|
|
2015-08-29 13:56:40 +03:00
|
|
|
group window API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_group_begin -- adds a scrollable fixed space inside the window
|
|
|
|
zr_group_begin -- ends the scrollable space
|
2015-07-29 23:19:17 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_group_begin(struct zr_context*, struct zr_context *tab,
|
|
|
|
const char *title, zr_flags, struct zr_vec2);
|
2015-08-29 13:56:40 +03:00
|
|
|
/* this function adds a grouped group window into the parent window
|
2015-09-18 00:09:49 +03:00
|
|
|
IMPORTANT: You need to set the height of the group with zr_row_layout
|
2015-08-11 15:44:53 +03:00
|
|
|
Input:
|
|
|
|
- group title to write into the header
|
|
|
|
- group scrollbar offset
|
|
|
|
Output:
|
|
|
|
- group layout to fill with widgets
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 zr_group_end(struct zr_context*, struct zr_context*);
|
2015-08-11 15:44:53 +03:00
|
|
|
/* this function finishes the previously started group layout
|
|
|
|
Output:
|
|
|
|
- The from user input updated group scrollbar pixel offset
|
|
|
|
*/
|
2015-09-10 00:12:03 +03:00
|
|
|
/* --------------------------------------------------------------
|
2015-08-11 15:44:53 +03:00
|
|
|
* SHELF
|
|
|
|
* --------------------------------------------------------------
|
|
|
|
SHELF
|
2015-08-29 12:04:09 +03:00
|
|
|
A shelf extends the concept of a group as an window inside a window
|
2015-08-12 16:18:44 +03:00
|
|
|
with the possibility to decide which content should be drawn into the group.
|
2015-08-29 12:04:09 +03:00
|
|
|
This is achieved by tabs on the top of the group window with one selected
|
2015-08-12 16:18:44 +03:00
|
|
|
tab. The selected tab thereby defines which content should be drawn inside
|
2015-08-29 12:04:09 +03:00
|
|
|
the group window by an index it returns. So you just have to check the returned
|
2015-08-12 16:18:44 +03:00
|
|
|
index and depending on it draw the wanted content.
|
2015-08-11 15:44:53 +03:00
|
|
|
|
2015-08-29 12:04:09 +03:00
|
|
|
shelf API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_shelf_begin -- begins a shelf with a number of selectable tabs
|
|
|
|
zr_shelf_end -- ends a previously started shelf build up process
|
2015-08-12 16:18:44 +03:00
|
|
|
|
2015-08-11 15:44:53 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size zr_shelf_begin(struct zr_context*, struct zr_context*,
|
|
|
|
const char *tabs[], zr_size size,
|
|
|
|
zr_size active, struct zr_vec2 offset);
|
2015-08-29 12:04:09 +03:00
|
|
|
/* this function adds a shelf child window into the parent window
|
2015-09-18 00:09:49 +03:00
|
|
|
IMPORTANT: You need to set the height of the shelf with zr_row_layout
|
2015-08-11 15:44:53 +03:00
|
|
|
Input:
|
|
|
|
- all possible selectible tabs of the shelf with names as a string array
|
|
|
|
- number of seletectible tabs
|
|
|
|
- current active tab array index
|
|
|
|
- scrollbar pixel offset for the shelf
|
|
|
|
Output:
|
|
|
|
- group layout to fill with widgets
|
|
|
|
- the from user input updated current shelf tab index
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 zr_shelf_end(struct zr_context*, struct zr_context*);
|
2015-08-11 15:44:53 +03:00
|
|
|
/* this function finishes the previously started shelf layout
|
|
|
|
Input:
|
|
|
|
- previously started group layout
|
|
|
|
Output:
|
|
|
|
- The from user input updated shelf scrollbar pixel offset
|
|
|
|
*/
|
2015-09-10 00:12:03 +03:00
|
|
|
/* --------------------------------------------------------------
|
2015-08-12 16:18:44 +03:00
|
|
|
* POPUP
|
|
|
|
* --------------------------------------------------------------
|
|
|
|
POPUP
|
2015-08-29 12:04:09 +03:00
|
|
|
The popup extends the normal window with an overlapping blocking
|
|
|
|
window that needs to be closed before the underlining main window can
|
2015-08-12 16:18:44 +03:00
|
|
|
be used again. Therefore popups are designed for messages,tooltips and
|
|
|
|
are used to create the combo box. Internally the popup creates a subbuffer
|
2015-08-29 12:04:09 +03:00
|
|
|
inside a command queue that will be drawn after the complete parent window.
|
2015-08-12 16:18:44 +03:00
|
|
|
|
|
|
|
USAGE
|
2015-09-18 00:09:49 +03:00
|
|
|
To create an popup the `zr_window_popup_begin` function needs to be called
|
2015-08-29 12:04:09 +03:00
|
|
|
with to the parent window local position and size and the wanted type with
|
|
|
|
static or dynamic window. A static window has a fixed size and behaves like a
|
|
|
|
normal window inside a window, but a dynamic window only takes up as much
|
|
|
|
height as needed up to a given maximum height. Dynamic windows are for example
|
|
|
|
combo boxes while static window make sense for messsages or tooltips.
|
2015-09-18 00:09:49 +03:00
|
|
|
To close a popup you can use the `zr_pop_close` function which takes
|
2015-08-29 12:04:09 +03:00
|
|
|
care of the closing process. Finally if the popup window was completly created
|
2015-09-18 00:09:49 +03:00
|
|
|
the `zr_popup_end` function finializes the popup.
|
2015-08-29 12:04:09 +03:00
|
|
|
|
2015-08-31 18:35:37 +03:00
|
|
|
window blocking popup API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_popup_begin -- adds a popup inside a window
|
|
|
|
zr_popup_close -- closes the popup window
|
|
|
|
zr_popup_end -- ends the popup building process
|
2015-08-31 18:35:37 +03:00
|
|
|
|
|
|
|
window non-blocking popup API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_popup_menu_begin -- begin a popup context menu
|
|
|
|
zr_popup_menu_close -- closes a popup context menu
|
|
|
|
zr_popup_menu_end -- ends the popup building process
|
2015-08-12 16:18:44 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_popup_type {
|
|
|
|
ZR_POPUP_STATIC,
|
2015-09-06 20:13:07 +03:00
|
|
|
/* static fixed height non growing popup */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_POPUP_DYNAMIC
|
2015-09-06 20:13:07 +03:00
|
|
|
/* dynamically growing popup with maximum height */
|
2015-08-12 16:18:44 +03:00
|
|
|
};
|
2015-09-09 14:54:20 +03:00
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_flags zr_popup_begin(struct zr_context *parent, struct zr_context *popup,
|
|
|
|
enum zr_popup_type, zr_flags, struct zr_rect bounds,
|
|
|
|
struct zr_vec2 offset);
|
2015-08-31 18:35:37 +03:00
|
|
|
/* this function adds a overlapping blocking popup menu
|
2015-08-12 16:18:44 +03:00
|
|
|
Input:
|
2015-08-31 18:35:37 +03:00
|
|
|
- type of the popup as either growing or static
|
|
|
|
- additonal popup window flags
|
2015-08-12 16:18:44 +03:00
|
|
|
- popup position and size of the popup (NOTE: local position)
|
2015-08-31 18:35:37 +03:00
|
|
|
- scrollbar offset of wanted
|
2015-08-12 16:18:44 +03:00
|
|
|
Output:
|
|
|
|
- popup layout to fill with widgets
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_popup_close(struct zr_context *popup);
|
2015-08-12 16:18:44 +03:00
|
|
|
/* this functions closes a previously opened popup */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 zr_popup_end(struct zr_context *parent,
|
|
|
|
struct zr_context *popup);
|
2015-08-12 16:18:44 +03:00
|
|
|
/* this function finishes the previously started popup layout
|
|
|
|
Output:
|
|
|
|
- The from user input updated popup scrollbar pixel offset
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_popup_nonblock_begin(struct zr_context *parent, struct zr_context *popup,
|
|
|
|
zr_flags flags, zr_state *active, struct zr_rect body);
|
2015-08-31 18:35:37 +03:00
|
|
|
/* this function adds a context menu popup
|
|
|
|
Input:
|
|
|
|
- type of the popup as either growing or static
|
|
|
|
- additonal popup window flags
|
|
|
|
- popup position and size of the popup (NOTE: local position)
|
|
|
|
- scrollbar offset of wanted
|
|
|
|
Output:
|
|
|
|
- popup layout to fill with widgets
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_state zr_popup_nonblock_close(struct zr_context *popup);
|
2015-08-31 18:35:37 +03:00
|
|
|
/* this functions closes the context menu
|
|
|
|
Output:
|
|
|
|
- update state of the context menu
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_popup_nonblock_end(struct zr_context *parent, struct zr_context *popup);
|
2015-08-31 18:35:37 +03:00
|
|
|
/* this functions closes a previously opened context menu */
|
2015-09-10 00:12:03 +03:00
|
|
|
/* --------------------------------------------------------------
|
2015-08-11 15:44:53 +03:00
|
|
|
* GRAPH
|
|
|
|
* --------------------------------------------------------------
|
|
|
|
GRAPH
|
2015-08-12 16:18:44 +03:00
|
|
|
The graph widget provided a way to visualize data in either a line or
|
|
|
|
column graph.
|
2015-08-11 15:44:53 +03:00
|
|
|
|
|
|
|
USAGE
|
2015-08-12 16:18:44 +03:00
|
|
|
To create a graph three different ways are provided. The first one
|
|
|
|
is an immediate mode API which allows the push values one by one
|
|
|
|
into the graph. The second one is a retain mode function which takes
|
|
|
|
an array of float values and converts them into a graph. The final
|
|
|
|
function is based on a callback and is mainly a good option if you
|
|
|
|
want to draw a mathematical function like for example sine or cosine.
|
2015-08-11 15:44:53 +03:00
|
|
|
|
|
|
|
graph widget API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_graph_begin -- immediate mode graph building begin sequence point
|
|
|
|
zr_graph_push -- push a value into a graph
|
|
|
|
zr_graph_end -- immediate mode graph building end sequence point
|
|
|
|
zr_graph -- retained mode graph with array of values
|
|
|
|
zr_graph_ex -- ratained mode graph with getter callback
|
|
|
|
*/
|
|
|
|
enum zr_graph_type {
|
|
|
|
ZR_GRAPH_LINES,
|
2015-07-30 23:19:06 +03:00
|
|
|
/* Line graph with each data point being connected with its previous and next node */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_GRAPH_COLUMN,
|
2015-07-30 23:19:06 +03:00
|
|
|
/* Column graph/Histogram with value represented as bars */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_GRAPH_MAX
|
2015-07-30 23:19:06 +03:00
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_graph {
|
|
|
|
zr_bool valid;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* graph valid flag to make sure that the graph is visible */
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_graph_type type;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* graph type with either line or column graph */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float x, y;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* graph canvas space position */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float w, h;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* graph canvas space size */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float min, max;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* min and max value for correct scaling of values */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 last;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* last line graph point to connect to. Only used by the line graph */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size index;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* current graph value index*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size count;
|
2015-07-30 23:19:06 +03:00
|
|
|
/* number of values inside the graph */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_graph_begin(struct zr_context*, struct zr_graph*,
|
|
|
|
enum zr_graph_type, zr_size count,
|
|
|
|
zr_float min, zr_float max);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function begins a graph building widget
|
|
|
|
Input:
|
|
|
|
- type of the graph with either lines or bars
|
|
|
|
- minimal graph value for the lower bounds of the graph
|
|
|
|
- maximal graph value for the upper bounds of the graph
|
|
|
|
Output:
|
|
|
|
- graph stack object that can be filled with values
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_bool zr_graph_push(struct zr_context*,struct zr_graph*,zr_float);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function pushes a value inside the pushed graph
|
|
|
|
Input:
|
|
|
|
- value data point to fill into the graph either as point or as bar
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_graph_end(struct zr_context *layout, struct zr_graph*);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function pops the graph from being used
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_int zr_graph(struct zr_context*, enum zr_graph_type,
|
|
|
|
const zr_float *values, zr_size count, zr_size offset);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function create a graph with given type from an array of value
|
|
|
|
Input:
|
|
|
|
- type of the graph with either line or bar graph
|
|
|
|
- graph values in continues array form
|
|
|
|
- number of graph values
|
|
|
|
- offset into the value array from which to begin drawing
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_int zr_graph_callback(struct zr_context*, enum zr_graph_type,
|
|
|
|
zr_size count, zr_float(*get_value)(void*, zr_size),
|
2015-07-14 14:26:53 +03:00
|
|
|
void *userdata);
|
2015-06-05 16:01:15 +03:00
|
|
|
/* this function create a graph with given type from callback providing the
|
|
|
|
graph with values
|
|
|
|
Input:
|
|
|
|
- type of the graph with either line or bar graph
|
|
|
|
- number of values inside the graph
|
|
|
|
- callback to access the values inside your datastrucutre
|
|
|
|
- userdata to pull the graph values from
|
|
|
|
*/
|
2015-09-10 00:12:03 +03:00
|
|
|
/* --------------------------------------------------------------
|
2015-08-12 16:18:44 +03:00
|
|
|
* COMBO BOX
|
|
|
|
* --------------------------------------------------------------
|
|
|
|
COMBO BOX
|
2015-08-29 12:04:09 +03:00
|
|
|
The combo box is a minimizable popup window and extends the old school
|
2015-08-12 16:18:44 +03:00
|
|
|
text combo box with the possibility to fill combo boxes with any kind of widgets.
|
2015-08-29 12:04:09 +03:00
|
|
|
The combo box is internall implemented with a dynamic popup window
|
|
|
|
and can only be as height as the window allows.
|
2015-08-12 16:18:44 +03:00
|
|
|
There are two different ways to create a combo box. The first one is a
|
2015-09-18 00:09:49 +03:00
|
|
|
standart text combo box which has it own function `zr_combo`. The second
|
2015-08-12 16:18:44 +03:00
|
|
|
way is the more complex immediate mode API which allows to create
|
|
|
|
any kind of content inside the combo box. In case of the second API it is
|
|
|
|
additionally possible and sometimes wanted to close the combo box popup
|
2015-09-18 00:09:49 +03:00
|
|
|
window This can be achived with `zr_combo_close`.
|
2015-08-12 16:18:44 +03:00
|
|
|
|
|
|
|
combo box API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_combo_begin -- begins the combo box popup window
|
|
|
|
zr_combo_close -- closes the previously opened combo box
|
|
|
|
zr_combo_end -- ends the combo box build up process
|
|
|
|
zr_combo -- shorthand version for a text based combo box
|
|
|
|
*/
|
|
|
|
void zr_combo(struct zr_context*, const char **entries,
|
|
|
|
zr_size count, zr_size *current, zr_size row_height,
|
|
|
|
zr_state *active);
|
2015-08-12 16:18:44 +03:00
|
|
|
/* this function creates a standart text based combobox
|
|
|
|
Input:
|
2015-08-29 12:04:09 +03:00
|
|
|
- parent window layout the combo box will be placed into
|
2015-08-12 16:18:44 +03:00
|
|
|
- string array of all items inside the combo box
|
|
|
|
- number of items inside the string array
|
|
|
|
- the index of the currently selected item
|
|
|
|
- the height of every widget inside the combobox
|
|
|
|
- the current state of the combobox
|
2015-08-29 12:04:09 +03:00
|
|
|
- the scrollbar offset of the window scrollbar
|
2015-08-12 16:18:44 +03:00
|
|
|
Output:
|
|
|
|
- updated currently selected index
|
2015-08-27 20:25:13 +03:00
|
|
|
- updated state of the combo box
|
2015-08-12 16:18:44 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_combo_begin(struct zr_context *parent,
|
|
|
|
struct zr_context *combo, const char *selected,
|
|
|
|
zr_state *active);
|
2015-08-12 16:18:44 +03:00
|
|
|
/* this function begins the combobox build up process
|
|
|
|
Input:
|
2015-08-29 12:04:09 +03:00
|
|
|
- parent window layout the combo box will be placed into
|
|
|
|
- ouput combo box window layout which will be needed to fill the combo box
|
2015-08-12 16:18:44 +03:00
|
|
|
- title of the combo box or in the case of the text combo box the selected item
|
2015-09-18 00:09:49 +03:00
|
|
|
- the current state of the combobox with either zr_true (active) or zr_false else
|
2015-08-29 12:04:09 +03:00
|
|
|
- the current scrollbar offset of the combo box popup window
|
2015-08-12 16:18:44 +03:00
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_combo_close(struct zr_context *combo);
|
2015-08-12 16:18:44 +03:00
|
|
|
/* this function closes a opened combobox */
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_combo_end(struct zr_context *parent, struct zr_context *combo);
|
2015-08-12 16:18:44 +03:00
|
|
|
/* this function ends the combobox build up process */
|
2015-09-10 00:12:03 +03:00
|
|
|
/*----------------------------------------------------------------
|
2015-08-13 16:57:28 +03:00
|
|
|
* MENU
|
|
|
|
* --------------------------------------------------------------
|
|
|
|
MENU
|
2015-08-29 12:04:09 +03:00
|
|
|
The menu widget provides a overlapping popup window which can
|
2015-08-13 16:57:28 +03:00
|
|
|
be opened/closed by clicking on the menu button. It is normally
|
2015-08-29 12:04:09 +03:00
|
|
|
placed at the top of the window and is independent of the parent
|
|
|
|
scrollbar offset. But if needed the menu can even be placed inside the window.
|
2015-09-06 20:13:07 +03:00
|
|
|
At the moment the menu only allows a single depth but that will change
|
|
|
|
in the future.
|
2015-08-13 16:57:28 +03:00
|
|
|
|
|
|
|
menu widget API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_menu_begin -- begins the menu item build up processs
|
|
|
|
zr_menu_push -- adds a item into the menu
|
|
|
|
zr_menu_end -- ends the menu item build up process
|
|
|
|
zr_menu -- shorthand retain mode array version
|
|
|
|
*/
|
|
|
|
#define ZR_NONE (-1)
|
|
|
|
zr_int zr_menu(struct zr_context*, const zr_char *title,
|
|
|
|
const char **entries, zr_size count, zr_size row_height,
|
|
|
|
zr_float width, zr_state *active);
|
2015-08-13 16:57:28 +03:00
|
|
|
/* this function creates a standart text based combobox
|
|
|
|
Input:
|
2015-08-29 12:04:09 +03:00
|
|
|
- parent window layout the combo box will be placed into
|
2015-08-13 16:57:28 +03:00
|
|
|
- string array of all items inside the menu
|
|
|
|
- number of menu items inside the string array
|
|
|
|
- the height of every widget inside the combobox
|
|
|
|
- the current state of the menu
|
|
|
|
Output:
|
|
|
|
- updated state of the menu
|
|
|
|
- index of the selected menu item or -1 otherwise
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_menu_begin(struct zr_context *parent,
|
|
|
|
struct zr_context *menu, const char *title,
|
|
|
|
zr_float width, zr_state *active);
|
2015-08-13 16:57:28 +03:00
|
|
|
/* this function begins the menu build up process
|
|
|
|
Input:
|
2015-08-29 12:04:09 +03:00
|
|
|
- parent window layout the menu will be placed into
|
|
|
|
- ouput menu window layout
|
2015-08-13 16:57:28 +03:00
|
|
|
- title of the menu to
|
2015-09-18 00:09:49 +03:00
|
|
|
- the current state of the menu with either zr_true (open) or zr_false else
|
2015-08-13 16:57:28 +03:00
|
|
|
*/
|
2015-09-10 00:12:03 +03:00
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_menu_close(struct zr_context *menu);
|
2015-08-13 16:57:28 +03:00
|
|
|
/* this function closes a opened menu */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 zr_menu_end(struct zr_context *parent,
|
|
|
|
struct zr_context *menu);
|
2015-08-13 16:57:28 +03:00
|
|
|
/* this function ends the menu build up process */
|
2015-08-12 16:18:44 +03:00
|
|
|
/*
|
|
|
|
* --------------------------------------------------------------
|
2015-08-11 15:44:53 +03:00
|
|
|
* TREE
|
|
|
|
* --------------------------------------------------------------
|
|
|
|
TREE
|
2015-08-12 16:18:44 +03:00
|
|
|
The tree widget is standart immediate mode API and divides tree nodes into
|
|
|
|
parent nodes and leafes. Nodes have immediate mode function points, while
|
|
|
|
leafes are just normal functions. In addition there is a icon version for each
|
|
|
|
of the two node types which allows you to add images into a tree node.
|
|
|
|
The tree widget supports in contrast to the tree layout a back channel
|
|
|
|
for each node and leaf. This allows to return commands back to the user
|
|
|
|
to declare what to do with the tree node. This includes cloning which is
|
|
|
|
copying the selected node and pasting it in the same parent node, cuting
|
|
|
|
which removes nodes from its parents and copyies it into a paste buffer,
|
|
|
|
pasting to take all nodes inside the paste buffer and copy it into a node and
|
|
|
|
finally removing a tree node.
|
2015-08-11 15:44:53 +03:00
|
|
|
|
|
|
|
tree widget API
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_tree_begin -- begins the tree build up processs
|
|
|
|
zr_tree_begin_node -- adds and opens a normal node to the tree
|
|
|
|
zr_tree_begin_node_icon -- adds a opens a node with an icon to the tree
|
|
|
|
zr_tree_end_node -- ends and closes a previously added node
|
|
|
|
zr_tree_leaf -- adds a leaf node to a prev opened node
|
|
|
|
zr_tree_leaf_icon -- adds a leaf icon node to a prev opended node
|
|
|
|
zr_tree_end -- ends the tree build up process
|
|
|
|
*/
|
|
|
|
enum zr_tree_nodes_states {
|
|
|
|
ZR_NODE_ACTIVE = 0x01,
|
2015-08-11 15:44:53 +03:00
|
|
|
/* the node is currently opened */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_NODE_SELECTED = 0x02
|
2015-08-11 15:44:53 +03:00
|
|
|
/* the node has been seleted by the user */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_tree_node_operation {
|
|
|
|
ZR_NODE_NOP,
|
2015-08-11 15:44:53 +03:00
|
|
|
/* node did not receive a command */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_NODE_CUT,
|
2015-08-11 15:44:53 +03:00
|
|
|
/* cut the node from the current tree and add into a buffer */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_NODE_CLONE,
|
2015-08-11 15:44:53 +03:00
|
|
|
/* copy current node and add copy into the parent node */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_NODE_PASTE,
|
2015-08-11 15:44:53 +03:00
|
|
|
/* paste all node in the buffer into the tree */
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_NODE_DELETE
|
2015-08-11 15:44:53 +03:00
|
|
|
/* remove the node from the parent tree */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_tree {
|
|
|
|
struct zr_context group;
|
2015-08-29 12:04:09 +03:00
|
|
|
/* window add the tree into */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_float x_off, at_x;
|
2015-08-11 15:44:53 +03:00
|
|
|
/* current x position of the next node */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_int skip;
|
2015-08-11 15:44:53 +03:00
|
|
|
/* flag that indicates that a node will be skipped */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_int depth;
|
2015-08-11 15:44:53 +03:00
|
|
|
/* current depth of the tree */
|
|
|
|
};
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_tree_begin(struct zr_context*, struct zr_tree*, const char *title,
|
|
|
|
zr_float row_height, struct zr_vec2 scrollbar);
|
2015-07-30 23:19:06 +03:00
|
|
|
/* this function begins the tree building process
|
|
|
|
Input:
|
|
|
|
- title describing the tree or NULL
|
2015-08-29 12:04:09 +03:00
|
|
|
- height of every node inside the window
|
2015-07-30 23:19:06 +03:00
|
|
|
- scrollbar offset
|
|
|
|
Output:
|
|
|
|
- tree build up state structure
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_tree_node_operation zr_tree_begin_node(struct zr_tree*, const char*,
|
|
|
|
zr_state*);
|
2015-07-30 23:19:06 +03:00
|
|
|
/* this function begins a parent node
|
|
|
|
Input:
|
|
|
|
- title of the node
|
|
|
|
- current node state
|
|
|
|
Output:
|
|
|
|
- operation identifier what should be done with this node
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_tree_node_operation zr_tree_begin_node_icon(struct zr_tree*,
|
|
|
|
const char*, struct zr_image,
|
|
|
|
zr_state*);
|
2015-07-30 23:19:06 +03:00
|
|
|
/* this function begins a text icon parent node
|
|
|
|
Input:
|
|
|
|
- title of the node
|
|
|
|
- icon of the node
|
|
|
|
- current node state
|
|
|
|
Output:
|
|
|
|
- operation identifier what should be done with this node
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
void zr_tree_end_node(struct zr_tree*);
|
2015-07-30 23:19:06 +03:00
|
|
|
/* this function ends a parent node */
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_tree_node_operation zr_tree_leaf(struct zr_tree*, const char*,
|
|
|
|
zr_state*);
|
2015-07-30 23:19:06 +03:00
|
|
|
/* this function pushes a leaf node to the tree
|
|
|
|
Input:
|
|
|
|
- title of the node
|
|
|
|
- current leaf node state
|
|
|
|
Output:
|
|
|
|
- operation identifier what should be done with this node
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
enum zr_tree_node_operation zr_tree_leaf_icon(struct zr_tree*,
|
|
|
|
const char*, struct zr_image,
|
|
|
|
zr_state*);
|
2015-07-30 23:19:06 +03:00
|
|
|
/* this function pushes a leaf icon node to the tree
|
|
|
|
Input:
|
|
|
|
- title of the node
|
|
|
|
- icon of the node
|
|
|
|
- current leaf node state
|
|
|
|
Output:
|
|
|
|
- operation identifier what should be done with this node
|
|
|
|
*/
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_vec2 zr_tree_end(struct zr_context*, struct zr_tree*);
|
2015-07-30 23:19:06 +03:00
|
|
|
/* this function ends a the tree building process */
|
2015-08-07 17:53:52 +03:00
|
|
|
|
2015-06-18 13:12:57 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
#endif /* ZR_H_ */
|