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

A colour wheel for N_GUI: one point in a disc, dragged. More...

#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <allegro5/allegro_color.h>
#include <allegro5/allegro_primitives.h>
#include "nilorea/n_common.h"
#include "nilorea/n_log.h"
#include "nilorea/n_gui_colorwheel.h"
Include dependency graph for n_gui_colorwheel.c:

Go to the source code of this file.

Data Structures

struct  _N_GUI_COLORWHEEL
 a wheel's state, owned by its custom widget More...
struct  _N_GUI_COLORWHEEL_BLOCK
 a wheel's state and its mouse callback's context in one allocation, because a custom widget owns one pointer More...
struct  _N_GUI_COLORWHEEL_MOUSE
 what a wheel's mouse callback needs: the context and the state More...

Macros

#define N_GUI_COLORWHEEL_PI   3.14159265358979f
 pi, not taken from math.h's M_PI, which strict C does not have
#define N_GUI_COLORWHEEL_RINGS   8
 rings and sectors the disc is drawn with: enough to look smooth at the sizes a panel gives it
#define N_GUI_COLORWHEEL_SECTORS   48
 rings and sectors the disc is drawn with: enough to look smooth at the sizes a panel gives it

Functions

static void _wheel_block_destroy (void *user_data)
 destroy callback for the block
static void _wheel_clamp (float *u, float *v)
 helper: the point kept inside the unit circle
static void _wheel_draw (N_GUI_WIDGET *widget, float x, float y, ALLEGRO_FONT *font, void *user_data)
 custom draw callback
static void _wheel_geometry (float x, float y, float w, float h, float *cx, float *cy, float *radius)
 helper: the disc's centre and radius in a widget of w by h at x, y
static int _wheel_mouse (int widget_id, const N_GUI_MOUSE_EVENT *ev, void *user_data)
 custom mouse callback
static _N_GUI_COLORWHEEL * _wheel_of (N_GUI_CTX *ctx, int widget_id)
 helper: find the wheel behind a widget id, or NULL
int n_gui_colorwheel_get (N_GUI_CTX *ctx, int widget_id, float *u, float *v)
 Read the point.
ALLEGRO_COLOR n_gui_colorwheel_hue (float u, float v, void *user_data)
 The default disc colour: HSV, hue by angle with red to the right and going counter clockwise, saturation by distance from the centre, value one.
int n_gui_colorwheel_new (N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, N_GUI_COLORWHEEL_CHANGE on_change, void *user_data)
 Add a colour wheel, its point in the centre.
int n_gui_colorwheel_set (N_GUI_CTX *ctx, int widget_id, float u, float v)
 Set the point.
void n_gui_colorwheel_set_colour (N_GUI_CTX *ctx, int widget_id, N_GUI_COLORWHEEL_COLOUR colour, void *user_data)
 Paint the disc with the caller's colours.

Detailed Description

A colour wheel for N_GUI: one point in a disc, dragged.

Author
Castagnier Mickael
Version
1.0
Date
28/09/2026

Definition in file n_gui_colorwheel.c.


Data Structure Documentation

◆ _N_GUI_COLORWHEEL

struct _N_GUI_COLORWHEEL

a wheel's state, owned by its custom widget

Definition at line 51 of file n_gui_colorwheel.c.

Collaboration diagram for _N_GUI_COLORWHEEL:
Data Fields
N_GUI_COLORWHEEL_COLOUR colour the disc's colour, the caller's or the default
void * colour_user_data handed back to colour
int dragging non-zero while the button is held
N_GUI_COLORWHEEL_CHANGE on_change the caller's change callback
double press_time time of the last left press, al_get_time(), for the double click
float press_x where it was, in the widget
float press_y where it was, in the widget
float u the point, across
void * user_data handed back to on_change
float v the point, up

◆ _N_GUI_COLORWHEEL_BLOCK

struct _N_GUI_COLORWHEEL_BLOCK

a wheel's state and its mouse callback's context in one allocation, because a custom widget owns one pointer

Definition at line 233 of file n_gui_colorwheel.c.

Collaboration diagram for _N_GUI_COLORWHEEL_BLOCK:
Data Fields
_N_GUI_COLORWHEEL cw what the draw callback sees
_N_GUI_COLORWHEEL_MOUSE mouse what the mouse callback sees

◆ _N_GUI_COLORWHEEL_MOUSE

struct _N_GUI_COLORWHEEL_MOUSE

what a wheel's mouse callback needs: the context and the state

Definition at line 165 of file n_gui_colorwheel.c.

Collaboration diagram for _N_GUI_COLORWHEEL_MOUSE:
Data Fields
N_GUI_CTX * ctx context
_N_GUI_COLORWHEEL * cw wheel

Macro Definition Documentation

◆ N_GUI_COLORWHEEL_PI

#define N_GUI_COLORWHEEL_PI   3.14159265358979f

pi, not taken from math.h's M_PI, which strict C does not have

Definition at line 42 of file n_gui_colorwheel.c.

Referenced by _wheel_draw(), and n_gui_colorwheel_hue().

◆ N_GUI_COLORWHEEL_RINGS

#define N_GUI_COLORWHEEL_RINGS   8

rings and sectors the disc is drawn with: enough to look smooth at the sizes a panel gives it

Definition at line 46 of file n_gui_colorwheel.c.

Referenced by _wheel_draw().

◆ N_GUI_COLORWHEEL_SECTORS

#define N_GUI_COLORWHEEL_SECTORS   48

rings and sectors the disc is drawn with: enough to look smooth at the sizes a panel gives it

Definition at line 48 of file n_gui_colorwheel.c.

Referenced by _wheel_draw().

Function Documentation

◆ _wheel_block_destroy()

void _wheel_block_destroy ( void * user_data)
static

destroy callback for the block

Definition at line 241 of file n_gui_colorwheel.c.

Referenced by n_gui_colorwheel_new().

Here is the caller graph for this function:

◆ _wheel_clamp()

void _wheel_clamp ( float * u,
float * v )
static

helper: the point kept inside the unit circle

Definition at line 87 of file n_gui_colorwheel.c.

Referenced by _wheel_mouse(), and n_gui_colorwheel_set().

Here is the caller graph for this function:

◆ _wheel_draw()

void _wheel_draw ( N_GUI_WIDGET * widget,
float x,
float y,
ALLEGRO_FONT * font,
void * user_data )
static

◆ _wheel_geometry()

void _wheel_geometry ( float x,
float y,
float w,
float h,
float * cx,
float * cy,
float * radius )
static

helper: the disc's centre and radius in a widget of w by h at x, y

Definition at line 97 of file n_gui_colorwheel.c.

Referenced by _wheel_draw(), and _wheel_mouse().

Here is the caller graph for this function:

◆ _wheel_mouse()

◆ _wheel_of()

_N_GUI_COLORWHEEL * _wheel_of ( N_GUI_CTX * ctx,
int widget_id )
static

helper: find the wheel behind a widget id, or NULL

Definition at line 153 of file n_gui_colorwheel.c.

References _wheel_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_colorwheel_get(), n_gui_colorwheel_set(), and n_gui_colorwheel_set_colour().

Here is the call graph for this function:
Here is the caller graph for this function: