Exemplo n.º 1
0
        private void AnnotateView(CanvasDrawingSession drawingSession)
        {
            CanvasTextFormat lineNumberFormat =
                new CanvasTextFormat
            {
                FontSize     = Convert.ToSingle(canvas.FontSize / 2),
                FontFamily   = canvas.FontFamily.Source,
                FontWeight   = canvas.FontWeight,
                WordWrapping = CanvasWordWrapping.NoWrap
            };

            for (var i = 0; i < Rows; i++)
            {
                string s          = i.ToString();
                var    textLayout = new CanvasTextLayout(drawingSession, s.ToString(), lineNumberFormat, 0.0f, 0.0f);
                float  y          = i * (float)CharacterHeight;
                drawingSession.DrawLine(0, y, (float)canvas.RenderSize.Width, y, Colors.Beige);
                drawingSession.DrawTextLayout(textLayout, (float)(canvas.RenderSize.Width - (CharacterWidth / 2 * s.Length)), y, Colors.Yellow);

                s          = (i + 1).ToString();
                textLayout = new CanvasTextLayout(drawingSession, s.ToString(), lineNumberFormat, 0.0f, 0.0f);
                drawingSession.DrawTextLayout(textLayout, (float)(canvas.RenderSize.Width - (CharacterWidth / 2 * (s.Length + 3))), y, Colors.Green);
            }

            var bigText       = Terminal.DebugText;
            var bigTextLayout = new CanvasTextLayout(drawingSession, bigText, lineNumberFormat, 0.0f, 0.0f);

            drawingSession.DrawTextLayout(bigTextLayout, (float)(canvas.RenderSize.Width - bigTextLayout.DrawBounds.Width - 100), 0, Colors.Yellow);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draws horizontal and vertical coordinates for the board.
        /// </summary>
        /// <param name="resourceCreator"></param>
        /// <param name="drawingSession">used for rendering</param>
        /// <param name="boardWidth">width of the game board</param>
        /// <param name="boardHeight">height of the game board</param>
        private void DrawBoardCoordinates(ICanvasResourceCreator resourceCreator, CanvasDrawingSession drawingSession, int boardWidth, int boardHeight)
        {
            if (!this.ShowCoordinates)
            {
                return;
            }



            int startPosition = _sharedBoardControlState.OriginX;

            float fontSize = Math.Min(boardWidth * _cellSize, boardHeight * _cellSize) / (float)ReferenceWidth;

            _textFormat.FontSize = ReferenceFontSize * fontSize;

            // Draw horizontal char coordinates
            for (int i = 0; i < boardWidth; i++)
            {
                var currentPosition = startPosition + i;
                var charCode        = GetHorizontalAxisCoordinate(currentPosition, boardWidth);

                CanvasTextLayout textLayout = RenderUtilities.GetCachedCanvasTextLayout(resourceCreator, ((char)(charCode)).ToString(), _textFormat, _cellSize);
                textLayout.VerticalAlignment   = CanvasVerticalAlignment.Center;
                textLayout.HorizontalAlignment = CanvasHorizontalAlignment.Center;

                drawingSession.DrawTextLayout(
                    textLayout,
                    ((i + 1) * _cellSize),
                    0,
                    Colors.Black);

                drawingSession.DrawTextLayout(
                    textLayout,
                    ((i + 1) * _cellSize), _cellSize * (boardHeight + 1),
                    Colors.Black);
            }

            // Draw vertical numerical coordinates
            for (int i = 0; i < boardHeight; i++)
            {
                int y = (boardHeight - i) + _sharedBoardControlState.OriginY;

                CanvasTextLayout textLayout = RenderUtilities.GetCachedCanvasTextLayout(resourceCreator, y.ToString(), _textFormat, _cellSize);
                textLayout.VerticalAlignment   = CanvasVerticalAlignment.Center;
                textLayout.HorizontalAlignment = CanvasHorizontalAlignment.Center;

                drawingSession.DrawTextLayout(
                    textLayout,
                    0,
                    ((i + 1) * _cellSize),
                    Colors.Black);

                drawingSession.DrawTextLayout(
                    textLayout, _cellSize * (boardWidth + 1),
                    ((i + 1) * _cellSize),
                    Colors.Black);
            }
        }
Exemplo n.º 3
0
 public void drawText(CanvasRenderTarget crt, Color color)
 {
     using (CanvasDrawingSession ds = crt.CreateDrawingSession())
     {
         ds.DrawTextLayout(textLayout, (float)location.X, (float)location.Y, color);
     }
 }
Exemplo n.º 4
0
        private void DrawPage(CanvasDrawingSession drawingSession, Rect imageableRect, GraphSize graphSize, LabelLocation labelLocation)
        {
            drawingSession.Transform = GetPrintTransfrom(imageableRect, graphSize, out Size size);

            _graph.DrawGraph(drawingSession, size, Colors.Black);

            IReadOnlyList <IFunction> functions = _graph.Functions;

            if (functions == null || labelLocation == LabelLocation.None)
            {
                return;
            }

            // Draw function labels.
            string functionString = GetFunctionString(functions, out FuntionLocation[] locations);

            using (var layout = new CanvasTextLayout(drawingSession, functionString, LabelFormat, 100, 20))
            {
                foreach (FuntionLocation location in locations)
                {
                    int start = location.Start;
                    layout.SetColor(start, location.Length, location.Color);
                    int parenLocation = functionString.IndexOf('(', start);

                    // ++ for the f
                    layout.SetTypography(++start, parenLocation - start, SubScriptTypography);
                }

                Vector2 labelPoint = GetLabelLocation(labelLocation, layout.LayoutBounds, size);
                drawingSession.DrawTextLayout(layout, labelPoint, Colors.Black);
            }
        }
Exemplo n.º 5
0
        /// <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);
            }
        }
Exemplo n.º 6
0
 internal virtual void drawString(string str, int x, int y)
 {
     using (createAlphaLayer())
     {
         CanvasTextLayout l = new CanvasTextLayout(graphics, str, font, 0.0f, 0.0f);
         graphics.DrawTextLayout(l, x, y, c);
     }
 }
Exemplo n.º 7
0
        public void DrawCommon(CanvasDrawingSession g)
        {
            if (X1 == -1 || Y1 == -1)
            {
                return;
            }
            if (X1 == X2 && Y1 == Y2)
            {
                return;
            }

            g.DrawLine(X1, Y1, X2, Y2, Pen.Color, Pen.Width);

            //save tansform
            var save = g.Transform;

            var radians = -(float)Radians;//反方向旋转绘图

            if (IsGlyphVisible)
            {
                g.Transform = Matrix3x2.CreateRotation(radians, new Vector2(X1, Y1));
                g.DrawLine(X1, Y1 - Pen.GlyphSize / 2, X1, Y1 + Pen.GlyphSize / 2,
                           Pen.Color, Pen.Width);

                g.Transform = Matrix3x2.CreateRotation(radians, new Vector2(X2, Y2));
                g.DrawLine(X2, Y2 - Pen.GlyphSize / 2, X2, Y2 + Pen.GlyphSize / 2,
                           Pen.Color, Pen.Width);
            }

            var textLayout = CreateTextLayout(Distance.Round3().ToString(), g);

            var bounds = textLayout.LayoutBounds;
            var size   = new Size(bounds.Width + 10, bounds.Height);

            var centerX  = X1 + (X2 - X1 - size.Width) / 2;
            var centerY  = Y1 + (Y2 - Y1 - size.Height) / 2;
            var ySegment = size.Height / 2 + Pen.Width / 2 + 5;
            var offsetX  = Math.Sin(radians) * ySegment;
            var offsetY  = Math.Cos(radians) * ySegment;

            offsetX = Math.Abs(offsetX);
            offsetX = radians < 0 ? offsetX : -offsetX;

            var left = centerX - offsetX;
            var top  = centerY - offsetY;

            centerX = left + size.Width / 2;
            centerY = top + size.Height / 2;

            g.Transform = Matrix3x2.CreateRotation(radians, new Vector2((float)centerX, (float)centerY));
            var rect = new Rect(left, top, size.Width, size.Height);

            g.FillRectangle(rect, Pen.TextBackground);
            g.DrawTextLayout(textLayout, (float)left + 5, (float)top, Pen.TextColor);

            //recover transform
            g.Transform = save;
        }
Exemplo n.º 8
0
        internal virtual void drawString(string str, int x, int y)
        {
            //graphics.DrawText(str, x, y, c, font);
            //font.VerticalAlignment = CanvasVerticalAlignment.Center;
            CanvasTextLayout l = new CanvasTextLayout(graphics, str, font, 0.0f, 0.0f);

            //graphics.DrawRectangle(x, y, (float)l.DrawBounds.Width, (float)l.DrawBounds.Height, Colors.Red);
            graphics.DrawTextLayout(l, x, y, c);
        }
Exemplo n.º 9
0
        internal virtual void drawString(string str, int x, int y)
        {
            //using (createAlphaLayer())
            //{
            CanvasTextLayout l = new CanvasTextLayout(graphics, str, font, 0.0f, 0.0f);

            graphics.DrawTextLayout(l, x, y, Color.FromArgb((byte)alpha, c.R, c.G, c.B));
            //}
        }
        private static void DrawTextOverWhiteRectangle(CanvasDrawingSession ds, Vector2 paddedTopLeft, CanvasTextLayout textLayout)
        {
            var bounds = textLayout.LayoutBounds;

            var rect = new Rect(bounds.Left + paddedTopLeft.X, bounds.Top + paddedTopLeft.Y, bounds.Width, bounds.Height);

            ds.FillRectangle(rect, Colors.White);
            ds.DrawTextLayout(textLayout, paddedTopLeft, Colors.Black);
        }
Exemplo n.º 11
0
            public void Draw(CanvasDrawingSession ds, int frameCounter, float width, float height)
            {
                ++frameCounter;
                float opacity = (float)(Math.Sin(frameCounter * 0.05) + 1) / 2;

                DoTest(opacity, ignoreSource, premultipliedTarget[0]);
                DoTest(opacity, ignoreSource, ignoreTarget[0]);
                DoTest(opacity, premultipliedSource, premultipliedTarget[1]);
                DoTest(opacity, premultipliedSource, ignoreTarget[1]);

                float halfWidth = width / 2;
                var   premultipliedToIgnoreLabel        = MakeLabel(ds, "Draw Premultiplied to Ignore", halfWidth);
                var   premultipliedToPremultipliedLabel = MakeLabel(ds, "Draw Premultiplied to Premultiplied", halfWidth);
                var   ignoreToIgnoreLabel        = MakeLabel(ds, "Draw Ignore to Ignore", halfWidth);
                var   ignoreToPremultipliedLabel = MakeLabel(ds, "Draw Ignore to Premultiplied", halfWidth);

                var totalHeight = 64 * 8.0f;

                float middle = width / 2;

                float imageX    = middle + 10;
                float textRight = middle - 10;

                float y     = (height / 2) - (totalHeight / 2);
                float ydiff = 64.0f * 2.0f;

                ds.DrawImage(premultipliedTarget[0], imageX, y);
                ds.DrawTextLayout(premultipliedToPremultipliedLabel, 0, y, Colors.White);
                y += ydiff;

                ds.DrawImage(ignoreTarget[0], imageX, y);
                ds.DrawTextLayout(premultipliedToIgnoreLabel, 0, y, Colors.White);
                y += ydiff;

                ds.DrawImage(premultipliedTarget[1], imageX, y);
                ds.DrawTextLayout(ignoreToPremultipliedLabel, 0, y, Colors.White);
                y += ydiff;

                ds.DrawImage(ignoreTarget[1], imageX, y);
                ds.DrawTextLayout(ignoreToIgnoreLabel, 0, y, Colors.White);
                y += ydiff;
            }
Exemplo n.º 12
0
        private void canvas_CreateResources(Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args)
        {
            scroller_layout = new CanvasTextLayout(canvas, about, scroller_format, 0.0f, 0.0f);
            scrollPos       = new Vector2((float)canvas.ActualWidth, 2f /*((float)canvas.ActualHeight / 2) - ((float)scroller_layout.DrawBounds.Height / 2)*/);
            tw = (float)canvas.ActualWidth;

            // create renderTarget
            scrollerTarget = new CanvasRenderTarget(canvas, (float)scroller_layout.LayoutBounds.Width, (float)scroller_layout.LayoutBounds.Height);
            using (CanvasDrawingSession drawingSession = scrollerTarget.CreateDrawingSession())
            {
                drawingSession.Clear(Colors.Transparent);
                drawingSession.DrawTextLayout(scroller_layout, new Vector2(0, 0), Colors.White);
            }
        }
        private void DrawTextWithBackground(CanvasDrawingSession ds, CanvasTextLayout layout, double x, double y)
        {
            var backgroundRect = layout.LayoutBounds;

            backgroundRect.X += x;
            backgroundRect.Y += y;

            backgroundRect.X      -= 20;
            backgroundRect.Y      -= 20;
            backgroundRect.Width  += 40;
            backgroundRect.Height += 40;

            ds.FillRectangle(backgroundRect, Colors.White);
            ds.DrawTextLayout(layout, (float)x, (float)y, Colors.Black);
        }
Exemplo n.º 14
0
        public void Draw(CanvasDrawingSession drawingSession, Rect sessionBounds)
        {
            const int        verticalMargin = 3;
            CanvasTextFormat format         = new CanvasTextFormat
            {
                FontSize     = FontSize,
                WordWrapping = CanvasWordWrapping.NoWrap,
                FontWeight   = IsBold ? FontWeights.Bold : FontWeights.Normal,
                FontStyle    = IsItalic ? FontStyle.Italic : FontStyle.Normal
            };

            CanvasTextLayout textLayout = new CanvasTextLayout(drawingSession, Text, format, 0.0f, 0.0f);

            drawingSession.DrawTextLayout(textLayout, (float)(Bounds.X - sessionBounds.X + HorizontalMarginBasedOnFont), (float)(Bounds.Y - sessionBounds.Y + verticalMargin), TextColor);
        }
Exemplo n.º 15
0
        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);
                    }
            }
        }
Exemplo n.º 16
0
        private void drawMeasure(CanvasDrawingSession g, Vector2 start, Vector2 end)
        {
            var textLayout = CreateTextLayout(Vector2.Distance(start, end).Round3().ToString(), g);

            var bounds = textLayout.LayoutBounds;
            var size   = new Size(bounds.Width + 10, bounds.Height);

            var ySegment = size.Height / 2 + Pen.Width / 2 + 5;
            var q        = (end - start).Quadrant();

            switch (q)
            {
            case 2:
            case 3:
                ySegment = -ySegment;
                break;

            case 1:
            case 4:
                break;
            }

            var centerX = start.X + (end.X - start.X - size.Width) / 2;
            var centerY = start.Y + (end.Y - start.Y - size.Height) / 2;

            var radians = start.RadianX(end);

            var offsetX = Math.Sin(radians) * ySegment;
            var offsetY = Math.Cos(radians) * ySegment;

            var left = centerX - offsetX;
            var top  = centerY - offsetY;

            centerX = left + size.Width / 2;
            centerY = top + size.Height / 2;

            g.Transform = Matrix3x2.CreateRotation(-radians, new Vector2((float)centerX, (float)centerY));

            var rect = new Rect(left, top, size.Width, size.Height);

            g.FillRectangle(rect, Pen.TextBackground);
            g.DrawTextLayout(textLayout, (float)left + 5, (float)top, Pen.TextColor);
        }
Exemplo n.º 17
0
        public void DrawCommon(CanvasDrawingSession g)
        {
            //save tansform
            var save = g.Transform;

            g.FillRectangle(new Rect(X, Y, Pen.Width, Pen.Width), Pen.Color);

            var c = Colors?[4];

            if (c != null)
            {
                g.Transform = Matrix3x2.CreateRotation(radians, new Vector2(X, Y));

                var color      = c.GetValueOrDefault();
                var text       = color.ToHex();
                var textLayout = CreateTextLayout(text, g);
                var bounds     = textLayout.LayoutBounds;
                var size       = new Size(bounds.Width + 10, bounds.Height);

                var colorBlock = new Rect(X + Pen.Width / 2, Y + Pen.Width * 3 / 2 + 5,
                                          Pen.GlyphSize, Pen.GlyphSize);
                if (IsGlyphVisible)
                {
                    g.FillRectangle(colorBlock, color);
                    g.DrawRectangle(colorBlock, Pen.Color, Pen.Width);
                    colorBlock.X -= Pen.Width / 2;
                    colorBlock.Y += colorBlock.Height + Pen.Width / 2 + 5;
                }

                var left = colorBlock.Left;
                var top  = colorBlock.Top;

                var rect = new Rect(left, top, size.Width, size.Height);
                g.FillRectangle(rect, Pen.TextBackground);

                g.DrawTextLayout(textLayout, (float)left + 5, (float)top, Pen.TextColor);
            }

            //recover transform
            g.Transform = save;
        }
        private void DoEffect(CanvasDrawingSession ds, Size size, float amount)
        {
            size.Width  = size.Width - ExpandAmount;
            size.Height = size.Height - ExpandAmount;

            var offset = (float)(ExpandAmount / 2);

            using (var textLayout = CreateTextLayout(ds, size))
                using (var textCommandList = new CanvasCommandList(ds))
                {
                    using (var textDs = textCommandList.CreateDrawingSession())
                    {
                        textDs.DrawTextLayout(textLayout, 0, 0, GlowColor);
                    }

                    glowEffectGraph.Setup(textCommandList, amount);
                    ds.DrawImage(glowEffectGraph.Output, offset, offset);

                    ds.DrawTextLayout(textLayout, offset, offset, TextColor);
                }
        }
Exemplo n.º 19
0
        private void DrawHex(CanvasDrawingSession drawingSession, Hex hex, Camera camera)
        {
            if (hex.Passable)
            {
                drawingSession.DrawLine(hex.Corners[0] - camera.Offset, hex.Corners[1] - camera.Offset, Colors.Black);
                drawingSession.DrawLine(hex.Corners[1] - camera.Offset, hex.Corners[2] - camera.Offset, Colors.Black);
                drawingSession.DrawLine(hex.Corners[2] - camera.Offset, hex.Corners[3] - camera.Offset, Colors.Black);
                drawingSession.DrawLine(hex.Corners[3] - camera.Offset, hex.Corners[4] - camera.Offset, Colors.Black);
                drawingSession.DrawLine(hex.Corners[4] - camera.Offset, hex.Corners[5] - camera.Offset, Colors.Black);
                drawingSession.DrawLine(hex.Corners[5] - camera.Offset, hex.Corners[0] - camera.Offset, Colors.Black);

                var centerPoint = hex.Center - camera.Offset;

                var rect = new Rect(centerPoint.ToPoint(), centerPoint.ToPoint());
                for (int i = 0; i < 6; i++)
                {
                    rect.Union((hex.Corners[i] - camera.Offset).ToPoint());
                }

                rect.Y      = Math.Floor(rect.Y) - 2.0d;
                rect.Height = Math.Ceiling(rect.Height) + 4.0d;
                drawingSession.DrawImage(_tileImage, rect);

                drawingSession.DrawCircle(centerPoint, 3, hex.IsSelected ? Colors.Blue : Colors.Gold);
                CanvasTextFormat format = new CanvasTextFormat {
                    FontSize = 20.0f, WordWrapping = CanvasWordWrapping.NoWrap
                };
                CanvasTextLayout textLayout = new CanvasTextLayout(drawingSession, hex.Coordinate.ToString(), format, 0.0f, 0.0f);
                drawingSession.DrawTextLayout(textLayout, centerPoint.X - (float)textLayout.DrawBounds.Width / 2.0f, centerPoint.Y, Colors.Black);

                if (hex.Pawn != null)
                {
                    drawingSession.FillRectangle(new Rect((centerPoint - new Vector2(25, 25)).ToPoint(), new Size(50, 50)), hex.Pawn.Selected ? Colors.HotPink : Colors.Red);
                }
            }
            else
            {
                HighlightHex(hex, drawingSession, Colors.DarkGray);
            }
        }
Exemplo n.º 20
0
        public async Task <StorageFile> DrawAsync()
        {
            if (!CheckResources())
            {
                throw new ArgumentOutOfRangeException();
            }

            var size      = GetTileSize();
            var device    = CanvasDevice.GetSharedDevice();
            var offscreen = new CanvasRenderTarget(device, (float)size.Width, (float)size.Height, 96);

            using (CanvasDrawingSession ds = offscreen.CreateDrawingSession())
            {
                ds.Clear(Colors.Transparent);
                for (int i = 0; i < List.Count(); i++)
                {
                    var todo = List[i];
                    ds.DrawTextLayout(CreateTextLayout(device, todo.Content), new Vector2(10f, 10 * i),
                                      new CanvasSolidColorBrush(device, Colors.White));
                }
            }

            var cacheFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("LiveTile", CreationCollisionOption.OpenIfExists);

            var file = await cacheFolder.CreateFileAsync($"{TileKind.ToString()}.png", CreationCollisionOption.GenerateUniqueName);

            var bytes = offscreen.GetPixelBytes();

            using (var fs = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fs);

                encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)size.Width, (uint)size.Height, 96, 96, bytes);
                await encoder.FlushAsync();
            }

            return(file);
        }
Exemplo n.º 21
0
        //////
        // GameTree drawing
        //////

        private void DrawGameTree(CanvasDrawingSession drawingSession, GameTreeNode gameTreeRoot)
        {
            int resultVerticalOffset = 0;

            WalkGameTree(gameTreeRoot, 0, ref resultVerticalOffset, 0,
                         (node, horizontalOffset, verticalOffset, parentVerticalOffset) =>
            {
                // Calculate node position
                Vector2 stoneTopLeft = new Vector2(
                    horizontalOffset * NODESIZE + horizontalOffset * NODESPACING,
                    verticalOffset * NODESIZE + verticalOffset * NODESPACING);

                Vector2 stoneCenter = stoneTopLeft;
                stoneCenter.X      += NODESIZE * 0.5f;
                stoneCenter.Y      += NODESIZE * 0.5f;

                string nodeText = "";

                // Get text for node
                if (node.Move.Kind == MoveKind.PlaceStone)
                {
                    nodeText = node.Move.Coordinates.ToIgsCoordinates();
                }
                else if (node.Move.Kind == MoveKind.Pass)
                {
                    nodeText = NODEPASSTEXT;
                }

                CanvasTextLayout textLayout = GetTextLayoutForString(drawingSession.Device, nodeText);
                // Draw node according to the color of player whose move that was
                if (node.Move.WhoMoves == StoneColor.Black)
                {
                    // Black move
                    drawingSession.FillEllipse(stoneCenter, NODESIZE * 0.5f, NODESIZE * 0.5f, BlackNodeColor);
                    drawingSession.DrawTextLayout(textLayout, stoneTopLeft, Colors.White);
                }
                else if (node.Move.WhoMoves == StoneColor.White)
                {
                    // White move
                    drawingSession.FillEllipse(stoneCenter, NODESIZE * 0.5f, NODESIZE * 0.5f, WhiteNodeColor);
                    drawingSession.DrawTextLayout(textLayout, stoneTopLeft, Colors.Black);
                }
                else
                {
                    // Empty node, no move
                    drawingSession.FillEllipse(stoneCenter, NODESIZE * 0.5f, NODESIZE * 0.5f, EmptyNodeColor);
                }

                // If the current node is the selected node, draw highlight
                if (node == ViewModel.SelectedGameTreeNode)
                {
                    drawingSession.DrawEllipse(stoneCenter, NODESIZE * 0.5f, NODESIZE * 0.5f, HighlightNodeColor, NODEHIGHLIGHTSTROKE);
                }

                // Calculate starting and end points for line connecting two nodes
                Vector2 lineStart = new Vector2(
                    (horizontalOffset) * NODESIZE + (horizontalOffset - 1) * NODESPACING,
                    (parentVerticalOffset) * NODESIZE + parentVerticalOffset * NODESPACING + NODESIZE * 0.5f);
                Vector2 lineEnd = new Vector2(
                    horizontalOffset * NODESIZE + horizontalOffset * NODESPACING,
                    verticalOffset * NODESIZE + verticalOffset * NODESPACING + NODESIZE * 0.5f);

                // Draw line between new node and its parent
                drawingSession.DrawLine(lineStart, lineEnd, LineColor);

                return(GameTreeNodeCallbackResultBehavior.Continue);
            });
        }
Exemplo n.º 22
0
        private void CanvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            // Get the canvas drawing session
            CanvasDrawingSession canvas = args.DrawingSession;

            double actualWidth  = sender.ActualWidth;
            double actualHeight = sender.ActualHeight;

            float xCentreBottomCircle     = (float)(actualWidth / 2);
            float yCenterBottomCircle     = (float)(actualHeight - (actualWidth / 2));
            float outerRadiusBottomCircle = (float)(actualWidth / 2);

            float outerRadiusTopCircle = (float)(outerRadiusBottomCircle / 2);
            float xCenterTopCircle     = (float)(actualWidth / 2);
            float yCentreTopCircle     = (float)(outerRadiusTopCircle);

            float outerRectangleWidth  = (float)(actualWidth / 2);
            float outerRectangleHeight = (float)(actualHeight - outerRadiusBottomCircle - outerRadiusTopCircle);
            float outerRectangleTop    = outerRadiusTopCircle;
            float outerRectangleLeft   = (float)(actualWidth - outerRectangleWidth) / 2;

            // Black Background
            canvas.FillCircle(xCenterTopCircle, yCentreTopCircle, outerRadiusTopCircle, Colors.Black);
            canvas.FillRectangle(outerRectangleLeft, outerRectangleTop, outerRectangleWidth, outerRectangleHeight, Colors.Black);
            canvas.FillCircle(xCentreBottomCircle, yCenterBottomCircle, outerRadiusBottomCircle, Colors.Black);

            float innerRadiusTopCircle = outerRadiusTopCircle - 5f;

            float innerRadiusBottomCircle = outerRadiusBottomCircle - 5f;

            float innerRectangleWidth  = outerRectangleWidth - 10f;
            float innerRectangleHeight = outerRectangleHeight;
            float innerRectangleTop    = outerRadiusTopCircle;
            float innerRectangleLeft   = (float)(actualWidth - innerRectangleWidth) / 2;

            // Inner parts
            canvas.FillCircle(xCenterTopCircle, yCentreTopCircle, innerRadiusTopCircle, Colors.White);
            canvas.FillRectangle(innerRectangleLeft, innerRectangleTop, innerRectangleWidth, innerRectangleHeight, Colors.White);
            canvas.FillCircle(xCentreBottomCircle, yCenterBottomCircle, innerRadiusBottomCircle, Colors.Red);

            float valueRectangleBottom = (float)(actualHeight - (2 * outerRadiusBottomCircle));

            float maximumValueLength = valueRectangleBottom - outerRadiusTopCircle;

            // Scale
            canvas.FillRectangle(innerRectangleLeft, valueRectangleBottom, innerRectangleWidth, outerRadiusBottomCircle, Colors.Red);

            float valueLength = (float)(maximumValueLength * (Clamp(Temperature, MinimumTemperature, MaximumTemperature) / (MaximumTemperature - MinimumTemperature)));

            canvas.FillRectangle(innerRectangleLeft, valueRectangleBottom - valueLength, innerRectangleWidth, valueLength, Colors.Red);

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

            FontWeight weight = new FontWeight();

            weight.Weight = 900;

            CanvasTextFormat format = new CanvasTextFormat {
                FontSize = 20f, FontWeight = weight, WordWrapping = CanvasWordWrapping.NoWrap,
            };

            CanvasTextLayout textLayout = new CanvasTextLayout(canvas, text, format, 0.0f, 0.0f);

            float xLoc = xCentreBottomCircle - ((float)textLayout.DrawBounds.Width / 2);
            float yLoc = yCenterBottomCircle - ((float)textLayout.DrawBounds.Height);

            canvas.DrawTextLayout(textLayout, xLoc, yLoc, Colors.White);
        }
Exemplo n.º 23
0
        private void PaintTextLayer(CanvasDrawingSession drawingSession, List <VirtualTerminal.Layout.LayoutRow> spans, CanvasTextFormat textFormat, bool showBlink)
        {
            var dipToDpiRatio = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi / 96;

            double lineY = 0;

            foreach (var textRow in spans)
            {
                drawingSession.Transform =
                    Matrix3x2.CreateScale(
                        (float)(textRow.DoubleWidth ? 2.0 : 1.0),                                 // Scale double width
                        (float)(textRow.DoubleHeightBottom | textRow.DoubleHeightTop ? 2.0 : 1.0) // Scale double high
                        );

                var drawY =
                    (lineY - (textRow.DoubleHeightBottom ? CharacterHeight : 0)) *        // Offset position upwards for bottom of double high char
                    ((textRow.DoubleHeightBottom | textRow.DoubleHeightTop) ? 0.5 : 1.0); // Scale position for double height

                double drawX = 0;
                foreach (var textSpan in textRow.Spans)
                {
                    var runWidth = CharacterWidth * (textSpan.Text.Length);

                    if (textSpan.Hidden || (textSpan.Blink && !showBlink))
                    {
                        drawX += runWidth;
                        continue;
                    }

                    var color = GetSolidColorBrush(textSpan.ForgroundColor);
                    textFormat.FontWeight = textSpan.Bold ? FontWeights.Bold : FontWeights.Light;

                    var textLayout = new CanvasTextLayout(drawingSession, textSpan.Text, textFormat, 0.0f, 0.0f);
                    drawingSession.DrawTextLayout(
                        textLayout,
                        (float)drawX,
                        (float)drawY,
                        color
                        );

                    // TODO : Come up with a better means of identifying line weight and offset
                    double underlineOffset = textLayout.LineMetrics[0].Baseline * dipToDpiRatio * 1.07;

                    if (textSpan.Underline)
                    {
                        drawingSession.DrawLine(
                            new Vector2(
                                (float)drawX,
                                (float)(drawY + underlineOffset)
                                ),
                            new Vector2(
                                (float)(drawX + runWidth),
                                (float)(drawY + underlineOffset)
                                ),
                            color
                            );
                    }

                    drawX += CharacterWidth * (textSpan.Text.Length);
                }

                lineY += CharacterHeight;
            }
        }
Exemplo n.º 24
0
        public static void DrawGrid(CanvasDrawingSession drawingSession, Transform transform, Color gridColor)
        {
            Rect labelBounds = GetLabelBounds(transform.CanvasSize);

            Vector2 xAxisLeft  = transform.GetDisplayVector(transform.Left, 0);
            Vector2 xAxisRight = transform.GetDisplayVector(transform.Right, 0);

            drawingSession.DrawLine(xAxisLeft, xAxisRight, gridColor, DisplayConstants.AxisLineWidth);

            Vector2 yAxisTop    = transform.GetDisplayVector(0, transform.Top);
            Vector2 yAxisBottom = transform.GetDisplayVector(0, transform.Bottom);

            drawingSession.DrawLine(yAxisTop, yAxisBottom, gridColor, DisplayConstants.AxisLineWidth);

            Vector2 unitNormal   = transform.GetLogicalNormal(DisplayConstants.GridInterval);
            double  interval     = GetInterval(unitNormal.X);
            double  halfInterval = interval / 2;
            double  x            = transform.Left - (transform.Left % halfInterval);
            bool    isLabelLine  = Math.IEEERemainder(x, interval).AlmostEqual(0);

            for (; x <= transform.Right - (transform.Right % halfInterval); x += halfInterval)
            {
                if (x.AlmostEqual(0))
                {
                    isLabelLine = !isLabelLine;
                    continue;
                }

                Vector2 xLineStart = transform.GetDisplayVector(x, transform.Top);
                Vector2 xLineEnd   = transform.GetDisplayVector(x, transform.Bottom);
                drawingSession.DrawLine(xLineStart, xLineEnd, gridColor, GetLineWidth(isLabelLine));

                // Add the interval labels.
                if (isLabelLine)
                {
                    CanvasTextLayout label        = CreateLabel(drawingSession, x);
                    Rect             layoutBounds = label.LayoutBounds.Offset(new Vector2(xLineStart.X + 1, xAxisLeft.Y));
                    layoutBounds = ClampY(layoutBounds, labelBounds);
                    drawingSession.DrawTextLayout(label, (float)layoutBounds.Left, (float)layoutBounds.Top, gridColor);
                }

                isLabelLine = !isLabelLine;
            }

            interval     = GetInterval(unitNormal.Y);
            halfInterval = interval / 2;
            double y = transform.Top - (transform.Top % halfInterval);

            isLabelLine = Math.IEEERemainder(y, interval).AlmostEqual(0);
            for (; y >= transform.Bottom - (transform.Bottom % halfInterval); y -= halfInterval)
            {
                if (y.AlmostEqual(0))
                {
                    isLabelLine = !isLabelLine;
                    continue;
                }

                Vector2 yLineStart = transform.GetDisplayVector(transform.Left, y);
                Vector2 yLineEnd   = transform.GetDisplayVector(transform.Right, y);
                drawingSession.DrawLine(yLineStart, yLineEnd, gridColor, GetLineWidth(isLabelLine));

                if (isLabelLine)
                {
                    CanvasTextLayout label        = CreateLabel(drawingSession, y);
                    Rect             layoutBounds = label.LayoutBounds.Offset(new Vector2(yAxisTop.X + 2, yLineStart.Y));
                    layoutBounds = ClampX(layoutBounds, labelBounds);
                    drawingSession.DrawTextLayout(label, (float)layoutBounds.Left, (float)layoutBounds.Top, gridColor);
                }

                isLabelLine = !isLabelLine;
            }
        }
Exemplo n.º 25
0
        private void canvas_RegionsInvalidated(CanvasVirtualControl sender, CanvasRegionsInvalidatedEventArgs args)
        {
            if (Text == null)
            {
                return;
            }

            // Update the diff map
            if (_parentScrollViewer == null)
            {
                _parentScrollViewer = VisualTreeHelper.FindParent <ScrollViewer>(this);
                if (_parentScrollViewer != null)
                {
                    _parentScrollViewer.ViewChanged += (s, e) =>
                    {
                        if (DiffMap != null)
                        {
                            DiffMap.UpdateTextViews();
                        }
                    };

                    // Force update once
                    if (DiffMap != null)
                    {
                        DiffMap.UpdateTextViews();
                    }
                }
            }

            if (_language == null && !string.IsNullOrEmpty(FileExtension))
            {
                _language = Languages.FindById(FileExtension);
            }

            foreach (Windows.Foundation.Rect region in args.InvalidatedRegions)
            {
                using (CanvasDrawingSession ds = sender.CreateDrawingSession(region))
                {
                    ds.Clear(_defaultBackgroundColor);

                    int startLine = (int)Math.Clamp(Math.Floor(region.Top / LineHeight), 0, Text.LineCount);

                    // add 2 to the end line count. we want to "overdraw" a bit if the line is going to be cut-off
                    int endLine = (int)Math.Clamp(Math.Ceiling(region.Bottom / LineHeight) + 2, 0, Text.LineCount);

                    StringBuilder stringRegion = new StringBuilder();
                    for (int i = startLine; i < endLine; i++)
                    {
                        ITextLine line = Text.GetLine(i);
                        if (line is DiffTextLine diffLine)
                        {
                            if (diffLine.ChangeType == DiffLineType.Empty)
                            {
                                stringRegion.AppendLine(); // null line
                            }
                            else
                            {
                                stringRegion.AppendLine(Text.GetLine(i).ToString());
                            }
                        }
                    }

                    using (var canvasText = new CanvasTextLayout(ds, stringRegion.ToString(), _textFormat, 9999, (float)region.Height))
                    {
                        // Handle the diff line background colors
                        int index = 0;
                        for (int i = startLine; i < endLine; i++)
                        {
                            var line = Text.GetLine(i);

                            if (line is DiffTextLine diffLine)
                            {
                                switch (diffLine.ChangeType)
                                {
                                case DiffLineType.Insert:
                                {
                                    ds.FillRectangle(0, i * LineHeight, (float)this.ActualWidth, MathF.Ceiling(LineHeight), _addedBackgroundColor);
                                    if (_language == null)
                                    {
                                        canvasText.SetBrush(index, line.Length, _addedForegroundBrush);
                                    }
                                }
                                break;

                                case DiffLineType.Remove:
                                {
                                    ds.FillRectangle(0, i * LineHeight, (float)this.ActualWidth, MathF.Ceiling(LineHeight), _removedBackgroundColor);
                                    if (_language == null)
                                    {
                                        canvasText.SetBrush(index, line.Length, _removedForegroundBrush);
                                    }
                                }
                                break;

                                case DiffLineType.Empty:
                                {
                                    ds.FillRectangle(0, i * LineHeight, (float)this.ActualWidth, MathF.Ceiling(LineHeight), _nullBrush);
                                }
                                break;

                                case DiffLineType.Unchanged:
                                default:
                                    break;
                                }
                            }

                            index += line.Length + 2; // add for newline
                        }

                        // Syntax highlight
                        if (_language != null)
                        {
                            _colorizer.FormatLine(_language, CanvasRoot, canvasText, stringRegion.ToString());
                        }

                        // Draw the text
                        ds.DrawTextLayout(canvasText, 0, startLine * LineHeight, _defaultForegroundBrush);
                    }
                }
            }
        }
Exemplo n.º 26
0
        void DrawVU(CanvasDrawingSession ds, float volumeLeft, float volumeRight)
        {
            //TODO: move consts out of here

            Color GreenLit  = Color.FromArgb(255, 0, 255, 0);
            Color GreenDim  = Color.FromArgb(255, 0, 153, 0);
            Color YellowLit = Color.FromArgb(255, 255, 255, 0);
            Color YellowDim = Color.FromArgb(255, 153, 153, 0);
            Color RedLit    = Color.FromArgb(255, 255, 0, 0);
            Color RedDim    = Color.FromArgb(255, 153, 0, 0);

            const float gap           = 3.0f;
            const float channelGap    = 10.0f;
            const float segmentHeight = 15.0f;
            const float segmentWidth  = 50.0f;

            float[] vuValues      = { -60, -57, -54, -51, -48, -45, -42, -39, -36, -33, -30, -27, -24, -21, -18, -15, -12, -9, -6, -3, 0 };
            Size    segmentSize   = new Size(segmentWidth, segmentHeight);
            Point   positionLeft  = new Point(channelGap * 4, channelGap * 2);
            Point   positionRight = new Point(positionLeft.X + segmentWidth + channelGap, positionLeft.Y);
            Rect    segmentLeft   = new Rect(positionLeft, segmentSize);
            Rect    segmentRight  = new Rect(positionRight, segmentSize);

            // Calculate real VU meter values with rise and fall times
            m_VolumeData[0] -= (m_VolumeData[0] - volumeLeft) * (m_VolumeData[0] < volumeLeft ? meterRiseTime : meterFallTime);
            m_VolumeData[1] -= (m_VolumeData[1] - volumeRight) * (m_VolumeData[1] < volumeRight ? meterRiseTime : meterFallTime);

            m_PeakVolumeData[0] -= (m_PeakVolumeData[0] - volumeLeft) * (m_PeakVolumeData[0] < volumeLeft ? peakMeterRiseTime : peakMeterFallTime);
            m_PeakVolumeData[1] -= (m_PeakVolumeData[1] - volumeRight) * (m_PeakVolumeData[1] < volumeRight ? peakMeterRiseTime : peakMeterFallTime);

            // Match meter values to meter indexes
            int foundIndex      = Array.BinarySearch <float>(vuValues, m_VolumeData[0]);
            int leftActiveIndex = foundIndex != -1 ? (foundIndex < 0 ? ~foundIndex : foundIndex) : -1;

            foundIndex = Array.BinarySearch <float>(vuValues, m_VolumeData[1]);
            int rightActiveIndex = foundIndex != -1 ? (foundIndex < 0 ? ~foundIndex : foundIndex) : -1;

            foundIndex = Array.BinarySearch <float>(vuValues, m_PeakVolumeData[0]);
            int leftPeakIndex = foundIndex != -1 ? (foundIndex < 0 ? ~foundIndex : foundIndex) : -1;

            foundIndex = Array.BinarySearch <float>(vuValues, m_PeakVolumeData[1]);
            int rightPeakIndex = foundIndex != -1 ? (foundIndex < 0 ? ~foundIndex : foundIndex) : -1;

            /* TODO - Remove replaced with Array.BinarySearch above
             * bool found = false;
             * for (int i = vuValues.Length - 2; i > 1; i--)
             * {
             *  if (volumeLeft > vuValues[i - 1] && volumeLeft < vuValues[i + 1])
             *  {
             *      leftActiveIndex = i;
             *      found = true;
             *      break;
             *  }
             * }
             *
             * if (!found)
             * {
             *  // Debug.WriteLine("Not found");
             * }
             *
             * for (int i = vuValues.Length - 2; i > 1; i--)
             * {
             *  if (volumeRight > vuValues[i - 1] && volumeRight < vuValues[i + 1])
             *  {
             *      rightActiveIndex = i;
             *      break;
             *  }
             * }*/

            Color litColor;
            Color unLitColor;

            CanvasTextFormat formatleft = new CanvasTextFormat();

            formatleft.FontSize            = 9;
            formatleft.HorizontalAlignment = CanvasHorizontalAlignment.Right;

            CanvasTextFormat formatright = new CanvasTextFormat();

            formatright.FontSize            = 9;
            formatright.HorizontalAlignment = CanvasHorizontalAlignment.Left;

            for (int i = vuValues.Length - 1; i >= 0; i--)
            {
                CanvasTextLayout text = new CanvasTextLayout(CanvasDevice.GetSharedDevice(), vuValues[i] + " dB", formatleft, 30, 50);
                ds.DrawTextLayout(text, new Vector2((float)positionLeft.X - 34.0f, (float)positionLeft.Y), Color.FromArgb(255, 0, 0, 0));

                CanvasTextLayout text2 = new CanvasTextLayout(CanvasDevice.GetSharedDevice(), vuValues[i] + " dB", formatright, 30, 50);
                ds.DrawTextLayout(text2, new Vector2((float)positionRight.X + (float)segmentSize.Width + 4.0f, (float)positionLeft.Y), Color.FromArgb(255, 0, 0, 0));
                if (i >= vuValues.Length - 3)
                {
                    litColor   = RedLit;
                    unLitColor = RedDim;
                }
                else if (i >= vuValues.Length - 6 && i < vuValues.Length - 3)
                {
                    litColor   = YellowLit;
                    unLitColor = YellowDim;
                }
                else
                {
                    litColor   = GreenLit;
                    unLitColor = GreenDim;
                }

                segmentLeft = new Rect(positionLeft, segmentSize);

                if (i <= leftActiveIndex || i == leftPeakIndex)
                {
                    ds.FillRectangle(segmentLeft, litColor);
                }
                else
                {
                    ds.FillRectangle(segmentLeft, unLitColor);
                }
                positionLeft = new Point(positionLeft.X, positionLeft.Y + gap + segmentSize.Height);

                segmentRight = new Rect(positionRight, segmentSize);

                if (i <= rightActiveIndex || i == rightPeakIndex)
                {
                    ds.FillRectangle(segmentRight, litColor);
                }
                else
                {
                    ds.FillRectangle(segmentRight, unLitColor);
                }

                positionRight = new Point(positionRight.X, positionRight.Y + gap + segmentSize.Height);
            }
        }
Exemplo n.º 27
0
        //Render Time to Drawing Session - Trio
        void DrawTimeOnTileTrio(CanvasDrawingSession ds, string TextTop, string TextMid, string TextBot)
        {
            try
            {
                CanvasTextLayout LayoutTop = new CanvasTextLayout(ds, TextTop, Win2DCanvasTextFormatTitle, LiveTileWidth, LiveTileHeight);
                CanvasTextLayout LayoutMid = new CanvasTextLayout(ds, TextMid, Win2DCanvasTextFormatBody, LiveTileWidth, LiveTileHeight);
                CanvasTextLayout LayoutBot = new CanvasTextLayout(ds, TextBot, Win2DCanvasTextFormatBody, LiveTileWidth, LiveTileHeight);

                //Live tile content - Time
                if (!setLiveTileTimeCutOut)
                {
                    //Live tile background photo or color
                    if (setDisplayBackgroundPhoto)
                    {
                        ds.Clear(Colors.Black); ds.DrawImage(Win2DCanvasBitmap, 0, 0, Win2DCanvasRenderTarget.Bounds, setDisplayBackgroundBrightnessFloat);
                    }
                    else
                    {
                        ds.Clear(Win2DCanvasColor);
                    }

                    //Live tile content - Center
                    if (setLiveTileFontDuoColor)
                    {
                        ds.DrawTextLayout(LayoutTop, 0, (TimeHeight1 - 66), Win2DFontColorWhite);
                    }
                    else
                    {
                        ds.DrawTextLayout(LayoutTop, 0, (TimeHeight1 - 66), Win2DFontColorCusto);
                    }
                    ds.DrawTextLayout(LayoutMid, 0, TimeHeight1, Win2DFontColorCusto);
                    ds.DrawTextLayout(LayoutBot, 0, (TimeHeight1 + 58), Win2DFontColorCusto);
                }
                else
                {
                    //Live tile background transparency
                    ds.Clear(Colors.Transparent);

                    CanvasGeometry GeometryBackground = CanvasGeometry.CreateRectangle(ds, 0, 0, LiveTileWidth, LiveTileHeight);
                    CanvasGeometry GeometryTop        = CanvasGeometry.CreateText(LayoutTop);
                    CanvasGeometry GeometryMid        = CanvasGeometry.CreateText(LayoutMid);
                    CanvasGeometry GeometryBot        = CanvasGeometry.CreateText(LayoutBot);

                    if (setDisplayBackgroundPhoto)
                    {
                        CanvasGeometry GeometryExclude1 = GeometryBackground.CombineWith(GeometryTop, Matrix3x2.CreateTranslation(0, (TimeHeight1 - 66)), CanvasGeometryCombine.Exclude);
                        GeometryExclude1 = GeometryExclude1.CombineWith(GeometryMid, Matrix3x2.CreateTranslation(0, TimeHeight1), CanvasGeometryCombine.Exclude);
                        GeometryExclude1 = GeometryExclude1.CombineWith(GeometryBot, Matrix3x2.CreateTranslation(0, (TimeHeight1 + 58)), CanvasGeometryCombine.Exclude);
                        ds.FillGeometry(GeometryExclude1, Colors.Black);
                        GeometryExclude1.Dispose();
                    }

                    CanvasGeometry GeometryExclude2 = GeometryBackground.CombineWith(GeometryTop, Matrix3x2.CreateTranslation(0, (TimeHeight1 - 66)), CanvasGeometryCombine.Exclude);
                    GeometryExclude2 = GeometryExclude2.CombineWith(GeometryMid, Matrix3x2.CreateTranslation(0, TimeHeight1), CanvasGeometryCombine.Exclude);
                    GeometryExclude2 = GeometryExclude2.CombineWith(GeometryBot, Matrix3x2.CreateTranslation(0, (TimeHeight1 + 58)), CanvasGeometryCombine.Exclude);
                    if (setDisplayBackgroundPhoto)
                    {
                        ds.FillGeometry(GeometryExclude2, Win2DCanvasImageBrush);
                    }
                    else
                    {
                        ds.FillGeometry(GeometryExclude2, Win2DCanvasColor);
                    }
                    GeometryExclude2.Dispose();

                    GeometryBackground.Dispose();
                    GeometryTop.Dispose();
                    GeometryMid.Dispose();
                    GeometryBot.Dispose();
                }

                LayoutTop.Dispose();
                LayoutMid.Dispose();
                LayoutBot.Dispose();
            }
            catch { }
        }
Exemplo n.º 28
0
        //Render Time to Drawing Session - Solo
        void DrawTimeOnTileSolo(CanvasDrawingSession ds, int AmPmHeightMargin, bool AmPmCenter, bool HorizontalTime)
        {
            try
            {
                //Set the text render layout
                CanvasTextLayout LayoutTimeHour  = new CanvasTextLayout(ds, TextTimeHour, Win2DCanvasTextFormatTitle, LiveTileWidth, LiveTileHeight);
                CanvasTextLayout LayoutTimeSplit = new CanvasTextLayout(ds, TextTimeSplit, Win2DCanvasTextFormatBody, LiveTileWidth, LiveTileHeight);
                CanvasTextLayout LayoutTimeMin   = new CanvasTextLayout(ds, TextTimeMin, Win2DCanvasTextFormatBody, LiveTileWidth, LiveTileHeight);
                CanvasTextLayout LayoutTimeAmPm  = new CanvasTextLayout(ds, TextTimeAmPm, Win2DCanvasTextFormatSub, LiveTileWidth, LiveTileHeight);

                //Calculate the render positions
                int SplitWidthMargin = 15;
                int SplitHorizontal  = 0;
                int HourHorizontal   = 0;
                int MinHorizontal    = 0;
                int AmPmHorizontal   = 0;
                int AmPmVertical     = 0;

                if (Win2DCanvasTextFormatTitle.HorizontalAlignment == CanvasHorizontalAlignment.Center)
                {
                    HourHorizontal = -Convert.ToInt32((LayoutTimeHour.DrawBounds.Width / 2) + (LayoutTimeSplit.DrawBounds.Width / 2) + SplitWidthMargin);
                    MinHorizontal  = Convert.ToInt32((LayoutTimeMin.DrawBounds.Width / 2) + (LayoutTimeSplit.DrawBounds.Width / 2) + SplitWidthMargin);

                    if (!HorizontalTime)
                    {
                        if (setDisplayTimeCustomText)
                        {
                            //Calculate margin difference and center the text
                            if (setDisplayAMPMClock)
                            {
                                if (!AmPmCenter)
                                {
                                    AmPmHorizontal = Convert.ToInt32(LayoutTimeSplit.DrawBounds.Right - LayoutTimeAmPm.DrawBounds.Width);
                                }
                                AmPmVertical = Convert.ToInt32(LayoutTimeSplit.DrawBounds.Bottom + TimeHeight1 - AmPmHeightMargin);
                            }
                        }
                        else
                        {
                            //Calculate margin difference and center the text
                            Int32 MarginDifference = (Math.Abs(MinHorizontal) - Math.Abs(HourHorizontal));
                            SplitHorizontal = SplitHorizontal - MarginDifference;
                            HourHorizontal  = HourHorizontal - MarginDifference;
                            MinHorizontal   = MinHorizontal - MarginDifference;
                            if (setDisplayAMPMClock)
                            {
                                if (!AmPmCenter)
                                {
                                    AmPmHorizontal = Convert.ToInt32(LayoutTimeMin.DrawBounds.Right + MinHorizontal - LayoutTimeAmPm.DrawBounds.Width);
                                }
                                AmPmVertical = Convert.ToInt32(LayoutTimeMin.DrawBounds.Bottom + TimeHeight1 - AmPmHeightMargin);
                            }
                        }
                    }
                    else
                    {
                        if (setDisplayTimeCustomText)
                        {
                            //Calculate margin difference and center the text
                            Int32 MarginDifference = 0;
                            if (setDisplayAMPMClock)
                            {
                                MarginDifference = MarginDifference + Convert.ToInt32((LayoutTimeAmPm.DrawBounds.Width / 2) + (SplitWidthMargin / 2));
                            }
                            SplitHorizontal = SplitHorizontal - MarginDifference;

                            if (setDisplayAMPMClock)
                            {
                                AmPmHorizontal = Convert.ToInt32(LayoutTimeSplit.DrawBounds.Right + SplitWidthMargin + SplitHorizontal);
                                int TimeAmPmHeightText = Convert.ToInt32(LayoutTimeAmPm.DrawBounds.Height + LayoutTimeAmPm.DrawBounds.Top);
                                AmPmVertical = Convert.ToInt32(LayoutTimeSplit.DrawBounds.Bottom + TimeHeight1 - TimeAmPmHeightText);
                            }
                        }
                        else
                        {
                            //Calculate margin difference and center the text
                            Int32 MarginDifference = (Math.Abs(MinHorizontal) - Math.Abs(HourHorizontal));
                            if (setDisplayAMPMClock)
                            {
                                MarginDifference = MarginDifference + Convert.ToInt32((LayoutTimeAmPm.DrawBounds.Width / 2) + (SplitWidthMargin / 2));
                            }
                            SplitHorizontal = SplitHorizontal - MarginDifference;
                            HourHorizontal  = HourHorizontal - MarginDifference;
                            MinHorizontal   = MinHorizontal - MarginDifference;

                            if (setDisplayAMPMClock)
                            {
                                AmPmHorizontal = Convert.ToInt32(LayoutTimeMin.DrawBounds.Right + SplitWidthMargin + MinHorizontal);
                                int TimeAmPmHeightText = Convert.ToInt32(LayoutTimeAmPm.DrawBounds.Height + LayoutTimeAmPm.DrawBounds.Top);
                                AmPmVertical = Convert.ToInt32(LayoutTimeMin.DrawBounds.Bottom + TimeHeight1 - TimeAmPmHeightText);
                            }
                        }
                    }
                }
                else if (Win2DCanvasTextFormatTitle.HorizontalAlignment == CanvasHorizontalAlignment.Right)
                {
                    if (setDisplayTimeCustomText)
                    {
                        SplitHorizontal = -LiveTilePadding;
                        AmPmHorizontal  = -LiveTilePadding;
                        AmPmVertical    = Convert.ToInt32(LayoutTimeSplit.DrawBounds.Bottom + TimeHeight1 - AmPmHeightMargin);
                    }
                    else
                    {
                        MinHorizontal   = -LiveTilePadding;
                        SplitHorizontal = -Convert.ToInt32(LiveTilePadding + LayoutTimeMin.DrawBounds.Width + SplitWidthMargin);
                        HourHorizontal  = -Convert.ToInt32(LiveTilePadding + LayoutTimeMin.DrawBounds.Width + SplitWidthMargin + LayoutTimeSplit.DrawBounds.Width + SplitWidthMargin);
                        AmPmHorizontal  = -LiveTilePadding;
                        AmPmVertical    = Convert.ToInt32(LayoutTimeMin.DrawBounds.Bottom + TimeHeight1 - AmPmHeightMargin);
                    }
                }
                else if (Win2DCanvasTextFormatTitle.HorizontalAlignment == CanvasHorizontalAlignment.Left)
                {
                    if (setDisplayTimeCustomText)
                    {
                        SplitHorizontal = LiveTilePadding;
                        AmPmHorizontal  = LiveTilePadding;
                        AmPmVertical    = Convert.ToInt32(LayoutTimeSplit.DrawBounds.Bottom + TimeHeight1 - AmPmHeightMargin);
                    }
                    else
                    {
                        HourHorizontal  = LiveTilePadding;
                        SplitHorizontal = Convert.ToInt32(LiveTilePadding + LayoutTimeHour.DrawBounds.Width + SplitWidthMargin);
                        MinHorizontal   = Convert.ToInt32(LiveTilePadding + LayoutTimeHour.DrawBounds.Width + SplitWidthMargin + LayoutTimeSplit.DrawBounds.Width + SplitWidthMargin);
                        AmPmHorizontal  = LiveTilePadding;
                        AmPmVertical    = Convert.ToInt32(LayoutTimeHour.DrawBounds.Bottom + TimeHeight1 - AmPmHeightMargin);
                    }
                }

                //Check the live tile text style
                if (!setLiveTileTimeCutOut)
                {
                    //Live tile background photo or color
                    if (setDisplayBackgroundPhoto)
                    {
                        ds.Clear(Colors.Black); ds.DrawImage(Win2DCanvasBitmap, 0, 0, Win2DCanvasRenderTarget.Bounds, setDisplayBackgroundBrightnessFloat);
                    }
                    else
                    {
                        ds.Clear(Win2DCanvasColor);
                    }

                    if (setLiveTileFontDuoColor)
                    {
                        ds.DrawTextLayout(LayoutTimeHour, HourHorizontal, TimeHeight1, Win2DFontColorWhite);
                        ds.DrawTextLayout(LayoutTimeSplit, SplitHorizontal, TimeHeight1, Win2DFontColorCusto);
                        ds.DrawTextLayout(LayoutTimeMin, MinHorizontal, TimeHeight1, Win2DFontColorCusto);
                        ds.DrawTextLayout(LayoutTimeAmPm, AmPmHorizontal, AmPmVertical, Win2DFontColorWhite);
                    }
                    else
                    {
                        ds.DrawTextLayout(LayoutTimeHour, HourHorizontal, TimeHeight1, Win2DFontColorCusto);
                        ds.DrawTextLayout(LayoutTimeSplit, SplitHorizontal, TimeHeight1, Win2DFontColorCusto);
                        ds.DrawTextLayout(LayoutTimeMin, MinHorizontal, TimeHeight1, Win2DFontColorCusto);
                        ds.DrawTextLayout(LayoutTimeAmPm, AmPmHorizontal, AmPmVertical, Win2DFontColorCusto);
                    }
                }
                else
                {
                    //Live tile background transparency
                    ds.Clear(Colors.Transparent);

                    CanvasGeometry GeometryBackground = CanvasGeometry.CreateRectangle(ds, 0, 0, LiveTileWidth, LiveTileHeight);
                    CanvasGeometry GeometryHour       = CanvasGeometry.CreateText(LayoutTimeHour);
                    CanvasGeometry GeometrySplit      = CanvasGeometry.CreateText(LayoutTimeSplit);
                    CanvasGeometry GeometryMin        = CanvasGeometry.CreateText(LayoutTimeMin);
                    CanvasGeometry GeometryAmPm       = CanvasGeometry.CreateText(LayoutTimeAmPm);

                    if (setDisplayBackgroundPhoto)
                    {
                        CanvasGeometry GeometryExclude1 = GeometryBackground.CombineWith(GeometryHour, Matrix3x2.CreateTranslation(HourHorizontal, TimeHeight1), CanvasGeometryCombine.Exclude);
                        GeometryExclude1 = GeometryExclude1.CombineWith(GeometrySplit, Matrix3x2.CreateTranslation(SplitHorizontal, TimeHeight1), CanvasGeometryCombine.Exclude);
                        GeometryExclude1 = GeometryExclude1.CombineWith(GeometryMin, Matrix3x2.CreateTranslation(MinHorizontal, TimeHeight1), CanvasGeometryCombine.Exclude);
                        GeometryExclude1 = GeometryExclude1.CombineWith(GeometryAmPm, Matrix3x2.CreateTranslation(AmPmHorizontal, AmPmVertical), CanvasGeometryCombine.Exclude);
                        ds.FillGeometry(GeometryExclude1, Colors.Black);
                        GeometryExclude1.Dispose();
                    }

                    CanvasGeometry GeometryExclude2 = GeometryBackground.CombineWith(GeometryHour, Matrix3x2.CreateTranslation(HourHorizontal, TimeHeight1), CanvasGeometryCombine.Exclude);
                    GeometryExclude2 = GeometryExclude2.CombineWith(GeometrySplit, Matrix3x2.CreateTranslation(SplitHorizontal, TimeHeight1), CanvasGeometryCombine.Exclude);
                    GeometryExclude2 = GeometryExclude2.CombineWith(GeometryMin, Matrix3x2.CreateTranslation(MinHorizontal, TimeHeight1), CanvasGeometryCombine.Exclude);
                    GeometryExclude2 = GeometryExclude2.CombineWith(GeometryAmPm, Matrix3x2.CreateTranslation(AmPmHorizontal, AmPmVertical), CanvasGeometryCombine.Exclude);
                    if (setDisplayBackgroundPhoto)
                    {
                        ds.FillGeometry(GeometryExclude2, Win2DCanvasImageBrush);
                    }
                    else
                    {
                        ds.FillGeometry(GeometryExclude2, Win2DCanvasColor);
                    }
                    GeometryExclude2.Dispose();

                    GeometryBackground.Dispose();
                    GeometryHour.Dispose();
                    GeometrySplit.Dispose();
                    GeometryMin.Dispose();
                    GeometryAmPm.Dispose();
                }

                LayoutTimeHour.Dispose();
                LayoutTimeSplit.Dispose();
                LayoutTimeMin.Dispose();
                LayoutTimeAmPm.Dispose();
            }
            catch { }
        }
Exemplo n.º 29
0
        private void OnCanvasDraw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            CanvasDrawingSession drawingSession = args.DrawingSession;

            CanvasTextFormat format =
                new CanvasTextFormat
            {
                FontSize     = Convert.ToSingle(canvas.FontSize),
                FontFamily   = canvas.FontFamily.Source,
                FontWeight   = canvas.FontWeight,
                WordWrapping = CanvasWordWrapping.NoWrap
            };

            ProcessTextFormat(drawingSession, format);

            drawingSession.FillRectangle(new Rect(0, 0, canvas.RenderSize.Width, canvas.RenderSize.Height), GetBackgroundColor(Terminal.CursorState.Attributes, false));

            lock (Terminal)
            {
                int   row            = ViewTop;
                float verticalOffset = -row * (float)CharacterHeight;

                var lines = Terminal.ViewPort.GetLines(ViewTop, Rows);

                var defaultTransform = drawingSession.Transform;
                foreach (var line in lines)
                {
                    if (line == null)
                    {
                        row++;
                        continue;
                    }

                    int column = 0;

                    drawingSession.Transform = Matrix3x2.CreateScale(
                        (float)(line.DoubleWidth ? 2.0 : 1.0),
                        (float)(line.DoubleHeightBottom | line.DoubleHeightTop ? 2.0 : 1.0)
                        );

                    var spanStart = 0;
                    while (column < line.Count)
                    {
                        bool selected        = TextSelection == null ? false : TextSelection.Within(column, row);
                        var  backgroundColor = GetBackgroundColor(line[column].Attributes, selected);

                        if (column < (line.Count - 1) && GetBackgroundColor(line[column + 1].Attributes, TextSelection == null ? false : TextSelection.Within(column + 1, row)) == backgroundColor)
                        {
                            column++;
                            continue;
                        }

                        var rect = new Rect(
                            spanStart * CharacterWidth,
                            ((row - (line.DoubleHeightBottom ? 1 : 0)) * CharacterHeight + verticalOffset) * (line.DoubleHeightBottom | line.DoubleHeightTop ? 0.5 : 1.0),
                            ((column - spanStart + 1) * CharacterWidth) + 0.9,
                            CharacterHeight + 0.9
                            );

                        drawingSession.FillRectangle(rect, backgroundColor);

                        column++;
                        spanStart = column;
                    }

                    row++;
                }
                drawingSession.Transform = defaultTransform;

                row = ViewTop;
                foreach (var line in lines)
                {
                    if (line == null)
                    {
                        row++;
                        continue;
                    }

                    int column = 0;

                    drawingSession.Transform = Matrix3x2.CreateScale(
                        (float)(line.DoubleWidth ? 2.0 : 1.0),
                        (float)(line.DoubleHeightBottom | line.DoubleHeightTop ? 2.0 : 1.0)
                        );

                    var    spanStart = 0;
                    string toDisplay = string.Empty;
                    while (column < line.Count)
                    {
                        bool selected        = TextSelection == null ? false : TextSelection.Within(column, row);
                        var  foregroundColor = GetForegroundColor(line[column].Attributes, selected);

                        toDisplay += line[column].Char.ToString() + line[column].CombiningCharacters;
                        if (
                            column < (line.Count - 1) &&
                            GetForegroundColor(line[column + 1].Attributes, TextSelection == null ? false : TextSelection.Within(column + 1, row)) == foregroundColor &&
                            line[column + 1].Attributes.Underscore == line[column].Attributes.Underscore &&
                            line[column + 1].Attributes.Reverse == line[column].Attributes.Reverse &&
                            line[column + 1].Attributes.Bright == line[column].Attributes.Bright
                            )
                        {
                            column++;
                            continue;
                        }

                        var rect = new Rect(
                            spanStart * CharacterWidth,
                            ((row - (line.DoubleHeightBottom ? 1 : 0)) * CharacterHeight + verticalOffset) * (line.DoubleHeightBottom | line.DoubleHeightTop ? 0.5 : 1.0),
                            ((column - spanStart + 1) * CharacterWidth) + 0.9,
                            CharacterHeight + 0.9
                            );

                        var textLayout = new CanvasTextLayout(drawingSession, toDisplay, format, 0.0f, 0.0f);

                        drawingSession.DrawTextLayout(
                            textLayout,
                            (float)rect.Left,
                            (float)rect.Top,
                            foregroundColor
                            );

                        if (line[column].Attributes.Underscore)
                        {
                            drawingSession.DrawLine(
                                new Vector2(
                                    (float)rect.Left,
                                    (float)rect.Bottom
                                    ),
                                new Vector2(
                                    (float)rect.Right,
                                    (float)rect.Bottom
                                    ),
                                foregroundColor
                                );
                        }

                        column++;
                        spanStart = column;
                        toDisplay = "";
                    }

                    //foreach (var character in line)
                    //{
                    //    bool selected = TextSelection == null ? false : TextSelection.Within(column, row);

                    //    var rect = new Rect(
                    //        column * CharacterWidth,
                    //        ((row - (line.DoubleHeightBottom ? 1 : 0)) * CharacterHeight + verticalOffset) * (line.DoubleHeightBottom | line.DoubleHeightTop ? 0.5 : 1.0),
                    //        CharacterWidth + 0.9,
                    //        CharacterHeight + 0.9
                    //    );

                    //    var toDisplay = character.Char.ToString() + character.CombiningCharacters;

                    //    var textLayout = new CanvasTextLayout(drawingSession, toDisplay, format, 0.0f, 0.0f);
                    //    var foregroundColor = GetForegroundColor(character.Attributes, selected);

                    //    drawingSession.DrawTextLayout(
                    //        textLayout,
                    //        (float)rect.Left,
                    //        (float)rect.Top,
                    //        foregroundColor
                    //    );

                    //    if (character.Attributes.Underscore)
                    //    {
                    //        drawingSession.DrawLine(
                    //            new Vector2(
                    //                (float)rect.Left,
                    //                (float)rect.Bottom
                    //            ),
                    //            new Vector2(
                    //                (float)rect.Right,
                    //                (float)rect.Bottom
                    //            ),
                    //            foregroundColor
                    //        );
                    //    }

                    //    column++;
                    //}
                    row++;
                }
                drawingSession.Transform = defaultTransform;

                if (Terminal.CursorState.ShowCursor)
                {
                    var cursorY    = Terminal.ViewPort.TopRow - ViewTop + Terminal.CursorState.CurrentRow;
                    var cursorRect = new Rect(
                        Terminal.CursorState.CurrentColumn * CharacterWidth,
                        cursorY * CharacterHeight,
                        CharacterWidth + 0.9,
                        CharacterHeight + 0.9
                        );

                    drawingSession.DrawRectangle(cursorRect, GetForegroundColor(Terminal.CursorState.Attributes, false));
                }
            }

            if (ViewDebugging)
            {
                AnnotateView(drawingSession);
            }
        }
Exemplo n.º 30
0
        public void Draw(CanvasDrawingSession drawingSession, CanvasTimingInformation timing)
        {
            float pulseTime(float period)
            {
                float modTime = (float)(timing.TotalTime.TotalMilliseconds % period);

                if (modTime < period / 2)
                {
                    return(modTime / (period / 2));
                }
                else
                {
                    return(1 - (modTime - period / 2) / (period / 2));
                }
            }

            fpsCounter.Draw(timing);
            using (var ds = bloomRendering.CreateDrawingSession())
            {
                ds.Clear(Colors.Black);
                ds.Transform = Camera.Transform;
                for (float x = -EntityManager.GameSize + 100; x < EntityManager.GameSize; x += 100)
                {
                    ds.DrawLine(new Vector2(x, -EntityManager.GameSize), new Vector2(x, EntityManager.GameSize), Color.FromArgb(255, 20, 0, 0), 2);
                }

                for (float y = -EntityManager.GameSize + 100; y < EntityManager.GameSize; y += 100)
                {
                    ds.DrawLine(new Vector2(-EntityManager.GameSize, y), new Vector2(EntityManager.GameSize, y), Color.FromArgb(255, 20, 0, 0), 2);
                }

                using (var spriteBatch = ds.CreateSpriteBatch())
                {
                    EntityRenderer.Draw(spriteBatch, timing);
                }


                float pulse = pulseTime(1000);

                ds.DrawLine(new Vector2(-EntityManager.GameSize, -EntityManager.GameSize), new Vector2(-EntityManager.GameSize, EntityManager.GameSize), Colors.OrangeRed, 3 + pulse * 2);
                ds.DrawLine(new Vector2(EntityManager.GameSize, -EntityManager.GameSize), new Vector2(EntityManager.GameSize, EntityManager.GameSize), Colors.OrangeRed, 3 + pulse * 2);
                ds.DrawLine(new Vector2(-EntityManager.GameSize, EntityManager.GameSize), new Vector2(EntityManager.GameSize, EntityManager.GameSize), Colors.OrangeRed, 3 + pulse * 2);
                ds.DrawLine(new Vector2(-EntityManager.GameSize, -EntityManager.GameSize), new Vector2(EntityManager.GameSize, -EntityManager.GameSize), Colors.OrangeRed, 3 + pulse * 2);
            }

            bloomRendering.DrawResult(drawingSession);
            foreach (var player in EntityManager.Entities.Where(e => e is Player).Cast <Player>())
            {
                var playerColor    = Color.FromArgb((byte)(player.Color.W * 255), (byte)(player.Color.X * 255), (byte)(player.Color.Y * 255), (byte)(player.Color.Z * 255));
                var playerPosition = Vector2.Transform(player.Position, Camera.Transform);
                var textLayout     = new CanvasTextLayout(drawingSession, player.Name, new CanvasTextFormat {
                    FontSize = 12
                }, 256.0f, 32.0f)
                {
                    WordWrapping = CanvasWordWrapping.NoWrap
                };
                var textSize = textLayout.LayoutBounds;
                drawingSession.DrawTextLayout(textLayout, playerPosition - new Vector2((float)(textSize.Width / 2), (float)(textSize.Height / 2 + 64)), playerColor);
                drawingSession.DrawRectangle(new Rect(playerPosition.X - 32, playerPosition.Y - 48, 64f, 8), playerColor);
                if (player.Health > 0)
                {
                    drawingSession.FillRectangle(new Rect(playerPosition.X - 32, playerPosition.Y - 48, 64f * player.Health / 100f, 8), playerColor);
                }
                if (player.Shield > 0)
                {
                    drawingSession.FillRectangle(new Rect(playerPosition.X - 32, playerPosition.Y - 48, 64f * player.Shield / 100f, 8), Colors.Aquamarine);
                }
            }

            drawingSession.DrawText("FPS: " + fpsCounter.FPS, new Vector2(0, 0), fpsCounter.FPS > 50 ? Colors.LimeGreen : fpsCounter.FPS > 40 ? Colors.YellowGreen : fpsCounter.FPS > 30 ? Colors.Yellow : fpsCounter.FPS > 20 ? Colors.Orange : fpsCounter.FPS > 10 ? Colors.OrangeRed : Colors.Red);
            drawingSession.DrawText("Ping: " + Math.Round(gameServer.PingMS), new Vector2(0, 32), gameServer.PingMS < 25 ? Colors.LimeGreen : gameServer.PingMS < 50 ? Colors.YellowGreen : gameServer.PingMS < 100 ? Colors.Yellow : gameServer.PingMS < 150 ? Colors.Orange : gameServer.PingMS < 300 ? Colors.OrangeRed : Colors.Red);
            drawingSession.DrawText(DebugString ?? "", new Vector2(0, 64), Colors.Wheat);
        }