![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
A colour picker dialog for N_GUI, and a swatch to show a colour. More...
#include <math.h>#include <stdio.h>#include <string.h>#include <allegro5/allegro_primitives.h>#include "nilorea/n_common.h"#include "nilorea/n_log.h"#include "nilorea/n_gui_color.h"Go to the source code of this file.
Data Structures | |
| struct | N_GUI_COLOR_PICKER |
| a colour picker: the ids of its widgets and the colour being edited More... | |
Macros | |
| #define | N_GUI_COLOR_BTN_W 90.0f |
| width of the Close button at scale 1 | |
| #define | N_GUI_COLOR_CHECK 6.0f |
| side of one checkerboard square behind a swatch, in pixels. | |
| #define | N_GUI_COLOR_LABEL 18.0f |
| height of a label at scale 1 | |
| #define | N_GUI_COLOR_PAD 10.0f |
| padding at scale 1 | |
| #define | N_GUI_COLOR_ROW 24.0f |
| height of a slider or button row at scale 1 | |
| #define | N_GUI_COLOR_SWATCH 48.0f |
| height of the large swatch at scale 1 | |
| #define | N_GUI_COLOR_W 300.0f |
| window width at scale 1: wide enough that a slider moved by one step in 255 moves by at least a pixel | |
Functions | |
| static float | _n_gui_color_clamp (float v) |
| helper: clamp a channel to 0..1 | |
| static void | _n_gui_color_draw_swatch (N_GUI_WIDGET *widget, float x, float y, ALLEGRO_FONT *font, void *user_data) |
| custom draw callback of the large swatch | |
| static void | _n_gui_color_on_close_button (int widget_id, void *user_data) |
| button callback: Close | |
| static void | _n_gui_color_on_close_window (int window_id, void *user_data) |
| title bar close: the same as the Close button, so the callback is forgotten either way | |
| static void | _n_gui_color_on_slider (int widget_id, double value, void *user_data) |
| slider callback: one channel moved | |
| static void | _n_gui_color_set_label (N_GUI_COLOR_PICKER *picker, int channel) |
| helper: write one channel's label, its name and its value out of 255 | |
| void | n_gui_color_picker_close (N_GUI_COLOR_PICKER *picker) |
| Close the picker. | |
| void | n_gui_color_picker_free (N_GUI_COLOR_PICKER **picker) |
| Close the picker's window and free the handle. | |
| int | n_gui_color_picker_get (const N_GUI_COLOR_PICKER *picker, float rgba[4]) |
| The colour the picker holds now. | |
| int | n_gui_color_picker_is_open (const N_GUI_COLOR_PICKER *picker) |
| Whether the picker is open. | |
| N_GUI_COLOR_PICKER * | n_gui_color_picker_new (N_GUI_CTX *ctx, const char *title, float scale) |
Build a colour picker window in ctx, closed. | |
| void | n_gui_color_picker_open (N_GUI_COLOR_PICKER *picker, const char *what, const float rgba[4], N_GUI_COLOR_FN on_change, void *user_data) |
| Open the picker on a colour, centred on the display. | |
| int | n_gui_color_picker_slider (const N_GUI_COLOR_PICKER *picker, int channel) |
| The slider for one channel, for a caller or a test that drives it. | |
| int | n_gui_color_picker_window (const N_GUI_COLOR_PICKER *picker) |
| The picker's window id, for a caller that walks its windows or sets their flags. | |
| void | n_gui_color_to_hex (const float rgba[4], char *out, size_t len) |
| Write a colour as #RRGGBBAA, each channel clamped to 0..1 and rounded to the nearest of 255 steps. | |
| void | n_gui_draw_color_swatch (float x, float y, float w, float h, const float rgba[4]) |
| Draw a colour as a swatch, over a checkerboard so its alpha shows, with a thin dark border. | |
| ALLEGRO_MOUSE_CURSOR * | n_gui_eyedropper_cursor (float scale) |
| Make a pipette mouse cursor, for a tool that picks a colour from an image. | |
Variables | |
| static const char *const | _n_gui_color_channels [4] = {"Red", "Green", "Blue", "Alpha"} |
| the four channels, in the order of the sliders | |
A colour picker dialog for N_GUI, and a swatch to show a colour.
Definition in file n_gui_color.c.
| struct N_GUI_COLOR_PICKER |
a colour picker: the ids of its widgets and the colour being edited
a colour picker dialog.
Opaque: make it with n_gui_color_picker_new(), release it with n_gui_color_picker_free().
Definition at line 61 of file n_gui_color.c.
| Data Fields | ||
|---|---|---|
| int | btn_close | the Close button |
| N_GUI_CTX * | ctx | the context the widgets live in |
| int | lbl[4] | name and value over each slider |
| int | lbl_what | what the colour is for |
| N_GUI_COLOR_FN | on_change | whom to tell |
| float | rgba[4] | the colour being edited |
| int | sl[4] | one slider per channel, 0 to 255 |
| int | swatch | the large swatch |
| int | syncing | non-zero while the sliders are set from code, so their callbacks are not taken for the user's |
| void * | user_data | handed back to on_change |
| int | window | the window |
| #define N_GUI_COLOR_BTN_W 90.0f |
width of the Close button at scale 1
Definition at line 52 of file n_gui_color.c.
Referenced by n_gui_color_picker_new().
| #define N_GUI_COLOR_CHECK 6.0f |
side of one checkerboard square behind a swatch, in pixels.
Not scaled: it only has to show that something is see-through.
Definition at line 55 of file n_gui_color.c.
Referenced by n_gui_draw_color_swatch().
| #define N_GUI_COLOR_LABEL 18.0f |
height of a label at scale 1
Definition at line 46 of file n_gui_color.c.
Referenced by n_gui_color_picker_new().
| #define N_GUI_COLOR_PAD 10.0f |
padding at scale 1
Definition at line 50 of file n_gui_color.c.
Referenced by n_gui_color_picker_new().
| #define N_GUI_COLOR_ROW 24.0f |
height of a slider or button row at scale 1
Definition at line 44 of file n_gui_color.c.
Referenced by n_gui_color_picker_new().
| #define N_GUI_COLOR_SWATCH 48.0f |
height of the large swatch at scale 1
Definition at line 48 of file n_gui_color.c.
Referenced by n_gui_color_picker_new().
| #define N_GUI_COLOR_W 300.0f |
window width at scale 1: wide enough that a slider moved by one step in 255 moves by at least a pixel
Definition at line 42 of file n_gui_color.c.
Referenced by n_gui_color_picker_new().
|
static |
helper: clamp a channel to 0..1
Definition at line 88 of file n_gui_color.c.
Referenced by n_gui_color_picker_open(), n_gui_color_to_hex(), and n_gui_draw_color_swatch().
|
static |
custom draw callback of the large swatch
Definition at line 188 of file n_gui_color.c.
References font, N_GUI_WIDGET::h, n_gui_draw_color_swatch(), N_GUI_COLOR_PICKER::rgba, and N_GUI_WIDGET::w.
Referenced by n_gui_color_picker_new().
|
static |
button callback: Close
Definition at line 222 of file n_gui_color.c.
References n_gui_color_picker_close().
Referenced by n_gui_color_picker_new().
|
static |
title bar close: the same as the Close button, so the callback is forgotten either way
Definition at line 229 of file n_gui_color.c.
References n_gui_color_picker_close().
Referenced by n_gui_color_picker_new().
|
static |
slider callback: one channel moved
Definition at line 205 of file n_gui_color.c.
References _n_gui_color_set_label(), N_GUI_COLOR_PICKER::ctx, n_gui_mark_dirty(), N_GUI_COLOR_PICKER::on_change, N_GUI_COLOR_PICKER::rgba, N_GUI_COLOR_PICKER::sl, N_GUI_COLOR_PICKER::syncing, and N_GUI_COLOR_PICKER::user_data.
Referenced by n_gui_color_picker_new().
|
static |
helper: write one channel's label, its name and its value out of 255
Definition at line 197 of file n_gui_color.c.
References _n_gui_color_channels, N_GUI_COLOR_PICKER::ctx, N_GUI_COLOR_PICKER::lbl, n_gui_label_set_text(), and N_GUI_COLOR_PICKER::rgba.
Referenced by _n_gui_color_on_slider(), and n_gui_color_picker_open().
|
static |
the four channels, in the order of the sliders
Definition at line 58 of file n_gui_color.c.
Referenced by _n_gui_color_set_label(), and n_gui_color_picker_new().