public static uint nk_chart_push_column(this NuklearContext ctx, nk_window win, nk_chart chart, float value, int slot) { var _out_ = win.Buffer; var _in_ = ctx.input; var layout = win.Layout; float ratio; var ret = (uint)0; var color = new Color(); var item = new RectangleF(); if (chart.slots[slot].Index >= chart.slots[slot].Count) { return(nk_false); } if (chart.slots[slot].Count != 0) { var padding = (float)(chart.slots[slot].Count - 1); item.Width = (chart.Width - padding) / chart.slots[slot].Count; } color = chart.slots[slot].Color; item.Height = chart.Height * (value / chart.slots[slot].Range < 0 ? -(value / chart.slots[slot].Range) : value / chart.slots[slot].Range); if (value >= 0) { ratio = (value + (chart.slots[slot].Min < 0 ? -chart.slots[slot].Min : chart.slots[slot].Min)) / (chart.slots[slot].Range < 0 ? -chart.slots[slot].Range : chart.slots[slot].Range); item.Y = chart.Y + chart.Height - chart.Height * ratio; } else { ratio = (value - chart.slots[slot].Max) / chart.slots[slot].Range; item.Y = chart.Y + chart.Height * (ratio < 0 ? -ratio : ratio) - item.Height; } item.X = chart.X + chart.slots[slot].Index * item.Width; item.X = item.X + chart.slots[slot].Index; if ((layout.Flags & NK_WINDOW_ROM) == 0 && item.X <= _in_.mouse.pos.X && _in_.mouse.pos.X < item.X + item.Width && item.Y <= _in_.mouse.pos.Y && _in_.mouse.pos.Y < item.Y + item.Height) { ret = NK_CHART_HOVERING; ret |= (uint) (!_in_.mouse.buttons[NK_BUTTON_LEFT].down && _in_.mouse.buttons[NK_BUTTON_LEFT].clicked != 0 ? NK_CHART_CLICKED : 0); color = chart.slots[slot].Highlight; } _out_.FillRect(item, 0, color); chart.slots[slot].Index += 1; return(ret); }
public static bool MenuBegin(this NuklearContext ctx, nk_window win, string id, bool is_clicked, RectangleF header, Vector2 size) { var is_open = 0; var is_active = 0; var body = new RectangleF(); nk_window popup; var hash = nk_murmur_hash(id, NK_PANEL_MENU); if (ctx == null || ctx.current == null || ctx.current.Layout == null) { return(false); } body.X = header.X; body.Width = size.X; body.Y = header.Y + header.Height; body.Height = size.Y; popup = win.Popup.Window; is_open = popup != null ? nk_true : nk_false; is_active = popup != null && win.Popup.Name == hash && win.Popup.Type == NK_PANEL_MENU ? 1 : 0; if (is_clicked && is_open != 0 && is_active == 0 || is_open != 0 && is_active == 0 || is_open == 0 && is_active == 0 && !is_clicked) { return(false); } if (!ctx.NonBlockBegin(NK_WINDOW_NO_SCROLLBAR, body, header, NK_PANEL_MENU)) { return(false); } win.Popup.Type = NK_PANEL_MENU; win.Popup.Name = hash; return(true); }
public static void PanelAllocRow(this NuklearContext ctx, nk_window win) { var layout = win.Layout; var spacing = ctx.style.window.spacing; var row_height = layout.Row.height - spacing.Y; PanelLayout(ctx, win, row_height, layout.Row.columns); }
public static nk_window nk_create_window(nk_context ctx) { var result = new nk_window { seq = ctx.seq }; return(result); }
public static void FinishPopup(this NuklearContext ctx, nk_window win) { if (ctx == null || win == null) { return; } win.Buffer = win.Popup.Buffer.OldBuffer; }
public static void nk_tree_state_pop(this NuklearContext ctx) { nk_window win = null; nk_panel layout = null; if (ctx == null || ctx.current == null || ctx.current.Layout == null) { return; } win = ctx.current; layout = win.Layout; layout.At_x -= ctx.style.tab.indent + ctx.style.window.padding.X; layout.Bounds.Width += ctx.style.tab.indent + ctx.style.window.padding.X; layout.Row.tree_depth--; }
public static void StartPopup(this NuklearContext ctx, nk_window win) { if (ctx == null || win == null) { return; } var buf = win.Popup.Buffer.Buffer; buf.First = buf.Last = null; buf.Count = 0; win.Popup.Buffer.OldBuffer = win.Buffer; win.Buffer = buf; }
public static void PanelLayout(this NuklearContext ctx, nk_window win, float height, int cols) { nk_panel layout; nk_style style; CommandBuffer _out_; var item_spacing = new Vector2(); var color = new Color(); if (ctx == null || ctx.current == null || ctx.current.Layout == null) { return; } layout = win.Layout; style = ctx.style; _out_ = win.Buffer; color = style.window.background; item_spacing = style.window.spacing; layout.Row.index = 0; layout.At_y += layout.Row.height; layout.Row.columns = cols; if (height == 0.0f) { layout.Row.height = (height < layout.Row.min_height ? layout.Row.min_height : height) + item_spacing.Y; } else { layout.Row.height = height + item_spacing.Y; } layout.Row.item_offset = 0; if ((layout.Flags & NK_WINDOW_DYNAMIC) != 0) { var background = new RectangleF(); background.X = win.Bounds.X; background.Width = win.Bounds.Width; background.Y = layout.At_y - 1.0f; background.Height = layout.Row.height + 1.0f; _out_.FillRect(background, 0, color); } }
public static bool ComboBegin(this NuklearContext ctx, nk_window win, Vector2 size, bool is_clicked, RectangleF header) { nk_window popup; var is_open = false; var is_active = false; var body = new RectangleF(); if (ctx == null || ctx.current == null || ctx.current.Layout == null) { return(false); } popup = win.Popup.Window; body.X = header.X; body.Width = size.X; body.Y = header.Y + header.Height - ctx.style.window.combo_border; body.Height = size.Y; var hash = win.Popup.ComboCount++; is_open = popup != null ? true : false; is_active = popup != null && win.Popup.Name == hash && win.Popup.Type == NK_PANEL_COMBO; if ((is_clicked && is_open && !is_active) || (is_open && !is_active) || (!is_open && !is_active && !is_clicked)) { return(false); } if (!ctx.NonBlockBegin(0, body, is_clicked && is_open ? new RectangleF(0, 0, 0, 0) : header, NK_PANEL_COMBO)) { return(false); } win.Popup.Type = NK_PANEL_COMBO; win.Popup.Name = hash; return(true); }
public static void nk_free_window(nk_context ctx, nk_window win) { nk_table it = win.tables; if (win.popup.win != null) { nk_free_window(ctx, win.popup.win); win.popup.win = null; } win.next = null; win.prev = null; while (it != null) { var n = it.next; nk_remove_table(win, it); if (it == win.tables) { win.tables = n; } it = n; } }
public static void LayoutWidgetSpace(ref RectangleF bounds, NuklearContext ctx, nk_window win, int modify) { nk_panel layout; nk_style style; var spacing = new Vector2(); var padding = new Vector2(); var item_offset = (float)0; var item_width = (float)0; var item_spacing = (float)0; var panel_space = (float)0; if (ctx == null || ctx.current == null || ctx.current.Layout == null) { return; } win = ctx.current; layout = win.Layout; style = ctx.style; spacing = style.window.spacing; padding = nk_panel_get_padding(style, layout.Type); panel_space = LayoutRowCalculateUsableSpace(ctx.style, layout.Type, layout.Bounds.Width, layout.Row.columns); switch (layout.Row.type) { case NK_LAYOUT_DYNAMIC_FIXED: { item_width = (1.0f < panel_space - 1.0f ? panel_space - 1.0f : 1.0f) / layout.Row.columns; item_offset = layout.Row.index * item_width; item_spacing = layout.Row.index * spacing.X; } break; case NK_LAYOUT_DYNAMIC_ROW: { item_width = layout.Row.item_width * panel_space; item_offset = layout.Row.item_offset; item_spacing = 0; if (modify != 0) { layout.Row.item_offset += item_width + spacing.X; layout.Row.Filled += layout.Row.item_width; layout.Row.index = 0; } } break; case NK_LAYOUT_DYNAMIC_FREE: { bounds.X = layout.At_x + layout.Bounds.Width * layout.Row.item.X; bounds.X -= layout.Offset.X; bounds.Y = layout.At_y + layout.Row.height * layout.Row.item.Y; bounds.Y -= layout.Offset.Y; bounds.Width = layout.Bounds.Width * layout.Row.item.Width; bounds.Height = layout.Row.height * layout.Row.item.Height; return; } case NK_LAYOUT_DYNAMIC: { float ratio; ratio = layout.Row.ratio[layout.Row.index] < 0 ? layout.Row.item_width : layout.Row.ratio[layout.Row.index]; item_spacing = layout.Row.index * spacing.X; item_width = ratio * panel_space; item_offset = layout.Row.item_offset; if (modify != 0) { layout.Row.item_offset += item_width; layout.Row.Filled += ratio; } } break; case NK_LAYOUT_STATIC_FIXED: { item_width = layout.Row.item_width; item_offset = layout.Row.index * item_width; item_spacing = layout.Row.index * spacing.X; } break; case NK_LAYOUT_STATIC_ROW: { item_width = layout.Row.item_width; item_offset = layout.Row.item_offset; item_spacing = layout.Row.index * spacing.X; if (modify != 0) { layout.Row.item_offset += item_width; } } break; case NK_LAYOUT_STATIC_FREE: { bounds.X = layout.At_x + layout.Row.item.X; bounds.Width = layout.Row.item.Width; if (bounds.X + bounds.Width > layout.Max_x && modify != 0) { layout.Max_x = bounds.X + bounds.Width; } bounds.X -= layout.Offset.X; bounds.Y = layout.At_y + layout.Row.item.Y; bounds.Y -= layout.Offset.Y; bounds.Height = layout.Row.item.Height; return; } case NK_LAYOUT_STATIC: { item_spacing = layout.Row.index * spacing.X; item_width = layout.Row.ratio[layout.Row.index]; item_offset = layout.Row.item_offset; if (modify != 0) { layout.Row.item_offset += item_width; } } break; case NK_LAYOUT_TEMPLATE: { item_width = layout.Row.templates[layout.Row.index]; item_offset = layout.Row.item_offset; item_spacing = layout.Row.index * spacing.X; if (modify != 0) { layout.Row.item_offset += item_width; } } break; default: ; break; } bounds.Width = item_width; bounds.Height = layout.Row.height - spacing.Y; bounds.Y = layout.At_y - layout.Offset.Y; bounds.X = layout.At_x + item_offset + item_spacing + padding.X; if (bounds.X + bounds.Width > layout.Max_x && modify != 0) { layout.Max_x = bounds.X + bounds.Width; } bounds.X -= layout.Offset.X; }
public static void nk_layout_widget_space(nk_rect *bounds, nk_context ctx, nk_window win, int modify) { nk_panel layout; nk_style style; nk_vec2 spacing = new nk_vec2(); nk_vec2 padding = new nk_vec2(); float item_offset = (float)(0); float item_width = (float)(0); float item_spacing = (float)(0); float panel_space = (float)(0); if (((ctx == null) || (ctx.current == null)) || (ctx.current.layout == null)) { return; } win = ctx.current; layout = win.layout; style = ctx.style; spacing = (nk_vec2)(style.window.spacing); padding = (nk_vec2)(nk_panel_get_padding(style, (int)(layout.type))); panel_space = (float) (nk_layout_row_calculate_usable_space(ctx.style, (int)(layout.type), (float)(layout.bounds.w), (int)(layout.row.columns))); switch (layout.row.type) { case NK_LAYOUT_DYNAMIC_FIXED: { item_width = (float)(((1.0f) < (panel_space - 1.0f) ? (panel_space - 1.0f) : (1.0f)) / (float)(layout.row.columns)); item_offset = (float)((float)(layout.row.index) * item_width); item_spacing = (float)((float)(layout.row.index) * spacing.x); } break; case NK_LAYOUT_DYNAMIC_ROW: { item_width = (float)(layout.row.item_width * panel_space); item_offset = (float)(layout.row.item_offset); item_spacing = (float)(0); if ((modify) != 0) { layout.row.item_offset += (float)(item_width + spacing.x); layout.row.filled += (float)(layout.row.item_width); layout.row.index = (int)(0); } } break; case NK_LAYOUT_DYNAMIC_FREE: { bounds->x = (float)(layout.at_x + (layout.bounds.w * layout.row.item.x)); bounds->x -= ((float)(layout.offset.x)); bounds->y = (float)(layout.at_y + (layout.row.height * layout.row.item.y)); bounds->y -= ((float)(layout.offset.y)); bounds->w = (float)(layout.bounds.w * layout.row.item.w); bounds->h = (float)(layout.row.height * layout.row.item.h); return; } case NK_LAYOUT_DYNAMIC: { float ratio; ratio = (float) (((layout.row.ratio[layout.row.index]) < (0)) ? layout.row.item_width : layout.row.ratio[layout.row.index]); item_spacing = (float)((float)(layout.row.index) * spacing.x); item_width = (float)(ratio * panel_space); item_offset = (float)(layout.row.item_offset); if ((modify) != 0) { layout.row.item_offset += (float)(item_width); layout.row.filled += (float)(ratio); } } break; case NK_LAYOUT_STATIC_FIXED: { item_width = (float)(layout.row.item_width); item_offset = (float)((float)(layout.row.index) * item_width); item_spacing = (float)((float)(layout.row.index) * spacing.x); } break; case NK_LAYOUT_STATIC_ROW: { item_width = (float)(layout.row.item_width); item_offset = (float)(layout.row.item_offset); item_spacing = (float)((float)(layout.row.index) * spacing.x); if ((modify) != 0) { layout.row.item_offset += (float)(item_width); } } break; case NK_LAYOUT_STATIC_FREE: { bounds->x = (float)(layout.at_x + layout.row.item.x); bounds->w = (float)(layout.row.item.w); if (((bounds->x + bounds->w) > (layout.max_x)) && ((modify) != 0)) { layout.max_x = (float)(bounds->x + bounds->w); } bounds->x -= ((float)(layout.offset.x)); bounds->y = (float)(layout.at_y + layout.row.item.y); bounds->y -= ((float)(layout.offset.y)); bounds->h = (float)(layout.row.item.h); return; } case NK_LAYOUT_STATIC: { item_spacing = (float)((float)(layout.row.index) * spacing.x); item_width = (float)(layout.row.ratio[layout.row.index]); item_offset = (float)(layout.row.item_offset); if ((modify) != 0) { layout.row.item_offset += (float)(item_width); } } break; case NK_LAYOUT_TEMPLATE: { item_width = (float)(layout.row.templates[layout.row.index]); item_offset = (float)(layout.row.item_offset); item_spacing = (float)((float)(layout.row.index) * spacing.x); if ((modify) != 0) { layout.row.item_offset += (float)(item_width); } } break; default: ; break; } bounds->w = (float)(item_width); bounds->h = (float)(layout.row.height - spacing.y); bounds->y = (float)(layout.at_y - (float)(layout.offset.y)); bounds->x = (float)(layout.at_x + item_offset + item_spacing + padding.x); if (((bounds->x + bounds->w) > (layout.max_x)) && ((modify) != 0)) { layout.max_x = (float)(bounds->x + bounds->w); } bounds->x -= ((float)(layout.offset.x)); }
public static uint nk_chart_pushLine(this NuklearContext ctx, nk_window win, nk_chart g, float value, int slot) { var layout = win.Layout; var i = ctx.input; var _out_ = win.Buffer; var ret = (uint)0; var cur = new Vector2(); var bounds = new RectangleF(); var color = new Color(); float step; float range; float ratio; step = g.Width / g.slots[slot].Count; range = g.slots[slot].Max - g.slots[slot].Min; ratio = (value - g.slots[slot].Min) / range; if (g.slots[slot].Index == 0) { g.slots[slot].Last.X = g.X; g.slots[slot].Last.Y = g.Y + g.Height - ratio * g.Height; bounds.X = g.slots[slot].Last.X - 2; bounds.Y = g.slots[slot].Last.Y - 2; bounds.Width = bounds.Height = 4; color = g.slots[slot].Color; if ((layout.Flags & NK_WINDOW_ROM) == 0 && g.slots[slot].Last.X - 3 <= i.mouse.pos.X && i.mouse.pos.X < g.slots[slot].Last.X - 3 + 6 && g.slots[slot].Last.Y - 3 <= i.mouse.pos.Y && i.mouse.pos.Y < g.slots[slot].Last.Y - 3 + 6) { ret = (uint)(nk_input_is_mouse_hovering_rect(i, bounds) ? NK_CHART_HOVERING : 0); ret |= (uint) (i.mouse.buttons[NK_BUTTON_LEFT].down && i.mouse.buttons[NK_BUTTON_LEFT].clicked != 0 ? NK_CHART_CLICKED : 0); color = g.slots[slot].Highlight; } _out_.FillRect(bounds, 0, color); g.slots[slot].Index += 1; return(ret); } color = g.slots[slot].Color; cur.X = g.X + step * g.slots[slot].Index; cur.Y = g.Y + g.Height - ratio * g.Height; _out_.StrokeLine(g.slots[slot].Last.X, g.slots[slot].Last.Y, cur.X, cur.Y, 1.0f, color); bounds.X = cur.X - 3; bounds.Y = cur.Y - 3; bounds.Width = bounds.Height = 6; if ((layout.Flags & NK_WINDOW_ROM) == 0) { if (nk_input_is_mouse_hovering_rect(i, bounds)) { ret = NK_CHART_HOVERING; ret |= (uint) (!i.mouse.buttons[NK_BUTTON_LEFT].down && i.mouse.buttons[NK_BUTTON_LEFT].clicked != 0 ? NK_CHART_CLICKED : 0); color = g.slots[slot].Highlight; } } _out_.FillRect(new RectangleF(cur.X - 2, cur.Y - 2, 4, 4), 0, color); g.slots[slot].Last.X = cur.X; g.slots[slot].Last.Y = cur.Y; g.slots[slot].Index += 1; return(ret); }
public void nk_start(nk_window win) { nk_start_buffer(win.Buffer); }