Table of Contents
include/nilorea/n_gui_color.h
A colour picker dialog for N_GUI, and a swatch to show a colour. More...
Detailed Description
A colour picker dialog for N_GUI, and a swatch to show a colour.
Author: Castagnier Mickael
Version: 1.0
Date: 24/09/2026
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.
Source code
/*
* Nilorea Library
* Copyright (C) 2005-2026 Castagnier Mickael
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __NILOREA_GUI_COLOR__
#define __NILOREA_GUI_COLOR__
/* Allegro only: the picker is N_GUI widgets and the swatch is drawn with
* allegro_primitives. */
#ifdef HAVE_ALLEGRO
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#include "nilorea/n_gui.h"
typedef struct N_GUI_COLOR_PICKER N_GUI_COLOR_PICKER;
typedef void (*N_GUI_COLOR_FN)(const float rgba[4], void* user_data);
N_GUI_COLOR_PICKER* n_gui_color_picker_new(N_GUI_CTX* ctx, const char* title, float scale);
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);
void n_gui_color_picker_close(N_GUI_COLOR_PICKER* picker);
int n_gui_color_picker_is_open(const N_GUI_COLOR_PICKER* picker);
int n_gui_color_picker_get(const N_GUI_COLOR_PICKER* picker, float rgba[4]);
int n_gui_color_picker_window(const N_GUI_COLOR_PICKER* picker);
int n_gui_color_picker_slider(const N_GUI_COLOR_PICKER* picker, int channel);
void n_gui_color_picker_free(N_GUI_COLOR_PICKER** picker);
void n_gui_draw_color_swatch(float x, float y, float w, float h, const float rgba[4]);
void n_gui_color_to_hex(const float rgba[4], char* out, size_t len);
ALLEGRO_MOUSE_CURSOR* n_gui_eyedropper_cursor(float scale);
#ifdef __cplusplus
}
#endif
#endif /* HAVE_ALLEGRO */
#endif /* __NILOREA_GUI_COLOR__ */
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