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