6 n__gui__colorwheel_8h
gullradriel edited this page 2026-10-09 00:55:18 +02:00

include/nilorea/n_gui_colorwheel.h

A colour wheel for N_GUI: one point in a disc, dragged. More...

Detailed Description

A colour wheel for N_GUI: one point in a disc, dragged.

Author: Castagnier Mickael

Version: 1.0

Date: 28/09/2026

A disc whose point, u across and v up, both -1 to 1 and never outside the unit circle, is set by pressing and dragging with the left button; a right press or a double click puts it back in the centre, the double click timed as the context times it (n_gui_set_double_click_time()). What the point means is the caller's: a hue and a strength, a shift on two colour axes, a direction. So is what the disc shows: n_gui_colorwheel_set_colour() paints each place of it with the caller's colour for that point, so the wheel shows what choosing it does. By default the disc is an HSV hue circle, saturated at the rim and grey in the centre.

The widget is a custom one (n_gui_add_custom() with n_gui_custom_set_mouse()), so it lives in any window and its state is freed with it. on_change is called on every change, with dragging set while the button is held.

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_COLORWHEEL__
#define __NILOREA_GUI_COLORWHEEL__

/* Allegro only: the wheel is an N_GUI widget drawn with allegro_primitives. */
#ifdef HAVE_ALLEGRO

#ifdef __cplusplus
extern "C" {
#endif


#include "nilorea/n_gui.h"

typedef void (*N_GUI_COLORWHEEL_CHANGE)(int widget_id, int dragging, void* user_data);

typedef ALLEGRO_COLOR (*N_GUI_COLORWHEEL_COLOUR)(float u, float v, void* user_data);

int n_gui_colorwheel_new(N_GUI_CTX* ctx, int window_id, float x, float y, float w, float h, N_GUI_COLORWHEEL_CHANGE on_change, void* user_data);

int n_gui_colorwheel_set(N_GUI_CTX* ctx, int widget_id, float u, float v);

int n_gui_colorwheel_get(N_GUI_CTX* ctx, int widget_id, float* u, float* v);

void n_gui_colorwheel_set_colour(N_GUI_CTX* ctx, int widget_id, N_GUI_COLORWHEEL_COLOUR colour, void* user_data);

ALLEGRO_COLOR n_gui_colorwheel_hue(float u, float v, void* user_data);


#ifdef __cplusplus
}
#endif

#endif /* HAVE_ALLEGRO */

#endif /* __NILOREA_GUI_COLORWHEEL__ */