2#include "nuklear_internal.h"
10nk_color_picker_behavior(nk_flags *state,
16 nk_bool value_changed = 0;
17 nk_bool hsv_changed = 0;
25 nk_colorf_hsva_fv(hsva, *color);
26 if (nk_button_behavior(state, *matrix, in, NK_BUTTON_REPEATER)) {
27 hsva[1] = NK_SATURATE((in->mouse.pos.x - matrix->x) / (matrix->w-1));
28 hsva[2] = 1.0f - NK_SATURATE((in->mouse.pos.y - matrix->y) / (matrix->h-1));
29 value_changed = hsv_changed = 1;
32 if (nk_button_behavior(state, *hue_bar, in, NK_BUTTON_REPEATER)) {
33 hsva[0] = NK_SATURATE((in->mouse.pos.y - hue_bar->y) / (hue_bar->h-1));
34 value_changed = hsv_changed = 1;
38 if (nk_button_behavior(state, *alpha_bar, in, NK_BUTTON_REPEATER)) {
39 hsva[3] = 1.0f - NK_SATURATE((in->mouse.pos.y - alpha_bar->y) / (alpha_bar->h-1));
43 nk_widget_state_reset(state);
45 *color = nk_hsva_colorfv(hsva);
53 if (nk_input_is_mouse_hovering_rect(in, *bounds))
57 else if (nk_input_is_mouse_prev_hovering_rect(in, *bounds))
66 NK_STORAGE
const struct nk_color black = {0,0,0,255};
67 NK_STORAGE
const struct nk_color white = {255, 255, 255, 255};
68 NK_STORAGE
const struct nk_color black_trans = {0,0,0,0};
70 const float crosshair_size = 7.0f;
81 nk_colorf_hsva_fv(hsva, col);
82 for (i = 0; i < 6; ++i) {
83 NK_GLOBAL
const struct nk_color hue_colors[] = {
84 {255, 0, 0, 255}, {255,255,0,255}, {0,255,0,255}, {0, 255,255,255},
85 {0,0,255,255}, {255, 0, 255, 255}, {255, 0, 0, 255}
87 nk_fill_rect_multi_color(o,
88 nk_rect(hue_bar->x, hue_bar->y + (
float)i * (hue_bar->h/6.0f) + 0.5f,
89 hue_bar->w, (hue_bar->h/6.0f) + 0.5f), hue_colors[i], hue_colors[i],
90 hue_colors[i+1], hue_colors[i+1]);
92 line_y = (float)(
int)(hue_bar->y + hsva[0] * matrix->h + 0.5f);
93 nk_stroke_line(o, hue_bar->x-1, line_y, hue_bar->x + hue_bar->w + 2,
94 line_y, 1, nk_rgb(255,255,255));
98 float alpha = NK_SATURATE(col.a);
99 line_y = (float)(
int)(alpha_bar->y + (1.0f - alpha) * matrix->h + 0.5f);
101 nk_fill_rect_multi_color(o, *alpha_bar, white, white, black, black);
102 nk_stroke_line(o, alpha_bar->x-1, line_y, alpha_bar->x + alpha_bar->w + 2,
103 line_y, 1, nk_rgb(255,255,255));
107 temp = nk_hsv_f(hsva[0], 1.0f, 1.0f);
108 nk_fill_rect_multi_color(o, *matrix, white, temp, temp, white);
109 nk_fill_rect_multi_color(o, *matrix, black_trans, black_trans, black, black);
112 {
struct nk_vec2 p;
float S = hsva[1];
float V = hsva[2];
113 p.x = (float)(
int)(matrix->x + S * matrix->w);
114 p.y = (float)(
int)(matrix->y + (1.0f - V) * matrix->h);
115 nk_stroke_line(o, p.x - crosshair_size, p.y, p.x-2, p.y, 1.0f, white);
116 nk_stroke_line(o, p.x + crosshair_size + 1, p.y, p.x+3, p.y, 1.0f, white);
117 nk_stroke_line(o, p.x, p.y + crosshair_size + 1, p.x, p.y+3, 1.0f, white);
118 nk_stroke_line(o, p.x, p.y - crosshair_size, p.x, p.y-2, 1.0f, white);}
121nk_do_color_picker(nk_flags *state,
123 enum nk_color_format fmt,
struct nk_rect bounds,
137 if (!out || !col || !state || !font)
141 bounds.x += padding.x;
142 bounds.y += padding.x;
143 bounds.w -= 2 * padding.x;
144 bounds.h -= 2 * padding.y;
149 matrix.w = bounds.w - (3 * padding.x + 2 * bar_w);
152 hue_bar.y = bounds.y;
153 hue_bar.h = matrix.h;
154 hue_bar.x = matrix.x + matrix.w + padding.x;
156 alpha_bar.x = hue_bar.x + hue_bar.w + padding.x;
157 alpha_bar.y = bounds.y;
159 alpha_bar.h = matrix.h;
161 ret = nk_color_picker_behavior(state, &bounds, &matrix, &hue_bar,
162 (fmt == NK_RGBA) ? &alpha_bar:0, col, in);
163 nk_draw_color_picker(out, &matrix, &hue_bar, (fmt == NK_RGBA) ? &alpha_bar:0, *col);
168 enum nk_color_format fmt)
180 NK_ASSERT(ctx->current);
181 NK_ASSERT(ctx->current->layout);
182 if (!ctx || !ctx->current || !ctx->current->layout || !color)
186 config = &ctx->style;
187 layout = win->layout;
188 state = nk_widget(&bounds, ctx);
189 if (!state)
return 0;
191 return nk_do_color_picker(&ctx->last_widget_state, &win->buffer, color, fmt, bounds,
192 nk_vec2(0,0), in, config->font);
196 enum nk_color_format fmt)
198 nk_color_pick(ctx, &color, fmt);
main API and documentation file
@ NK_WINDOW_ROM
sets window widgets into a read only mode and does not allow input changes
NK_API void nk_stroke_line(struct nk_command_buffer *b, float x0, float y0, float x1, float y1, float line_thickness, struct nk_color)
shape outlines
@ NK_WIDGET_STATE_LEFT
!< widget is currently activated
@ NK_WIDGET_STATE_ENTERED
!< widget is neither active nor hovered
@ NK_WIDGET_STATE_HOVER
!< widget has been hovered on the current frame
@ NK_WIDGET_STATE_ACTIVE
!< widget is being hovered
@ NK_WIDGET_STATE_HOVERED
!< widget is from this frame on not hovered anymore
@ NK_WIDGET_DISABLED
The widget is manually disabled and acts like NK_WIDGET_ROM.
@ NK_WIDGET_ROM
The widget is partially visible and cannot be updated.
float height
!< user provided font handle