public static int ColorPick(this NuklearContext ctx, Colorf *color, int fmt) { nk_window win; nk_panel layout; nk_style config; nk_input _in_; int state; var bounds = new RectangleF(); if (ctx == null || ctx.current == null || ctx.current.Layout == null || color == null) { return(0); } win = ctx.current; config = ctx.style; layout = win.Layout; state = ctx.Widget(ref bounds); if (state == 0) { return(0); } _in_ = state == NK_WIDGET_ROM || (layout.Flags & NK_WINDOW_ROM) != 0 ? null : ctx.input; return (nk_do_color_picker(ref ctx.last_widget_state, win.Buffer, color, fmt, bounds, new Vector2(0, 0), _in_, config.font)); }
public static int nk_do_color_picker(ref uint state, CommandBuffer _out_, Colorf *col, int fmt, RectangleF bounds, Vector2 padding, nk_input _in_, nk_font font) { var ret = 0; var matrix = new RectangleF(); var hue_bar = new RectangleF(); var alpha_bar = new RectangleF(); float bar_w; if (_out_ == null || col == null || font == null) { return(ret); } bar_w = font.Size; bounds.X += padding.X; bounds.Y += padding.X; bounds.Width -= 2 * padding.X; bounds.Height -= 2 * padding.Y; matrix.X = bounds.X; matrix.Y = bounds.Y; matrix.Height = bounds.Height; matrix.Width = bounds.Width - (3 * padding.X + 2 * bar_w); hue_bar.Width = bar_w; hue_bar.Y = bounds.Y; hue_bar.Height = matrix.Height; hue_bar.X = matrix.X + matrix.Width + padding.X; alpha_bar.X = hue_bar.X + hue_bar.Width + padding.X; alpha_bar.Y = bounds.Y; alpha_bar.Width = bar_w; alpha_bar.Height = matrix.Height; ret = ColorPickerBehavior(ref state, &bounds, &matrix, &hue_bar, fmt == NK_RGBA ? &alpha_bar : null, col, _in_); _out_.DrawColorPicker(&matrix, &hue_bar, fmt == NK_RGBA ? &alpha_bar : null, *col); return(ret); }
public static int ColorPickerBehavior(ref uint state, RectangleF *bounds, RectangleF *matrix, RectangleF *hue_bar, RectangleF *alpha_bar, Colorf *color, nk_input _in_) { var hsva = stackalloc float[4]; var value_changed = 0; var hsv_changed = 0; Colorf_hsva_fv(hsva, *color); if (ButtonBehavior(ref state, *matrix, _in_, NK_BUTTON_REPEATER)) { hsva[1] = 0 < (1.0f < (_in_.mouse.pos.X - matrix->X) / (matrix->Width - 1) ? 1.0f : (_in_.mouse.pos.X - matrix->X) / (matrix->Width - 1)) ? 1.0f < (_in_.mouse.pos.X - matrix->X) / (matrix->Width - 1) ? 1.0f : (_in_.mouse.pos.X - matrix->X) / (matrix->Width - 1) : 0; hsva[2] = 1.0f - (0 < (1.0f < (_in_.mouse.pos.Y - matrix->Y) / (matrix->Height - 1) ? 1.0f : (_in_.mouse.pos.Y - matrix->Y) / (matrix->Height - 1)) ? 1.0f < (_in_.mouse.pos.Y - matrix->Y) / (matrix->Height - 1) ? 1.0f : (_in_.mouse.pos.Y - matrix->Y) / (matrix->Height - 1) : 0); value_changed = hsv_changed = 1; } if (ButtonBehavior(ref state, *hue_bar, _in_, NK_BUTTON_REPEATER)) { hsva[0] = 0 < (1.0f < (_in_.mouse.pos.Y - hue_bar->Y) / (hue_bar->Height - 1) ? 1.0f : (_in_.mouse.pos.Y - hue_bar->Y) / (hue_bar->Height - 1)) ? 1.0f < (_in_.mouse.pos.Y - hue_bar->Y) / (hue_bar->Height - 1) ? 1.0f : (_in_.mouse.pos.Y - hue_bar->Y) / (hue_bar->Height - 1) : 0; value_changed = hsv_changed = 1; } if (alpha_bar != null) { if (ButtonBehavior(ref state, *alpha_bar, _in_, NK_BUTTON_REPEATER)) { hsva[3] = 1.0f - (0 < (1.0f < (_in_.mouse.pos.Y - alpha_bar->Y) / (alpha_bar->Height - 1) ? 1.0f : (_in_.mouse.pos.Y - alpha_bar->Y) / (alpha_bar->Height - 1)) ? 1.0f < (_in_.mouse.pos.Y - alpha_bar->Y) / (alpha_bar->Height - 1) ? 1.0f : (_in_.mouse.pos.Y - alpha_bar->Y) / (alpha_bar->Height - 1) : 0); value_changed = 1; } } if ((state & NK_WIDGET_STATE_MODIFIED) != 0) { state = NK_WIDGET_STATE_INACTIVE | NK_WIDGET_STATE_MODIFIED; } else { state = NK_WIDGET_STATE_INACTIVE; } if (hsv_changed != 0) { *color = nk_hsva_colorfv(hsva); state = NK_WIDGET_STATE_ACTIVE; } if (value_changed != 0) { color->A = hsva[3]; state = NK_WIDGET_STATE_ACTIVE; } if (nk_input_is_mouse_hovering_rect(_in_, *bounds)) { state = NK_WIDGET_STATE_HOVERED; } if ((state & NK_WIDGET_STATE_HOVER) != 0 && !nk_input_is_mouse_prev_hovering_rect(_in_, *bounds)) { state |= NK_WIDGET_STATE_ENTERED; } else if (nk_input_is_mouse_prev_hovering_rect(_in_, *bounds)) { state |= NK_WIDGET_STATE_LEFT; } return(value_changed); }