Beispiel #1
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, 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);
        }