Пример #1
0
 public override void RenderGeometry(CanvasControl canvas)
 {
     _canvas  = canvas;
     Geometry = CanvasGeometry.CreateRectangle(_canvas, 0f, 0f, 0f, 0f);
     Brush    = new CanvasSolidColorBrush(canvas, Colour);
     base.RenderGeometry(canvas);
 }
Пример #2
0
        private CanvasSolidColorBrush GetSolidColorBrush(CanvasVirtualControl resourceCreator, string hex)
        {
            hex = hex.Replace("#", string.Empty);
            byte a      = 255;
            int  index3 = 0;

            if (hex.Length == 8)
            {
                a       = (byte)Convert.ToUInt32(hex.Substring(index3, 2), 16);
                index3 += 2;
            }

            byte r = (byte)Convert.ToUInt32(hex.Substring(index3, 2), 16);

            index3 += 2;

            byte g = (byte)Convert.ToUInt32(hex.Substring(index3, 2), 16);

            index3 += 2;

            byte b = (byte)Convert.ToUInt32(hex.Substring(index3, 2), 16);

            var color = Color.FromArgb(a, r, g, b);

            if (_brushLookup.TryGetValue(color, out CanvasSolidColorBrush brush))
            {
                return(brush);
            }

            var newBrush = new CanvasSolidColorBrush(resourceCreator, color);

            _brushLookup.Add(color, newBrush);

            return(newBrush);
        }
Пример #3
0
        //CanvasBitmap _brush_image;
        //public async void InitImageBrush()
        //{
        //    if (DrawingColor == Colors.Transparent)
        //    {
        //        if (_brush_image == null)
        //        {
        //            CanvasDevice cd = CanvasDevice.GetSharedDevice();
        //            _brush_image = await CanvasBitmap.LoadAsync(cd, new Uri("ms-appx:///Images/default_back.png"));
        //        }
        //    }
        //}
        public void Draw(CanvasDrawingSession graphics, float scale)
        {
            if (_points != null && _points.Count > 0)
            {
                ICanvasBrush brush;
                //if (DrawingColor == Colors.Transparent)
                //{
                //    if (_brush_image == null)
                //        return;
                //    //brush = new CanvasImageBrush(graphics, _brush_image);
                //}
                //else
                //{
                //    brush = new CanvasSolidColorBrush(graphics, DrawingColor);
                //}
                brush = new CanvasSolidColorBrush(graphics, DrawingColor);

                if (_points.Count == 1)
                {
                    graphics.DrawLine((float)_points[0].X * scale, (float)_points[0].Y * scale, (float)_points[0].X * scale, (float)_points[0].Y * scale, brush, DrawingSize * scale);
                }
                else
                {
                    var style = new CanvasStrokeStyle();
                    style.DashCap  = CanvasCapStyle.Round;
                    style.StartCap = CanvasCapStyle.Round;
                    style.EndCap   = CanvasCapStyle.Round;
                    for (int i = 0; i < _points.Count - 1; ++i)
                    {
                        graphics.DrawLine((float)_points[i].X * scale, (float)_points[i].Y * scale, (float)_points[i + 1].X * scale, (float)_points[i + 1].Y * scale, brush, DrawingSize * scale, style);
                    }
                }
            }
        }
Пример #4
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="device">ICanvasResourceCreator</param>
 /// <param name="strokeColor">Color of the stroke</param>
 /// <param name="strokeWidth">Width of the stroke</param>
 /// <param name="strokeStyle">Style of the stroke</param>
 public CanvasStroke(ICanvasResourceCreator device, Color strokeColor, float strokeWidth,
                     CanvasStrokeStyle strokeStyle)
 {
     Brush = new CanvasSolidColorBrush(device, strokeColor);
     Width = strokeWidth;
     Style = strokeStyle;
 }
Пример #5
0
        public void Draw(CanvasDrawingSession graphics)
        {
            if (_points == null || _points.Count == 0)
            {
                return;
            }

            var brush = new CanvasSolidColorBrush(graphics, drawingColor);

            if (_points.Count == 1)
            {
                graphics.DrawLine((float)_points[0].X, (float)_points[0].Y, (float)_points[0].X, (float)_points[0].Y, brush, drawingSize);
                return;
            }
            var style = new CanvasStrokeStyle()
            {
                DashCap  = CanvasCapStyle.Round,
                StartCap = CanvasCapStyle.Round,
                EndCap   = CanvasCapStyle.Round
            };

            for (int i = 0; i < _points.Count - 1; ++i)
            {
                graphics.DrawLine((float)_points[i].X, (float)_points[i].Y,
                                  (float)_points[i + 1].X, (float)_points[i + 1].Y,
                                  brush, drawingSize, style);
            }
        }
Пример #6
0
 private ICanvasBrush CreatePaint(CanvasDrawingSession session, Rect area, SvgPaint paint, SvgNumber?opacity)
 {
     if (paint == null || paint.PaintType == SvgPaintType.RgbColor)
     {
         var alpha = (byte)(255.0F * (opacity?.Value ?? 1.0F));
         var brush = new CanvasSolidColorBrush(
             this.ResourceCreator,
             paint != null
                                         ? Color.FromArgb(alpha, paint.RgbColor.Red, paint.RgbColor.Green, paint.RgbColor.Blue)
                                         : Color.FromArgb(alpha, 0, 0, 0));
         this.DisposableObjects.Add(brush);
         return(brush);
     }
     if (paint.PaintType == SvgPaintType.Uri && paint.Uri[0] == '#')
     {
         var key  = paint.Uri.Substring(1);
         var grad = this.TargetDocument.GetElementById(key);
         if (grad.GetType() == typeof(SvgLinearGradientElement))
         {
             return(this.CreateLinearGradient(session, area, (SvgLinearGradientElement)grad));
         }
         if (grad.GetType() == typeof(SvgRadialGradientElement))
         {
             return(this.CreateRadialGradient(session, area, (SvgRadialGradientElement)grad));
         }
     }
     throw new NotImplementedException();
 }
        public static CanvasRenderTarget CreateFromSharedDevice(ICanvasResourceCreator resourceCreator, double width, double height)
        {
            var device = CanvasDevice.GetSharedDevice();
            var target = new CanvasRenderTarget(device, (float)width, (float)height, 96);

            using (var session = target.CreateDrawingSession())
            {
                session.Clear(Colors.Transparent);
                var pathBuilder = new CanvasPathBuilder(session);
                pathBuilder.BeginFigure(170, 90, CanvasFigureFill.Default);
                pathBuilder.AddCubicBezier(new Vector2(130, 100), new Vector2(130, 150), new Vector2(230, 150));
                pathBuilder.AddCubicBezier(new Vector2(250, 180), new Vector2(320, 180), new Vector2(340, 150));
                pathBuilder.AddCubicBezier(new Vector2(420, 150), new Vector2(420, 120), new Vector2(390, 100));
                pathBuilder.AddCubicBezier(new Vector2(430, 40), new Vector2(370, 30), new Vector2(340, 50));
                pathBuilder.AddCubicBezier(new Vector2(320, 5), new Vector2(250, 20), new Vector2(250, 50));
                pathBuilder.AddCubicBezier(new Vector2(200, 5), new Vector2(150, 20), new Vector2(170, 80));
                pathBuilder.EndFigure(CanvasFigureLoop.Closed);
                var cloudFigure = CanvasGeometry.CreatePath(pathBuilder);

                session.FillGeometry(cloudFigure, Color.FromArgb((byte)(255 * 0.7), 0, 255, 0));
                var strokeColor = new CanvasSolidColorBrush(session, Color.FromArgb(255, 0, 0, 0));
                session.DrawGeometry(cloudFigure, strokeColor, 12);
                session.FillCircle(500, 20, 20, Colors.White);
            }
            return(target);
        }
Пример #8
0
        /// <summary>
        /// Draws a healthbar above the character.
        /// </summary>
        /// <param name="draw">Canvas session to be used for drawing the rectangle and other decorative stuff.</param>
        void DrawHealthbar(CanvasDrawingSession draw)
        {
            var rectangleHeight = Width / 30;

            var rect = new Windows.Foundation.Rect();

            rect.X      = X;
            rect.Width  = Width;
            rect.Y      = Y - rectangleHeight / 2;
            rect.Height = rectangleHeight;

            int healthPercent = Health * 100 / MaxHealth;

            ICanvasBrush brush;

            if (healthPercent > 80)
            {
                brush = new CanvasSolidColorBrush(draw, Colors.Green);
            }
            else if (healthPercent > 30)
            {
                brush = new CanvasSolidColorBrush(draw, Colors.Yellow);
            }
            else
            {
                brush = new CanvasSolidColorBrush(draw, Colors.Red);
            }

            draw.DrawRoundedRectangle(rect, 5, 5, brush);

            rect.Width = ((float)healthPercent / 100) * Width;

            draw.FillRoundedRectangle(rect, 5, 5, brush);
        }
        private void AnimatedControl_CreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            // Initialize the brushes.
            backgroundDefaultBrush = CreateRadialGradientBrush(sender,
                                                               Color.FromArgb(0x00, 0x6E, 0xEF, 0xF8), Color.FromArgb(0x4D, 0x6E, 0xEF, 0xF8));
            backgroundAnswerCorrectBrush = CreateRadialGradientBrush(sender,
                                                                     Color.FromArgb(0x00, 0x42, 0xC9, 0xC5), Color.FromArgb(0x4D, 0x42, 0xC9, 0xC5));
            backgroundAnswerIncorrectBrush = CreateRadialGradientBrush(sender,
                                                                       Color.FromArgb(0x00, 0xDE, 0x01, 0x99), Color.FromArgb(0x4D, 0xDE, 0x01, 0x99));
            borderDefaultBrush  = new CanvasSolidColorBrush(sender, Color.FromArgb(0xFF, 0x6E, 0xEF, 0xF8));
            borderGradientBrush = new CanvasLinearGradientBrush(sender,
                                                                Color.FromArgb(0xFF, 0x0F, 0x56, 0xA4), Color.FromArgb(0xFF, 0x6E, 0xEF, 0xF8))
            {
                StartPoint = new Vector2(centerPoint.X - radius, centerPoint.Y),
                EndPoint   = new Vector2(centerPoint.X + radius, centerPoint.Y)
            };
            borderAnswerCorrectBrush   = new CanvasSolidColorBrush(sender, Color.FromArgb(0xFF, 0x42, 0xC9, 0xC5));
            borderAnswerIncorrectBrush = new CanvasSolidColorBrush(sender, Color.FromArgb(0xFF, 0xDE, 0x01, 0x99));

            // Calculate the text position for vertical centering to account for the
            // fact that text is not vertically centered within its layout bounds.
            var textLayout        = new CanvasTextLayout(sender, "0123456789", textFormat, 0, 0);
            var drawMidpoint      = (float)(textLayout.DrawBounds.Top + (textLayout.DrawBounds.Height / 2));
            var layoutMidpoint    = (float)(textLayout.LayoutBounds.Top + (textLayout.LayoutBounds.Height / 2));
            var textPositionDelta = drawMidpoint - layoutMidpoint;

            textPosition = new Vector2(centerPoint.X, centerPoint.Y - textPositionDelta);
        }
Пример #10
0
        public void Draw(CanvasDrawingSession graphics)
        {
            CanvasDevice device  = CanvasDevice.GetSharedDevice();
            var          builder = new CanvasPathBuilder(device);
            var          brush   = new CanvasSolidColorBrush(graphics, drawingColor);

            graphics.DrawEllipse(centerX, centerY, radiusX, radiusY, brush, drawingSize);
        }
Пример #11
0
        // New Ulisses 03-10-2020 - Copied from XLinearGradientBrush.cs
#if UWP
        internal override ICanvasBrush RealizeCanvasBrush()
        {
            ICanvasBrush brush;

            brush = new CanvasSolidColorBrush(CanvasDevice.GetSharedDevice(), Colors.RoyalBlue);

            return(brush);
        }
Пример #12
0
        public void Draw(CanvasDrawingSession graphics)
        {
            CanvasDevice device  = CanvasDevice.GetSharedDevice();
            var          builder = new CanvasPathBuilder(device);
            var          brush   = new CanvasSolidColorBrush(graphics, drawingColor);

            graphics.DrawRectangle(x, y, width, height, brush, drawingSize);
        }
Пример #13
0
        /// <summary>
        /// title bar design
        /// </summary>
        /// <param name="dp"></param>
        /// <param name="sr">log panel drawing area</param>
        /// <returns></returns>
        protected virtual ScreenY drawTitleBar(DrawProperty dp, ScreenRect sr)
        {
            var _bd         = new CanvasSolidColorBrush(dp.Canvas, Color.FromArgb(64, 0, 0, 0));
            var titleHeight = 8;
            var w3          = sr.Width / 4;
            var pst         = new ScreenPos[] { ScreenPos.From(sr.LT.X, sr.LT.Y + titleHeight + 16), ScreenPos.From(sr.LT.X, sr.LT.Y), ScreenPos.From(sr.RB.X, sr.LT.Y), };
            var psb         = new ScreenPos[] { ScreenPos.From(sr.RB.X, sr.LT.Y + titleHeight), ScreenPos.From(sr.RB.X - w3, sr.LT.Y + titleHeight + 2), ScreenPos.From(sr.RB.X - w3 * 2, sr.LT.Y + titleHeight + 8), ScreenPos.From(sr.RB.X - w3 * 3, sr.LT.Y + titleHeight + 16), ScreenPos.From(sr.LT.X, sr.LT.Y + titleHeight + 16), };
            var ps          = pst.Union(psb).ToList();
            var path        = new CanvasPathBuilder(dp.Canvas);

            path.BeginFigure(ps[0]);
            for (var i = 1; i < ps.Count; i++)
            {
                path.AddLine(ps[i]);
            }
            path.EndFigure(CanvasFigureLoop.Closed);
            var geo = CanvasGeometry.CreatePath(path);

            dp.Graphics.FillGeometry(geo, _bd);

            // edge highlight
            for (var i = 1; i < pst.Length; i++)
            {
                dp.Graphics.DrawLine(pst[i - 1], pst[i], Color.FromArgb(96, 255, 255, 255));
            }
            // edge shadow
            for (var i = 1; i < psb.Length; i++)
            {
                dp.Graphics.DrawLine(psb[i - 1], psb[i], Color.FromArgb(96, 0, 0, 0));
            }

            // title bar design
            var btr = sr.Clone();

            btr.RB = ScreenPos.From(btr.LT.X + ScreenX.From(24), btr.LT.Y + ScreenY.From(12));
            btr    = btr + ScreenPos.From(4, 4);
            var imgttl = Assets.Image("LogPanelTitileDesign");

            if (imgttl != null)
            {
                dp.Graphics.DrawImage(imgttl, btr.LT + ScreenSize.From(-3, -14));
            }
            btr = btr + ScreenX.From(50);

            // title filter buttons
            var btn1 = Assets.Image("btnLogPanel");
            var btn0 = Assets.Image("btnLogPanelOff");

            if (btn1 != null && btn0 != null)
            {
                var ctfb = new CanvasTextFormat
                {
                    FontFamily = "Arial",
                    FontSize   = 10.0f,
                    FontWeight = FontWeights.Normal,
                    FontStyle  = FontStyle.Italic,
                };
                foreach ((var lv, var caption) in new (LLV, string)[] { (LLV.ERR, "e"), (LLV.WAR, "w"), (LLV.INF, "i"), (LLV.DEV, "d") })
Пример #14
0
        private ICanvasBrush CreateSolidBrush(ICanvasResourceCreator resourceCreator)
        {
            var brush = new CanvasSolidColorBrush(resourceCreator, Color)
            {
                Opacity = Opacity
            };

            return(brush);
        }
Пример #15
0
        public void DrawLine(Pen pen, Point startPoint, Point endPoint)
        {
            var canvasSolidColorBrush = new CanvasSolidColorBrush(drawingSession, pen.Brush.Color.ToWin2D());
            var start        = ((Vector)startPoint).ToWin2D();
            var end          = ((Vector)endPoint).ToWin2D();
            var penThickness = (float)pen.Thickness;

            drawingSession.DrawLine(start, end, canvasSolidColorBrush, penThickness);
        }
Пример #16
0
        private CanvasSolidColorBrush CreateColor(CanvasDrawingSession session, SvgColor color)
        {
            var brush = new CanvasSolidColorBrush(this.ResourceCreator,
                                                  color != null
                                        ? Color.FromArgb(0xff, color.RgbColor.Red, color.RgbColor.Green, color.RgbColor.Blue)
                                        : Color.FromArgb(0xff, 0, 0, 0));

            this.DisposableObjects.Add(brush);
            return(brush);
        }
        public async void DrawBoxes(IRandomAccessStream imageStream, List <CubicBoundingBox> boxes)
        {
            var device = canvasDevice;

            var image = await CanvasBitmap.LoadAsync(device, imageStream);

            var offscreen = canvasRenderTarget;

            //CanvasSolidColorBrush brush = new CanvasSolidColorBrush(device, Windows.UI.Color.FromArgb(255, 255, 0, 0));
            using (var ds = offscreen.CreateDrawingSession())
            {
                ds.DrawImage(image);
                if (boxes != null)
                {
                    foreach (var box in boxes)
                    {
                        CanvasSolidColorBrush brush = new CanvasSolidColorBrush(device, Colors.Red);

                        var points = (from p in box.ControlPoint
                                      select new Vector2((float)(p.X * image.Bounds.Width), (float)(p.Y * image.Bounds.Height))).ToArray();

                        ds.DrawLine(points[0], points[1], brush);
                        ds.DrawLine(points[0], points[4], brush);
                        ds.DrawLine(points[1], points[5], brush);
                        ds.DrawLine(points[4], points[5], brush);
                        ds.DrawLine(points[5], points[7], brush);
                        ds.DrawLine(points[1], points[3], brush);
                        ds.DrawLine(points[4], points[6], brush);
                        ds.DrawLine(points[0], points[2], brush);
                        ds.DrawLine(points[2], points[6], brush);
                        ds.DrawLine(points[2], points[3], brush);
                        ds.DrawLine(points[3], points[7], brush);
                        ds.DrawLine(points[7], points[6], brush);
                    }
                }
            }

            BitmapSource bitmapImageSouce;

            using (var stream = new InMemoryRandomAccessStream())
            {
                await offscreen.SaveAsync(stream, CanvasBitmapFileFormat.Jpeg);

                bitmapImageSouce = new BitmapImage();

                stream.Seek(0);
                await bitmapImageSouce.SetSourceAsync(stream);
            }

            await Window.Current.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                OutputImage.Source = bitmapImageSouce;
            });
        }
Пример #18
0
        public async Task <Size> DrawOutlineText(int dim, string font, string text, string saved_file)
        {
            Size         size   = new Size();
            CanvasDevice device = CanvasDevice.GetSharedDevice();

            using (CanvasRenderTarget offscreen = new CanvasRenderTarget(device, dim, dim, 96, Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized,
                                                                         CanvasAlphaMode.Premultiplied))
            {
                using (CanvasDrawingSession ds = offscreen.CreateDrawingSession())
                {
                    ds.Clear(ColorHelper.FromArgb(255, 255, 255, 255));

                    Color text_color = Colors.White;

                    CanvasSolidColorBrush brush  = new CanvasSolidColorBrush(device, text_color);
                    CanvasTextFormat      format = new CanvasTextFormat();
                    format.FontFamily = font;
                    format.FontStyle  = Windows.UI.Text.FontStyle.Normal;
                    format.FontSize   = 60;
                    format.FontWeight = Windows.UI.Text.FontWeights.Bold;

                    float            layoutWidth  = dim;
                    float            layoutHeight = dim;
                    CanvasTextLayout textLayout   = new CanvasTextLayout(device, text, format, layoutWidth, layoutHeight);
                    CanvasGeometry   geometry     = CanvasGeometry.CreateText(textLayout);

                    CanvasStrokeStyle stroke = new CanvasStrokeStyle();
                    stroke.DashStyle = CanvasDashStyle.Solid;
                    stroke.DashCap   = CanvasCapStyle.Round;
                    stroke.StartCap  = CanvasCapStyle.Round;
                    stroke.EndCap    = CanvasCapStyle.Round;
                    stroke.LineJoin  = CanvasLineJoin.Round;

                    ds.DrawGeometry(geometry, 10.0f, 10.0f, Colors.Black, 10.0f, stroke);

                    ds.FillGeometry(geometry, 10.0f, 10.0f, brush);
                }
                Windows.Storage.StorageFolder storageFolder =
                    Windows.Storage.ApplicationData.Current.TemporaryFolder;
                string saved_file2 = "\\";
                saved_file2 += saved_file;
                await offscreen.SaveAsync(storageFolder.Path + saved_file2);

                imgOutlineText.Source = new BitmapImage(new Uri(storageFolder.Path + saved_file2));

                using (CanvasDrawingSession ds = offscreen.CreateDrawingSession())
                {
                    ds.Clear(Colors.White);
                }

                return(size);
            }
        }
Пример #19
0
        public ICanvasBrush Brush(Color color, float opacity)
        {
            return(cachedColors.GetOrAddDefault(new Tuple <Color, float>(color, opacity), x =>
            {
                var brush = new CanvasSolidColorBrush(canvas.Device, color)
                {
                    Opacity = opacity
                };

                return brush;
            }));
        }
        /// <summary>
        /// Creates a GeometrySurface having the given size, geometry and foreground brush with
        /// MaskMode as False.
        /// </summary>
        /// <param name="size">Size of the mask</param>
        /// <param name="geometry">Geometry of the mask</param>
        /// <param name="foregroundBrush">The brush with which the geometry has to be filled</param>
        /// <returns>IGeometrySurface</returns>
        public IGeometrySurface CreateGeometrySurface(Size size, CanvasGeometry geometry, ICanvasBrush foregroundBrush)
        {
            // Create the background brush
            var backgroundBrush = new CanvasSolidColorBrush(Device, Colors.Transparent);
            // Initialize the mask
            IGeometrySurface mask = new GeometrySurface(this, size, geometry, foregroundBrush, backgroundBrush);

            // Render the mask
            mask.Redraw();

            return(mask);
        }
Пример #21
0
        public void Draw(CanvasDrawingSession graphics)
        {
            CanvasDevice device      = CanvasDevice.GetSharedDevice();
            var          builder     = new CanvasPathBuilder(device);
            var          brush       = new CanvasSolidColorBrush(graphics, drawingColor);
            var          strokeStyle = new CanvasStrokeStyle()
            {
                DashStyle = CanvasDashStyle.Dash, DashOffset = 5f
            };

            graphics.DrawRectangle(x, y, width, height, brush, drawingSize, strokeStyle);
        }
Пример #22
0
        internal virtual void clearRect(int x, int y, int w, int h)
        {
            CanvasBlend oldBlend = graphics.Blend;

            graphics.Blend = CanvasBlend.Copy;
            CanvasSolidColorBrush brush = new CanvasSolidColorBrush(graphics, Colors.Transparent);

            brush.Color   = Colors.Transparent;
            brush.Opacity = 1;
            graphics.FillRectangle(x, y, w, h, brush);
            graphics.Blend = oldBlend;
        }
Пример #23
0
        private void Canvas_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
        {
            if (this.covidGame.GameOver == false)
            {
                if (!PAUSED)
                {
                    args.DrawingSession.DrawImage(background, 0, 50);
                    covidGame.Draw(args.DrawingSession);

                    args.DrawingSession.DrawImage(greenVirus, 370, 0);
                    args.DrawingSession.DrawImage(redVirus, 625, 0);

                    Color color = new Color();
                    color.A = 100;
                    color.R = 100;
                    color.G = 0;
                    color.B = 0;

                    Vector2 point1 = covidGame.player.position;
                    point1.X += 50;
                    point1.Y += 30;
                    Vector2 point2 = covidGame.player.targetPosition;
                    //set laser sight
                    args.DrawingSession.DrawLine(point1, point2, color, 5);

                    foreach (Bullet bullet in covidGame.bullets)
                    {
                        bullet.Draw(args.DrawingSession);
                    }

                    if (SHOTCOUNTER > 0)
                    {
                        Point point = new Point();
                        point.X = 250;
                        point.Y = 250;
                        Size size = new Size(500, 500);
                        Rect rect = new Rect(point, size);
                        CanvasSolidColorBrush brush = new CanvasSolidColorBrush(args.DrawingSession, Colors.WhiteSmoke);
                        brush.Opacity = (float)0.7;
                        args.DrawingSession.DrawRectangle(rect, brush, 1000);
                        SHOTCOUNTER--;
                    }
                }
            }
            else
            {
                Vector2 textPoint = new Vector2();
                textPoint.X = 250;
                textPoint.Y = 250;
                args.DrawingSession.DrawText("You are dead, press escape to exit", textPoint, Colors.Black);
            }
        }
Пример #24
0
        private CanvasSolidColorBrush CreateColor(CanvasDrawingSession session, SvgColor color)
        {
            var code = (int)(0xff000000 | (uint)(color.RgbColor.Red << 16 | color.RgbColor.Green << 8 | color.RgbColor.Blue));

            if (this.SolidResourceCache.ContainsKey(code))
            {
                return(this.SolidResourceCache[code]);
            }

            var brush = new CanvasSolidColorBrush(this.ResourceCreator, color?.ToPlatformColor(0xff) ?? Color.FromArgb(0xff, 0, 0, 0));

            this.DisposableObjects.Add(brush);
            this.SolidResourceCache.Add(code, brush);
            return(brush);
        }
Пример #25
0
        internal void DrawRect(Rect rect, Paint paint)
        {
            UpdateDrawingSessionWithFlags(paint.Flags);
            _drawingSession.Transform = GetCurrentTransform();
            var brush = new CanvasSolidColorBrush(_device, paint.Color);

            if (paint.Style == Paint.PaintStyle.Stroke)
            {
                _drawingSession.DrawRectangle(rect, brush, paint.StrokeWidth, GetCanvasStrokeStyle(paint));
            }
            else
            {
                _drawingSession.FillRectangle(rect, brush);
            }
        }
Пример #26
0
        public virtual void Render(CanvasDrawingSession ds, Vector4 boundsDips)
        {
            if (_isInitialized == false)
            {
                throw new InvalidOperationException();
            }

            Vector4 color = new Vector4(_params.BaseHue * _params.BaseLuminance, 1.0f);
            CanvasSolidColorBrush brush = CanvasSolidColorBrush.CreateHdr(ds, color);

            var posDips = new Vector2(_position.X / _metersPerDip, _position.Y / _metersPerDip);

            // TODO: respect boundsDips
            ds.FillCircle(posDips, _maxRenderRadiusDips, brush);
        }
Пример #27
0
        public ICanvasBrush GetBrush(ICanvasResourceCreator canvasResourceCreator)
        {
            //ICanvasBrush Brush;
            //if (BrushType == BrushTypes.SolidColorBrush)
            var Brush = new CanvasSolidColorBrush(canvasResourceCreator, SelectColor);

            //else if (BrushType == BrushTypes.LinearColorBrush)
            //{
            //    Brush = new CanvasLinearGradientBrush(canvasResourceCreator, CanvasColorStops);
            //    (Brush as CanvasLinearGradientBrush).StartPoint=StartPoint;
            //    (Brush as CanvasLinearGradientBrush).EndPoint = EndPoint;
            //}
            //else
            //    Brush = new CanvasRadialGradientBrush(canvasResourceCreator, CanvasColorStops);
            return(Brush);
        }
Пример #28
0
        private ICanvasBrush CreatePaint(CanvasDrawingSession session, Rect area, SvgPaint paint, SvgNumber?opacity, CssStyleDeclaration style)
        {
            if (paint == null || paint.PaintType == SvgPaintType.RgbColor)
            {
                var alpha = (byte)(255.0F * (opacity?.Value ?? 1.0F));
                var code  = paint == null ? alpha << 24 : alpha << 24 | paint.RgbColor.Red << 16 | paint.RgbColor.Green << 8 | paint.RgbColor.Blue;
                if (this.SolidResourceCache.ContainsKey(code))
                {
                    return(this.SolidResourceCache[code]);
                }

                var brush = new CanvasSolidColorBrush(this.ResourceCreator, paint?.ToPlatformColor(alpha) ?? Color.FromArgb(alpha, 0, 0, 0));
                this.DisposableObjects.Add(brush);
                this.SolidResourceCache.Add(code, brush);
                return(brush);
            }
            if (paint.PaintType == SvgPaintType.CurrentColor)
            {
                var color = style.Color;
                var alpha = (byte)(255.0F * (opacity?.Value ?? 1.0F));
                var code  = alpha << 24 | color.RgbColor.Red << 16 | color.RgbColor.Green << 8 | color.RgbColor.Blue;
                if (this.SolidResourceCache.ContainsKey(code))
                {
                    return(this.SolidResourceCache[code]);
                }

                var brush = new CanvasSolidColorBrush(this.ResourceCreator, color.ToPlatformColor(alpha));
                this.DisposableObjects.Add(brush);
                this.SolidResourceCache.Add(code, brush);
                return(brush);
            }
            if (paint.PaintType == SvgPaintType.Uri && paint.Uri[0] == '#')
            {
                var key  = paint.Uri.Substring(1);
                var grad = this.TargetDocument.GetElementById(key);
                if (grad.GetType() == typeof(SvgLinearGradientElement))
                {
                    return(this.CreateLinearGradient(session, area, (SvgLinearGradientElement)grad));
                }
                if (grad.GetType() == typeof(SvgRadialGradientElement))
                {
                    return(this.CreateRadialGradient(session, area, (SvgRadialGradientElement)grad));
                }
            }
            throw new NotImplementedException();
        }
Пример #29
0
        public TextControl()
        {
            this.InitializeComponent();

            _textFormat = new CanvasTextFormat
            {
                FontFamily   = "Consolas",
                FontSize     = 12,
                WordWrapping = CanvasWordWrapping.NoWrap
            };

            CanvasRoot.CreateResources += (s, e) =>
            {
                _defaultForegroundBrush = new CanvasSolidColorBrush(s, _defaultForegroundColor);
                _addedForegroundBrush   = new CanvasSolidColorBrush(s, _addedForegroundColor);
                _removedForegroundBrush = new CanvasSolidColorBrush(s, _removedForegroundColor);

                var stops = new CanvasGradientStop[4]
                {
                    new CanvasGradientStop {
                        Color = _defaultBackgroundColor, Position = 0
                    },
                    new CanvasGradientStop {
                        Color = _defaultBackgroundColor, Position = 0.5f
                    },
                    new CanvasGradientStop {
                        Color = _nullBackgroundColor, Position = 0.5f
                    },
                    new CanvasGradientStop {
                        Color = _nullBackgroundColor, Position = 1
                    }
                };

                _nullBrush = new CanvasLinearGradientBrush(s, stops, CanvasEdgeBehavior.Mirror, CanvasAlphaMode.Premultiplied)
                {
                    StartPoint = new System.Numerics.Vector2(0, 0),
                    EndPoint   = new System.Numerics.Vector2(4, 4)
                };
            };

            CanvasRoot.SizeChanged += (s, e) =>
            {
                CanvasRoot.Invalidate();
            };
        }
Пример #30
0
        public async Task <Size> DrawOutlineTextWithLibrary(int dim, string font, string text, string saved_file)
        {
            Size         size   = new Size();
            CanvasDevice device = CanvasDevice.GetSharedDevice();

            using (CanvasRenderTarget offscreen = new CanvasRenderTarget(device, dim, dim, 96, Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized,
                                                                         CanvasAlphaMode.Premultiplied))
            {
                using (CanvasDrawingSession ds = offscreen.CreateDrawingSession())
                {
                    ds.Clear(Colors.White);
                }
                Color text_color = Colors.White;

                CanvasSolidColorBrush brush  = new CanvasSolidColorBrush(device, text_color);
                CanvasTextFormat      format = new CanvasTextFormat();
                format.FontFamily = font;
                format.FontStyle  = Windows.UI.Text.FontStyle.Normal;
                format.FontSize   = 60;
                format.FontWeight = Windows.UI.Text.FontWeights.Bold;

                float            layoutWidth  = dim;
                float            layoutHeight = dim;
                CanvasTextLayout textLayout   = new CanvasTextLayout(device, text, format, layoutWidth, layoutHeight);

                ITextStrategy strat = CanvasHelper.TextOutline(Colors.Blue, Colors.Black, 10);
                CanvasHelper.DrawTextImage(strat, offscreen, new Point(10.0, 10.0), textLayout);

                Windows.Storage.StorageFolder storageFolder =
                    Windows.Storage.ApplicationData.Current.TemporaryFolder;
                string saved_file2 = "\\";
                saved_file2 += saved_file;
                await offscreen.SaveAsync(storageFolder.Path + saved_file2);

                imgOutlineText.Source = new BitmapImage(new Uri(storageFolder.Path + saved_file2));

                using (CanvasDrawingSession ds = offscreen.CreateDrawingSession())
                {
                    ds.Clear(Colors.White);
                }

                return(size);
            }
        }
Пример #31
0
        void EnsureResources(ICanvasResourceCreatorWithDpi resourceCreator, Size targetSize)
        {
            if (!needsResourceRecreation)
                return;

            if (textLayout != null)
            {
                textLayout.Dispose();
                textReference.Dispose();
                textBrush.Dispose();
            }

            textLayout = CreateTextLayout(resourceCreator, (float)targetSize.Width, (float)targetSize.Height);

            textReference = CanvasGeometry.CreateText(textLayout);

            textBrush = new CanvasSolidColorBrush(resourceCreator, Colors.LightBlue);

            needsResourceRecreation = false;
        }
Пример #32
0
            public void DrawGlyphRun(
                Vector2 position,
                CanvasFontFace fontFace,
                float fontSize,
                CanvasGlyph[] glyphs,
                bool isSideways,
                uint bidiLevel,
                object brush,
                CanvasTextMeasuringMode measuringMode,
                string locale,
                string textString,
                int[] clusterMapIndices,
                uint textPosition,
                CanvasGlyphOrientation glyphOrientation)
            {
                var script = GetScript(textPosition);

                if (CurrentMode == Mode.BuildTypographyList)
                {
                    CanvasTypographyFeatureName[] features = fontFace.GetSupportedTypographicFeatureNames(script);

                    foreach (var featureName in features)
                    {
                        TypographyFeatureInfo featureInfo = new TypographyFeatureInfo(featureName);

                        if (!TypographyOptions.Contains(featureInfo))
                        {
                            TypographyOptions.Add(featureInfo);
                        }
                    }
                }
                else
                {
                    if (glyphs == null || glyphs.Length == 0)
                        return;
                    //
                    // This demo handles only simple Latin text with no diacritical
                    // markers or ligatures, so we can make assumptions about the 
                    // mapping of text positions to glyph indices. This works fine for
                    // the sake of this example.
                    //
                    // In general, apps should use the cluster map to map text 
                    // positions to glyphs while knowing that glyph substitution can happen 
                    // for reasons besides typography.
                    //
                    uint[] codePoints = new uint[glyphs.Length];
                    for (int i = 0; i < glyphs.Length; i++)
                    {
                        int glyphTextPosition = 0;
                        for (int j=0; j<clusterMapIndices.Length; j++)
                        {
                            if (clusterMapIndices[j] == i)
                            {
                                glyphTextPosition = j;
                                break;
                            }
                        }
                        codePoints[i] = textString[glyphTextPosition];
                    }
                    int[] nominalGlyphIndices = fontFace.GetGlyphIndices(codePoints);

                    CanvasGlyph[] unsubstitutedGlyphs = new CanvasGlyph[glyphs.Length];
                    for (int i = 0; i < glyphs.Length; i++)
                    {
                        unsubstitutedGlyphs[i] = glyphs[i];
                        unsubstitutedGlyphs[i].Index = nominalGlyphIndices[i];
                    }

                    bool[] eligible = fontFace.GetTypographicFeatureGlyphSupport(script, FeatureToHighlight, unsubstitutedGlyphs);

                    var highlightBrush = new CanvasSolidColorBrush(currentDrawingSession, Colors.Yellow);

                    for (int i = 0; i < glyphs.Length; ++i)
                    {
                        if (eligible[i])
                        {
                            CanvasGlyph[] singleGlyph = new CanvasGlyph[1];
                            singleGlyph[0] = glyphs[i];

                            currentDrawingSession.DrawGlyphRun(
                                position,
                                fontFace,
                                fontSize,
                                singleGlyph,
                                isSideways,
                                bidiLevel,
                                highlightBrush);
                        }

                        position.X += glyphs[i].Advance;
                    }
                }
            }
        /// <summary>
        /// Creates a GeometrySurface having the given size, geometry, foreground color and
        /// background brush with MaskMode as False.
        /// </summary>
        /// <param name="size">Size of the mask</param>
        /// <param name="geometry">Geometry of the mask</param>
        /// <param name="foregroundColor">Fill color of the geometry</param>
        /// <param name="backgroundBrush">The brush to fill the Mask background surface which is 
        /// not covered by the geometry</param>
        /// <returns>IGeometrySurface</returns>
        public IGeometrySurface CreateGeometrySurface(Size size, CanvasGeometry geometry, Color foregroundColor,
            ICanvasBrush backgroundBrush)
        {
            // Create the foreground brush
            var foregroundBrush = new CanvasSolidColorBrush(Device, foregroundColor);
            // Initialize the mask
            IGeometrySurface mask = new GeometrySurface(this, size, geometry, foregroundBrush, backgroundBrush);

            // Render the mask
            mask.Redraw();

            return mask;
        }
Пример #34
0
        void EnsureResources(ICanvasResourceCreatorWithDpi resourceCreator, Size targetSize)
        {
            if (resourceRealizationSize == targetSize && !needsResourceRecreation)
                return;

            float canvasWidth = (float)targetSize.Width;
            float canvasHeight = (float)targetSize.Height;
            sizeDim = Math.Min(canvasWidth, canvasHeight);
            
            textBrush = new CanvasSolidColorBrush(resourceCreator, Colors.Thistle);

            if (!defaultFontSizeSet)
            {
                if (ThumbnailGenerator.IsDrawingThumbnail)
                {
                    CurrentFontSize = 180;
                }
                else
                {
                    CurrentFontSize = sizeDim / 20;
                }
                CurrentFontSize = Math.Max((float)fontSizeSlider.Minimum, CurrentFontSize);
                CurrentFontSize = Math.Min((float)fontSizeSlider.Maximum, CurrentFontSize);
                fontSizeSlider.Value = CurrentFontSize;
                defaultFontSizeSet = true;
            }
            
            string sampleText = null;
            switch (CurrentTextSampleOption)
            {
                case TextSampleOption.ChemicalFormula:
                    sampleText =
                        "H2O is the chemical formula for water.\r\n\r\n" +
                        "And, the isotope Carbon-12 may be written as 12C.\r\n\r\n" +
                        "Often, chemical formulas make use of both superscript and subscript text.";
                    break;
                case TextSampleOption.RightTriangle:
                    sampleText =
                        "The side lengths of a right-angle triangle can be written as a2 + b2 = c2.\r\n\r\n" +
                        "If the triangle's shorter sides are lengths 3 and 4, the remaining side must be 5, since 32 + 42 = 52.";
                    break;
                case TextSampleOption.ShortExpression:
                    sampleText = "ax2by3";
                    break;
                default:
                    Debug.Assert(false, "Unexpected text sample option");
                    break;
            }

            if (textLayout != null)
                textLayout.Dispose();
            textLayout = CreateTextLayout(sampleText, resourceCreator, canvasWidth, canvasHeight);

            switch (CurrentTextSampleOption)
            {
                case TextSampleOption.ChemicalFormula:
                    SetSubscript(textLayout, sampleText.IndexOf("H2O") + 1, 1);
                    SetSuperscript(textLayout, sampleText.IndexOf("12C"), 2);
                    SetSubscript(textLayout, sampleText.IndexOf("subscript"), "subscript".Length);
                    SetSuperscript(textLayout, sampleText.IndexOf("superscript"), "superscript".Length);
                    break;
                case TextSampleOption.RightTriangle:
                    for (int i = 0; i < sampleText.Length; ++i)
                    {
                        if (sampleText[i] == '2')
                            SetSuperscript(textLayout, i, 1);
                    }
                    break;
                case TextSampleOption.ShortExpression:
                    SetSubscript(textLayout, 1, 1);
                    SetSuperscript(textLayout, 2, 1);
                    SetSubscript(textLayout, 4, 1);
                    SetSuperscript(textLayout, 5, 1);
                    break;
                default:
                    Debug.Assert(false, "Unexpected text sample option");
                    break;
            }
            
            subscriptSuperscriptRenderer = new SubscriptSuperscriptRenderer();

            needsResourceRecreation = false;
            resourceRealizationSize = targetSize;
        }
Пример #35
0
        internal override ICanvasBrush RealizeCanvasBrush()
        {
            ICanvasBrush brush;

            brush = new CanvasSolidColorBrush(CanvasDevice.GetSharedDevice(), Colors.RoyalBlue);

            return brush;
        }
Пример #36
0
 public CustomTextRenderer(CanvasSolidColorBrush brush)
 {
     textBrush = brush;
 }