![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
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"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. | |
A colour wheel for N_GUI: one point in a disc, dragged.
Definition in file n_gui_colorwheel.c.
| struct _N_GUI_COLORWHEEL |
a wheel's state, owned by its custom widget
Definition at line 51 of file n_gui_colorwheel.c.
| 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 |
| 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.
| Data Fields | ||
|---|---|---|
| _N_GUI_COLORWHEEL | cw | what the draw callback sees |
| _N_GUI_COLORWHEEL_MOUSE | mouse | what the mouse callback sees |
| 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.
| Data Fields | ||
|---|---|---|
| N_GUI_CTX * | ctx | context |
| _N_GUI_COLORWHEEL * | cw | wheel |
| #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().
| #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().
| #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().
|
static |
destroy callback for the block
Definition at line 241 of file n_gui_colorwheel.c.
Referenced by n_gui_colorwheel_new().
|
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().
|
static |
custom draw callback
Definition at line 107 of file n_gui_colorwheel.c.
References _wheel_geometry(), N_GUI_THEME::bg_normal, N_GUI_THEME::border_normal, _N_GUI_COLORWHEEL::colour, _N_GUI_COLORWHEEL::colour_user_data, font, N_GUI_WIDGET::h, N_GUI_COLORWHEEL_PI, N_GUI_COLORWHEEL_RINGS, N_GUI_COLORWHEEL_SECTORS, N_GUI_THEME::text_normal, N_GUI_WIDGET::theme, _N_GUI_COLORWHEEL::u, _N_GUI_COLORWHEEL::v, and N_GUI_WIDGET::w.
Referenced by _wheel_of(), and n_gui_colorwheel_new().
|
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().
|
static |
custom mouse callback
Definition at line 175 of file n_gui_colorwheel.c.
References _wheel_clamp(), _wheel_geometry(), N_GUI_MOUSE_EVENT::button, _N_GUI_COLORWHEEL_MOUSE::ctx, _N_GUI_COLORWHEEL_MOUSE::cw, N_GUI_CTX::double_click_radius, N_GUI_CTX::double_click_time, _N_GUI_COLORWHEEL::dragging, N_GUI_WIDGET::h, n_gui_get_widget(), n_gui_mark_dirty(), N_GUI_MOUSE_DOWN, N_GUI_MOUSE_DRAG, N_GUI_MOUSE_UP, _N_GUI_COLORWHEEL::on_change, _N_GUI_COLORWHEEL::press_time, _N_GUI_COLORWHEEL::press_x, _N_GUI_COLORWHEEL::press_y, N_GUI_MOUSE_EVENT::type, _N_GUI_COLORWHEEL::u, _N_GUI_COLORWHEEL::user_data, _N_GUI_COLORWHEEL::v, N_GUI_WIDGET::w, N_GUI_MOUSE_EVENT::x, and N_GUI_MOUSE_EVENT::y.
Referenced by n_gui_colorwheel_new().
|
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().