Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_gui_curve.h File Reference

A curve editor for N_GUI: control points on a curve over [0,1]. More...

#include "nilorea/n_gui.h"
Include dependency graph for n_gui_curve.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

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.
typedef void(* N_GUI_CURVE_CHANGE) (int widget_id, int dragging, void *user_data)
 called on every change of the points.
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.

Functions

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.

Detailed Description

A curve editor for N_GUI: control points on a curve over [0,1].

A tone curve, an easing curve, a gain curve: a function from [0,1] to [0,1] shaped by dragging points. The editor is a custom widget (n_gui_add_custom() with n_gui_custom_set_mouse()), so it lives in any window like any other widget and its state is freed with it.

  • A left press on a point takes it; anywhere else adds a point there and takes that. Dragging moves the taken point: its y anywhere in [0,1], its x between its neighbours, and never the x of the first or the last point, so the curve's domain stays whole.
  • A right press on a point removes it, unless it is the first or the last.
  • on_change is called on every change, with dragging set while the change is a step of a drag, so a caller can make one undo step of a whole drag.

The points are the caller's data as much as the widget's: set them from the model, read them back in on_change. What the curve between them is, is the caller's too: n_gui_curve_set_eval() draws the caller's own interpolation, so what is drawn is exactly what the caller computes. By default it is n_gui_curve_eval_points(), a monotone cubic Hermite spline that holds its end values outside the points and never overshoots them.

Colours come from the widget's theme: bg_normal under everything, border_normal for the frame, the quarter grid and the diagonal, text_normal for the curve and the points.

Author
Castagnier Mickael
Version
1.0
Date
24/09/2026

Definition in file n_gui_curve.h.