protected override bool OnDraw(SciterElement se, DrawArgs args)
        {
            if (args.DrawEvent == _drawEvent)
            {
                using (SKBitmap bitmap = new SKBitmap(width: args.Area.Width, height: args.Area.Height, colorType: SKColorType.Rgba8888, alphaType: SKAlphaType.Premul))
                    using (SKCanvas canvas = new SKCanvas(bitmap))
                        using (SKPaint paint = new SKPaint())
                        {
                            paint.IsAntialias = true;
                            canvas.Clear();

                            paint.Shader = SKShader.CreateRadialGradient(
                                new SKPoint(args.Area.Width / 2f, args.Area.Height / 2f),
                                Math.Max(args.Area.Width, args.Area.Height) / 10f,
                                new SKColor[] { SKColor.Parse("#77FFFFFF"), SKColor.Parse("#33FFFFFF"), SKColor.Parse("#00000000") },
                                null,
                                SKShaderTileMode.Mirror);

                            canvas.DrawRect(new SKRect(0, 0, args.Area.Width, args.Area.Height), paint);

                            var img = bitmap.ToSciterImage();
                            var gfx = SciterGraphics.Create(args.Handle);
                            gfx.BlendImage(img, args.Area.Left, args.Area.Top);

                            //return true;
                        }
            }

            return(base.OnDraw(se, args));
        }
Example #2
0
        protected override bool OnDraw(SciterElement se, DrawArgs args)
        {
            if (args.DrawEvent == DrawEvent.Content)
            {
                using (var graphics = SciterGraphics.Create(args.Handle))
                {
                    graphics.SaveState()
                    .Translate(args.Area.Left, args.Area.Top)
                    .SetLineColor(SciterColor.Create(0, 255, 255, .75f))
                    .SetFillColor(SciterColor.Create(127, 78, 194, .75f))
                    .SetLineWidth(4)
                    .DrawPolygon(
                        PolygonPoint.Create(51.0f, 58.0f),
                        PolygonPoint.Create(70.0f, 28.0f),
                        PolygonPoint.Create(48.0f, 1.0f),
                        PolygonPoint.Create(15.0f, 14.0f),
                        PolygonPoint.Create(17.0f, 49.0f)
                        )
                    .DrawEllipse(200, 50, 50, 50)
                    .RestoreState();
                }

                return(true);
            }
            return(false);
        }
        public static SciterGraphics DrawPolygon(this SciterGraphics graphics, Func <IEnumerable <PolygonPoint> > pointsFunc)
        {
            if (pointsFunc == null)
            {
                throw new ArgumentNullException(nameof(pointsFunc), @"Cannot be null.");
            }

            return(graphics?.DrawPolygon(points: pointsFunc.Invoke()?.ToArray()));
        }
        public static bool TryDrawPolyline(this SciterGraphics graphics, Func <IEnumerable <PolylinePoint> > pointsFunc)
        {
            if (pointsFunc == null)
            {
                throw new ArgumentNullException(nameof(pointsFunc), @"Cannot be null.");
            }

            return(graphics?.TryDrawPolyline(points: pointsFunc.Invoke()) == true);
        }
        public static SciterGraphics DrawPolygon(this SciterGraphics graphics, IEnumerable <PolygonPoint> points)
        {
            if (points?.Any() != true)
            {
                throw new ArgumentNullException(nameof(points), @"Cannot be null.");
            }

            graphics?.DrawPolygonInternal(points: points);
            return(graphics);
        }
Example #6
0
        public static bool TryCreate(SciterValue sciterValue, out SciterGraphics sciterGraphics)
        {
            var value  = sciterValue.ToVALUE();
            var result = GraphicsApi.ValueUnWrapGfx(ref value, out var graphicsHandle)
                         .IsOk();

            sciterGraphics = result ? new SciterGraphics(graphicsHandle: graphicsHandle) : default;

            return(result);
        }
Example #7
0
        protected override bool OnDraw(SciterElement se, DrawArgs args)
        {
            if (args.DrawEvent != DrawEvent.Content)
            {
                return(false);
            }

            var txt = SciterText.CreateForElement("hi", se);

            using (var g = SciterGraphics.Create(args.Handle))
            {
                g.DrawText(txt, 0, 0, 1);
            }

            return(true);
        }
        protected override bool OnDraw(SciterElement se, DrawArgs args)
        {
            if (args.DrawEvent == _drawEvent)
            {
                using (var bitmap = new SKBitmap(width: args.Area.Width, height: args.Area.Height, colorType: SKColorType.Rgba8888, alphaType: SKAlphaType.Premul))
                    using (var canvas = new SKCanvas(bitmap: bitmap))
                    {
                        canvas.Clear(color: SKColor.Parse("#445F59").WithAlpha(255));

                        var img = bitmap.ToSciterImage();
                        var gfx = SciterGraphics.Create(args.Handle);
                        gfx.BlendImage(img, args.Area.Left, args.Area.Top);
                    }
            }

            return(base.OnDraw(se, args));
        }
Example #9
0
        protected override bool OnDraw(SciterElement se, DrawArgs args)
        {
            if (args.DrawEvent == DrawEvent.Content)
            {
                using (var graphics = SciterGraphics.Create(args.Handle))
                {
                    graphics
                    .SaveState()
                    .Translate(args.Area.Left, args.Area.Top)
                    .SetLineColor(0, 255, 255, .75f)
                    .SetFillColor(127, 78, 194, .75f)
                    .SetLineWidth(4)
                    .DrawPolygon(
                        PolygonPoint.Create(51.0f, 58.0f),
                        PolygonPoint.Create(70.0f, 28.0f),
                        PolygonPoint.Create(48.0f, 1.0f),
                        PolygonPoint.Create(15.0f, 14.0f),
                        PolygonPoint.Create(17.0f, 49.0f)
                        )
                    .SetLineWidth(2)
                    .SetLineColor(SciterColor.IndianRed)
                    .SetFillColor(SciterColor.CornflowerBlue)
                    .DrawRectangle(25, 125, 75, 175)
                    .SetLineColor(SciterColor.Goldenrod)
                    .DrawLine(50, 125, 50, 175)
                    .DrawLine(25, 150, 75, 150)

                    .SetLineWidth(0)
                    .SetLineColor(127, 78, 194, .75f)
                    .SetFillColor(0, 255, 255, .75f)
                    .DrawEllipse(200, 50, 50, 50)
                    .SetFillColor(127, 78, 194, .75f)
                    .DrawEllipse(225, 100, 50, 50)
                    .SetFillColor(255, 0, 0, 127)
                    .DrawEllipse(175, 100, 50, 50)

                    .RestoreState();
                }

                return(true);
            }
            return(false);
        }
Example #10
0
        protected override bool OnDraw(SciterElement se, DrawArgs args)
        {
            if (args.DrawEvent == DrawEvent.Foreground)
            {
                using (SKBitmap bitmap = new SKBitmap(width: args.Area.Width, height: args.Area.Height, colorType: SKColorType.Rgba8888, alphaType: SKAlphaType.Premul))
                    using (SKCanvas canvas = new SKCanvas(bitmap))
                        using (SKPaint paint = new SKPaint())
                        {
                            canvas.Clear();

                            paint.IsAntialias = true;
                            paint.TextSize    = 14f;

                            var hasAltText = se.Attributes.TryGetValue("alt", out var altText);

                            if (hasAltText)
                            {
                                SKRect textBounds = new SKRect();
                                paint.MeasureText(altText, ref textBounds);

                                paint.Color = new SKColor(0, 0, 0, 127);
                                canvas.DrawRect(bitmap.Width, bitmap.Height, -(textBounds.Width + 10),
                                                -(textBounds.Height + 10), paint);

                                paint.Color     = new SKColor(255, 255, 255);
                                paint.TextAlign = SKTextAlign.Right;
                                canvas.DrawText(altText, bitmap.Width - 5, bitmap.Height - 5, paint);
                            }

                            var img = bitmap.ToSciterImage();
                            var gfx = SciterGraphics.Create(args.Handle);
                            gfx.BlendImage(img, args.Area.Left, args.Area.Top);
                        }
            }

            // Resume normal drawing
            return(false);
        }
 public static bool TryScale(this SciterGraphics graphics, float x, float y)
 {
     return(graphics?.TryScaleInternal(x: x, y: y) == true);
 }
 public static bool TryDrawLine(this SciterGraphics graphics, float x1, float y1, float x2, float y2)
 {
     return(graphics?.TryDrawLineInternal(x1: x1, y1: y1, x2: x2, y2: y2) == true);
 }
 public static SciterGraphics DrawLine(this SciterGraphics graphics, float x1, float y1, float x2, float y2)
 {
     graphics?.DrawLineInternal(x1: x1, y1: y1, x2: x2, y2: y2);
     return(graphics);
 }
 public static SciterGraphics Using(this SciterGraphics graphics, Action <SciterGraphics> action)
 {
     action?.Invoke(graphics);
     return(graphics);
 }
 public static SciterGraphics DrawText(this SciterGraphics graphics, SciterText text, float px, float py, uint position)
 {
     graphics?.DrawTextInternal(text: text, px: px, py: py, position: position);
     return(graphics);
 }
 public static SciterGraphics SkewInternal(this SciterGraphics graphics, float dx, float dy)
 {
     graphics?.SkewInternal(dx: dx, dy: dy);
     return(graphics);
 }
 public static bool TryPopClip(this SciterGraphics graphics)
 {
     return(graphics?.TryPopClipInternal() == true);
 }
 public static SciterGraphics PushClipPath(this SciterGraphics graphics, SciterPath path, float opacity = 1)
 {
     graphics?.PushClipPathInternal(path: path, opacity: opacity);
     return(graphics);
 }
 public static bool TryPushClipPath(this SciterGraphics graphics, SciterPath path, float opacity = 1)
 {
     return(graphics?.TryPushClipPathInternal(path: path, opacity: opacity) == true);
 }
 public static bool TryPushClipBox(this SciterGraphics graphics, float x1, float y1, float x2, float y2, float opacity = 1)
 {
     return(graphics?.TryPushClipBoxInternal(x1: x1, y1: y1, x2: x2, y2: y2, opacity: opacity) == true);
 }
 public static SciterGraphics PushClipBox(this SciterGraphics graphics, float x1, float y1, float x2, float y2, float opacity = 1)
 {
     graphics?.PushClipBoxInternal(x1: x1, y1: y1, x2: x2, y2: y2, opacity: opacity);
     return(graphics);
 }
 public static bool TryDrawText(this SciterGraphics graphics, SciterText text, float px, float py, uint position)
 {
     return(graphics?.TryDrawTextInternal(text: text, px: px, py: py, position: position) == true);
 }
 public static SciterGraphics DrawPolygon(this SciterGraphics graphics, params PolygonPoint[] points)
 {
     return(graphics?.DrawPolygon(points: points?.AsEnumerable()));
 }
 public static SciterGraphics SaveState(this SciterGraphics graphics)
 {
     graphics?.SaveStateInternal();
     return(graphics);
 }
 public static SciterGraphics Scale(this SciterGraphics graphics, float x, float y)
 {
     graphics?.ScaleInternal(x: x, y: y);
     return(graphics);
 }
 public static SciterGraphics RestoreState(this SciterGraphics graphics)
 {
     graphics?.RestoreStateInternal();
     return(graphics);
 }
 public static bool TryTranslate(this SciterGraphics graphics, float cx, float cy)
 {
     return(graphics?.TryTranslateInternal(cx: cx, cy: cy) == true);
 }
 public static bool TryRestoreState(this SciterGraphics graphics)
 {
     return(graphics?.TryRestoreStateInternal() == true);
 }
 public static SciterGraphics PopClipInternal(this SciterGraphics graphics)
 {
     graphics?.PopClipInternal();
     return(graphics);
 }
 public static bool TrySkewInternal(this SciterGraphics graphics, float dx, float dy)
 {
     return(graphics?.TrySkewInternal(dx: dx, dy: dy) == true);
 }