Table of Contents
GUI CURVE: a curve editor widget
Types
| Name | |
|---|---|
| typedef float(*)(const float *xs, const float *ys, int count, float x, void *user_data) | N_GUI_CURVE_EVAL the caller's curve through the points, for drawing. |
| typedef void(*)(int widget_id, int dragging, void *user_data) | N_GUI_CURVE_CHANGE called on every change of the points. |
| typedef void(*)(float x, float y, float w, float h, void *user_data) | N_GUI_CURVE_BACKGROUND drawn behind the grid and the curve, such as a histogram. |
Functions
| Name | |
|---|---|
| int | n_gui_curve_set_points(N_GUI_CTX * ctx, int widget_id, const float * xs, const float * ys, int count) Replace the points. |
| void | n_gui_curve_set_point_radius(N_GUI_CTX * ctx, int widget_id, float radius) Size of the drawn points, for a display scale. |
| void | n_gui_curve_set_eval(N_GUI_CTX * ctx, int widget_id, N_GUI_CURVE_EVAL eval, void * user_data) Draw the caller's own curve through the points. |
| void | n_gui_curve_set_background(N_GUI_CTX * ctx, int widget_id, N_GUI_CURVE_BACKGROUND draw, void * user_data) Draw something behind the grid and the curve. |
| int | n_gui_curve_new(N_GUI_CTX * ctx, int window_id, float x, float y, float w, float h, int max_points, N_GUI_CURVE_CHANGE on_change, void * user_data) Add a curve editor to a window. |
| int | n_gui_curve_get_points(N_GUI_CTX * ctx, int widget_id, float * xs, float * ys, int max) Read the points. |
| float | n_gui_curve_eval_points(const float * xs, const float * ys, int count, float x) A monotone cubic Hermite spline through points. |
| float | n_gui_curve_eval(N_GUI_CTX * ctx, int widget_id, float x) The editor's curve at x, as it is drawn. |
Types Documentation
typedef N_GUI_CURVE_EVAL
typedef float(* N_GUI_CURVE_EVAL) (const float *xs, const float *ys, int count, float x, void *user_data);
the caller's curve through the points, for drawing.
Parameters:
- xs the points' x, ascending, in [0,1]
- ys the points' y, in [0,1]
- count how many points, at least 2
- x where to evaluate, in [0,1]
- user_data what was handed to n_gui_curve_set_eval()
Return: the curve's value at x
typedef N_GUI_CURVE_CHANGE
typedef void(* N_GUI_CURVE_CHANGE) (int widget_id, int dragging, void *user_data);
called on every change of the points.
Parameters:
- widget_id the editor
- dragging 1 while the change is a step of a drag of one point, 0 for a point added or removed
- user_data what was handed to n_gui_curve_new()
typedef N_GUI_CURVE_BACKGROUND
typedef void(* N_GUI_CURVE_BACKGROUND) (float x, float y, float w, float h, void *user_data);
drawn behind the grid and the curve, such as a histogram.
Parameters:
- x left edge on screen
- y top edge on screen
- w width
- h height
- user_data what was handed to n_gui_curve_set_background()
Functions Documentation
function n_gui_curve_set_points
int n_gui_curve_set_points(
N_GUI_CTX * ctx,
int widget_id,
const float * xs,
const float * ys,
int count
)
Replace the points.
Parameters:
- ctx the GUI context.
- widget_id the editor.
- xs the points' x. Must not be NULL.
- ys the points' y. Must not be NULL.
- count how many, 2 to the editor's maximum.
Return: TRUE, or FALSE when refused or on a bad argument.
on_change is not called.
Refused while a point is being dragged, so a model echoing a change back cannot pull the point from under the pointer. The points are sorted by x and clamped to [0,1].
function n_gui_curve_set_point_radius
void n_gui_curve_set_point_radius(
N_GUI_CTX * ctx,
int widget_id,
float radius
)
Size of the drawn points, for a display scale.
Parameters:
- ctx the GUI context.
- widget_id the editor.
- radius in pixels, 4 by default. Zero or less is ignored.
A press within two and a half radii of a point takes it.
function n_gui_curve_set_eval
void n_gui_curve_set_eval(
N_GUI_CTX * ctx,
int widget_id,
N_GUI_CURVE_EVAL eval,
void * user_data
)
Draw the caller's own curve through the points.
Parameters:
- ctx the GUI context.
- widget_id the editor.
- eval the caller's curve; NULL goes back to n_gui_curve_eval_points().
- user_data handed back to
eval.
function n_gui_curve_set_background
void n_gui_curve_set_background(
N_GUI_CTX * ctx,
int widget_id,
N_GUI_CURVE_BACKGROUND draw,
void * user_data
)
Draw something behind the grid and the curve.
Parameters:
- ctx the GUI context.
- widget_id the editor.
- draw the callback; NULL draws nothing there.
- user_data handed back to
draw.
function n_gui_curve_new
int n_gui_curve_new(
N_GUI_CTX * ctx,
int window_id,
float x,
float y,
float w,
float h,
int max_points,
N_GUI_CURVE_CHANGE on_change,
void * user_data
)
Add a curve editor to a window.
Parameters:
- ctx the GUI context. Must not be NULL.
- window_id the window to add it to.
- x left, relative to the window.
- y top, relative to the window.
- w width.
- h height.
- max_points how many points it may hold, 2 or more.
- on_change called on every change. May be NULL.
- user_data handed back to
on_change.
Return: the widget id, or -1 on error. The editor's state is the widget's and is freed with it.
It starts as the identity, two points at (0,0) and (1,1).
function n_gui_curve_get_points
int n_gui_curve_get_points(
N_GUI_CTX * ctx,
int widget_id,
float * xs,
float * ys,
int max
)
Read the points.
Parameters:
- ctx the GUI context.
- widget_id the editor.
- xs receives up to
maxx, ascending. May be NULL to count only. - ys receives up to
maxy. May be NULL to count only. - max room in
xsandys.
Return: how many points the editor holds, or -1 when it is not an editor.
function n_gui_curve_eval_points
float n_gui_curve_eval_points(
const float * xs,
const float * ys,
int count,
float x
)
A monotone cubic Hermite spline through points.
Parameters:
- xs the points' x, ascending. Must not be NULL.
- ys the points' y. Must not be NULL.
- count how many. 0 gives
x, 1 gives that point's y. - x where, clamped to [0,1].
Return: the value.
The tangents are the averaged secant slopes, zeroed at a local extremum and limited to three times the segment's slope (Fritsch-Carlson), so a segment never overshoots its end points. Outside the points the curve holds the end value. The result is clamped to [0,1].
function n_gui_curve_eval
float n_gui_curve_eval(
N_GUI_CTX * ctx,
int widget_id,
float x
)
The editor's curve at x, as it is drawn.
Parameters:
- ctx the GUI context.
- widget_id the editor.
- x where, clamped to [0,1].
Return: the value, or x when widget_id is not an editor.
Modules
- AABB3D
- ACCEPT_POOL
- ALLEGRO4
- ALLEGRO5
- ANIM_LIB
- ASTAR
- ATLAS_LIB
- AVRO
- CLOCK_SYNC
- COMMONS
- CONFIGFILE
- CYPHER_BASE64
- CYPHER_VIGENERE
- DEAD_RECKONING
- ENUMS
- EXCEPTIONS
- GAME_ENV
- GIT
- GUI
- HASH_TABLE
- ISOMETRIC_ENGINE
- LIST
- LOG
- LOGNODUP
- LZ4
- NETWORKING
- NETWORK_MSG
- N_COOKIES
- N_DIFF
- N_DIGEST
- N_DISK_CACHE
- N_DNS
- N_ECC
- N_ENTROPY
- N_FILES
- N_FLUIDS
- N_GUI_COLOR
- N_GUI_COLORWHEEL
- N_GUI_CURVE
- N_GUI_GRID
- N_GUI_POPUP
- N_HEX
- N_HTTP3
- N_HTTP_COOKIE
- N_HTTP_FORM
- N_HTTP_MIME
- N_HTTP_REQ
- N_HTTP_RESP
- N_HTTP_ROUTER
- N_HTTP_SERVER
- N_ICC
- N_JSON
- N_KAFKA
- N_LINALG
- N_MODULE
- N_OPENSSL_COMPAT
- N_PRETTY
- N_PTH
- N_QUERY
- N_RANDOM
- N_SHA256
- N_STR
- N_TIFF
- N_TIME
- N_USER
- N_X509
- N_ZIP
- PARTICLES
- PCRE
- PHYSICS
- SIGNALS
- STACK
- THREADS
- TRAJECTORY
- TREE
- ZLIB