Ejemplo n.º 1
0
        public static float nk_layout_row_calculate_usable_space(NkStyle style, NkPanelType type, float total_space, int columns)
        {
            float  panel_padding;
            float  panel_spacing;
            float  panel_space;
            NkVec2 spacing = new NkVec2();
            NkVec2 padding = new NkVec2();

            spacing       = (NkVec2)(style.Window.spacing);
            padding       = (NkVec2)(nk_panel_get_padding(style, (type)));
            panel_padding = (float)(2 * padding.x);
            panel_spacing = (float)((float)((columns - 1) < (0) ? (0) : (columns - 1)) * spacing.x);
            panel_space   = (float)(total_space - panel_padding - panel_spacing);
            return((float)(panel_space));
        }
Ejemplo n.º 2
0
        /// <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, NkVec2 pos, float radius,
                                     NkImage[] icons, int itemCount)
        {
            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 = Nk.nk_style_item_hide();
            ctx.Ctx.Style.Window.border_color     = Nk.nk_rgba(0, 0, 0, 0);

            var totalSpace = ctx.WindowGetContentRegion();

            ctx.Ctx.Style.Window.spacing = Nk.nk_vec2_(0, 0);
            ctx.Ctx.Style.Window.padding = Nk.nk_vec2_(0, 0);

            if (ctx.PopupBegin(NkPopupType.NK_POPUP_STATIC, "piemenu", PanelFlags.NO_SCROLLBAR,
                               Nk.nk_rect_(pos.x - totalSpace.x - radius, pos.y - radius - totalSpace.y,
                                           2 * radius, 2 * radius)))
            {
                var o   = ctx.WindowGetCanvas();
                var inp = ctx.Ctx.Input;

                totalSpace = ctx.WindowGetContentRegion();
                ctx.Ctx.Style.Window.spacing = Nk.nk_vec2_(4, 4);
                ctx.Ctx.Style.Window.padding = Nk.nk_vec2_(8, 8);
                ctx.LayoutRowDynamic(totalSpace.h, 1);
                NkRect bounds;
                Nk.nk_widget(&bounds, ctx.Ctx);

                /* outer circle */
                Nk.nk_fill_circle(o, bounds, Nk.nk_rgb(50, 50, 50));
                int activeItem;
                {
                    /* circle buttons */
                    var   step = 2 * 3.141592654f / Math.Max(1, itemCount);
                    float aMin = 0;
                    var   aMax = step;

                    var center = Nk.nk_vec2_(bounds.x + bounds.w / 2.0f, bounds.y + bounds.h / 2.0f);
                    var drag   = Nk.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;
                    }
                    activeItem = (int)(angle / step);

                    int i;
                    for (i = 0; i < itemCount; ++i)
                    {
                        NkRect content;
                        Nk.nk_fill_arc(o, center.x, center.y, bounds.w / 2.0f,
                                       aMin, aMax, activeItem == i ? Nk.nk_rgb(45, 100, 255) : Nk.nk_rgb(60, 60, 60));

                        /* separator line */
                        var   rx = bounds.w / 2.0f;
                        float ry = 0;
                        var   dx = rx * (float)Math.Cos(aMin) - ry * (float)Math.Sin(aMin);
                        var   dy = rx * (float)Math.Sin(aMin) + ry * (float)Math.Cos(aMin);
                        Nk.nk_stroke_line(o, center.x, center.y,
                                          center.x + dx, center.y + dy, 1.0f, Nk.nk_rgb(50, 50, 50));

                        /* button content */
                        var a = aMin + (aMax - aMin) / 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);
                        Nk.nk_draw_image(o, content, icons[i], Nk.nk_rgb(255, 255, 255));
                        aMin  = aMax;
                        aMax += step;
                    }
                }
                {
                    /* inner circle */
                    NkRect 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;
                    Nk.nk_fill_circle(o, inner, Nk.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;
                    Nk.nk_draw_image(o, bounds, icons[activeItem], Nk.nk_rgb(255, 255, 255));
                }
                ctx.LayoutSpaceEnd();
                if (Nk.nk_input_is_mouse_down(ctx.Ctx.Input, NkButtons.RIGHT) == 0)
                {
                    ctx.PopupClose();
                    ret = activeItem;
                }
            }
            else
            {
                ret = -2;
            }
            ctx.Ctx.Style.Window.spacing = Nk.nk_vec2_(4, 4);
            ctx.Ctx.Style.Window.padding = Nk.nk_vec2_(8, 8);
            ctx.PopupEnd();

            ctx.Ctx.Style.Window.fixed_background = background;
            ctx.Ctx.Style.Window.border_color     = border;
            return(ret);
        }
Ejemplo n.º 3
0
        public static void basic_demo(NuklearContext ctx, Media media)
        {
            int i;

            ctx.StyleSetFont(media.Font20.Handle);
            ctx.Begin("Basic Demo", Nk.nk_rect_(320, 50, 275, 610),
                      PanelFlags.BORDER | PanelFlags.MOVABLE | PanelFlags.TITLE);

            ui_header(ctx, media, "Popup & Scrollbar & Images");
            ui_widget(ctx, media, 35);
            if (ctx.ButtonImageLabel(media.Dir, "Images", Alignment.MIDDLECENTERED))
            {
                _imageActive = !_imageActive;
            }

            ui_header(ctx, media, "Selected Image");
            ui_widget_centered(ctx, media, 100);
            ctx.Image(media.Images[_selectedImage]);

            if (_imageActive)
            {
                if (ctx.PopupBegin(NkPopupType.NK_POPUP_STATIC, "Image Popup", 0, Nk.nk_rect_(265, 0, 320, 220)))
                {
                    ctx.LayoutRowStatic(82, 82, 3);
                    for (i = 0; i < 9; ++i)
                    {
                        if (ctx.ButtonImage(media.Images[i]))
                        {
                            _selectedImage = i;
                            _imageActive   = false;
                            ctx.PopupClose();
                        }
                    }
                    ctx.PopupEnd();
                }
            }

            ui_header(ctx, media, "Combo box");
            ui_widget(ctx, media, 40);
            if (ctx.ComboBeginLabel(Items2[_selectedItem1], Nk.nk_vec2_(ctx.WidgetWidth(), 200)))
            {
                ctx.LayoutRowDynamic(35, 1);
                for (i = 0; i < 3; ++i)
                {
                    if (ctx.ComboItemLabel(Items2[i], Alignment.MIDDLELEFT))
                    {
                        _selectedItem1 = i;
                    }
                }
                ctx.ComboEnd();
            }

            ui_widget(ctx, media, 40);
            if (ctx.ComboBeginImageLabel(Items2[_selectedIcon], media.Images[_selectedIcon],
                                         Nk.nk_vec2_(ctx.WidgetWidth(), 200)))
            {
                ctx.LayoutRowDynamic(35, 1);
                for (i = 0; i < 3; ++i)
                {
                    if (ctx.ComboItemImageLabel(media.Images[i], Items2[i], Alignment.MIDDLERIGHT))
                    {
                        _selectedIcon = 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, Nk.nk_true);

            if (Nk.nk_input_is_mouse_click_down_in_rect(ctx.Ctx.Input, NkButtons.RIGHT,
                                                        ctx.WindowGetBounds(), Nk.nk_true) != 0)
            {
                _piemenuPos    = ctx.Ctx.Input.mouse.Pos;
                _piemenuActive = true;
            }

            if (_piemenuActive)
            {
                var ret = ui_piemenu(ctx, _piemenuPos, 140, media.Menu, 6);
                if (ret == -2)
                {
                    _piemenuActive = false;
                }
                if (ret != -1)
                {
                    Console.Write("piemenu selected: {0}\n", ret);
                    _piemenuActive = false;
                }
            }

            ctx.StyleSetFont(media.Font14.Handle);
            ctx.End();
        }