Ejemplo n.º 1
0
        public static uint nk_chart_push_column(this NuklearContext ctx, nk_window win, nk_chart chart, float value,
                                                int slot)
        {
            var   _out_  = win.Buffer;
            var   _in_   = ctx.input;
            var   layout = win.Layout;
            float ratio;
            var   ret   = (uint)0;
            var   color = new Color();
            var   item  = new RectangleF();

            if (chart.slots[slot].Index >= chart.slots[slot].Count)
            {
                return(nk_false);
            }
            if (chart.slots[slot].Count != 0)
            {
                var padding = (float)(chart.slots[slot].Count - 1);
                item.Width = (chart.Width - padding) / chart.slots[slot].Count;
            }

            color       = chart.slots[slot].Color;
            item.Height =
                chart.Height *
                (value / chart.slots[slot].Range < 0
                                        ? -(value / chart.slots[slot].Range)
                                        : value / chart.slots[slot].Range);
            if (value >= 0)
            {
                ratio =
                    (value + (chart.slots[slot].Min < 0 ? -chart.slots[slot].Min : chart.slots[slot].Min)) /
                    (chart.slots[slot].Range < 0 ? -chart.slots[slot].Range : chart.slots[slot].Range);
                item.Y = chart.Y + chart.Height - chart.Height * ratio;
            }
            else
            {
                ratio  = (value - chart.slots[slot].Max) / chart.slots[slot].Range;
                item.Y = chart.Y + chart.Height * (ratio < 0 ? -ratio : ratio) - item.Height;
            }

            item.X = chart.X + chart.slots[slot].Index * item.Width;
            item.X = item.X + chart.slots[slot].Index;
            if ((layout.Flags & NK_WINDOW_ROM) == 0 && item.X <= _in_.mouse.pos.X &&
                _in_.mouse.pos.X < item.X + item.Width && item.Y <= _in_.mouse.pos.Y &&
                _in_.mouse.pos.Y < item.Y + item.Height)
            {
                ret  = NK_CHART_HOVERING;
                ret |=
                    (uint)
                    (!_in_.mouse.buttons[NK_BUTTON_LEFT].down &&
                     _in_.mouse.buttons[NK_BUTTON_LEFT].clicked != 0
                                                ? NK_CHART_CLICKED
                                                : 0);
                color = chart.slots[slot].Highlight;
            }

            _out_.FillRect(item, 0, color);
            chart.slots[slot].Index += 1;
            return(ret);
        }
Ejemplo n.º 2
0
        public static uint nk_chart_pushLine(this NuklearContext ctx, nk_window win, nk_chart g, float value, int slot)
        {
            var   layout = win.Layout;
            var   i      = ctx.input;
            var   _out_  = win.Buffer;
            var   ret    = (uint)0;
            var   cur    = new Vector2();
            var   bounds = new RectangleF();
            var   color  = new Color();
            float step;
            float range;
            float ratio;

            step  = g.Width / g.slots[slot].Count;
            range = g.slots[slot].Max - g.slots[slot].Min;
            ratio = (value - g.slots[slot].Min) / range;
            if (g.slots[slot].Index == 0)
            {
                g.slots[slot].Last.X = g.X;
                g.slots[slot].Last.Y = g.Y + g.Height - ratio * g.Height;
                bounds.X             = g.slots[slot].Last.X - 2;
                bounds.Y             = g.slots[slot].Last.Y - 2;
                bounds.Width         = bounds.Height = 4;
                color = g.slots[slot].Color;
                if ((layout.Flags & NK_WINDOW_ROM) == 0 && g.slots[slot].Last.X - 3 <= i.mouse.pos.X &&
                    i.mouse.pos.X < g.slots[slot].Last.X - 3 + 6 && g.slots[slot].Last.Y - 3 <= i.mouse.pos.Y &&
                    i.mouse.pos.Y < g.slots[slot].Last.Y - 3 + 6)
                {
                    ret  = (uint)(nk_input_is_mouse_hovering_rect(i, bounds) ? NK_CHART_HOVERING : 0);
                    ret |=
                        (uint)
                        (i.mouse.buttons[NK_BUTTON_LEFT].down && i.mouse.buttons[NK_BUTTON_LEFT].clicked != 0
                                                        ? NK_CHART_CLICKED
                                                        : 0);
                    color = g.slots[slot].Highlight;
                }

                _out_.FillRect(bounds, 0, color);
                g.slots[slot].Index += 1;
                return(ret);
            }

            color = g.slots[slot].Color;
            cur.X = g.X + step * g.slots[slot].Index;
            cur.Y = g.Y + g.Height - ratio * g.Height;
            _out_.StrokeLine(g.slots[slot].Last.X, g.slots[slot].Last.Y, cur.X,
                             cur.Y, 1.0f, color);
            bounds.X     = cur.X - 3;
            bounds.Y     = cur.Y - 3;
            bounds.Width = bounds.Height = 6;
            if ((layout.Flags & NK_WINDOW_ROM) == 0)
            {
                if (nk_input_is_mouse_hovering_rect(i, bounds))
                {
                    ret  = NK_CHART_HOVERING;
                    ret |=
                        (uint)
                        (!i.mouse.buttons[NK_BUTTON_LEFT].down && i.mouse.buttons[NK_BUTTON_LEFT].clicked != 0
                                                        ? NK_CHART_CLICKED
                                                        : 0);
                    color = g.slots[slot].Highlight;
                }
            }

            _out_.FillRect(new RectangleF(cur.X - 2, cur.Y - 2, 4, 4),
                           0, color);
            g.slots[slot].Last.X = cur.X;
            g.slots[slot].Last.Y = cur.Y;
            g.slots[slot].Index += 1;
            return(ret);
        }