![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
A curve editor for N_GUI: control points on a curve over [0,1]. More...
#include <math.h>#include <stdlib.h>#include <string.h>#include <allegro5/allegro_primitives.h>#include "nilorea/n_common.h"#include "nilorea/n_log.h"#include "nilorea/n_gui_curve.h"Go to the source code of this file.
Data Structures | |
| struct | _N_GUI_CURVE |
| an editor's state, owned by its custom widget More... | |
| struct | _N_GUI_CURVE_BLOCK |
| an editor's state and its mouse callback's context in one allocation, because a custom widget owns one pointer More... | |
| struct | _N_GUI_CURVE_MOUSE |
| what an editor's mouse callback needs: the context, to find the widget and mark the GUI dirty, and the editor's state More... | |
Macros | |
| #define | N_GUI_CURVE_MIN_GAP (1.0f / 1024.0f) |
| how close in x two points may come, so neither is ever a zero width segment | |
| #define | N_GUI_CURVE_SEGMENTS 64 |
| segments the drawn curve is made of: fine enough to look smooth at any size an editor has on a screen | |
Functions | |
| static void | _curve_block_destroy (void *user_data) |
| destroy callback for the block holding both | |
| static float | _curve_clamp (float v) |
| helper: clamp to [0,1] | |
| static void | _curve_draw (N_GUI_WIDGET *widget, float x, float y, ALLEGRO_FONT *font, void *user_data) |
| custom draw callback | |
| static int | _curve_insert (_N_GUI_CURVE *cv, float px, float py) |
| helper: insert a point in x order; returns its index or -1 when full | |
| static int | _curve_mouse (int widget_id, const N_GUI_MOUSE_EVENT *ev, void *user_data) |
| custom mouse callback | |
| static _N_GUI_CURVE * | _curve_of (N_GUI_CTX *ctx, int widget_id) |
| helper: find the editor state behind a widget id, or NULL | |
| static int | _curve_point_at (const _N_GUI_CURVE *cv, const N_GUI_WIDGET *wgt, float lx, float ly) |
| helper: the point within grab distance of a widget-local position, or -1 | |
| static float | _curve_value (const _N_GUI_CURVE *cv, float x) |
| helper: the editor's curve at x, the caller's or the built-in one | |
| float | n_gui_curve_eval (N_GUI_CTX *ctx, int widget_id, float x) |
The editor's curve at x, as it is drawn. | |
| float | n_gui_curve_eval_points (const float *xs, const float *ys, int count, float x) |
| A monotone cubic Hermite spline through points. | |
| int | n_gui_curve_get_points (N_GUI_CTX *ctx, int widget_id, float *xs, float *ys, int max) |
| Read the points. | |
| 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. | |
| 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. | |
| 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_point_radius (N_GUI_CTX *ctx, int widget_id, float radius) |
| Size of the drawn points, for a display scale. | |
| int | n_gui_curve_set_points (N_GUI_CTX *ctx, int widget_id, const float *xs, const float *ys, int count) |
| Replace the points. | |
A curve editor for N_GUI: control points on a curve over [0,1].
Definition in file n_gui_curve.c.
| struct _N_GUI_CURVE |
an editor's state, owned by its custom widget
Definition at line 48 of file n_gui_curve.c.
| Data Fields | ||
|---|---|---|
| N_GUI_CURVE_BACKGROUND | background | drawn behind everything, or NULL |
| void * | background_user_data | handed back to background |
| int | count | how many points |
| int | dragging | the point being dragged, or -1 |
| N_GUI_CURVE_EVAL | eval | the caller's curve, or NULL for the built-in one |
| void * | eval_user_data | handed back to eval |
| int | id | the widget |
| int | max | room in xs and ys |
| N_GUI_CURVE_CHANGE | on_change | the caller's change callback |
| float | radius | drawn point radius, pixels |
| void * | user_data | handed back to on_change |
| float * | xs | points' x, ascending |
| float * | ys | points' y |
| struct _N_GUI_CURVE_BLOCK |
an editor's state and its mouse callback's context in one allocation, because a custom widget owns one pointer
Definition at line 294 of file n_gui_curve.c.
| Data Fields | ||
|---|---|---|
| _N_GUI_CURVE | cv | what the draw callback sees |
| _N_GUI_CURVE_MOUSE | mouse | what the mouse callback sees |
| struct _N_GUI_CURVE_MOUSE |
what an editor's mouse callback needs: the context, to find the widget and mark the GUI dirty, and the editor's state
Definition at line 225 of file n_gui_curve.c.
| Data Fields | ||
|---|---|---|
| N_GUI_CTX * | ctx | context |
| _N_GUI_CURVE * | cv | editor |
| #define N_GUI_CURVE_MIN_GAP (1.0f / 1024.0f) |
how close in x two points may come, so neither is ever a zero width segment
Definition at line 45 of file n_gui_curve.c.
Referenced by _curve_insert(), and _curve_mouse().
| #define N_GUI_CURVE_SEGMENTS 64 |
segments the drawn curve is made of: fine enough to look smooth at any size an editor has on a screen
Definition at line 42 of file n_gui_curve.c.
Referenced by _curve_draw().
|
static |
destroy callback for the block holding both
Definition at line 302 of file n_gui_curve.c.
References _N_GUI_CURVE_BLOCK::cv, _N_GUI_CURVE::xs, and _N_GUI_CURVE::ys.
Referenced by n_gui_curve_new().
|
static |
helper: clamp to [0,1]
Definition at line 78 of file n_gui_curve.c.
Referenced by _curve_mouse(), _curve_value(), n_gui_curve_eval_points(), and n_gui_curve_set_points().
|
static |
custom draw callback
Definition at line 133 of file n_gui_curve.c.
References _curve_value(), _N_GUI_CURVE::background, _N_GUI_CURVE::background_user_data, N_GUI_THEME::bg_normal, N_GUI_THEME::border_normal, _N_GUI_CURVE::count, font, N_GUI_WIDGET::h, N_GUI_CURVE_SEGMENTS, _N_GUI_CURVE::radius, N_GUI_THEME::text_normal, N_GUI_WIDGET::theme, N_GUI_WIDGET::w, _N_GUI_CURVE::xs, and _N_GUI_CURVE::ys.
Referenced by _curve_of(), and n_gui_curve_new().
|
static |
helper: insert a point in x order; returns its index or -1 when full
Definition at line 193 of file n_gui_curve.c.
References _N_GUI_CURVE::count, _N_GUI_CURVE::max, N_GUI_CURVE_MIN_GAP, _N_GUI_CURVE::xs, and _N_GUI_CURVE::ys.
Referenced by _curve_mouse().
|
static |
custom mouse callback
Definition at line 235 of file n_gui_curve.c.
References _curve_clamp(), _curve_insert(), _curve_point_at(), N_GUI_MOUSE_EVENT::button, _N_GUI_CURVE::count, _N_GUI_CURVE_MOUSE::ctx, _N_GUI_CURVE_MOUSE::cv, _N_GUI_CURVE::dragging, N_GUI_WIDGET::h, N_GUI_CURVE_MIN_GAP, n_gui_get_widget(), n_gui_mark_dirty(), N_GUI_MOUSE_DOWN, N_GUI_MOUSE_DRAG, N_GUI_MOUSE_UP, _N_GUI_CURVE::on_change, N_GUI_MOUSE_EVENT::type, _N_GUI_CURVE::user_data, N_GUI_WIDGET::w, N_GUI_MOUSE_EVENT::x, _N_GUI_CURVE::xs, N_GUI_MOUSE_EVENT::y, and _N_GUI_CURVE::ys.
Referenced by n_gui_curve_new().
|
static |
helper: find the editor state behind a widget id, or NULL
Definition at line 212 of file n_gui_curve.c.
References _curve_draw(), N_GUI_WIDGET::data, N_GUI_CUSTOM_DATA::draw, n_gui_get_widget(), N_GUI_TYPE_CUSTOM, N_GUI_WIDGET::type, and N_GUI_CUSTOM_DATA::user_data.
Referenced by n_gui_curve_eval(), n_gui_curve_get_points(), n_gui_curve_set_background(), n_gui_curve_set_eval(), n_gui_curve_set_point_radius(), and n_gui_curve_set_points().
|
static |
helper: the point within grab distance of a widget-local position, or -1
Definition at line 174 of file n_gui_curve.c.
References _N_GUI_CURVE::count, N_GUI_WIDGET::h, _N_GUI_CURVE::radius, N_GUI_WIDGET::w, _N_GUI_CURVE::xs, and _N_GUI_CURVE::ys.
Referenced by _curve_mouse().
|
static |
helper: the editor's curve at x, the caller's or the built-in one
Definition at line 125 of file n_gui_curve.c.
References _curve_clamp(), _N_GUI_CURVE::count, _N_GUI_CURVE::eval, _N_GUI_CURVE::eval_user_data, n_gui_curve_eval_points(), _N_GUI_CURVE::xs, and _N_GUI_CURVE::ys.
Referenced by _curve_draw(), and n_gui_curve_eval().