/// <summary>
        /// Draw the stuff on the canvas
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void CanvasControl_Draw(
            Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender,
            Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            Debug.WriteLine("canvas draw");
            CanvasDrawingSession ds = args.DrawingSession;

            if (this.currentGraph != null)
            {
                this.currentGraph.Draw(args.DrawingSession);
            }
            else
            {
                Single           x      = (Single)(this.MainCanvas.ActualWidth / 2);
                Single           y      = (Single)(this.MainCanvas.ActualHeight / 2);
                CanvasTextFormat format = new CanvasTextFormat
                {
                    FontSize     = 30.0f,
                    WordWrapping = CanvasWordWrapping.NoWrap
                };

                CanvasTextLayout textLayout = new CanvasTextLayout(ds,
                                                                   "Nothing to see here.", format, 0.0f, 0.0f);
                Rect   bounds = textLayout.LayoutBounds;
                Single newX   = (Single)((this.MainCanvas.ActualWidth / 2) - (bounds.Width / 2));
                Single newY   = (Single)((this.MainCanvas.ActualHeight / 2) - (bounds.Height / 2));

                ds.DrawTextLayout(textLayout, newX, newY, Colors.White);
            }
        }
Exemple #2
0
 private void Win2DCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
 {
     if (_DrawingCanvas != null)
     {
         args.DrawingSession.DrawImage(_DrawingCanvas, new Rect(new Point(0, 0), _DrawingCanvas.Size), new Rect(new Point(0, 0), _DrawingCanvas.Size));
     }
 }
 private void canvasControl_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
 {
     if (_contentProvider != null)
     {
         _contentProvider.Draw(sender, args);
     }
 }
Exemple #4
0
 // The Draw event is raised once when the CanvasControl first becomes visible, then again any time its contents need to be redrawn.
 // This can occur, for example, if the control is resized. You can manually trigger a Draw event yourself by calling Invalidate().
 //
 // Reference: https://microsoft.github.io/Win2D/html/E_Microsoft_Graphics_Canvas_UI_Xaml_CanvasControl_Draw.htm
 private void canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
 {
     if (canvasEffect != null)
     {
         args.DrawingSession.DrawImage(canvasEffect);
     }
 }
Exemple #5
0
        private void OnDebugDraw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            var session = args.DrawingSession;

            session.Clear(Colors.DarkSlateBlue);

            var dpi = Windows.Graphics.Display.DisplayProperties.LogicalDpi;

            var layers = Sequensor.Controller.CachedFrame;

            foreach (var layer in layers)
            {
                var l = layer;
                foreach (var render in layer)
                {
                    var          cbi   = CanvasBitmap.CreateFromSoftwareBitmap(session.Device, render.Source);
                    ICanvasImage image = new Transform2DEffect
                    {
                        Source          = cbi,
                        TransformMatrix = render.Transformaion
                    };
                    session.DrawImage(image);
                }
            }
        }
 private void canvasControl_CreateResources(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args)
 {
     if (_contentProvider != null)
     {
         _contentProvider.Load(sender, args);
     }
 }
Exemple #7
0
        private void led_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            led.Width  = ActualHeight;
            led.Height = ActualHeight;

            using (CanvasDrawingSession canvas = args.DrawingSession)
            {
                // Calculate the centre of the led
                Vector2 centrePoint = new Vector2();

                centrePoint.X = (float)(led.ActualWidth / 2);
                centrePoint.Y = (float)(led.ActualHeight / 2);

                // Calculate the radius of the LED
                float ledRadius = (float)(ActualHeight / 2.0f);

                // Draw the LED
                if (LedOn)
                {
                    canvas.FillCircle(centrePoint, ledRadius, OnColor);
                }
                else
                {
                    canvas.FillCircle(centrePoint, ledRadius, OffColor);
                }

                // Draw the Border of the LED
                float borderRadius = (float)(ledRadius - (BorderWidth / 2));

                canvas.DrawCircle(centrePoint, borderRadius, BorderColor, (float)BorderWidth);
            }
        }
Exemple #8
0
        private void BackgroundCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            //var startAngle = DegreesToRadians(-15);
            //var sweepAngle = DegreesToRadians(30);

            //var progress = (float)Slide.Value / 100f;
            //var size = 1 + 4 * progress;

            //for (int i = 0; i < 4; i++)
            //{
            //    using (var builder = new CanvasPathBuilder(sender))
            //    {

            //        var centerPoint = new Vector2((1 + 4 * progress), 6);
            //        var startPoint = centerPoint + Vector2.Transform(Vector2.UnitX, Matrix3x2.CreateRotation(startAngle)) * size;

            //        builder.BeginFigure(startPoint);
            //        builder.AddArc(centerPoint, size, size, startAngle, sweepAngle);
            //        builder.EndFigure(CanvasFigureLoop.Open);

            //        using (var geometry = CanvasGeometry.CreatePath(builder))
            //        {
            //            var alpha = (i == 0) ? progress : (i == 4 - 1) ? (1.0f - progress) : 1.0f;
            //            args.DrawingSession.DrawGeometry(geometry, Color.FromArgb((byte)(alpha * 255), 0xFF, 0x00, 0x0), 2, new CanvasStrokeStyle { StartCap = CanvasCapStyle.Round, EndCap = CanvasCapStyle.Round });
            //        }

            //        size += 4;
            //    }
            //}
        }
Exemple #9
0
        private void CanvasControlRight_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            Rect destRect;

            lock (lockObj)
            {
                CanvasBitmap c;

                if (background == null)
                {
                    return;
                }
                c = CanvasBitmap.CreateFromSoftwareBitmap(args.DrawingSession, background);

                var rects = GetSourceDest(background, args);

                args.DrawingSession.DrawImage(c, rects.Item2, rects.Item1);
                destRect = rects.Item2;
            }

            if (figure == null)
            {
                return;
            }

            DrawFigure(args, destRect, zIndex, rightEyePos);
        }
Exemple #10
0
        unsafe private void AudioCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender,
                                             Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            if (this.m_AudioFrameOutputNode != null)
            {
                using (ICanvasBrush ybrush = new Microsoft.Graphics.Canvas.Brushes.CanvasSolidColorBrush(sender.Device,
                                                                                                         Windows.UI.Colors.Yellow))
                    using (ICanvasBrush bbrush = new Microsoft.Graphics.Canvas.Brushes.CanvasSolidColorBrush(sender.Device,
                                                                                                             Windows.UI.Colors.Red))
                    {
                        // get a float pointer to the fftw in array
                        float *fpin = (float *)pin;

                        float halfHeight = (float)sender.ActualHeight / 2.0f;
                        for (int i = 0; i < this.m_QuantumSamples.Length; i += 2)
                        {
                            int   ii = i / 2;
                            float f  = this.m_QuantumSamples[i];
                            if ((ii) < sender.ActualWidth)
                            {
                                args.DrawingSession.DrawLine(
                                    (float)ii,
                                    (float)halfHeight,
                                    (float)ii,
                                    (float)halfHeight + (f * halfHeight), ybrush);
                            }
                            // put the float value in the real part (even index)
                            // odd index is imaginery
                            fpin[i] = f;
                        }

                        FFTWSharp.fftw.execute(fplan);

                        float *fpout  = (float *)pout;
                        double maxmag = 100;
                        double mult   = this.m_AudioGraph.SamplesPerQuantum / maxmag;
                        int    halfi  = 0;
                        for (int i = 0; i < m_FFTSampleSize; i += 2)
                        {
                            double mag_k = 2.0 * Math.Sqrt(fpout[i] * fpout[i]) + (fpout[i + 1] * fpout[i + 1]) / (double)this.m_FFTSampleSize;
                            double a_k   = 20.0 * Math.Log10(mag_k);
                            halfi = i / 2;
                            args.DrawingSession.DrawLine(0, halfi * 2, (float)(a_k * mult), halfi * 2, bbrush);
                            args.DrawingSession.DrawLine(0, halfi * 2 + 1, (float)(a_k * mult), halfi * 2 + 1, bbrush);
                        }
                    }

                //args.DrawingSession.DrawText("Samples Per Quantum = " + this.m_AudioGraph.SamplesPerQuantum,
                //0, 0, Windows.UI.Colors.Yellow);

                //args.DrawingSession.DrawText($"{this.m_FrameCount} "
                //    + $"spq {this.m_AudioGraph.SamplesPerQuantum} "
                //    + $"cap {this.m_Capacity} "
                //    + $"abcap {this.m_abCap} "
                //    + $"ablen {this.m_abLen}", 0, 0, Windows.UI.Colors.Yellow);
                //args.DrawingSession.DrawText($"bps {this.m_AudioGraph.EncodingProperties.BitsPerSample} "
                //    + $"ch {this.m_AudioGraph.EncodingProperties.ChannelCount} "
                //    + $"sr {this.m_AudioGraph.EncodingProperties.SampleRate}", 0, 18, Windows.UI.Colors.Yellow);
            }
        }
 private void DrawerCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
 {
     foreach (PageLayer item in LayerItems)
     {
         item.Draw(args.DrawingSession);
     }
 }
Exemple #12
0
        public GameCharacter(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl canvas)
        {
            //Starting positions
            x = 40;
            y = canvas.ActualHeight - 115;

            box = new Rect(x, y, 40, 40);
        }
Exemple #13
0
        private void joinCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            var canvas_target = GetDrawing(true);

            if (canvas_target != null)
            {
                args.DrawingSession.DrawImage(canvas_target);
            }
        }
Exemple #14
0
        /// <summary>
        /// 画布绘制
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void MyCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            var target = GetDrawings(true); //

            if (target != null)
            {
                args.DrawingSession.DrawImage(target);
            }
        }
Exemple #15
0
        private void Canvas_OnDraw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            var draw = args.DrawingSession;

            var s = ViewModel.Solid;

            //var c = 0;
            //var r = 0;
            //var w = ViewModel.Width;

            for (var i = 0; i < s.Length; i++)
            {
                var temp = s[i];
                draw.FillRectangle(Rectangle[i], temp.WeizCsefsimile ? FillSolidColor.Color : Colors.Transparent);
                draw.DrawRectangle(Rectangle[i], temp.WeizCsefsimile ? BoundColor : Colors.Transparent);
                //c++;
                //if (c == ViewModel.Col)
                //{
                //    c = 0;
                //    r++;
                //}
            }

            //draw.DrawText("lindexi", Ran.Next(10, 100), Ran.Next(10, 100), 500, 50, r(), new CanvasTextFormat()
            //{
            //    FontSize = 100
            //});

            //for (int i = 0; i < 10; i++)
            //{
            //    draw.DrawLine(Ran.Next(10, 100), Ran.Next(10, 100), Ran.Next(100, 1000), Ran.Next(100, 1000), r());
            //}
            //if (img != null)
            //{
            //    draw.DrawImage(img, Ran.Next(10, 1000), rc());
            //}
            //else
            //{
            //    Img().Wait();
            //}

            //Color r()
            //{
            //    return Color.FromArgb(0xFF, rc(), rc(), rc());
            //}

            //byte rc()
            //{
            //    return (byte)(Ran.NextDouble() * 255);
            //}

            //async Task Img()
            //{
            //    img = await CanvasBitmap.LoadAsync(canvas, new Uri("ms-appx:///Assets/SplashScreen.png"));
            //}
        }
Exemple #16
0
        private void Canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            var opacityMask = CreateOpacityMask(sender, 800, 800);
            var brush       = new CanvasImageBrush(sender, opacityMask);

            using (var layer = args.DrawingSession.CreateLayer(brush))
            {
                args.DrawingSession.FillRectangle(new Rect(100, 0, 500, 350), Colors.BlueViolet);
            }
        }
        private void CanvasControl_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            CanvasDrawingSession ds = args.DrawingSession;

            ds.Clear(Colors.White);
            if (canvasBitmap != null)
            {
                //ds.DrawRectangle(10, 10, 100, 100, Colors.Red);
                ds.DrawImage(canvasBitmap);
            }
        }
Exemple #18
0
 private void ChartWin2DCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
 {
     if (_offscreenBackGround != null)
     {
         args.DrawingSession.DrawImage(_offscreenBackGround);// new Rect(new Point(0, 0), ), new Rect(new Point(0, 0), _offscreenBackGround.Size));
     }
     else
     {
         args.DrawingSession.DrawRectangle(0, 0, (float)chartGrid.Width, (float)chartGrid.Height, Colors.LightBlue);
     }
 }
Exemple #19
0
        private void Canvas_CreateResources(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args)
        {
            // Create instance of radial gradient brush; the center will be transparent and the extremes opaque black.
            radialBrush = new CanvasRadialGradientBrush(sender, Colors.Transparent, Colors.Black);

            // Load image to draw.
            args.TrackAsyncAction(Task.Run(async() =>
            {
                image = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///SpotlightImage.png"));
            }).AsAsyncAction());
        }
        private void Canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            float centerX   = _centerVector.X;
            float centerY   = _centerVector.Y;
            float radiusMax = _radiusMax;
            float radiusMin = _radiusMin;

            // 创建路径变量
            int    colorCount = _wheelColors.Count; // 颜色数量
            Double angel = 360.0 / colorCount;      // 计算夹角(注:计算参数必须为浮点数,否则结果为0)
            Double rotate = 0;                      // 起始角度
            float  pointX, pointY;                  // 缓存绘图路径点

            _wheelColors.ForEach((color) =>
            {
                color.A        = Argb_A;
                pointX         = centerX + radiusMin * (float)Math.Cos(rotate * Math.PI / 180);
                pointY         = centerY + radiusMin * (float)Math.Sin(rotate * Math.PI / 180);
                Vector2 point1 = new Vector2(pointX, pointY);
                rotate        += angel;
                pointX         = centerX + radiusMax * (float)Math.Cos(rotate * Math.PI / 180);
                pointY         = centerY + radiusMax * (float)Math.Sin(rotate * Math.PI / 180);
                Vector2 point3 = new Vector2(pointX, pointY);

                double d = Math.Atan2((_getColorPointer.Y - _centerVector.Y), (_getColorPointer.X - _centerVector.X)) * 180 / Math.PI;
                d        = Math.Round(d);
                double r = Math.Round(rotate);
                if (d < 0)
                {
                    d = d + 360;
                }
                if (d == r)
                {
                    centercolors = color;
                }

                CanvasPathBuilder path = new CanvasPathBuilder(sender);
                path.BeginFigure(point1);
                path.AddLine(point3);
                path.EndFigure(CanvasFigureLoop.Open);
                CanvasGeometry apple = CanvasGeometry.CreatePath(path);

                args.DrawingSession.DrawGeometry(apple, color);
            });

            centercolors.A = Argb_A;
            args.DrawingSession.FillCircle(_centerVector, _radiusCenter, centercolors);
            args.DrawingSession.DrawCircle(_getColorPointer, _radiusGetColor, Colors.Wheat);

            sliderColor.Color = Color.FromArgb(centercolors.A, centercolors.R, centercolors.G, centercolors.B);
        }
Exemple #21
0
        private void canvasControl_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            int   stroke   = 3;
            float width    = (float)this.ActualWidth;
            float height   = (float)this.ActualHeight;
            float radius   = Math.Min(width, height) / 2 - 2 * stroke;
            float centerX  = width / 2;
            float centerY  = height / 2;
            float lineEndX = radius * (float)Math.Cos(Math.PI * Angle / 180) + centerX;
            float lineEndY = radius * (float)Math.Sin(Math.PI * Angle / 180) + centerY;

            args.DrawingSession.DrawCircle(centerX, centerY, radius, Colors.Red, stroke);
            args.DrawingSession.DrawLine(centerX, centerY, lineEndX, lineEndY, Colors.Green, stroke);
            args.DrawingSession.DrawText(Angle.ToString(), centerX, centerY, Colors.Black);
        }
Exemple #22
0
 //отрисовка тестового набора
 private void canvas_Draw(
     Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender,
     Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
 {
     for (int x = 0; x < DIMENSION; x++)
     {
         for (int y = 0; y < DIMENSION; y++)
         {
             args.DrawingSession.DrawRectangle(x * width, y * width, width, width, Color.FromArgb(254, (byte)(Convert.ToInt32(TrainingSet[x * DIMENSION + y][0] * 254)),
                                                                                                  (byte)(Convert.ToInt32(TrainingSet[x * DIMENSION + y][1] * 254)),
                                                                                                  (byte)(Convert.ToInt32(TrainingSet[x * DIMENSION + y][2] * 254))
                                                                                                  ), width);
         }
     }
 }
Exemple #23
0
 private void canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
 {
     for (int i = 0; i < DataPointsPerFrame; i++)
     {
         var delta = _rand.NextDouble() * .1 - .05;
         _lastValue = Math.Max(0d, Math.Min(1d, _lastValue + delta));
         _data.Add(_lastValue);
     }
     if (Data.IsChecked == true)
     {
         _chartRenderer.RenderData(canvas, args, Colors.Black, DataStrokeThickness, _data, renderArea: ChartShow.IsChecked == true);
     }
     canvas.Invalidate();
     //_chartRenderer.RenderAveragesAsPieChart(canvas, args, pieValues, new List<Color>(new[] { Colors.DarkSalmon, Colors.Azure, Colors.LemonChiffon, Colors.Honeydew, Colors.Pink }));
 }
        private void gauge_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            using (CanvasDrawingSession drawingSession = args.DrawingSession)
            {
                Vector2 outputSize = new Vector2((float)(ActualWidth), (float)(ActualHeight));
                Vector2 sourceSize = new Vector2(100.0f, -100.0f);

                drawingSession.Transform = GetDisplayTransform(outputSize, sourceSize);

                using (var geometry = CanvasGeometry.CreatePath(CreateBackgroundGauge(sender)))
                {
                    drawingSession.FillGeometry(geometry, Color.FromArgb(255, 25, 25, 25)); // Colors.DarkSlateGray);
                }

                using (var geometry2 = CanvasGeometry.CreatePath(CreateForegroundGauge(sender)))
                {
                    drawingSession.FillGeometry(geometry2, ForegroundColor);
                }

                using (var geometry3 = CanvasGeometry.CreatePath(CreateBorderGauge(sender)))
                {
                    drawingSession.DrawGeometry(geometry3, Colors.White, 2.0f);
                }

                string text = string.Format("{0:+#0.0;-#0.0;0.0} °C", Temperature);

                FontWeight weight = new FontWeight();

                weight.Weight = 500;

                using (CanvasTextFormat textFormat = new CanvasTextFormat {
                    FontSize = 15.0f, FontWeight = weight, WordWrapping = CanvasWordWrapping.NoWrap
                })
                    using (CanvasTextLayout layout = new CanvasTextLayout(drawingSession, text, textFormat, 0.0f, 0.0f))
                    {
                        float xLocation = -(float)layout.DrawBounds.Width / 2;
                        float yLocation = -(float)layout.DrawBounds.Height;

                        outputSize = new Vector2((float)(ActualWidth), (float)(ActualHeight));
                        sourceSize = new Vector2(100.0f, 100.0f);

                        drawingSession.Transform = GetDisplayTransform(outputSize, sourceSize);

                        drawingSession.DrawTextLayout(layout, xLocation, yLocation, ForegroundColor);
                    }
            }
        }
        private void myCanvasControl_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            MvvmPoint?lastPoint = null;

            //await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            //{
            //    pointsToPlotTemp = PointsToPlot;
            //}).AsTask().ConfigureAwait(true);

            if (myPointsToPlot != null)
            {
                var minX = PointsToPlot.Min((item) => item.X);
                var minY = PointsToPlot.Min((item) => item.Y);

                //var drawingBrush = new Microsoft.Graphics.Canvas.Brushes.CanvasSolidColorBrush(
                //    args.DrawingSession.Device, Colors.White);

                foreach (var pointItem in PointsToPlot)
                {
                    if (!lastPoint.HasValue)
                    {
                        lastPoint = pointItem;
                    }
                    else
                    {
                        try
                        {
                            //We just ignore weird calculation results.

                            args.DrawingSession.DrawLine((float)lastPoint.Value.X,
                                                         (float)lastPoint.Value.Y,
                                                         (float)pointItem.X,
                                                         (float)pointItem.Y,
                                                         Colors.White, 3);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }

                        lastPoint = pointItem;
                    }
                }
            }
        }
Exemple #26
0
        private void Canvas1_CreateResources(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args)
        {
            if (mainCharacter == null)
            {
                mainCharacter = new GameCharacter(Canvas1);
            }

            //Grass
            shapes.Add(new Rect(0, Canvas1.ActualHeight - 75, Canvas1.ActualWidth, 75), Colors.Green);

            for (int i = 0; i < 5; i++)
            {
                shapes.Add(new Rect(100 + (i * 150), Canvas1.ActualHeight - (150 + i * 80), 140, 10), Colors.Brown);
            }

            shapes.Add(new Rect(1000, 300, 140, 10), Colors.Green);

            args.TrackAsyncAction(mainCharacter.CreateResources(sender).AsAsyncAction());
        }
        private void BGCycle_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            CanvasGradientStop[] gradientStop = new CanvasGradientStop[2];
            gradientStop[0]          = new CanvasGradientStop();
            gradientStop[0].Color    = Color.FromArgb(180, 18, 208, 255);
            gradientStop[0].Position = 0f;

            gradientStop[1]          = new CanvasGradientStop();
            gradientStop[1].Color    = Color.FromArgb(0, 255, 255, 255);
            gradientStop[1].Position = 1f;

            CanvasRadialGradientBrush brush = new CanvasRadialGradientBrush(sender, gradientStop);

            brush.RadiusX = 200;
            brush.RadiusY = 200;
            brush.Center  = new Vector2(200, 200);

            args.DrawingSession.FillCircle(200, 200, 200, brush);
        }
        //CanvasControl raises Draw whenever your app needs to draw or redraw its content.
        private void canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            CanvasCommandList cl = new CanvasCommandList(sender);

            using (CanvasDrawingSession clds = cl.CreateDrawingSession())
            {
                for (int i = 0; i < 100; i++)
                {
                    clds.DrawText("Hello, World!", RndPosition(), Color.FromArgb(255, RndByte(), RndByte(), RndByte()));
                    clds.DrawCircle(RndPosition(), RndRadius(), Color.FromArgb(255, RndByte(), RndByte(), RndByte()));
                    clds.DrawLine(RndPosition(), RndPosition(), Color.FromArgb(255, RndByte(), RndByte(), RndByte()));
                }
            }

            GaussianBlurEffect blur1 = new GaussianBlurEffect();

            blur1.Source     = cl;
            blur1.BlurAmount = 10.0f;
            args.DrawingSession.DrawImage(blur1);
        }
        private void ImageCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            var ds = args.DrawingSession;

            if (_canvasImage == null)
            {
                ds.Clear(Colors.White);
                return;
            }

            var imageBounds = _canvasImage.GetBounds(sender);
            var min         = Math.Min(imageBounds.Height, imageBounds.Width);

            imageBounds.X      = (imageBounds.Width - min) / 2;
            imageBounds.Y      = (imageBounds.Height - min) / 2;
            imageBounds.Height = min;
            imageBounds.Width  = min;

            ds.Clear(Colors.White);
            ds.DrawImageWithEffect(_canvasImage, new Rect(0, 0, 950, 950), imageBounds, _selectedEffectType);
        }
Exemple #30
0
        private void Canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            // Start drawing session and clear background to white.
            var session = args.DrawingSession;

            args.DrawingSession.Clear(Colors.White);

            // Set the center of the radial gradient as the center of the image.
            radialBrush.Center = new System.Numerics.Vector2((float)(image.Size.Width / 2.0f), (float)(image.Size.Height / 2.0f));
            // Assing gradient radius from slider control.
            radialBrush.RadiusX = radialBrush.RadiusY = (float)BlurRadius.Value;

            // Draw unaltered image first.
            session.DrawImage(image, image.Bounds);

            // Create a layer, this way all elements drawn will be affected by a transparent mask
            // which in our case is the radial gradient.
            using (session.CreateLayer(radialBrush))
            {
                // Create gaussian blur effect.
                using (var blurEffect = new GaussianBlurEffect())
                {
                    // Set image to blur.
                    blurEffect.Source = image;
                    // Set blur amount from slider control.
                    blurEffect.BlurAmount = (float)BlurAmount.Value;
                    // Explicitly set optimization mode to highest quality, since we are using big blur amount values.
                    blurEffect.Optimization = EffectOptimization.Quality;
                    // This prevents the blur effect from wrapping around.
                    blurEffect.BorderMode = EffectBorderMode.Hard;
                    // Draw blurred image on top of the unaltered one. It will be masked by the radial gradient
                    // thus showing a transparent hole in the middle, and properly overlaying the alpha values.
                    session.DrawImage(blurEffect, 0, 0);
                }
            }
        }