Beispiel #1
0
        private void canvas1_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
        {
            if (controller == null || !controller.isIniialized)
            {
                return;
            }
            var draw = args.DrawingSession;
            //Rect rect = new Rect(0, 0, maxHeightWidth.X, maxHeightWidth.Y);
            //args.DrawingSession.DrawRectangle(rect, Colors.Black);
            List <OutputGeometry> pointSetList = controller.outputCoordinates[0].outputPointSetList;

            if (pointSetList != null)
            {
                for (int i = 0; i < pointSetList.Count; i++)
                {
                    if (pointSetList[i].isVisible)
                    {
                        if (pointSetList[i] is OutputCircle)
                        {
                            var realCircle = pointSetList[i] as OutputCircle;
                            if (realCircle.circle.isSelected)
                            {
                                args.DrawingSession.DrawCircle(realCircle.center, realCircle.radius, realCircle.selectedLineColor, realCircle.thickness);
                            }
                            else
                            {
                                args.DrawingSession.DrawCircle(realCircle.center, realCircle.radius, realCircle.lineColor, realCircle.thickness);
                            }
                        }
                        else if (pointSetList[i] is OutputLine)
                        {
                            var realLine = pointSetList[i] as OutputLine;
                            if (realLine.line.isSelected)
                            {
                                args.DrawingSession.DrawLine(realLine.p1, realLine.p2, realLine.selectedLineColor, realLine.thickness);
                            }
                            else
                            {
                                args.DrawingSession.DrawLine(realLine.p1, realLine.p2, realLine.lineColor, realLine.thickness);
                            }
                        }
                    }
                }
            }

            List <OutputPoint> pointList = controller.outputCoordinates[0].outputPointList;

            if (pointList != null)
            {
                for (int i = 0; i < pointList.Count; i++)
                {
                    if (pointList[i].isVisible)
                    {
                        if (pointList[i].point.isSelected)
                        {
                            args.DrawingSession.FillCircle(pointList[i].viewPoint, OutputPoint.scopeLength, pointList[i].selectedFillColor);
                            args.DrawingSession.DrawCircle(pointList[i].viewPoint, OutputPoint.scopeLength, pointList[i].selectedLineColor, pointList[i].thickness);
                        }
                        else
                        {
                            args.DrawingSession.FillCircle(pointList[i].viewPoint, OutputPoint.scopeLength, pointList[i].fillColor);
                            args.DrawingSession.DrawCircle(pointList[i].viewPoint, OutputPoint.scopeLength, pointList[i].lineColor, pointList[i].thickness);
                        }
                    }
                }
            }
        }
        //---------------------------- Win2D Stuffs ------------------------------

        private void Canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
        {
            args.DrawingSession.DrawRectangle(10, 10, 500, 700, Colors.DeepSkyBlue);

            DrawInstructionsTitle(args);
            DrawInstructions(args);
            DrawReturnButton(args);
        }
Beispiel #3
0
        /// <summary>
        /// Drw du SlateView
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>

        private void OnSlateViewDraw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
        {
            // appel du UpdateCallback
            var screenArgb32Array = this.machine.RenderOneFrame(args.Timing.IsRunningSlowly);

            this.machine.CopyToBgraByteArray(screenArgb32Array, screenArray);

            var screen = this.machine.Screen;

            this.SlateView.SetPixels(screenArray, screen.Width, screen.Height);
        }
Beispiel #4
0
 private void CanvasAnimatedControl_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
 {
     args.DrawingSession.Clear(Colors.Black);
     foreach (var drawer in _drawers)
     {
         drawer.Draw(sender, args);
     }
 }
        //---------------------------- Win2D Stuffs ------------------------------

        private void Canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
        {
            args.DrawingSession.DrawRectangle(10, 10, 500, 700, Colors.DeepSkyBlue);

            mastermind.DrawMastermind(args.DrawingSession);
            DrawCheckButton(args);
            DrawReturnButton(args);
        }
Beispiel #6
0
        protected void CanvasAnimatedControl_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
        {
            // First, ensure we have exclusive access to the list of sprites. we don't want this changing while we are trying
            // to draw it. If another thread has access to it, we will skip drawing this frame.

            if (Monitor.TryEnter(Sprite.Sprites))
            {
                try
                {
                    // Establish the scale. Normally we draw at 1.0 scale. However, if the drawing surface is SMALLER than our coordinate space, we
                    // need to scale down. Likewise, if we are in fullscreen mode, we'll need to scale up.
                    if (sender.Size.Width < Dimensions.Width || sender.Size.Height < Dimensions.Height || fullscreen)
                    {
                        scale = (float)Math.Min(sender.Size.Width / Dimensions.Width, sender.Size.Height / Dimensions.Height);
                    }
                    else
                    {
                        scale = 1.0f;
                    }

                    // Draw the 'scale' transform into the scene
                    args.DrawingSession.Transform = Matrix3x2.CreateScale(scale, new Vector2((float)(sender.Size.Width / 2), (float)(sender.Size.Height / 2)));

                    // Upper-left corner of the destination drawing space
                    var origin = new Point()
                    {
                        X = (sender.Size.Width - Dimensions.Width) / 2, Y = (sender.Size.Height - Dimensions.Height) / 2
                    };

                    // Rectangle describing the destination drawing space
                    var destrect = new Rect(origin, Dimensions);

                    // Creating a layer around the destination drawing space is how we clip drawing to only the
                    // expected drawing space
                    using (args.DrawingSession.CreateLayer(1.0f, destrect))
                    {
                        // Draw the background
                        if (background != null && bitmaps.ContainsKey(background))
                        {
                            args.DrawingSession.DrawImage(bitmaps[background], destrect);
                        }

                        // The sprites are all positioned relative to the 'center', so we need to know where that is
                        // on the screen right now
                        var center = new Point(sender.Size.Width / 2, sender.Size.Height / 2);

                        // Draw each sprite
                        foreach (var sprite in Sprite.Sprites.OrderBy(x => x.Layer))
                        {
                            // Only draw the sprite if we have a costume loaded for it
                            if (sprite.Costume != null && sprite.Visible && bitmaps.ContainsKey(sprite.Costume))
                            {
                                // Fetch the correct drawing resource for this sprite
                                var bitmap = bitmaps[sprite.Costume];

                                // Figure out how big of space the sprite will occupy in the scene. This is where we
                                // apply sprite scaling. Also, this value is used for collisions.
                                sprite.CostumeSize = new Size(bitmap.Size.Width * sprite.Scale, bitmap.Size.Height * sprite.Scale);

                                // The 'drawme' is the canvas image we will ultimately draw. Along the way we will optionally
                                // apply effects to it.
                                ICanvasImage drawme = bitmap;

                                // Opacity effect if we are not fully opaque
                                if (sprite.Opacity < 1.0)
                                {
                                    drawme = new OpacityEffect()
                                    {
                                        Source  = drawme,
                                        Opacity = (float)sprite.Opacity
                                    };
                                }

                                // Rotation effect if we are rotated.
                                if (sprite.RotationAngle != 0.0)
                                {
                                    drawme = new Transform2DEffect()
                                    {
                                        Source          = drawme,
                                        TransformMatrix = Matrix3x2.CreateRotation((float)sprite.RotationAngle, new Vector2((float)bitmap.Size.Width / 2, (float)bitmap.Size.Height / 2))
                                    };
                                }

                                // Flip horizontal, if so indicated
                                if (sprite.FlipHorizontal)
                                {
                                    drawme = new Transform2DEffect()
                                    {
                                        Source          = drawme,
                                        TransformMatrix = Matrix3x2.CreateScale(-1.0f, 1.0f, new Vector2((float)bitmap.Size.Width / 2, (float)bitmap.Size.Height / 2))
                                    };
                                }

                                // Where in the scene to draw the sprite
                                var draw_at = new Point(center.X + sprite.Position.X - sprite.CostumeSize.Width / 2, center.Y - sprite.Position.Y - sprite.CostumeSize.Height / 2);

                                // Draw the sprite!
                                args.DrawingSession.DrawImage(drawme, new Rect(draw_at, sprite.CostumeSize), new Rect(new Point(0, 0), bitmap.Size));

                                // Render the 'saying'
                                if (sprite.Saying?.Length > 0)
                                {
                                    var drawingSession = args.DrawingSession;
                                    var format         = new CanvasTextFormat {
                                        FontSize = 30.0f, WordWrapping = CanvasWordWrapping.NoWrap
                                    };
                                    var textLayout = new CanvasTextLayout(drawingSession, sprite.Saying, format, 0.0f, 0.0f);

                                    float xcenter = (float)(center.X + sprite.Position.X);
                                    float ytop    = (float)(center.Y - sprite.Position.Y + bitmap.Size.Height / 2 + 10.0);

                                    var theRectYouAreLookingFor = new Rect(xcenter - textLayout.LayoutBounds.Width / 2 - 5, ytop, textLayout.LayoutBounds.Width + 10, textLayout.LayoutBounds.Height);
                                    drawingSession.FillRectangle(theRectYouAreLookingFor, Colors.White);
                                    drawingSession.DrawTextLayout(textLayout, xcenter - (float)textLayout.LayoutBounds.Width / 2, ytop, Colors.Black);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    // This is not a great thing to do with exceptions...
                }
                finally
                {
                    Monitor.Exit(Sprite.Sprites);
                }
            }
        }
Beispiel #7
0
        private void canvas_AnimatedDraw(
            Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender,
            Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
        {
            if (state == snake)
            {
                // background
                args.DrawingSession.FillRectangle(0, 0, 600, 600, Color.FromArgb(255, 100, 100, 100));
                // background
                args.DrawingSession.FillRectangle(200, 200, 200, 200, Color.FromArgb(255, 0, 0, 0));
                // snake head
                args.DrawingSession.FillRectangle(playerXaxis, playerYaxis, 4, 4, Color.FromArgb(255, 0, 200, 0));
                // snake body
                for (int i = 0; i <= foodAmount; i++)
                {
                    args.DrawingSession.DrawRectangle((arrayX[i]), (arrayY[i]), 4, 4, Color.FromArgb(255, 0, 255, 0));
                }
                // borders
                args.DrawingSession.FillRectangle(200, 200, 4, 200, Color.FromArgb(255, 0, 255, 0));
                args.DrawingSession.FillRectangle(200, 200, 200, 4, Color.FromArgb(255, 0, 255, 0));
                args.DrawingSession.FillRectangle(200, 396, 200, 4, Color.FromArgb(255, 0, 255, 0));
                args.DrawingSession.FillRectangle(396, 200, 4, 200, Color.FromArgb(255, 0, 255, 0));
                // food
                args.DrawingSession.FillRectangle(foodX, foodY, 4, 4, Color.FromArgb(255, 255, 0, 0));
                // score
                string foodAmountString = (foodAmount + 1).ToString();
                args.DrawingSession.DrawText("Score:", 300, 175, Colors.PowderBlue);
                args.DrawingSession.DrawText(foodAmountString, 370, 175, Colors.PowderBlue);
            }
            if (state == intro)
            {
                // background
                args.DrawingSession.FillRectangle(0, 0, 600, 600, Color.FromArgb(intro_color, 0, 255, 0));
                args.DrawingSession.DrawText("Welcome to Snake C# 0.01v", 180, 280, Colors.Blue);
                intro_color++;
                if (intro_color == 255)
                {
                    state = mainMenu;
                }
            }
            if (state == about)
            {
                {
                    // background
                    args.DrawingSession.FillRectangle(0, 0, 600, 600, Color.FromArgb(255, 100, 100, 100));
                    args.DrawingSession.DrawText("Created By", 240, 240, Colors.Blue);
                    args.DrawingSession.DrawText("Cooked Kraken", 240, 260, Colors.Blue);
                    args.DrawingSession.DrawText("1/31/2017", 240, 280, Colors.Blue);
                    args.DrawingSession.DrawText("11AM", 240, 300, Colors.Blue);
                }
            }
            if (state == gameOver)
            {
                {
                    Windows.Storage.StorageFolder installedLocation = Windows.Storage.ApplicationData.Current.LocalFolder;

                    // background
                    args.DrawingSession.FillRectangle(0, 0, 600, 600, Color.FromArgb(255, 0, 0, 0));
                    args.DrawingSession.DrawText("Game Over", 240, 240, Colors.Red);

                    var scoresFilePath = Path.Combine(installedLocation.Path, "scores.text");
                    // score
                    string foodAmountString = (foodAmount + 1).ToString();
                    if (System.IO.File.ReadAllLines(scoresFilePath) != null)
                    {
                        foreach (var item in System.IO.File.ReadAllLines(scoresFilePath))
                        {
                            lines.Add(item); // get each score
                        }
                    }

                    lines.Add(foodAmountString); // add current score
                    foreach (var val in lines)   // copy the string list to an int list
                    {
                        lines2.Add(Int32.Parse(val));
                    }
                    foreach (var val in lines2.Reverse())// lines3 = lines2 reversed, shortened to 10
                    {
                        lines3.Add(val);
                        if (lines3.LongCount() >= 10)
                        {
                            break;
                        }
                    }
                    if (lines2.LongCount() >= 10)
                    {
                        lines2.Clear();
                        foreach (var val in lines3.Reverse())
                        {
                            lines2.Add(val);
                            if (lines2.LongCount() >= 10)
                            {
                                break;
                            }
                        }
                    }
                    if (lines3.LongCount() >= 10)
                    {
                        lines3.Clear();
                        foreach (var val in lines2.Reverse())
                        {
                            lines3.Add(val);
                            if (lines3.LongCount() >= 10)
                            {
                                break;
                            }
                        }
                    }

                    System.IO.File.WriteAllLines(scoresFilePath, lines);
                    lines.Clear();

                    args.DrawingSession.DrawText("Score:", 240, 200, Colors.PowderBlue);
                    args.DrawingSession.DrawText(foodAmountString, 310, 200, Colors.PowderBlue);

                    (lines3.Reverse()).Where(x => x != 0).Each(matthew => args.DrawingSession.DrawText(matthew.ToString(), 240, 280 + (20 * Array.FindIndex((lines3.Reverse()).ToArray(), y => matthew == y) + 1), Colors.Blue));
                }
            }
            if (state == mainMenu)
            {
                // background
                args.DrawingSession.FillRectangle(0, 0, 600, 600, Color.FromArgb(255, 0, 0, 0));
                args.DrawingSession.DrawText("Start Snake", 240, 240, Colors.Blue);
                args.DrawingSession.DrawText("High Score", 240, 260, Colors.Blue);
                args.DrawingSession.DrawText("My Options", 240, 280, Colors.Blue);
                args.DrawingSession.DrawText("About Game", 240, 300, Colors.Blue);

                if (menu_selector == 0)
                {
                    args.DrawingSession.FillRectangle(230, 245, 130, 20, Color.FromArgb(100, 0, 0, 150));
                }

                if (menu_selector == 1)
                {
                    args.DrawingSession.FillRectangle(230, 265, 130, 20, Color.FromArgb(100, 0, 0, 150));
                }

                if (menu_selector == 2)
                {
                    args.DrawingSession.FillRectangle(230, 285, 130, 20, Color.FromArgb(100, 0, 0, 150));
                }

                if (menu_selector == 3)
                {
                    args.DrawingSession.FillRectangle(230, 305, 130, 20, Color.FromArgb(100, 0, 0, 150));
                }
            }
        }
        private void Canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
        {
            if (!mainMenu.gameStarted)
            {
                if (mainMenu.onInstructions == false && mainMenu.onCredits == false)
                {
                    mainMenu.DrawMainMenu(args.DrawingSession);
                }
                else if (mainMenu.onInstructions == true && mainMenu.onCredits == false)
                {
                    mainMenu.DrawInstructions(args.DrawingSession);
                }
                else
                {
                    mainMenu.DrawCredits(args.DrawingSession);
                }
            }
            else if (!game.gameOver)
            {
                game.DrawAllGameObjects(args.DrawingSession);
            }
            else
            {
                var fontFormat = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat
                {
                    FontSize = 48
                };

                args.DrawingSession.DrawImage(spaceImage);//would put rect in here

                args.DrawingSession.DrawText("  Game over! Do you want to play again? (Y/N)", 0, 200, Colors.LightYellow, fontFormat);
            }
        }
Beispiel #9
0
        private void canvasAnimatedControl_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs 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;
                }

                using (CanvasPathBuilder path = new CanvasPathBuilder(sender))
                {
                    path.BeginFigure(point1);
                    path.AddLine(point3);
                    path.EndFigure(CanvasFigureLoop.Open);

                    using (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);
        }
 private void BlurCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
 {
     if (scaleEffect == null)
     {
         return;
     }
     args.DrawingSession.DrawImage(scaleEffect);
     sender.Paused = true;
 }
Beispiel #11
0
 private void CanvasAnimatedControl_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
 {
     if (IsLoadInProgress())
     {
         args.DrawingSession.Clear(Colors.Red);
     }
     else
     {
         args.DrawingSession.Clear(Colors.Green);
         if (canvasBitmap != null)
         {
             args.DrawingSession.DrawImage(canvasBitmap);
         }
     }
 }
Beispiel #12
0
 private void CanvasAnimatedControl_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
 {
     ViewModel.Draw(sender, args);
 }