/// <summary> /// User interfaces the piemenu. /// </summary> /// <returns>The piemenu.</returns> /// <param name="ctx">Context.</param> /// <param name="pos">Position.</param> /// <param name="radius">Radius.</param> /// <param name="icons">Icons.</param> /// <param name="item_count">Item count.</param> public static int ui_piemenu(this NuklearContext ctx, Vector2 pos, float radius, nk_image[] icons, int item_count) { var ret = -1; /* pie menu popup */ var border = ctx.style.window.border_color; var background = ctx.style.window.fixed_background; ctx.style.window.fixed_background = Nuklear.nk_style_item_hide(); ctx.style.window.border_color = Color.Transparent; var total_space = ctx.WindowGetContentRegion(); ctx.style.window.spacing = new Vector2(0, 0); ctx.style.window.padding = new Vector2(0, 0); if (ctx.PopupBegin(Nuklear.NK_POPUP_STATIC, "piemenu", Nuklear.NK_WINDOW_NO_SCROLLBAR, new RectangleF(pos.X - total_space.X - radius, pos.Y - radius - total_space.Y, 2 * radius, 2 * radius))) { var o = ctx.WindowGetCanvas(); var inp = ctx.input; total_space = ctx.WindowGetContentRegion(); ctx.style.window.spacing = new Vector2(4, 4); ctx.style.window.padding = new Vector2(8, 8); ctx.LayoutRowDynamic(total_space.Height, 1); var bounds = new RectangleF(); ctx.Widget(ref bounds); /* outer circle */ o.nk_fill_circle(bounds, new Color(50, 50, 50)); int active_item; { /* circle buttons */ var step = 2 * 3.141592654f / Math.Max(1, item_count); float a_min = 0; var a_max = step; var center = new Vector2(bounds.X + bounds.Width / 2.0f, bounds.Y + bounds.Height / 2.0f); var drag = new Vector2(inp.mouse.pos.X - center.X, inp.mouse.pos.Y - center.Y); var angle = (float)Math.Atan2(drag.Y, drag.X); if (angle < -0.0f) { angle += 2.0f * 3.141592654f; } active_item = (int)(angle / step); int i; for (i = 0; i < item_count; ++i) { RectangleF content; o.FillArc(center.X, center.Y, bounds.Width / 2.0f, a_min, a_max, active_item == i ? new Color(45, 100, 255) : new Color(60, 60, 60)); /* separator line */ var rx = bounds.Width / 2.0f; float ry = 0; var dx = rx * (float)Math.Cos(a_min) - ry * (float)Math.Sin(a_min); var dy = rx * (float)Math.Sin(a_min) + ry * (float)Math.Cos(a_min); o.StrokeLine(center.X, center.Y, center.X + dx, center.Y + dy, 1.0f, new Color(50, 50, 50)); /* button content */ var a = a_min + (a_max - a_min) / 2.0f; rx = bounds.Width / 2.5f; ry = 0; content.Width = 30; content.Height = 30; content.X = center.X + (rx * (float)Math.Cos(a) - ry * (float)Math.Sin(a) - content.Width / 2.0f); content.Y = center.Y + (rx * (float)Math.Sin(a) + ry * (float)Math.Cos(a) - content.Height / 2.0f); o.DrawImage(content, icons[i], Color.White); a_min = a_max; a_max += step; } } { /* inner circle */ RectangleF inner; inner.X = bounds.X + bounds.Width / 2 - bounds.Width / 4; inner.Y = bounds.Y + bounds.Height / 2 - bounds.Height / 4; inner.Width = bounds.Width / 2; inner.Height = bounds.Height / 2; o.nk_fill_circle(inner, new Color(45, 45, 45)); /* active icon content */ bounds.Width = inner.Width / 2.0f; bounds.Height = inner.Height / 2.0f; bounds.X = inner.X + inner.Width / 2 - bounds.Width / 2; bounds.Y = inner.Y + inner.Height / 2 - bounds.Height / 2; o.DrawImage(bounds, icons[active_item], Color.White); } ctx.LayoutSpaceEnd(); if (!Nuklear.nk_input_is_mouse_down(ctx.input, Nuklear.NK_BUTTON_RIGHT)) { ctx.PopupClose(); ret = active_item; } } else { ret = -2; } ctx.style.window.spacing = new Vector2(4, 4); ctx.style.window.padding = new Vector2(8, 8); ctx.PopupEnd(); ctx.style.window.fixed_background = background; ctx.style.window.border_color = border; return(ret); }
public int insert_at(int pos, char *ptr) { return(insert_at(pos, ptr, Nuklear.nk_strlen(ptr))); }
public static void basic_demo(this NuklearContext ctx, Media media) { int i; ctx.StyleSetFont(media.font); ctx.StyleSetFontSize(20); ctx.Begin("Basic Demo", new RectangleF(320, 50, 275, 610), Nuklear.NK_WINDOW_BORDER | Nuklear.NK_WINDOW_MOVABLE | Nuklear.NK_WINDOW_TITLE); ui_header(ctx, media, "Popup & Scrollbar & Images"); ui_widget(ctx, media, 35); if (ctx.ButtonImageLabel(media.dir, "Images", nk_text_align.NK_TEXT_CENTERED)) { image_active = !image_active; } ui_header(ctx, media, "Selected Image"); ui_widget_centered(ctx, media, 100); ctx.Image(media.images[selected_image]); if (image_active) { if (ctx.PopupBegin(Nuklear.NK_POPUP_STATIC, "Image Popup", 0, new RectangleF(265, 0, 320, 220))) { ctx.LayoutRowStatic(82, 82, 3); for (i = 0; i < 9; ++i) { if (ctx.ButtonImage(media.images[i])) { selected_image = i; image_active = false; ctx.PopupClose(); } } ctx.PopupEnd(); } } ui_header(ctx, media, "Combo box"); ui_widget(ctx, media, 40); if (ctx.ComboBeginLabel(items2[selected_item], new Vector2(ctx.WidgetWidth(), 200))) { ctx.LayoutRowDynamic(35, 1); for (i = 0; i < 3; ++i) { if (ctx.ComboItemLabel(items2[i], nk_text_align.NK_TEXT_LEFT)) { selected_item = i; } } ctx.ComboEnd(); } ui_widget(ctx, media, 40); if (ctx.ComboBeginImageLabel(items2[selected_icon], media.images[selected_icon], new Vector2(ctx.WidgetWidth(), 200))) { ctx.LayoutRowDynamic(35, 1); for (i = 0; i < 3; ++i) { if (ctx.ComboItemImageLabel(media.images[i], items2[i], nk_text_align.NK_TEXT_RIGHT)) { selected_icon = i; } } ctx.ComboEnd(); } ui_header(ctx, media, "Checkbox"); ui_widget(ctx, media, 30); ctx.CheckboxLabel("Flag 1", ref check0); ui_widget(ctx, media, 30); ctx.CheckboxLabel("Flag 2", ref check1); ui_header(ctx, media, "Progressbar"); ui_widget(ctx, media, 35); ctx.Progress(ref prog, 100, Nuklear.nk_true); if (Nuklear.nk_input_is_mouse_click_down_in_rect(ctx.input, Nuklear.NK_BUTTON_RIGHT, ctx.WindowGetBounds(), true)) { piemenu_pos = ctx.input.mouse.pos; piemenu_active = true; } if (piemenu_active) { var ret = ui_piemenu(ctx, piemenu_pos, 140, media.menu, 6); if (ret == -2) { piemenu_active = false; } if (ret != -1) { Console.Write("piemenu selected: {0}\n", ret); piemenu_active = false; } } ctx.StyleSetFontSize(14); ctx.End(); }
public int append(char *ptr) { return(append(ptr, Nuklear.nk_strlen(ptr))); }
private void Render(bool HadInput) { if (HadInput) { var Dirty = true; if (_frameBuffered != null) { Dirty = false; var MemoryBuffer = Nuklear.nk_buffer_memory(&_nuklearContext->memory); if ((int)_nuklearContext->memory.allocated == 0) { Dirty = true; } if (!Dirty) { if (_lastMemory == null || _lastMemory.Length < (int)_nuklearContext->memory.allocated) { _lastMemory = new byte[(int)_nuklearContext->memory.allocated]; Dirty = true; } } if (!Dirty) { fixed(byte *LastMemoryPtr = _lastMemory) if (MemoryManagement.MemCmp(new IntPtr(LastMemoryPtr), MemoryBuffer, _nuklearContext->memory.allocated) != 0) { Dirty = true; Marshal.Copy(MemoryBuffer, _lastMemory, 0, (int)_nuklearContext->memory.allocated); } } } if (Dirty) { var convertResult = (nk_convert_result)Nuklear.nk_convert( _nuklearContext, _commands, _vertices, _indices, _convertConfig ); if (convertResult != nk_convert_result.Success) { throw new Exception(convertResult.ToString()); } var nkVertices = new nk_vertex[(int)_vertices->needed / sizeof(nk_vertex)]; var verticesPtr = (nk_vertex *)_vertices->memory.ptr; if (verticesPtr == null) { throw new Exception("Vertex buffer pointer invalid."); } for (var i = 0; i < nkVertices.Length; i++) { nkVertices[i] = verticesPtr[i]; } var nkIndices = new ushort[(int)_indices->needed / sizeof(ushort)]; var indicesPtr = (ushort *)_indices->memory.ptr; if (indicesPtr == null) { throw new Exception("Index buffer pointer invalid."); } for (var i = 0; i < nkIndices.Length; i++) { nkIndices[i] = indicesPtr[i]; } Device.SetBuffer(nkVertices, nkIndices); _frameBuffered?.BeginBuffering(); uint Offset = 0; Device.BeginRender(); Nuklear.nk_draw_foreach(_nuklearContext, _commands, (command) => { if (command->elem_count == 0) { return; } Device.Render( command->userdata, command->texture.id, command->clip_rect, Offset, command->elem_count ); Offset += command->elem_count; }); Device.EndRender(); _frameBuffered?.EndBuffering(); } var list = &_nuklearContext->draw_list; if (list->buffer != null) { Nuklear.nk_buffer_clear(list->buffer); } if (list->vertices != null) { Nuklear.nk_buffer_clear(list->vertices); } if (list->elements != null) { Nuklear.nk_buffer_clear(list->elements); } Nuklear.nk_clear(_nuklearContext); } _frameBuffered?.RenderFinal(); }
private bool HandleInput() { var hasInput = _frameBuffered == null || Device.Events.Count > 0; if (hasInput) { Nuklear.nk_input_begin(_nuklearContext); while (Device.Events.Count > 0) { var deviceEvent = Device.Events.Dequeue(); switch (deviceEvent.Type) { case NuklearEvent.EventType.MouseButton: Nuklear.nk_input_button( _nuklearContext, (nk_buttons)deviceEvent.Button, deviceEvent.X, deviceEvent.Y, deviceEvent.IsDown ? 1 : 0 ); break; case NuklearEvent.EventType.MouseMove: Nuklear.nk_input_motion(_nuklearContext, deviceEvent.X, deviceEvent.Y); break; case NuklearEvent.EventType.Scroll: Nuklear.nk_input_scroll( _nuklearContext, new nk_vec2 { x = deviceEvent.ScrollX, y = deviceEvent.ScrollY } ); break; case NuklearEvent.EventType.Text: for (var i = 0; i < deviceEvent.Text.Length; i++) { if (!char.IsControl(deviceEvent.Text[i])) { Nuklear.nk_input_unicode(_nuklearContext, deviceEvent.Text[i]); } } break; case NuklearEvent.EventType.KeyboardKey: Nuklear.nk_input_key(_nuklearContext, deviceEvent.Key, deviceEvent.IsDown ? 1 : 0); break; case NuklearEvent.EventType.ForceUpdate: break; default: throw new NotSupportedException("This event type is not supported."); } } Nuklear.nk_input_end(_nuklearContext); } return(hasInput); }
/// <summary> /// User interfaces the piemenu. /// </summary> /// <returns>The piemenu.</returns> /// <param name="ctx">Context.</param> /// <param name="pos">Position.</param> /// <param name="radius">Radius.</param> /// <param name="icons">Icons.</param> /// <param name="item_count">Item count.</param> public static int ui_piemenu(NuklearContext ctx, Nuklear.nk_vec2 pos, float radius, Nuklear.nk_image[] icons, int item_count) { var ret = -1; /* pie menu popup */ var border = ctx.Ctx.style.window.border_color; var background = ctx.Ctx.style.window.fixed_background; ctx.Ctx.style.window.fixed_background = Nuklear.nk_style_item_hide(); ctx.Ctx.style.window.border_color = Nuklear.nk_rgba(0, 0, 0, 0); var total_space = ctx.WindowGetContentRegion(); ctx.Ctx.style.window.spacing = Nuklear.nk_vec2_(0, 0); ctx.Ctx.style.window.padding = Nuklear.nk_vec2_(0, 0); if (ctx.PopupBegin(Nuklear.NK_POPUP_STATIC, "piemenu", Nuklear.NK_WINDOW_NO_SCROLLBAR, Nuklear.nk_rect_(pos.x - total_space.x - radius, pos.y - radius - total_space.y, 2 * radius, 2 * radius))) { var o = ctx.WindowGetCanvas(); var inp = ctx.Ctx.input; total_space = ctx.WindowGetContentRegion(); ctx.Ctx.style.window.spacing = Nuklear.nk_vec2_(4, 4); ctx.Ctx.style.window.padding = Nuklear.nk_vec2_(8, 8); ctx.LayoutRowDynamic(total_space.h, 1); Nuklear.nk_rect bounds; Nuklear.nk_widget(&bounds, ctx.Ctx); /* outer circle */ Nuklear.nk_fill_circle(o, bounds, Nuklear.nk_rgb(50, 50, 50)); int active_item; { /* circle buttons */ var step = 2 * 3.141592654f / Math.Max(1, item_count); float a_min = 0; var a_max = step; var center = Nuklear.nk_vec2_(bounds.x + bounds.w / 2.0f, bounds.y + bounds.h / 2.0f); var drag = Nuklear.nk_vec2_(inp.mouse.pos.x - center.x, inp.mouse.pos.y - center.y); var angle = (float)Math.Atan2(drag.y, drag.x); if (angle < -0.0f) { angle += 2.0f * 3.141592654f; } active_item = (int)(angle / step); int i; for (i = 0; i < item_count; ++i) { Nuklear.nk_rect content; Nuklear.nk_fill_arc(o, center.x, center.y, bounds.w / 2.0f, a_min, a_max, active_item == i ? Nuklear.nk_rgb(45, 100, 255) : Nuklear.nk_rgb(60, 60, 60)); /* separator line */ var rx = bounds.w / 2.0f; float ry = 0; var dx = rx * (float)Math.Cos(a_min) - ry * (float)Math.Sin(a_min); var dy = rx * (float)Math.Sin(a_min) + ry * (float)Math.Cos(a_min); Nuklear.nk_stroke_line(o, center.x, center.y, center.x + dx, center.y + dy, 1.0f, Nuklear.nk_rgb(50, 50, 50)); /* button content */ var a = a_min + (a_max - a_min) / 2.0f; rx = bounds.w / 2.5f; ry = 0; content.w = 30; content.h = 30; content.x = center.x + (rx * (float)Math.Cos(a) - ry * (float)Math.Sin(a) - content.w / 2.0f); content.y = center.y + (rx * (float)Math.Sin(a) + ry * (float)Math.Cos(a) - content.h / 2.0f); Nuklear.nk_draw_image(o, content, icons[i], Nuklear.nk_rgb(255, 255, 255)); a_min = a_max; a_max += step; } } { /* inner circle */ Nuklear.nk_rect inner; inner.x = bounds.x + bounds.w / 2 - bounds.w / 4; inner.y = bounds.y + bounds.h / 2 - bounds.h / 4; inner.w = bounds.w / 2; inner.h = bounds.h / 2; Nuklear.nk_fill_circle(o, inner, Nuklear.nk_rgb(45, 45, 45)); /* active icon content */ bounds.w = inner.w / 2.0f; bounds.h = inner.h / 2.0f; bounds.x = inner.x + inner.w / 2 - bounds.w / 2; bounds.y = inner.y + inner.h / 2 - bounds.h / 2; Nuklear.nk_draw_image(o, bounds, icons[active_item], Nuklear.nk_rgb(255, 255, 255)); } ctx.LayoutSpaceEnd(); if (Nuklear.nk_input_is_mouse_down(ctx.Ctx.input, Nuklear.NK_BUTTON_RIGHT) == 0) { ctx.PopupClose(); ret = active_item; } } else { ret = -2; } ctx.Ctx.style.window.spacing = Nuklear.nk_vec2_(4, 4); ctx.Ctx.style.window.padding = Nuklear.nk_vec2_(8, 8); ctx.PopupEnd(); ctx.Ctx.style.window.fixed_background = background; ctx.Ctx.style.window.border_color = border; return(ret); }
public static void button_demo(NuklearContext ctx, Media media) { ctx.StyleSetFont(media.font_20.handle); ctx.Begin("Button Demo", Nuklear.nk_rect_(50, 50, 255, 610), Nuklear.NK_WINDOW_BORDER | Nuklear.NK_WINDOW_MOVABLE | Nuklear.NK_WINDOW_TITLE); /*------------------------------------------------ * MENU *------------------------------------------------*/ ctx.MenubarBegin(); { /* toolbar */ ctx.LayoutRowStatic(40, 40, 4); if (ctx.MenuBeginImage("Music", media.play, Nuklear.nk_vec2_(110, 120))) { /* settings */ ctx.LayoutRowDynamic(25, 1); ctx.MenuItemImageLabel(media.play, "Play", Nuklear.NK_TEXT_RIGHT); ctx.MenuItemImageLabel(media.stop, "Stop", Nuklear.NK_TEXT_RIGHT); ctx.MenuItemImageLabel(media.pause, "Pause", Nuklear.NK_TEXT_RIGHT); ctx.MenuItemImageLabel(media.next, "Next", Nuklear.NK_TEXT_RIGHT); ctx.MenuItemImageLabel(media.prev, "Prev", Nuklear.NK_TEXT_RIGHT); ctx.MenuEnd(); } ctx.ButtonImage(media.tools); ctx.ButtonImage(media.cloud); ctx.ButtonImage(media.pen); } ctx.MenubarEnd(); /*------------------------------------------------ * BUTTON *------------------------------------------------*/ ui_header(ctx, media, "Push buttons"); ui_widget(ctx, media, 35); if (ctx.ButtonLabel("Push me")) { Console.Write("pushed!\n"); } ui_widget(ctx, media, 35); if (ctx.ButtonImageLabel(media.rocket, "Styled", Nuklear.NK_TEXT_CENTERED)) { Console.Write("rocket!\n"); } /*------------------------------------------------ * REPEATER *------------------------------------------------*/ ui_header(ctx, media, "Repeater"); ui_widget(ctx, media, 35); if (ctx.ButtonLabel("Press me")) { Console.Write("pressed!\n"); } /*------------------------------------------------ * TOGGLE *------------------------------------------------*/ ui_header(ctx, media, "Toggle buttons"); ui_widget(ctx, media, 35); if (ctx.ButtonImageLabel(toggle0 ? media.checkd : media.uncheckd, "Toggle", Nuklear.NK_TEXT_LEFT)) { toggle0 = !toggle0; } ui_widget(ctx, media, 35); if (ctx.ButtonImageLabel(toggle1 ? media.checkd : media.uncheckd, "Toggle", Nuklear.NK_TEXT_LEFT)) { toggle1 = !toggle1; } ui_widget(ctx, media, 35); if (ctx.ButtonImageLabel(toggle2 ? media.checkd : media.uncheckd, "Toggle", Nuklear.NK_TEXT_LEFT)) { toggle2 = !toggle2; } /*------------------------------------------------ * RADIO *------------------------------------------------*/ ui_header(ctx, media, "Radio buttons"); ui_widget(ctx, media, 35); if (ctx.ButtonSymbolLabel(option == 0 ? Nuklear.NK_SYMBOL_CIRCLE_OUTLINE : Nuklear.NK_SYMBOL_CIRCLE_SOLID, "Select", Nuklear.NK_TEXT_LEFT)) { option = 0; } ui_widget(ctx, media, 35); if (ctx.ButtonSymbolLabel(option == 1 ? Nuklear.NK_SYMBOL_CIRCLE_OUTLINE : Nuklear.NK_SYMBOL_CIRCLE_SOLID, "Select", Nuklear.NK_TEXT_LEFT)) { option = 1; } ui_widget(ctx, media, 35); if (ctx.ButtonSymbolLabel(option == 2 ? Nuklear.NK_SYMBOL_CIRCLE_OUTLINE : Nuklear.NK_SYMBOL_CIRCLE_SOLID, "Select", Nuklear.NK_TEXT_LEFT)) { option = 2; } /*------------------------------------------------ * CONTEXTUAL *------------------------------------------------*/ ctx.StyleSetFont(media.font_18.handle); if (ctx.ContextualBegin(Nuklear.NK_WINDOW_NO_SCROLLBAR, Nuklear.nk_vec2_(150, 300), ctx.WindowGetBounds())) { ctx.LayoutRowDynamic(30, 1); if (ctx.ContextualItemImageLabel(media.copy, "Clone", Nuklear.NK_TEXT_RIGHT)) { Console.Write("pressed clone!\n"); } if (ctx.ContextualItemImageLabel(media.del, "Delete", Nuklear.NK_TEXT_RIGHT)) { Console.Write("pressed delete!\n"); } if (ctx.ContextualItemImageLabel(media.convert, "Convert", Nuklear.NK_TEXT_RIGHT)) { Console.Write("pressed convert!\n"); } if (ctx.ContextualItemImageLabel(media.edit, "Edit", Nuklear.NK_TEXT_RIGHT)) { Console.Write("pressed edit!\n"); } ctx.ContextualEnd(); } ctx.StyleSetFont(media.font_14.handle); ctx.End(); }