Table of Contents
include/nilorea/n_gui_curve.h
A curve editor for N_GUI: control points on a curve over [0,1]. More...
Detailed Description
A curve editor for N_GUI: control points on a curve over [0,1].
Author: Castagnier Mickael
Version: 1.0
Date: 24/09/2026
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.
Source code
/*
* Nilorea Library
* Copyright (C) 2005-2026 Castagnier Mickael
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __NILOREA_GUI_CURVE__
#define __NILOREA_GUI_CURVE__
/* Allegro only: the editor is an N_GUI widget drawn with allegro_primitives. */
#ifdef HAVE_ALLEGRO
#ifdef __cplusplus
extern "C" {
#endif
#include "nilorea/n_gui.h"
typedef void (*N_GUI_CURVE_CHANGE)(int widget_id, int dragging, void* user_data);
typedef float (*N_GUI_CURVE_EVAL)(const float* xs, const float* ys, int count, float x, void* user_data);
typedef void (*N_GUI_CURVE_BACKGROUND)(float x, float y, float w, float h, void* user_data);
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);
int n_gui_curve_set_points(N_GUI_CTX* ctx, int widget_id, const float* xs, const float* ys, int count);
int n_gui_curve_get_points(N_GUI_CTX* ctx, int widget_id, float* xs, float* ys, int max);
void n_gui_curve_set_eval(N_GUI_CTX* ctx, int widget_id, N_GUI_CURVE_EVAL eval, void* user_data);
void n_gui_curve_set_background(N_GUI_CTX* ctx, int widget_id, N_GUI_CURVE_BACKGROUND draw, void* user_data);
void n_gui_curve_set_point_radius(N_GUI_CTX* ctx, int widget_id, float radius);
float n_gui_curve_eval(N_GUI_CTX* ctx, int widget_id, float x);
float n_gui_curve_eval_points(const float* xs, const float* ys, int count, float x);
#ifdef __cplusplus
}
#endif
#endif /* HAVE_ALLEGRO */
#endif /* __NILOREA_GUI_CURVE__ */
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