public static void DrawButtonSymbol(this CommandBuffer _out_, RectangleF *bounds, RectangleF *content, uint state, nk_style_button style, nk_symbol_type type, nk_font font) { var sym = new Color(); var bg = new Color(); nk_style_item background; background = DrawButton(_out_, bounds, state, style); if (background.type == NK_STYLE_ITEM_COLOR) { bg = background.Color; } else { bg = style.text_background; } if ((state & NK_WIDGET_STATE_HOVER) != 0) { sym = style.text_hover; } else if ((state & NK_WIDGET_STATE_ACTIVED) != 0) { sym = style.text_active; } else { sym = style.text_normal; } _out_.DrawSymbol(type, *content, bg, sym, 1, font); }
public static void DrawButtonTextImage(this CommandBuffer _out_, RectangleF *bounds, RectangleF *label, RectangleF *image, uint state, nk_style_button style, string str, nk_font font, nk_image img) { var text = new nk_text(); nk_style_item background; background = DrawButton(_out_, bounds, state, style); if (background.type == NK_STYLE_ITEM_COLOR) { text.Background = background.Color; } else { text.Background = style.text_background; } if ((state & NK_WIDGET_STATE_HOVER) != 0) { text.text = style.text_hover; } else if ((state & NK_WIDGET_STATE_ACTIVED) != 0) { text.text = style.text_active; } else { text.text = style.text_normal; } text.padding = new Vector2(0, 0); _out_.WidgetText(*label, str, &text, nk_text_align.NK_TEXT_CENTERED, font); _out_.DrawImage(*image, img, nk_white); }
public static nk_style_item DrawButton(this CommandBuffer _out_, RectangleF *bounds, uint state, nk_style_button style) { nk_style_item background; if ((state & NK_WIDGET_STATE_HOVER) != 0) { background = style.hover; } else if ((state & NK_WIDGET_STATE_ACTIVED) != 0) { background = style.active; } else { background = style.normal; } if (background.type == NK_STYLE_ITEM_IMAGE) { _out_.DrawImage(*bounds, background.Image, nk_white); } else { _out_.FillRect(*bounds, style.Rounding, background.Color); _out_.StrokeRect(*bounds, style.Rounding, style.border, style.border_color); } return(background); }
public static void DrawButtonText(this CommandBuffer _out_, RectangleF *bounds, RectangleF *content, uint state, nk_style_button style, StringSegment txt, nk_text_align text_alignment, nk_font font) { var text = new nk_text(); nk_style_item background; background = DrawButton(_out_, bounds, state, style); if (background.type == NK_STYLE_ITEM_COLOR) { text.Background = background.Color; } else { text.Background = style.text_background; } if ((state & NK_WIDGET_STATE_HOVER) != 0) { text.text = style.text_hover; } else if ((state & NK_WIDGET_STATE_ACTIVED) != 0) { text.text = style.text_active; } else { text.text = style.text_normal; } text.padding = new Vector2(0, 0); _out_.WidgetText(*content, txt, &text, text_alignment, font); }
public static void DrawButtonImage(this CommandBuffer _out_, RectangleF *bounds, RectangleF *content, uint state, nk_style_button style, nk_image img) { DrawButton(_out_, bounds, state, style); _out_.DrawImage(*content, img, nk_white); }
public static void DrawColorPicker(this CommandBuffer o, RectangleF *matrix, RectangleF *hue_bar, RectangleF *alpha_bar, Colorf col) { var black = nk_black; var white = nk_white; var black_trans = new Color(); var crosshair_size = 7.0f; var temp = new Color(); var hsva = stackalloc float[4]; float line_y; int i; Colorf_hsva_fv(hsva, col); for (i = 0; i < 6; ++i) { o.FillRectMultiColor( new RectangleF(hue_bar->X, hue_bar->Y + i * (hue_bar->Height / 6.0f) + 0.5f, hue_bar->Width, hue_bar->Height / 6.0f + 0.5f), hue_colors[i], hue_colors[i], hue_colors[i + 1], hue_colors[i + 1]); } line_y = (int)(hue_bar->Y + hsva[0] * matrix->Height + 0.5f); o.StrokeLine(hue_bar->X - 1, line_y, hue_bar->X + hue_bar->Width + 2, line_y, 1, Color.White); if (alpha_bar != null) { var alpha = 0 < (1.0f < col.A ? 1.0f : col.A) ? 1.0f < col.A ? 1.0f : col.A : 0; line_y = (int)(alpha_bar->Y + (1.0f - alpha) * matrix->Height + 0.5f); o.FillRectMultiColor(*alpha_bar, white, white, black, black); o.StrokeLine(alpha_bar->X - 1, line_y, alpha_bar->X + alpha_bar->Width + 2, line_y, 1, Color.White); } temp = nk_hsv_f(hsva[0], 1.0f, 1.0f); o.FillRectMultiColor(*matrix, white, temp, temp, white); o.FillRectMultiColor(*matrix, black_trans, black_trans, black, black); { var p = new Vector2(); var S = hsva[1]; var V = hsva[2]; p.X = (int)(matrix->X + S * matrix->Width); p.Y = (int)(matrix->Y + (1.0f - V) * matrix->Height); o.StrokeLine(p.X - crosshair_size, p.Y, p.X - 2, p.Y, 1.0f, white); o.StrokeLine(p.X + crosshair_size + 1, p.Y, p.X + 3, p.Y, 1.0f, white); o.StrokeLine(p.X, p.Y + crosshair_size + 1, p.X, p.Y + 3, 1.0f, white); o.StrokeLine(p.X, p.Y - crosshair_size, p.X, p.Y - 2, 1.0f, white); } }
public static void DrawOption(this CommandBuffer _out_, uint state, nk_style_toggle style, bool active, RectangleF *label, RectangleF *selector, RectangleF *cursors, string _string_, nk_font font) { nk_style_item background; nk_style_item cursor; var text = new nk_text(); if ((state & NK_WIDGET_STATE_HOVER) != 0) { background = style.hover; cursor = style.cursor_hover; text.text = style.text_hover; } else if ((state & NK_WIDGET_STATE_ACTIVED) != 0) { background = style.hover; cursor = style.cursor_hover; text.text = style.text_active; } else { background = style.normal; cursor = style.cursor_normal; text.text = style.text_normal; } if (background.type == NK_STYLE_ITEM_COLOR) { _out_.nk_fill_circle(*selector, style.border_color); _out_.nk_fill_circle(RectangleF.nk_shrink_rect_(*selector, style.border), background.Color); } else { _out_.DrawImage(*selector, background.Image, nk_white); } if (active) { if (cursor.type == NK_STYLE_ITEM_IMAGE) { _out_.DrawImage(*cursors, cursor.Image, nk_white); } else { _out_.nk_fill_circle(*cursors, cursor.Color); } } text.padding.X = 0; text.padding.Y = 0; text.Background = style.text_background; _out_.WidgetText(*label, _string_, &text, nk_text_align.NK_TEXT_LEFT, font); }
static void Add(NSMutableDictionary dict, IntPtr key, RectangleF?val) { if (!val.HasValue) { return; } NSData data; unsafe { RectangleF f = val.Value; RectangleF *pf = &f; data = NSData.FromBytes((IntPtr)pf, 16); } dict.LowlevelSetObject(data, key); }
public static void DrawProgress(this CommandBuffer _out_, uint state, nk_style_progress style, RectangleF *bounds, RectangleF *scursor, ulong value, ulong max) { nk_style_item background; nk_style_item cursor; if ((state & NK_WIDGET_STATE_ACTIVED) != 0) { background = style.active; cursor = style.cursor_active; } else if ((state & NK_WIDGET_STATE_HOVER) != 0) { background = style.hover; cursor = style.cursor_hover; } else { background = style.normal; cursor = style.cursor_normal; } if (background.type == NK_STYLE_ITEM_COLOR) { _out_.FillRect(*bounds, style.Rounding, background.Color); _out_.StrokeRect(*bounds, style.Rounding, style.border, style.border_color); } else { _out_.DrawImage(*bounds, background.Image, nk_white); } if (cursor.type == NK_STYLE_ITEM_COLOR) { _out_.FillRect(*scursor, style.Rounding, cursor.Color); _out_.StrokeRect(*scursor, style.Rounding, style.border, style.border_color); } else { _out_.DrawImage(*scursor, cursor.Image, nk_white); } }
public static bool DoButton(ref uint state, CommandBuffer _out_, RectangleF r, nk_style_button style, nk_input _in_, int behavior, RectangleF *content) { var bounds = new RectangleF(); if (_out_ == null || style == null) { return(false); } content->X = r.X + style.padding.X + style.border + style.Rounding; content->Y = r.Y + style.padding.Y + style.border + style.Rounding; content->Width = r.Width - (2 * style.padding.X + style.border + style.Rounding * 2); content->Height = r.Height - (2 * style.padding.Y + style.border + style.Rounding * 2); bounds.X = r.X - style.touch_padding.X; bounds.Y = r.Y - style.touch_padding.Y; bounds.Width = r.Width + 2 * style.touch_padding.X; bounds.Height = r.Height + 2 * style.touch_padding.Y; return(ButtonBehavior(ref state, bounds, _in_, behavior)); }
public static void DrawProperty(this CommandBuffer _out_, nk_style_property style, RectangleF *bounds, RectangleF *label, uint state, string name, nk_font font) { var text = new nk_text(); nk_style_item background; if ((state & NK_WIDGET_STATE_ACTIVED) != 0) { background = style.active; text.text = style.label_active; } else if ((state & NK_WIDGET_STATE_HOVER) != 0) { background = style.hover; text.text = style.label_hover; } else { background = style.normal; text.text = style.label_normal; } if (background.type == NK_STYLE_ITEM_IMAGE) { _out_.DrawImage(*bounds, background.Image, nk_white); text.Background = Color.Transparent; } else { text.Background = background.Color; _out_.FillRect(*bounds, style.Rounding, background.Color); _out_.StrokeRect(*bounds, style.Rounding, style.border, background.Color); } text.padding = new Vector2(0, 0); _out_.WidgetText(*label, name, &text, nk_text_align.NK_TEXT_CENTERED, font); }
public static float nk_scrollbar_behavior(ref uint state, nk_input _in_, bool has_scrolling, RectangleF *scroll, ref RectangleF cursor, RectangleF *empty0, RectangleF *empty1, float scroll_offset, float target, float scroll_step, int o) { var ws = (uint)0; bool left_mouse_down; bool left_mouse_click_in_cursor; float scroll_delta; if ((state & NK_WIDGET_STATE_MODIFIED) != 0) { state = NK_WIDGET_STATE_INACTIVE | NK_WIDGET_STATE_MODIFIED; } else { state = NK_WIDGET_STATE_INACTIVE; } if (_in_ == null) { return(scroll_offset); } left_mouse_down = _in_.mouse.buttons[NK_BUTTON_LEFT].down; left_mouse_click_in_cursor = nk_input_has_mouse_click_down_in_rect(_in_, NK_BUTTON_LEFT, cursor, true); if (nk_input_is_mouse_hovering_rect(_in_, *scroll)) { state = NK_WIDGET_STATE_HOVERED; } scroll_delta = o == NK_VERTICAL ? _in_.mouse.scroll_delta.Y : _in_.mouse.scroll_delta.X; if (left_mouse_down && left_mouse_click_in_cursor) { float pixel; float delta; state = NK_WIDGET_STATE_ACTIVE; if (o == NK_VERTICAL) { float cursor_y; pixel = _in_.mouse.delta.Y; delta = pixel / scroll->Height * target; scroll_offset = (scroll_offset + delta < target - scroll->Height ? scroll_offset + delta : target - scroll->Height) < 0 ? 0 : scroll_offset + delta < target - scroll->Height ? scroll_offset + delta : target - scroll->Height; cursor_y = scroll->Y + scroll_offset / target * scroll->Height; _in_.mouse.buttons[NK_BUTTON_LEFT].clicked_pos.Y = cursor_y + cursor.Height / 2.0f; } else { float cursor_x; pixel = _in_.mouse.delta.X; delta = pixel / scroll->Width * target; scroll_offset = (scroll_offset + delta < target - scroll->Width ? scroll_offset + delta : target - scroll->Width) < 0 ? 0 : scroll_offset + delta < target - scroll->Width ? scroll_offset + delta : target - scroll->Width; cursor_x = scroll->X + scroll_offset / target * scroll->Width; _in_.mouse.buttons[NK_BUTTON_LEFT].clicked_pos.X = cursor_x + cursor.Width / 2.0f; } } else if (nk_input_is_key_pressed(_in_, NK_KEY_SCROLL_UP) && o == NK_VERTICAL && has_scrolling || ButtonBehavior(ref ws, *empty0, _in_, NK_BUTTON_DEFAULT)) { if (o == NK_VERTICAL) { scroll_offset = 0 < scroll_offset - scroll->Height ? scroll_offset - scroll->Height : 0; } else { scroll_offset = 0 < scroll_offset - scroll->Width ? scroll_offset - scroll->Width : 0; } } else if (nk_input_is_key_pressed(_in_, NK_KEY_SCROLL_DOWN) && o == NK_VERTICAL && has_scrolling || ButtonBehavior(ref ws, *empty1, _in_, NK_BUTTON_DEFAULT)) { if (o == NK_VERTICAL) { scroll_offset = scroll_offset + scroll->Height < target - scroll->Height ? scroll_offset + scroll->Height : target - scroll->Height; } else { scroll_offset = scroll_offset + scroll->Width < target - scroll->Width ? scroll_offset + scroll->Width : target - scroll->Width; } } else if (has_scrolling) { if (scroll_delta < 0 || scroll_delta > 0) { scroll_offset = scroll_offset + scroll_step * -scroll_delta; if (o == NK_VERTICAL) { scroll_offset = (scroll_offset < target - scroll->Height ? scroll_offset : target - scroll->Height) < 0 ? 0 : scroll_offset < target - scroll->Height ? scroll_offset : target - scroll->Height; } else { scroll_offset = (scroll_offset < target - scroll->Width ? scroll_offset : target - scroll->Width) < 0 ? 0 : scroll_offset < target - scroll->Width ? scroll_offset : target - scroll->Width; } } else if (nk_input_is_key_pressed(_in_, NK_KEY_SCROLL_START)) { if (o == NK_VERTICAL) { scroll_offset = 0; } } else if (nk_input_is_key_pressed(_in_, NK_KEY_SCROLL_END)) { if (o == NK_VERTICAL) { scroll_offset = target - scroll->Height; } } } if ((state & NK_WIDGET_STATE_HOVER) != 0 && !nk_input_is_mouse_prev_hovering_rect(_in_, *scroll)) { state |= NK_WIDGET_STATE_ENTERED; } else if (nk_input_is_mouse_prev_hovering_rect(_in_, *scroll)) { state |= NK_WIDGET_STATE_LEFT; } return(scroll_offset); }
internal static extern int GdipAddPathRectangles(HandleRef path, RectangleF *rects, int count);
internal static partial int GdipAddPathRectangles( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif HandleRef path, RectangleF *rects, int count);
internal static extern int GdipRecordMetafileStream(IntPtr stream, IntPtr referenceHdc, EmfType emfType, RectangleF *frameRect, MetafileFrameUnit frameUnit, string?description, IntPtr *metafile);
unsafe extern static void RectFillList(RectangleF *rects, int count);
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); }
internal static extern int GdipDrawRectangles(HandleRef graphics, HandleRef pen, RectangleF *rects, int count);
internal static extern int GdipFillRectangles(HandleRef graphics, HandleRef brush, RectangleF *rects, int count);
public static void DrawSelectable(this CommandBuffer _out_, uint state, nk_style_selectable style, bool active, RectangleF *bounds, RectangleF *icon, nk_image img, string _string_, nk_text_align align, nk_font font) { nk_style_item background; var text = new nk_text(); text.padding = style.padding; if (!active) { if ((state & NK_WIDGET_STATE_ACTIVED) != 0) { background = style.pressed; text.text = style.text_pressed; } else if ((state & NK_WIDGET_STATE_HOVER) != 0) { background = style.hover; text.text = style.text_hover; } else { background = style.normal; text.text = style.text_normal; } } else { if ((state & NK_WIDGET_STATE_ACTIVED) != 0) { background = style.pressed_active; text.text = style.text_pressed_active; } else if ((state & NK_WIDGET_STATE_HOVER) != 0) { background = style.hover_active; text.text = style.text_hover_active; } else { background = style.normal_active; text.text = style.text_normal_active; } } if (background.type == NK_STYLE_ITEM_IMAGE) { _out_.DrawImage(*bounds, background.Image, nk_white); text.Background = Color.Transparent; } else { _out_.FillRect(*bounds, style.Rounding, background.Color); text.Background = background.Color; } if (img != null && icon != null) { _out_.DrawImage(*icon, img, nk_white); } _out_.WidgetText(*bounds, _string_, &text, align, font); }