Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_gui_color.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
45
46#ifndef __NILOREA_GUI_COLOR__
47#define __NILOREA_GUI_COLOR__
48
49/* Allegro only: the picker is N_GUI widgets and the swatch is drawn with
50 * allegro_primitives. */
51#ifdef HAVE_ALLEGRO
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
61
62#include <stddef.h>
63
64#include "nilorea/n_gui.h"
65
69
73typedef void (*N_GUI_COLOR_FN)(const float rgba[4], void* user_data);
74
91N_GUI_COLOR_PICKER* n_gui_color_picker_new(N_GUI_CTX* ctx, const char* title, float scale);
92
107void 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);
108
116
125
134int n_gui_color_picker_get(const N_GUI_COLOR_PICKER* picker, float rgba[4]);
135
145
155int n_gui_color_picker_slider(const N_GUI_COLOR_PICKER* picker, int channel);
156
168
182void n_gui_draw_color_swatch(float x, float y, float w, float h, const float rgba[4]);
183
192void n_gui_color_to_hex(const float rgba[4], char* out, size_t len);
193
213ALLEGRO_MOUSE_CURSOR* n_gui_eyedropper_cursor(float scale);
214
216
217#ifdef __cplusplus
218}
219#endif
220#endif /* HAVE_ALLEGRO */
221#endif /* __NILOREA_GUI_COLOR__ */
static void on_change(const float rgba[4], void *user_data)
the picker's callback
The top-level GUI context that holds all windows.
Definition n_gui.h:1669
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_FN)(const float rgba[4], void *user_data)
called each time the picked colour changes.
Definition n_gui_color.h:73
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.
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.
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_close(N_GUI_COLOR_PICKER *picker)
Close the picker.
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_picker_free(N_GUI_COLOR_PICKER **picker)
Close the picker's window and free the handle.
int n_gui_color_picker_is_open(const N_GUI_COLOR_PICKER *picker)
Whether the picker is open.
ALLEGRO_MOUSE_CURSOR * n_gui_eyedropper_cursor(float scale)
Make a pipette mouse cursor, for a tool that picks a colour from an image.
Definition n_gui_color.c:92
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.
float rgba[4]
the colour being edited
Definition n_gui_color.c:77
void * user_data
handed back to on_change
Definition n_gui_color.c:84
N_GUI_CTX * ctx
the context the widgets live in
Definition n_gui_color.c:63
a colour picker: the ids of its widgets and the colour being edited
Definition n_gui_color.c:61