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

A colour picker dialog for N_GUI, and a swatch to show a colour. More...

#include <stddef.h>
#include "nilorea/n_gui.h"
Include dependency graph for n_gui_color.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* N_GUI_COLOR_FN) (const float rgba[4], void *user_data)
 called each time the picked colour changes.

Functions

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.

Detailed Description

A colour picker dialog for N_GUI, and a swatch to show a colour.

The picker is a popup window built from ordinary N_GUI widgets: a line saying what the colour is for, a large swatch over a checkerboard, four sliders 0 to 255 for red, green, blue and alpha, and a Close button. It calls back on every change rather than once on close, because whatever the colour is for should follow it as the slider moves; there is therefore nothing to cancel.

One picker serves any number of colours: opening it again, on another colour, replaces what it edits and whom it tells.

A colour is four floats, red, green, blue and alpha, each 0 to 1, display encoded, straight (not premultiplied) alpha. The picker keeps them in steps of 1/255, so the number on a label is the number that is kept.

n_gui_draw_color_swatch() is usable on its own, from a custom widget or anywhere else, to show a colour beside the button that opens the picker.

Author
Castagnier Mickael
Version
1.0
Date
24/09/2026

Definition in file n_gui_color.h.