Table of Contents
- GUI COLOR: a colour picker dialog and a swatch
- Types
- Functions
- Types Documentation
- Functions Documentation
- function n_gui_eyedropper_cursor
- function n_gui_draw_color_swatch
- function n_gui_color_to_hex
- function n_gui_color_picker_window
- function n_gui_color_picker_slider
- function n_gui_color_picker_open
- function n_gui_color_picker_new
- function n_gui_color_picker_is_open
- function n_gui_color_picker_get
- function n_gui_color_picker_free
- function n_gui_color_picker_close
GUI COLOR: a colour picker dialog and a swatch
Types
| Name | |
|---|---|
| typedef void(*)(const float rgba[4], void *user_data) | N_GUI_COLOR_FN called each time the picked colour changes. |
Functions
| Name | |
|---|---|
| ALLEGRO_MOUSE_CURSOR * | n_gui_eyedropper_cursor(float scale) Make a pipette mouse cursor, for a tool that picks a colour from an image. |
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |
| 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. |
| int | n_gui_color_picker_is_open(const N_GUI_COLOR_PICKER * picker) Whether the picker is open. |
| int | n_gui_color_picker_get(const N_GUI_COLOR_PICKER * picker, float rgba[4]) The colour the picker holds now. |
| void | n_gui_color_picker_free(N_GUI_COLOR_PICKER ** picker) Close the picker's window and free the handle. |
| void | n_gui_color_picker_close(N_GUI_COLOR_PICKER * picker) Close the picker. |
Types Documentation
typedef N_GUI_COLOR_FN
typedef void(* N_GUI_COLOR_FN) (const float rgba[4], void *user_data);
called each time the picked colour changes.
Parameters:
- rgba the colour now: red, green, blue, alpha, 0 to 1
- user_data what was handed to n_gui_color_picker_open()
Functions Documentation
function n_gui_eyedropper_cursor
ALLEGRO_MOUSE_CURSOR * n_gui_eyedropper_cursor(
float scale
)
Make a pipette mouse cursor, for a tool that picks a colour from an image.
Parameters:
- scale the interface scale; the cursor is 32 pixels at 1.0, and never under 16.
Return: the cursor, or NULL when Allegro could not make one.
Allegro's system cursors have no pipette, and a crosshair says "point at something" without saying "a colour will be taken from it". Drawn with primitives rather than read from a file, so there is nothing to ship: a pale glass tube with a dark rubber bulb, outlined in black and white so it shows on a dark photograph and on a light one. The hot spot is the tip, at the bottom left, which is the pixel the colour is read from.
Needs a display to exist, as al_create_mouse_cursor() does. Show it with n_gui_set_cursor(); release it with al_destroy_mouse_cursor(), after setting another cursor, never while it is showing.
function n_gui_draw_color_swatch
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.
Parameters:
- x left edge.
- y top edge.
- w width. Nothing is drawn when zero or less.
- h height. Nothing is drawn when zero or less.
- rgba the colour, straight alpha. Must not be NULL.
Draws on the current target with the current transform and blender, which is expected to be Allegro's default premultiplied one.
function n_gui_color_to_hex
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.
Parameters:
- rgba the colour. NULL writes an empty string.
- out receives the text. Must not be NULL.
- len room in
out; 10 bytes holds all of it. Zero writes nothing.
function n_gui_color_picker_window
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.
Parameters:
- picker the picker.
Return: the window id, or -1 for a NULL picker.
function n_gui_color_picker_slider
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.
Parameters:
- picker the picker.
- channel 0 red, 1 green, 2 blue, 3 alpha.
Return: the slider's widget id, or -1 for a NULL picker or a channel out of range.
function n_gui_color_picker_open
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.
Parameters:
- picker the picker. Must not be NULL.
- what what the colour is, shown over the swatch, such as "Watermark: Colour". May be NULL.
- rgba the colour to start from, clamped to 0..1. Must not be NULL.
- on_change called on every change. May be NULL.
- user_data handed back to
on_change.
Replaces whatever the picker was editing, and whom it told, with rgba and on_change. Setting the sliders to rgba does not call on_change: only the user's changes do.
function n_gui_color_picker_new
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.
Parameters:
- ctx GUI context. Must not be NULL.
- title window title. NULL gives "Colour".
- scale multiplies every size, for a caller that sizes its dialogs by a display scale. Zero or less is taken as 1.
Return: a new picker owned by the caller, to release with n_gui_color_picker_free() before n_gui_destroy_ctx(), or NULL when a widget could not be created.
The window is a popup (N_GUI_ZORDER_POPUP) with a close button in its title bar. Its widgets belong to ctx like any others; the returned handle only remembers their ids and the colour being edited.
function n_gui_color_picker_is_open
int n_gui_color_picker_is_open(
const N_GUI_COLOR_PICKER * picker
)
Whether the picker is open.
Parameters:
- picker the picker. NULL gives 0.
Return: 1 when its window is open, 0 otherwise.
function n_gui_color_picker_get
int n_gui_color_picker_get(
const N_GUI_COLOR_PICKER * picker,
float rgba[4]
)
The colour the picker holds now.
Parameters:
- picker the picker. Must not be NULL.
- rgba receives red, green, blue, alpha, 0 to 1. Must not be NULL.
Return: TRUE, or FALSE on a NULL argument.
function n_gui_color_picker_free
void n_gui_color_picker_free(
N_GUI_COLOR_PICKER ** picker
)
Close the picker's window and free the handle.
Parameters:
- picker address of the handle; set to NULL. NULL, or a pointer to NULL, is a no-op.
The window and its widgets stay in the context, closed, until n_gui_destroy_ctx(); nothing in them points at the handle once it is closed. Call it while the context is still alive.
function n_gui_color_picker_close
void n_gui_color_picker_close(
N_GUI_COLOR_PICKER * picker
)
Close the picker.
Parameters:
- picker the picker. NULL is a no-op.
The colour stays as it was last changed, and on_change is forgotten. The title bar's close button does the same.
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