Exemplo n.º 1
0
        public NuklearContext(Game game)
        {
            ConvertConfig = new nk_convert_config
            {
                global_alpha         = 1f,
                shape_AA             = NK_ANTI_ALIASING_ON,
                line_AA              = NK_ANTI_ALIASING_ON,
                circle_segment_count = 22,
                curve_segment_count  = 22,
                arc_segment_count    = 22
            };

            _game = game;

            _effect           = new Effect(game.GraphicsDevice, Resources.EffectSource);
            _textureParam     = _effect.Parameters["g_texture"];
            _transformParam   = _effect.Parameters["g_transform"];
            _techniqueColor   = _effect.Techniques["Color"];
            _techniqueTexture = _effect.Techniques["Texture"];

            draw_list = new DrawList(game.GraphicsDevice);

            this.StyleDefault();
            seq = 1;
        }
Exemplo n.º 2
0
 internal void Setup(nk_convert_config config, Buffer <DrawCommand> cmds,
                     Buffer <Vertex> vertices, Buffer <short> elements, int line_aa, int shape_aa)
 {
     if (config == null || cmds == null || vertices == null || elements == null)
     {
         return;
     }
     _buffer   = cmds;
     _config   = config;
     _elements = elements;
     _vertices = vertices;
     _lineAA   = line_aa;
     _shapeAA  = shape_aa;
     _clipRect = RectangleF.Null;
 }
Exemplo n.º 3
0
        internal uint nk_convert(Buffer <DrawCommand> cmds, Buffer <Vertex> vertices,
                                 Buffer <short> elements, nk_convert_config config)
        {
            var res = (uint)NK_CONVERT_SUCCESS;

            if (cmds == null || vertices == null || elements == null || config == null)
            {
                return(NK_CONVERT_INVALID_PARAM);
            }
            draw_list.Setup(config, cmds, vertices, elements, config.line_AA, config.shape_AA);
            var top_window = nk__begin();

            var cnt = 0;

            for (var cmd = top_window.Value.Buffer.First; cmd != null; cmd = cmd.Next)
            {
                switch (cmd.Type)
                {
                case CommandType.Nop:
                    break;

                case CommandType.Scissor:
                {
                    var s = (CommandScissor)cmd;
                    draw_list.AddClip(
                        new RectangleF(s.X, s.Y, s.Width, s.Height));
                }
                break;

                case CommandType.Line:
                {
                    var l = (CommandLine)cmd;
                    draw_list.StrokeLine(new Vector2(l.Begin.X, l.Begin.Y),
                                         new Vector2(l.End.X, l.End.Y), l.Color, l.LineThickness);
                }
                break;

                case CommandType.Curve:
                {
                    var q = (CommandCurve)cmd;
                    draw_list.StrokeCurve(new Vector2(q.Begin.X, q.Begin.Y),
                                          new Vector2(q.Ctrl0.X, q.Ctrl0.Y),
                                          new Vector2(q.Ctrl1.X, q.Ctrl1.Y),
                                          new Vector2(q.End.X, q.End.Y), q.Color,
                                          config.curve_segment_count, q.LineThickness);
                }
                break;

                case CommandType.Rect:
                {
                    var r = (CommandRect)cmd;
                    draw_list.StrokeRect(
                        new RectangleF(r.X, r.Y, r.Width, r.Height), r.Color,
                        r.Rounding, r.LineThickness);
                }
                break;

                case CommandType.RectFilled:
                {
                    var r = (CommandRectFilled)cmd;
                    draw_list.FillRect(
                        new RectangleF(r.X, r.Y, r.Width, r.Height), r.Color,
                        r.Rounding);
                }
                break;

                case CommandType.RectMultiColor:
                {
                    var r = (CommandRectMultiColor)cmd;
                    draw_list.FillRectMultiColor(
                        new RectangleF(r.X, r.Y, r.Width, r.Height), r.Left,
                        r.Top, r.Right, r.Bottom);
                }
                break;

                case CommandType.Circle:
                {
                    var c = (CommandCircle)cmd;
                    draw_list.StrokeCircle(
                        new Vector2(c.X + (float)c.Width / 2, c.Y + (float)c.Height / 2),
                        (float)c.Width / 2, c.Color, config.circle_segment_count, c.LineThickness);
                }
                break;

                case CommandType.CircleFilled:
                {
                    var c = (CommandCircleFilled)cmd;
                    draw_list.FillCircle(
                        new Vector2(c.X + (float)c.Width / 2, c.Y + (float)c.Height / 2),
                        (float)c.Width / 2, c.Color, config.circle_segment_count);
                }
                break;

                case CommandType.Arc:
                {
                    var c = (CommandArc)cmd;
                    draw_list.PathLineTo(new Vector2(c.X, c.Y));
                    draw_list.PathArcTo(new Vector2(c.X, c.Y), c.Radius,
                                        c.AngleMin, c.AngleMax, config.arc_segment_count);
                    draw_list.PathStroke(c.Color, NK_STROKE_CLOSED, c.LineThickness);
                }
                break;

                case CommandType.ArcFilled:
                {
                    var c = (CommandArcFilled)cmd;
                    draw_list.PathLineTo(new Vector2(c.X, c.Y));
                    draw_list.PathArcTo(new Vector2(c.X, c.Y), c.Radius,
                                        c.AngleMin, c.AngleMax, config.arc_segment_count);
                    draw_list.PathFill(c.Color);
                }
                break;

                case CommandType.Triangle:
                {
                    var t = (CommandTriangle)cmd;
                    draw_list.StrokeTriangle(new Vector2(t.A.X, t.A.Y),
                                             new Vector2(t.B.X, t.B.Y), new Vector2(t.C.X, t.C.Y),
                                             t.Color, t.LineThickness);
                }
                break;

                case CommandType.TriangleFilled:
                {
                    var t = (CommandTriangleFilled)cmd;
                    draw_list.FillTriangle(new Vector2(t.A.X, t.A.Y),
                                           new Vector2(t.B.X, t.B.Y), new Vector2(t.C.X, t.C.Y),
                                           t.Color);
                }
                break;

                case CommandType.Polygon:
                {
                    int i;
                    var p = (CommandPolygon)cmd;
                    for (i = 0; i < p.Points.Length; ++i)
                    {
                        var pnt = new Vector2(p.Points[i].X, p.Points[i].Y);
                        draw_list.PathLineTo(pnt);
                    }

                    draw_list.PathStroke(p.Color, NK_STROKE_CLOSED, p.LineThickness);
                }
                break;

                case CommandType.PolygonFilled:
                {
                    int i;
                    var p = (CommandPolygonFilled)cmd;
                    for (i = 0; i < p.Points.Length; ++i)
                    {
                        var pnt = new Vector2(p.Points[i].X, p.Points[i].Y);
                        draw_list.PathLineTo(pnt);
                    }

                    draw_list.PathFill(p.Color);
                }
                break;

                case CommandType.Polyline:
                {
                    int i;
                    var p = (CommandPolyline)cmd;
                    for (i = 0; i < p.Points.Length; ++i)
                    {
                        var pnt = new Vector2(p.Points[i].X, p.Points[i].Y);
                        draw_list.PathLineTo(pnt);
                    }

                    draw_list.PathStroke(p.Color, NK_STROKE_OPEN, p.LineThickness);
                }
                break;

                case CommandType.Text:
                {
                    var t = (CommandText)cmd;
                    draw_list.AddText(t.Font,
                                      new RectangleF(t.X, t.Y, t.Width, t.Height), t.Text, t.FontHeight, t.Foreground);
                }
                break;

                case CommandType.Image:
                {
                    var i = (CommandImage)cmd;
                    draw_list.AddImage(i.Image,
                                       new RectangleF(i.X, i.Y, i.Width, i.Height), i.Color);
                }
                break;

                case CommandType.Custom:
                {
                    var c = (CommandCustom)cmd;
                    c.callback(draw_list, c.X, c.Y, c.Width, c.Height);
                }
                break;
                }

                ++cnt;
            }

            return(res);
        }