public static int nk_popup_begin(NkContext ctx, NkPopupType type, string title, PanelFlags flags, NkRect rect) { fixed(char *ptr = title) { return(nk_popup_begin(ctx, type, ptr, flags, rect)); } }
public static void nk_layout_peek(NkRect *bounds, NkContext ctx) { float y; int index; NkWindow win; NkPanel layout; if (((ctx == null) || (ctx.Current == null)) || (ctx.Current.Layout == null)) { return; } win = ctx.Current; layout = win.Layout; y = (float)(layout.AtY); index = (int)(layout.Row.index); if ((layout.Row.index) >= (layout.Row.columns)) { layout.AtY += (float)(layout.Row.height); layout.Row.index = (int)(0); } nk_layout_widget_space(bounds, ctx, win, (int)(nk_false)); if (layout.Row.index == 0) { bounds->x -= (float)(layout.Row.item_offset); } layout.AtY = (float)(y); layout.Row.index = (int)(index); }
public static NkWindow nk_create_window(NkContext ctx) { var result = new NkWindow { Seq = ctx.Seq }; return(result); }
public static void nk_free(NkContext ctx) { if (ctx == null) { return; } ctx.Seq = 0; ctx.Build = 0; ctx.Begin = null; ctx.End = null; ctx.Active = null; ctx.Current = null; ctx.Count = 0; }
public static void nk_panel_alloc_space(NkRect *bounds, NkContext ctx) { NkWindow win; NkPanel layout; if (((ctx == null) || (ctx.Current == null)) || (ctx.Current.Layout == null)) { return; } win = ctx.Current; layout = win.Layout; if ((layout.Row.index) >= (layout.Row.columns)) { nk_panel_alloc_row(ctx, win); } nk_layout_widget_space(bounds, ctx, win, (int)(nk_true)); layout.Row.index++; }
public static NkWidgetLayoutStates nk_widget(NkRect *bounds, NkContext ctx) { NkRect c = new NkRect(); NkRect v = new NkRect(); NkWindow win; NkPanel layout; nk_input _in_; if (((ctx == null) || (ctx.Current == null)) || (ctx.Current.Layout == null)) { return(NkWidgetLayoutStates.NK_WIDGET_INVALID); } nk_panel_alloc_space(bounds, ctx); win = ctx.Current; layout = win.Layout; _in_ = ctx.Input; c = (NkRect)(layout.Clip); bounds->x = ((float)((int)(bounds->x))); bounds->y = ((float)((int)(bounds->y))); bounds->w = ((float)((int)(bounds->w))); bounds->h = ((float)((int)(bounds->h))); c.x = ((float)((int)(c.x))); c.y = ((float)((int)(c.y))); c.w = ((float)((int)(c.w))); c.h = ((float)((int)(c.h))); nk_unify(ref v, ref c, (float)(bounds->x), (float)(bounds->y), (float)(bounds->x + bounds->w), (float)(bounds->y + bounds->h)); if ( !(!(((((bounds->x) > (c.x + c.w)) || ((bounds->x + bounds->w) < (c.x))) || ((bounds->y) > (c.y + c.h))) || ((bounds->y + bounds->h) < (c.y))))) { return(NkWidgetLayoutStates.NK_WIDGET_INVALID); } if ( !((((v.x) <= (_in_.mouse.Pos.x)) && ((_in_.mouse.Pos.x) < (v.x + v.w))) && (((v.y) <= (_in_.mouse.Pos.y)) && ((_in_.mouse.Pos.y) < (v.y + v.h))))) { return(NkWidgetLayoutStates.NK_WIDGET_ROM); } return(NkWidgetLayoutStates.NK_WIDGET_VALID); }
public static NkWindow nk__begin(NkContext ctx) { if (ctx == null || ctx.Count == 0) { return(null); } if (ctx.Build == 0) { nk_build(ctx); ctx.Build = nk_true; } var iter = ctx.Begin; while (iter != null && (iter.Buffer.Count == 0 || (iter.Flags & PanelFlags.HIDDEN) != 0 || iter.Seq != ctx.Seq)) { iter = iter.Next; } return(iter); }
public static void nk_free_window(NkContext ctx, NkWindow 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 NkWidgetLayoutStates nk_widget_fitting(NkRect *bounds, NkContext ctx, NkVec2 item_padding) { NkWindow win; NkStyle style; NkPanel layout; NkWidgetLayoutStates state; NkVec2 panel_padding = new NkVec2(); if (((ctx == null) || (ctx.Current == null)) || (ctx.Current.Layout == null)) { return(NkWidgetLayoutStates.NK_WIDGET_INVALID); } win = ctx.Current; style = ctx.Style; layout = win.Layout; state = (nk_widget(bounds, ctx)); panel_padding = (NkVec2)(nk_panel_get_padding(style, (layout.Type))); if ((layout.Row.index) == (1)) { bounds->w += (float)(panel_padding.x); bounds->x -= (float)(panel_padding.x); } else { bounds->x -= (float)(item_padding.x); } if ((layout.Row.index) == (layout.Row.columns)) { bounds->w += (float)(panel_padding.x); } else { bounds->w += (float)(item_padding.x); } return(state); }
public static void nk_layout_widget_space(NkRect *bounds, NkContext ctx, NkWindow win, int modify) { NkPanel layout; NkStyle style; NkVec2 spacing = new NkVec2(); NkVec2 padding = new NkVec2(); 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 = (NkVec2)(style.Window.spacing); padding = (NkVec2)(nk_panel_get_padding(style, (layout.Type))); panel_space = (float) (nk_layout_row_calculate_usable_space(ctx.Style, (layout.Type), (float)(layout.Bounds.w), (int)(layout.Row.columns))); switch (layout.Row.type) { case NkPanelRowLayoutType.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 NkPanelRowLayoutType.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 NkPanelRowLayoutType.DYNAMIC_FREE: { bounds->x = (float)(layout.AtX + (layout.Bounds.w * layout.Row.item.x)); bounds->x -= ((float)(layout.Offset.x)); bounds->y = (float)(layout.AtY + (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 NkPanelRowLayoutType.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 NkPanelRowLayoutType.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 NkPanelRowLayoutType.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 NkPanelRowLayoutType.STATIC_FREE: { bounds->x = (float)(layout.AtX + layout.Row.item.x); bounds->w = (float)(layout.Row.item.w); if (((bounds->x + bounds->w) > (layout.MaxX)) && ((modify) != 0)) { layout.MaxX = (float)(bounds->x + bounds->w); } bounds->x -= ((float)(layout.Offset.x)); bounds->y = (float)(layout.AtY + layout.Row.item.y); bounds->y -= ((float)(layout.Offset.y)); bounds->h = (float)(layout.Row.item.h); return; } case NkPanelRowLayoutType.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 NkPanelRowLayoutType.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.AtY - (float)(layout.Offset.y)); bounds->x = (float)(layout.AtX + item_offset + item_spacing + padding.x); if (((bounds->x + bounds->w) > (layout.MaxX)) && ((modify) != 0)) { layout.MaxX = (float)(bounds->x + bounds->w); } bounds->x -= ((float)(layout.Offset.x)); }
public static void nk_property_(NkContext ctx, char *name, NkPropertyVariant *variant, float incPerPixel, NkPropertyFilter filter) { var bounds = new NkRect(); uint hash; string dummyBuffer = null; NkPropertyStatus dummyState = NkPropertyStatus.NK_PROPERTY_DEFAULT; var dummyCursor = 0; var dummySelectBegin = 0; var dummySelectEnd = 0; if (ctx == null || ctx.Current == null || ctx.Current.Layout == null) { return; } var win = ctx.Current; var layout = win.Layout; var style = ctx.Style; var s = nk_widget(&bounds, ctx); if (s == 0) { return; } if (name[0] == '#') { hash = nk_murmur_hash(name, nk_strlen(name), win.Property.seq++); name++; } else { hash = nk_murmur_hash(name, nk_strlen(name), 42); } var _in_ = s == NkWidgetLayoutStates.NK_WIDGET_ROM && win.Property.active == 0 || (layout.Flags & PanelFlags.ROM) != 0 ? null : ctx.Input; NkPropertyStatus oldState, state; string buffer; int cursor, selectBegin, selectEnd; if (win.Property.active != 0 && hash == win.Property.name) { oldState = win.Property.state; nk_do_property(ref ctx.LastWidgetState, win.Buffer, bounds, name, variant, incPerPixel, ref win.Property.buffer, ref win.Property.state, ref win.Property.cursor, ref win.Property.select_start, ref win.Property.select_end, style.Property, filter, _in_, style.Font, ctx.TextEdit, ctx.ButtonBehavior); state = win.Property.state; buffer = win.Property.buffer; cursor = win.Property.cursor; selectBegin = win.Property.select_start; selectEnd = win.Property.select_end; } else { oldState = dummyState; nk_do_property(ref ctx.LastWidgetState, win.Buffer, bounds, name, variant, incPerPixel, ref dummyBuffer, ref dummyState, ref dummyCursor, ref dummySelectBegin, ref dummySelectEnd, style.Property, filter, _in_, style.Font, ctx.TextEdit, ctx.ButtonBehavior); state = dummyState; buffer = dummyBuffer; cursor = dummyCursor; selectBegin = dummySelectBegin; selectEnd = dummySelectEnd; } ctx.TextEdit.clip = ctx.Clip; if (_in_ != null && state != NkPropertyStatus.NK_PROPERTY_DEFAULT && win.Property.active == 0) { win.Property.active = 1; win.Property.buffer = buffer; win.Property.cursor = cursor; win.Property.state = state; win.Property.name = hash; win.Property.select_start = selectBegin; win.Property.select_end = selectEnd; if (state == NkPropertyStatus.NK_PROPERTY_DRAG) { ctx.Input.mouse.Grab = nk_true; ctx.Input.mouse.Grabbed = nk_true; } } if (state == NkPropertyStatus.NK_PROPERTY_DEFAULT && oldState != NkPropertyStatus.NK_PROPERTY_DEFAULT) { if (oldState == NkPropertyStatus.NK_PROPERTY_DRAG) { ctx.Input.mouse.Grab = nk_false; ctx.Input.mouse.Grabbed = nk_false; ctx.Input.mouse.Ungrab = nk_true; } win.Property.select_start = 0; win.Property.select_end = 0; win.Property.active = 0; } }
public static void nk_free_panel(NkContext ctx, NkPanel panel) { }
public static NkPanel nk_create_panel(NkContext ctx) { var result = new NkPanel(); return(result); }
public static nk_table nk_create_table(NkContext ctx) { var result = new nk_table(); return(result); }
public static void nk_build(NkContext ctx) { if (ctx.Style.CursorActive == null) { ctx.Style.CursorActive = ctx.Style.Cursors[(int)NkStyleCursor.ARROW]; } if (ctx.Style.CursorActive != null && ctx.Input.mouse.Grabbed == 0 && ctx.Style.CursorVisible != 0) { var mouseBounds = new NkRect(); var cursor = ctx.Style.CursorActive; nk_command_buffer_init(ctx.Overlay, false); nk_start_buffer(ctx, ctx.Overlay); mouseBounds.x = ctx.Input.mouse.Pos.x - cursor.offset.x; mouseBounds.y = ctx.Input.mouse.Pos.y - cursor.offset.y; mouseBounds.w = cursor.size.x; mouseBounds.h = cursor.size.y; nk_draw_image(ctx.Overlay, mouseBounds, cursor.img, nk_white); } var it = ctx.Begin; NkCommandBase cmd = null; for (; it != null;) { var next = it.Next; if ((it.Flags & PanelFlags.HIDDEN) != 0 || it.Seq != ctx.Seq) { goto cont; } cmd = it.Buffer.Last; while (next != null && (next.Buffer == null || next.Buffer.Count == 0 || (next.Flags & PanelFlags.HIDDEN) != 0)) { next = next.Next; } if (next != null) { cmd.Next = next.Buffer.First; } cont: it = next; } it = ctx.Begin; while (it != null) { var next = it.Next; if (it.Popup.buf.Buffer.Count == 0) { goto skip; } var buf = it.Popup.buf.Buffer; cmd.Next = buf.First; cmd = buf.Last; it.Popup.buf.Buffer.Count = 0; skip: it = next; } if (cmd != null) { cmd.Next = ctx.Overlay.Count > 0 ? ctx.Overlay.First : null; } }