Ejemplo n.º 1
0
        public void DrawLine_with_lineCap_and_lineJoin(string behaviorName, LineCapType lineCap, LineJoinType lineJoin)
        {
            var random = new Random();

            _mockBehaviorResolver.Setup(resolver => resolver.GetBehaviorHandler(behaviorName))
            .Returns(() =>
            {
                return(new DrawContentBehavior(_sciterWindow, (element, args) =>
                {
                    if (args.DrawEvent != DrawEvent.Content)
                    {
                        return false;
                    }

                    using (var graphics = SciterGraphics.Create(args.Handle))
                    {
                        for (var i = 0; i < byte.MaxValue; i++)
                        {
                            graphics.SaveState()
                            .Translate(args.Area.Left, args.Area.Top)
                            .SetLineColor(
                                (byte)random.Next(byte.MinValue, byte.MaxValue),
                                (byte)random.Next(byte.MinValue, byte.MaxValue),
                                (byte)random.Next(byte.MinValue, byte.MaxValue),
                                (byte)random.Next(byte.MinValue, byte.MaxValue))
                            .SetFillColor(
                                (byte)random.Next(byte.MinValue, byte.MaxValue),
                                (byte)random.Next(byte.MinValue, byte.MaxValue),
                                (byte)random.Next(byte.MinValue, byte.MaxValue),
                                (byte)random.Next(byte.MinValue, byte.MaxValue))
                            .SetLineWidth(random.Next(2, 10))
                            .SetLineCap(lineCap)
                            .SetLineJoin(lineJoin)
                            .DrawLine(random.Next(byte.MinValue, args.Area.Width),
                                      random.Next(byte.MinValue, args.Area.Height),
                                      random.Next(byte.MinValue, args.Area.Width),
                                      random.Next(byte.MinValue, args.Area.Height))
                            .SetLineGradientLinear(
                                0f,
                                0f,
                                args.Area.Width / 2f,
                                args.Area.Height,
                                SciterColorStop.Create(0f,
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue)),
                                SciterColorStop.Create(.5f,
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue)),
                                SciterColorStop.Create(1f,
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue)))
                            .DrawLine(random.Next(byte.MinValue, args.Area.Width),
                                      random.Next(byte.MinValue, args.Area.Height),
                                      random.Next(byte.MinValue, args.Area.Width),
                                      random.Next(byte.MinValue, args.Area.Height))
                            .RestoreState();
                        }
                    }

                    element?.Window?.Close();

                    return true;
                }));
            });

            _ = new TestableSciterHost(_sciterWindow)
                .SetBehaviorResolver(_mockBehaviorResolver.Object);

            _sciterWindow.Show();

            _sciterWindow.RootElement.AppendElement("body", elm => elm)
            .SetStyleValue("background", $"rgb({random.Next(byte.MinValue, byte.MaxValue)}, {random.Next(byte.MinValue, byte.MaxValue)}, {random.Next(byte.MinValue, byte.MaxValue)})")
            .SetStyleValue("behavior", behaviorName);

            SciterPlatform.RunMessageLoop();

            //Assert.NotNull(_sciterGraphics);
        }
Ejemplo n.º 2
0
        public void Draw_line_with_linear_gradient(string behaviorName)
        {
            var random = new Random();

            _mockBehaviorResolver
            .Setup(resolver => resolver.GetBehaviorHandler(behaviorName)).Returns(() =>
            {
                return(new DrawContentBehavior(_sciterWindow, (element, args) =>
                {
                    if (args.DrawEvent != DrawEvent.Content)
                    {
                        return false;
                    }

                    using (var graphics = SciterGraphics.Create(args.Handle))
                    {
                        for (var i = 0; i < 10; i++)
                        {
                            graphics.SaveState()
                            .Translate(args.Area.Left, args.Area.Top)
                            .SetLineWidth(random.Next(5, 15))
                            .SetLineGradientLinear(
                                0f,
                                0f,
                                args.Area.Width,
                                args.Area.Height,
                                SciterColorStop.Create(0f, Color.Aqua),

                                SciterColorStop.Create(.25f,
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (float)random.NextDouble()),
                                SciterColorStop.Create(.5f,
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue)),
                                SciterColorStop.Create(.75f,
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue)),
                                SciterColorStop.Create(1f, SciterColor.Lime))

                            .DrawLine(random.Next(byte.MinValue, args.Area.Width),
                                      random.Next(byte.MinValue, args.Area.Height),
                                      random.Next(byte.MinValue, args.Area.Width),
                                      random.Next(byte.MinValue, args.Area.Height));

                            graphics.SaveState()
                            .Translate((args.Area.Right - args.Area.Left) / 2f,
                                       (args.Area.Height - args.Area.Top) / 2f)

                            .SetLineGradientLinear(
                                0f,
                                0f,
                                args.Area.Width,
                                args.Area.Height,
                                SciterColorStop.Create(0f, Color.Orange),

                                SciterColorStop.Create(.25f,
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (float)random.NextDouble()),
                                SciterColorStop.Create(.5f,
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue)),
                                SciterColorStop.Create(.75f,
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue)),
                                SciterColorStop.Create(1f, SciterColor.Indigo))

                            .DrawEllipse(0,
                                         random.Next(0),
                                         random.Next(byte.MinValue, args.Area.Width / 2),
                                         random.Next(byte.MinValue, args.Area.Height / 2))

                            .DrawRectangle(random.Next(byte.MinValue, args.Area.Width),
                                           random.Next(byte.MinValue, args.Area.Height),
                                           random.Next(byte.MinValue, args.Area.Width / 2),
                                           random.Next(byte.MinValue, args.Area.Height / 2))

                            .RestoreState();

                            graphics.SaveState()
                            .Translate(args.Area.Left, args.Area.Top)

                            .SetLineGradientLinear(
                                0f,
                                0f,
                                args.Area.Width,
                                args.Area.Height,
                                SciterColorStop.Create(0f, Color.Coral),

                                SciterColorStop.Create(.25f,
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (float)random.NextDouble()),
                                SciterColorStop.Create(.5f,
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue)),
                                SciterColorStop.Create(.75f,
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue),
                                                       (byte)random.Next(byte.MinValue, byte.MaxValue)),
                                SciterColorStop.Create(1f, SciterColor.Magenta))

                            .DrawRectangle(random.Next(byte.MinValue, args.Area.Width),
                                           random.Next(byte.MinValue, args.Area.Height),
                                           random.Next(byte.MinValue, args.Area.Width / 2),
                                           random.Next(byte.MinValue, args.Area.Height / 2))

                            .RestoreState();

                            graphics.RestoreState();
                        }
                    }

                    element?.Window?.Close();

                    return true;
                }));
            });

            _ = new TestableSciterHost(_sciterWindow)
                .SetBehaviorResolver(_mockBehaviorResolver.Object);

            _sciterWindow.Show();

            _sciterWindow.RootElement.AppendElement("body", elm => elm)
            .SetStyleValue("background-color", $"rgb({random.Next(byte.MinValue, byte.MaxValue)}, {random.Next(byte.MinValue, byte.MaxValue)}, {random.Next(byte.MinValue, byte.MaxValue)})")
            .SetStyleValue("behavior", behaviorName);

            SciterPlatform.RunMessageLoop();
        }
Ejemplo n.º 3
0
        protected override bool OnDraw(SciterElement element, DrawArgs args)
        {
            if (args.DrawEvent != DrawEvent.Foreground)
            {
                return(false);
            }

            var scale = args.Area.Width < args.Area.Height ? args.Area.Width / 300.0f : args.Area.Height / 300.0f;

            //if (args.Event == MouseEvents.MouseClick)
            using (var graphics = SciterGraphics.Create(args.Handle))
            {
                graphics.SaveState()

                .Translate(args.Area.Left, args.Area.Top)
                .SetLineWidth(2)
                .SetLineJoin(LineJoinType.Round)
                .SetLineGradientLinear(
                    1, 1, args.Area.Width, args.Area.Height,
                    SciterColorStop.Create(0f, 0, 255, 0, 1f),
                    SciterColorStop.Create(.5f, 255, 255, 0, 1f),
                    SciterColorStop.Create(1f, 255, 0, 0, 1f))
                .SetFillGradientLinear(
                    1, 1, args.Area.Width, args.Area.Height,
                    SciterColorStop.Create(0f, 0, 255, 0, .5f),
                    SciterColorStop.Create(.5f, 255, 255, 0, .5f),
                    SciterColorStop.Create(1f, 255, 0, 0, .5f));

                var path = SciterPath.Create();
                path.MoveTo(_points[0].X, _points[0].Y, false);

                for (var i = 0; i < _points.Count; i++)
                {
                    path.LineTo(_points[i].X, _points[i].Y, false);
                    //path.BezierCurveTo(_points[i].X,_points[i].Y, _points[i].X,_points[i].Y, _points[i].X,_points[i].Y,false);
                }

                graphics.SaveState()
                .DrawPath(path, DrawPathMode.FillOnly)
                .RestoreState();

                graphics.SaveState()
                .DrawPath(path, DrawPathMode.StrokeOnly)
                .RestoreState();

                //graphics.SaveState()
                //    .DrawPolyline(() => { return _points.Select(s => PolylinePoint.Create(s.X, s.Y)); })
                //    .RestoreState();

                //for (int i = 1; i < _points.Count; i++)
                //{
                //
                //    graphics.DrawLine(_points[i-1].X, _points[i-1].Y, _points[i].X, _points[i].Y);
                //}
                //graphics.RestoreState();

                graphics.RestoreState();
            }

            return(true);
        }
Ejemplo n.º 4
0
        private void DrawCirclesClock(
            SciterGraphics graphics,
            SciterRectangle area,
            float scale,
            DateTime timeInfo)
        {
            var markColor   = SciterColor.Parse("#969696");
            var hourColor   = SciterColor.Parse("#969696");
            var minuteColor = SciterColor.Parse("#969696");
            var secondColor = SciterColor.Parse("#64C439");

            graphics
            .SaveState()
            .Translate(area.Left + area.Width / 2.0f, area.Top + area.Height / 2.0f)
            .Scale(scale, scale)
            .Rotate(-Pi / 2)
            .SetLineColor(SciterColor.Transparent)
            .SetLineCap(LineCapType.Square);

            int sec = timeInfo.Second;
            int min = timeInfo.Minute;
            int hr  = timeInfo.Hour;

            hr = hr >= 12 ? hr - 12 : hr;

            // Background
            graphics
            .SaveState()
            .Translate(0, 0)
            .SetLineColor(SciterColor.Transparent)
            .SetFillGradientLinear(0f, 75f, 150f, 75f, SciterColorStop.Create(0f, SciterColor.Parse("#242424")), SciterColorStop.Create(1f, SciterColor.Parse("#545454")))
            .DrawEllipse(0, 0, 150, 150)
            .SetFillColor(SciterColor.Transparent)
            .SetLineColor(minuteColor)
            .DrawEllipse(0, 0, 150, 150)
            .RestoreState();

            graphics
            .SaveState()
            .Translate(-(area.Height / 3.0f), 0)
            .SetLineWidth(2f)
            .SetLineColor(SciterColor.Black)
            .SetFillColor(SciterColor.Parse("#222222"))
            .DrawEllipse(0, 0, 50, 50)
            .SetLineColor(markColor)
            .Using(@ref =>
            {
                for (var i = 0; i < 12; ++i)
                {
                    @ref
                    .Rotate(Pi / 6, 0, 0)
                    .DrawLine(34, 0, 44f, 0);
                }
            })
            .RestoreState();

            graphics
            .SaveState()
            .Translate(-(area.Height / 3.0f), 0)
            .SetLineColor(secondColor)
            .Using(@ref =>
            {
                @ref
                .SetLineWidth(2f)
                .SetLineColor(markColor);

                for (var i = 0; i < 60; ++i)
                {
                    if (i % 5 != 0)
                    {
                        @ref.DrawLine(40f, 0, 44f, 0);
                    }
                    @ref.Rotate(Pi / 30f);
                }
            })
            .RestoreState();

            graphics
            .SaveState()
            .Translate(-(area.Height / 3.0f), 0)
            .Rotate(sec * Pi / 30)
            .SetLineColor(secondColor)
            .SetFillColor(secondColor)
            .SetLineWidth(2f)
            .DrawLine(0, 0, 44, 0)
            .DrawEllipse(0, 0, 3, 3)
            .RestoreState();

            // Hour marks
            graphics
            .SaveState()
            .SetLineColor(markColor)
            .Using(@ref =>
            {
                for (var i = 0; i < 12; ++i)
                {
                    @ref.Rotate(Pi / 6, 0, 0);
                    if (new [] { 2, 5, 8, 11 }.Contains(i))
                    {
                        @ref
                        .SetLineWidth(8f)
                        .DrawLine(125f, 0, 142f, 0);
                    }
                    else
                    {
                        @ref
                        .SetLineWidth(2f)
                        .DrawLine(125f, 0, 145f, 0);
                    }
                }
            })
            .RestoreState();

            // Minute marks
            graphics
            .SaveState()
            .SetLineWidth(2f)
            .SetLineColor(markColor)
            .Using(@ref =>
            {
                for (var i = 0; i < 60; ++i)
                {
                    if (i % 5 != 0)
                    {
                        @ref.DrawLine(138f, 0, 144f, 0);
                    }
                    @ref.Rotate(Pi / 30f);
                }
            })
            .SetLineColor(minuteColor)
            .DrawEllipse(0, 0, 150, 150)
            .RestoreState();

            // draw Hours
            graphics.SaveState()
            .Rotate(hr * (Pi / 6) + (Pi / 360) * min + (Pi / 21600) * sec)
            .SetLineWidth(1f)
            .SetFillGradientLinear(50f, -3f, 50f, 3f,
                                   SciterColorStop.Create(0f, SciterColor.Parse("#c4c4c4")),
                                   SciterColorStop.Create(1f, SciterColor.Parse("#B2B2B2")))
            .DrawPolygon(() => new List <PolygonPoint>()
            {
                PolygonPoint.Create(0f, -3f),
                PolygonPoint.Create(90f, -3f),
                PolygonPoint.Create(100f, 0f),
                PolygonPoint.Create(90f, 3f),
                PolygonPoint.Create(0f, 3f),
            })
            //.SetLineWidth(0f)
            //.DrawEllipse(0, 0, 10, 10)
            .RestoreState();

            // draw Minutes
            graphics
            .SaveState()
            .Rotate((Pi / 30) * min + (Pi / 1800) * sec)
            //.SetLineColor(SciterColor.Transparent)
            //.SetLineWidth(0f)
            //.SetFillColor(SciterColor.Create(0, 0, 0, .5f))
            //.DrawEllipse(0, 0, 10, 10)

            .SetLineWidth(1f)
            .SetLineColor(minuteColor)
            .SetFillColor(minuteColor)
            .SetFillGradientLinear(65, -3f, 65f, 3f,
                                   SciterColorStop.Create(0f, SciterColor.Parse("#c4c4c4")),
                                   SciterColorStop.Create(1f, SciterColor.Parse("#B2B2B2")))
            .DrawPolygon(() => new List <PolygonPoint>()
            {
                PolygonPoint.Create(0, -3),
                PolygonPoint.Create(120, -3),
                PolygonPoint.Create(130, 0),
                PolygonPoint.Create(120, 3),
                PolygonPoint.Create(0, 3),
            })
            .DrawEllipse(0, 0, 8, 8)
            .SetLineColor(SciterColor.Parse("#686868"))
            .SetFillColor(SciterColor.Parse("#2E2E2E"))
            .SetLineWidth(2f)
            .DrawEllipse(0, 0, 4, 4)
            //.SetLineWidth(1f)

            .RestoreState();

            // Outer ring
            graphics
            .SaveState()
            .SetLineColor(minuteColor)
            .DrawEllipse(0, 0, 150, 150)
            .RestoreState();

            graphics.RestoreState();
        }
Ejemplo n.º 5
0
        protected override bool OnDraw(SciterElement se, DrawArgs args)
        {
            if (args.DrawEvent != DrawEvent.Content)
            {
                return(false);
            }

            se.Attributes.TryGetValue("fill", out var fillStyle);

            var random  = new Random(50);
            var padding = 8;

            using (var graphics = SciterGraphics.Create(args.Handle))
            {
                for (var i = 0; i < 50; i++)
                {
                    var lineX1   = random.Next(padding, args.Area.Width - padding);
                    var lineY1   = random.Next(padding, args.Area.Height - padding);
                    var lineX2   = random.Next(padding, args.Area.Width - padding);
                    var lineY2   = random.Next(padding, args.Area.Height - padding);
                    var alpha    = (byte)random.Next(byte.MinValue, byte.MaxValue);
                    var lineCap  = (LineCapType)random.Next((int)LineCapType.Butt, ((int)LineCapType.Round) + 1);
                    var lineJoin = (LineJoinType)random.Next((int)LineJoinType.Miter, ((int)LineJoinType.MiterOrBevel) + 1);

                    var lineColorR = (byte)random.Next(byte.MinValue, byte.MaxValue);
                    var lineColorG = (byte)random.Next(byte.MinValue, byte.MaxValue);
                    var lineColorB = (byte)random.Next(byte.MinValue, byte.MaxValue);

                    var lineColorWidth = random.Next(2, 10);

                    switch ((fillStyle ?? string.Empty).ToLowerInvariant())
                    {
                    case "linear-gradient":
                        graphics.SaveState()
                        .Translate(args.Area.Left, args.Area.Top)
                        .SetLineWidth(lineColorWidth)
                        .SetLineCap(lineCap)
                        .SetLineJoin(lineJoin)
                        .SetLineGradientLinear(
                            lineX1, lineY1, lineX2, lineY2,
                            SciterColorStop.Create(0f, 0, 255, 0, alpha),
                            SciterColorStop.Create(.5f, 255, 255, 0, alpha),
                            SciterColorStop.Create(1f, 255, 0, 0, alpha))
                        .DrawLine(lineX1, lineY1, lineX2, lineY2)

                        .RestoreState();
                        break;

                    case "alt-linear-gradient":
                        graphics.SaveState()
                        .Translate(args.Area.Left, args.Area.Top)
                        .SetLineWidth(lineColorWidth)
                        .SetLineCap(lineCap)
                        .SetLineJoin(lineJoin)
                        .SetLineGradientLinear(
                            0f,
                            0f,
                            args.Area.Width,
                            args.Area.Height,
                            SciterColorStop.Create(0f, 0, 255, 0, alpha),
                            SciterColorStop.Create(.5f, 255, 255, 0, alpha),
                            SciterColorStop.Create(1f, 255, 0, 0, alpha))
                        .DrawLine(lineX1, lineY1, lineX2, lineY2)

                        //.SetFillGradientLinear(
                        //	0f,
                        //	0f,
                        //	args.Area.Width,
                        //	args.Area.Height,
                        //	SciterColorStop.Create(0f, 0, 255, 0, alpha),
                        //	SciterColorStop.Create(.5f, 255, 255, 0, alpha),
                        //	SciterColorStop.Create(1f, 255, 0, 0, alpha))
                        //.DrawRectangle(lineX1, lineY1, lineX2, lineY2)

                        .RestoreState();
                        break;

                    default:
                        graphics.SaveState()
                        .Translate(args.Area.Left, args.Area.Top)
                        .SetLineWidth(lineColorWidth)
                        .SetLineColor(
                            lineColorR,
                            lineColorG,
                            lineColorB,
                            alpha)
                        .SetLineCap(lineCap)
                        .SetLineJoin(lineJoin)
                        .DrawLine(lineX1, lineY1, lineX2, lineY2)

                        .RestoreState();
                        break;
                    }
                }
            }

            return(true);
        }