Example #1
0
        //Draw Wide Numm Live Tile
        async Task ClockTileWideNumm()
        {
            try
            {
                //Load Tile Render Variables
                if (!TileRenderVarsLoaded)
                {
                    CanvasHorizontalAlignment HorizontalAlignmentTime = CanvasHorizontalAlignment.Center;
                    switch (setDisplayHorizontalAlignmentTime)
                    {
                    case 1: { HorizontalAlignmentTime = CanvasHorizontalAlignment.Left; break; }

                    case 2: { HorizontalAlignmentTime = CanvasHorizontalAlignment.Center; break; }

                    case 3: { HorizontalAlignmentTime = CanvasHorizontalAlignment.Right; break; }
                    }

                    //Live tile font styles
                    Win2DCanvasTextFormatTitle = new CanvasTextFormat()
                    {
                        FontFamily = setLiveTileFont, FontWeight = Win2DFontWeightTitle, FontSize = 79 + setLiveTileFontSize, WordWrapping = CanvasWordWrapping.NoWrap, HorizontalAlignment = HorizontalAlignmentTime, VerticalAlignment = CanvasVerticalAlignment.Center, OpticalAlignment = CanvasOpticalAlignment.NoSideBearings
                    };
                    Win2DCanvasTextFormatBody = new CanvasTextFormat()
                    {
                        FontFamily = setLiveTileFont, FontWeight = Win2DFontWeightBody, FontSize = 79 + setLiveTileFontSize, WordWrapping = CanvasWordWrapping.NoWrap, HorizontalAlignment = HorizontalAlignmentTime, VerticalAlignment = CanvasVerticalAlignment.Center, OpticalAlignment = CanvasOpticalAlignment.NoSideBearings
                    };

                    //Live tile text positions
                    switch (setLiveTileFont)
                    {
                    case "Segoe UI": { TimeHeight1 = -54; TimeHeight2 = 40; break; }

                    case "/Assets/Fonts/Gothic720-Light.ttf#Gothic720 Lt BT": { TimeHeight1 = -60; TimeHeight2 = 35; break; }

                    case "/Assets/Fonts/HelveticaNeue-UltraLight.ttf#Helvetica Neue": { TimeHeight1 = -64; TimeHeight2 = 30; break; }

                    case "/Assets/Fonts/Existence-Light.ttf#Existence": { TimeHeight1 = -63; TimeHeight2 = 31; break; }

                    case "/Assets/Fonts/OneDay-Light.ttf#ONE DAY": { TimeHeight1 = -71; TimeHeight2 = 25; break; }

                    case "/Assets/Fonts/Pier-Regular.ttf#Pier Sans": { TimeHeight1 = -54; TimeHeight2 = 41; break; }

                    case "/Assets/Fonts/Panama-Light.ttf#Panama": { TimeHeight1 = -60; TimeHeight2 = 36; break; }

                    case "/Assets/Fonts/Bellota-Light.ttf#Bellota": { TimeHeight1 = -48; TimeHeight2 = 47; break; }

                    case "/Assets/Fonts/Nooa-Semiserif.ttf#Nooa Semiserif": { TimeHeight1 = -68; TimeHeight2 = 20; break; }

                    case "/Assets/Fonts/Modeka-Light.ttf#Modeka": { TimeHeight1 = -65; TimeHeight2 = 31; break; }

                    case "/Assets/Fonts/Rawengulk-Light.ttf#Rawengulk": { TimeHeight1 = -74; TimeHeight2 = 21; break; }

                    case "/Assets/Fonts/Dense-Regular.ttf#Dense": { TimeHeight1 = -71; TimeHeight2 = 25; break; }

                    case "/Assets/Fonts/DigitalDisplay.ttf#digital display tfb": { TimeHeight1 = -75; TimeHeight2 = 20; break; }
                    }

                    TileRenderVarsLoaded = true;
                }

                using (CanvasDrawingSession ds = Win2DCanvasRenderTarget.CreateDrawingSession())
                {
                    //Live tile content - Time
                    if (setDisplayTimeCustomText)
                    {
                        DrawTimeOnTileDuo(ds, TextTimeSplit, string.Empty);
                    }
                    else
                    {
                        DrawTimeOnTileDuo(ds, TextTimeHour, TextTimeMin);
                    }
                }
                await ExportLiveTile();
            }
            catch { }
        }
        public void Draw(CanvasAnimatedDrawEventArgs args, CanvasDrawingSession ds, float width, float height)
        {
            drawCount++;

            const int maxEntries = 120;

            updatesPerDraw.Enqueue(updatesThisDraw);
            while (updatesPerDraw.Count > maxEntries)
            {
                updatesPerDraw.Dequeue();
            }

            ds.Antialiasing = CanvasAntialiasing.Aliased;

            var barWidth = width / (float)maxEntries;

            const float heightPerUpdate = 10.0f;
            float       barBottom       = height * 0.25f;

            int maxUpdates = 0;
            int maxIndex   = -1;

            int index = 0;

            foreach (int update in updatesPerDraw)
            {
                float barHeight = update * heightPerUpdate;
                Color color     = Colors.Gray;
                if ((Math.Max(0, drawCount - maxEntries) + index) % 60 == 0)
                {
                    color = Colors.White;
                }

                ds.FillRectangle(barWidth * index, height - barHeight - barBottom, barWidth, barHeight + barBottom, color);

                if (update > maxUpdates)
                {
                    maxIndex   = index;
                    maxUpdates = update;
                }
                index++;
            }

            if (maxUpdates > 0)
            {
                var y = height - maxUpdates * heightPerUpdate - barBottom;

                ds.DrawLine(0, y, width, y, Colors.White, 1, maxStroke);

                ds.DrawText(
                    maxUpdates.ToString(),
                    0,
                    height - maxUpdates * heightPerUpdate - barBottom,
                    Colors.White,
                    new CanvasTextFormat()
                {
                    FontSize            = heightPerUpdate * 2,
                    HorizontalAlignment = CanvasHorizontalAlignment.Left,
                    VerticalAlignment   = CanvasVerticalAlignment.Bottom
                });
            }

            using (var textFormat = new CanvasTextFormat()
            {
                FontSize = width * 0.05f,
                HorizontalAlignment = CanvasHorizontalAlignment.Left,
                VerticalAlignment = CanvasVerticalAlignment.Top
            })
            {
                float y = 1;
                ds.DrawText("Updates per Draw", 1, y, Colors.White, textFormat);
                y += textFormat.FontSize * 2;

                textFormat.FontSize *= 0.6f;

                ds.DrawText(string.Format("{0} total updates", args.Timing.UpdateCount), 1, y, Colors.Red, textFormat);
                y += textFormat.FontSize * 1.2f;

                ds.DrawText(string.Format("{0} total draws", drawCount), 1, y, Colors.Green, textFormat);
            }

            updatesThisDraw = 0;
        }
Example #3
0
        public async Task <Point> DrawRss(CanvasDrawingSession ds, CanvasDevice device, CanvasBitmap canvasBitmap, Point drawPoint)
        {
            if (SettingManager.GetIsDisplayRss().Item1)
            {
                var screenSize = SettingManager.GetWindowsResolution();

                string rssLink = SettingManager.GetRssLink();
                if (string.IsNullOrEmpty(rssLink))
                {
                    return(drawPoint);
                }

                string text = await BuildRssText(rssLink);

                if (String.IsNullOrEmpty(text))
                {
                    return(drawPoint);
                }

                Rect drawRect = new Rect(0, 0, 0, 0)
                {
                    X     = (screenSize.Width / 10) * 6.5,
                    Width = (screenSize.Width / 10) * 3.35,
                    Y     = drawPoint.Y
                };

                CanvasTextFormat format = new CanvasTextFormat
                {
                    FontFamily          = "Segoe UI",
                    FontSize            = (float)(screenSize.Height * 2 / 100),
                    VerticalAlignment   = CanvasVerticalAlignment.Top,
                    HorizontalAlignment = CanvasHorizontalAlignment.Left,
                    WordWrapping        = CanvasWordWrapping.WholeWord
                };

                var drawSize = BitmapHelper.TextRect(text, format, ds, drawRect.Width);

                //Margin
                //drawRect.Width = drawRect.Width + 12;
                //drawRect.Height = drawRect.Height + 8;
                //drawRect.X += 30;

                if (drawPoint.X == 0)
                {
                    drawRect.X = screenSize.Height * 1.7 / 100 + screenSize.Width - (screenSize.Width / 10 * 6.5 - screenSize.Height * 1.3 / 100)
                                 - (screenSize.Width / 10 * 3.35 + screenSize.Height * 2.5 / 100);
                }

                if (Math.Abs(drawPoint.X - screenSize.Width / 2) < 0.5)
                {
                    var haftWidth = (drawRect.Width + screenSize.Height * 2.5 / 100) / 2;
                    drawRect.X = screenSize.Width / 2 - haftWidth - (screenSize.Height * 1.3 / 100) / 2;
                }

                if (drawPoint.Y >= screenSize.Height)
                {
                    var tempHeight = drawSize.Height + screenSize.Height * 4 / 100;
                    drawRect.Y = drawPoint.Y > screenSize.Height ? drawPoint.Y - screenSize.Height - tempHeight : screenSize.Height - tempHeight - screenSize.Height * 3 / 100;
                }

                ds.FillRoundedRectangle(new Rect((int)(drawRect.X - screenSize.Height * 1.3 / 100),
                                                 (int)(drawRect.Y - screenSize.Height / 100),
                                                 (int)(drawRect.Width + screenSize.Height * 2.5 / 100),
                                                 (int)(drawSize.Height + screenSize.Height * 4 / 100)), 20, 20,
                                        new CanvasSolidColorBrush(device, Colors.Black)
                {
                    Opacity = 0.4F
                });
                ds.DrawText(text, drawRect, Colors.White, format);

                if (drawPoint.Y >= screenSize.Height)
                {
                    var tempY = drawRect.Y - screenSize.Height / 100;
                    if (tempY + screenSize.Height <= screenSize.Height * 2)
                    {
                        return(new Point(drawPoint.X, tempY + screenSize.Height));
                    }
                    return(new Point(-1, -1));
                }
                else
                {
                    var tempY = drawRect.Y - screenSize.Height / 100 + drawSize.Height + screenSize.Height * 4 / 100;
                    if (tempY <= screenSize.Height)
                    {
                        return(new Point(drawPoint.X, tempY));
                    }
                    return(new Point(-1, -1));
                }
            }
            //return new Point(0,0);
            return(drawPoint);
        }
Example #4
0
        private void LoadNodes()
        {
            _nodes = new List <NodeInfo>(200);

            //
            // First, add in the text nodes
            //

            CanvasTextFormat monthsTextFormat = new CanvasTextFormat();

            monthsTextFormat.FontFamily = "Segoe UI";
            monthsTextFormat.FontSize   = 120.0f;

            CanvasTextFormat textFormat = new CanvasTextFormat();

            textFormat.FontFamily = "Segoe UI";
            textFormat.FontSize   = 36.0f;

            _textNodes = new TextNodeInfo[]
            {
                new TextNodeInfo("JAN    FEB    MAR    APR    MAY", monthsTextFormat, new Vector2(1920, 200), new Vector3(0.0f, -2500.0f, -3000.0f), 10.0f, 0.1f, false),
                new TextNodeInfo("LAYOUT", textFormat, new Vector2(180, 52), new Vector3(76.1f, 131.2f, -100.0f), 1.0f, 0.5f, true),
                new TextNodeInfo("ADVENTURE", textFormat, new Vector2(240, 52), new Vector3(-259.8f, -101.1f, -500.0f), 0.8f, 0.5f, true),
                new TextNodeInfo("ENGINEERING", textFormat, new Vector2(280, 52), new Vector3(509.8f, 51.1f, -322.2f), 0.8f, 0.5f, true),
            };

            _nodes.AddRange(_textNodes);



            //
            // Add some extra random images to fill up the world
            //


            //
            // Set the min/max of the images to limits how far in each directly we randomly place each image.
            //
            // Note: for z-position, the items are also randomly placed on one of several planes.  It looks
            // a little too scattered/chaotic otherwise.
            //

            var min = new Vector3(_positionTracker.MinPosition.X, -_rootContainer.Size.Y * 0.65f, -25);
            var max = new Vector3(_positionTracker.MaxPosition.X, _rootContainer.Size.Y * 0.65f, 25);


            NodeManager.Instance.MinPosition = min;
            NodeManager.Instance.MaxPosition = max;

            NodeManager.Instance.MinScale = 0.05f;
            NodeManager.Instance.MaxScale = 0.4f;

            for (int i = _nodes.Count; i < _nodes.Capacity; i++)
            {
                _nodes.Add(NodeManager.Instance.GenerateRandomImageNode());
            }


            //
            // Sort the list by z, then x, then y so that they draw in the correct order.
            //

            _nodes.Sort();
        }
Example #5
0
        /// <summary>
        /// check font size
        /// </summary>
        /// <param name="resourceCreator">canvas</param>
        /// <param name="text">measure text</param>
        /// <param name="textFormat">the text format</param>
        /// <param name="limitedToWidth">0=auto</param>
        /// <param name="limitedToHeight">0=auto</param>
        /// <returns></returns>
        public static ScreenSize MeasureString(ICanvasResourceCreator resourceCreator, string text, CanvasTextFormat textFormat, float limitedToWidth = 0.0f, float limitedToHeight = 0.0f)
        {
            var tmp = textFormat.WordWrapping;

            if (limitedToHeight < 0.001f && limitedToWidth < 0.001f)
            {
                textFormat.WordWrapping = CanvasWordWrapping.NoWrap;
            }
            var layout = new CanvasTextLayout(resourceCreator, text, textFormat, limitedToWidth, limitedToHeight);

            textFormat.WordWrapping = tmp;
            return(ScreenSize.From(layout.DrawBounds.Width, layout.DrawBounds.Height));
        }
Example #6
0
        static public CompositionDrawingSurface LoadText(string text, Size sizeTarget, CanvasTextFormat textFormat, Color textColor, Color bgColor)
        {
            CompositionDrawingSurface surface = _compositionDevice.CreateDrawingSurface(sizeTarget, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);

            using (var ds = CanvasComposition.CreateDrawingSession(surface))
            {
                ds.Clear(bgColor);
                ds.DrawText(text, new Rect(0, 0, sizeTarget.Width, sizeTarget.Height), textColor, textFormat);
            }

            return(surface);
        }
 public void Draw(CanvasAnimatedDrawEventArgs args, Vector2 position, CanvasTextFormat font)
 {
     args.DrawingSession.DrawText(String, position, Color, font);
 }
Example #8
0
 internal override void setFont(CanvasTextFormat font)
 {
     this.font = font;
 }
Example #9
0
        void canvas_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args)
        {
            // Fix the source rendertarget at 96 DPI, but let the destination rendertarget inherit
            // its DPI from the CanvasControl. This means their DPI will differ when run on a high
            // DPI display, so we can make sure the region mapping functions handle that correctly.
            sourceRenderTarget = new CanvasRenderTarget(sender, width, height, 96);
            destRenderTarget   = new CanvasRenderTarget(sender, width, height);

            // Effect graph applies a subtle blur to the image, and also creates a shadow
            // with a larger blur amount and offset translation.
            blurEffect = new GaussianBlurEffect
            {
                Source     = sourceRenderTarget,
                BlurAmount = 2
            };

            shadowEffect = new ShadowEffect
            {
                Source     = sourceRenderTarget,
                BlurAmount = 6
            };

            compositeEffect = new CompositeEffect
            {
                Sources =
                {
                    new Transform2DEffect
                    {
                        Source          = shadowEffect,
                        TransformMatrix = Matrix3x2.CreateTranslation(16, 16),
                    },

                    blurEffect
                }
            };

            // Arrange a bunch of text characters.
            var textFormat = new CanvasTextFormat
            {
                FontFamily = "Comic Sans MS",
                FontSize   = 60,
            };

            characterLayouts   = new List <CanvasTextLayout>();
            characterPositions = new List <Vector2>();

            var position = Vector2.Zero;

            for (char character = 'a'; character <= 'z'; character++)
            {
                var textLayout = new CanvasTextLayout(sender, character.ToString(), textFormat, width, height);

                characterLayouts.Add(textLayout);
                characterPositions.Add(position);

                if (character == 'm')
                {
                    position.X  = 0;
                    position.Y += (float)textLayout.LayoutBounds.Height;
                }
                else
                {
                    position.X += (float)textLayout.LayoutBounds.Width;
                }
            }
        }
Example #10
0
        public void Draw(CanvasDrawingSession graphics, float scale)
        {
            var x = X * scale;
            var y = Y * scale;

            var radius = 4;
            var color  = Color.FromArgb(200, 0xD0, 0xD0, 0xD0);
            var color2 = Color.FromArgb(200, 0xD0, 0xD0, 0xD0);

            graphics.FillCircle((float)x, (float)y, radius, color);
            graphics.DrawCircle((float)x, (float)y, radius, color2);
            if (!_translated)
            {
                _translated = true;
                if (TagType == 0)
                {
                    TagText = "@" + TagText;
                }
                else if (TagType == 1)
                {
                    TagText = "#" + TagText + "#";
                }
                else
                {
                    //TagText = "↓" + TagText;
                }
            }
            var ctFormat = new CanvasTextFormat {
                FontSize = 11.0f * scale, WordWrapping = CanvasWordWrapping.NoWrap, FontFamily = "微软雅黑"
            };
            var ctLayout = new CanvasTextLayout(graphics, TagText, ctFormat, 0.0f, 0.0f);
            //字体占用高度、宽度
            var width  = ctLayout.DrawBounds.Width + 10 * scale;
            var height = ctLayout.DrawBounds.Height + 12 * scale;

            var w           = x + width + 10 * scale + height;
            var pathBuilder = new CanvasPathBuilder(graphics);


            if (w > Bound.Width * scale)  //超出画布边界
            {
                pathBuilder.BeginFigure((float)x - 5 * scale, (float)y);
                pathBuilder.AddLine((float)x - 5 * scale - 6 * scale, (float)y - (float)height / 2);
                pathBuilder.AddLine((float)x - (float)width - 5 * scale - 6 * scale, (float)y - (float)height / 2);
                pathBuilder.AddLine((float)x - (float)width - 5 * scale - 6 * scale, (float)y + (float)height / 2);
                pathBuilder.AddLine((float)x - 5 * scale - 6 * scale, (float)y + (float)height / 2);

                pathBuilder.EndFigure(CanvasFigureLoop.Closed);

                var geometry = CanvasGeometry.CreatePath(pathBuilder);

                graphics.FillGeometry(geometry, color2);
                graphics.DrawText(TagText, (float)x - (float)width - 5 * scale - 6 * scale + 5 * scale, (float)y - (float)height / 2 + 4 * scale, Colors.White, ctFormat);


                _region       = new Rect((float)x - (float)width - 5 * scale - 6 * scale, (float)y - (float)height / 2, width, height);
                _close_region = new Rect((float)x - (float)width - 5 * scale - 6 * scale - height, (float)y - (float)height / 2, height, height);

                if (ShowCloseBtn && scale == 1) //显示关闭按钮 且没有缩放
                {
                    graphics.FillRectangle(_close_region, color2);
                    graphics.DrawLine((float)_close_region.Left, (float)_close_region.Top, (float)_close_region.Left, (float)_close_region.Top + (float)height, Colors.White, 0.5f);
                    graphics.DrawText("×", (float)_close_region.Left + 6, (float)_close_region.Top, Colors.White, new CanvasTextFormat()
                    {
                        FontSize = 15, FontFamily = "微软雅黑"
                    });
                }
            }
            else
            {
                pathBuilder.BeginFigure((float)x + 5 * scale, (float)y);
                pathBuilder.AddLine((float)x + 5 * scale + 6 * scale, (float)y - (float)height / 2);
                pathBuilder.AddLine((float)x + (float)width + 5 * scale + 6 * scale, (float)y - (float)height / 2);
                pathBuilder.AddLine((float)x + (float)width + 5 * scale + 6 * scale, (float)y + (float)height / 2);
                pathBuilder.AddLine((float)x + 5 * scale + 6 + scale, (float)y + (float)height / 2);

                pathBuilder.EndFigure(CanvasFigureLoop.Closed);

                var geo = CanvasGeometry.CreatePath(pathBuilder);

                graphics.FillGeometry(geo, color2);
                graphics.DrawText(TagText, (float)x + 5 * scale + 4 * scale + 5 * scale, (float)y - (float)height / 2 + 4 * scale, Colors.White, ctFormat);

                _region       = new Rect((float)x + 5 * scale + 6 * scale, (float)y - (float)height / 2, width, height);
                _close_region = new Rect((float)x + (float)width + 5 * scale + 6 * scale, (float)y - (float)height / 2, height, height);

                if (ShowCloseBtn && scale == 1) //显示关闭按钮  且 没有缩放
                {
                    graphics.FillRectangle(_close_region, color2);
                    graphics.DrawLine((float)_close_region.Left, (float)_close_region.Top, (float)_close_region.Left, (float)_close_region.Top + (float)height, Colors.White, 0.5f);
                    graphics.DrawText("×", (float)_close_region.Left + 6, (float)_close_region.Top, Colors.White, new CanvasTextFormat()
                    {
                        FontSize = 15, FontFamily = "微软雅黑"
                    });
                }
            }
        }
Example #11
0
        //Draw Wide Lefty Live Tile
        async Task ClockTileWideLefty()
        {
            try
            {
                //Load Tile Render Variables
                if (!TileRenderVarsLoaded)
                {
                    CanvasHorizontalAlignment HorizontalAlignmentTime = CanvasHorizontalAlignment.Left;
                    switch (setDisplayHorizontalAlignmentTime)
                    {
                    case 1: { HorizontalAlignmentTime = CanvasHorizontalAlignment.Left; break; }

                    case 2: { HorizontalAlignmentTime = CanvasHorizontalAlignment.Center; break; }

                    case 3: { HorizontalAlignmentTime = CanvasHorizontalAlignment.Right; break; }
                    }

                    //Live tile font styles
                    Win2DCanvasTextFormatTitle = new CanvasTextFormat()
                    {
                        FontFamily = setLiveTileFont, FontWeight = Win2DFontWeightTitle, FontSize = 90 + setLiveTileFontSize, WordWrapping = CanvasWordWrapping.NoWrap, HorizontalAlignment = HorizontalAlignmentTime, VerticalAlignment = CanvasVerticalAlignment.Center, OpticalAlignment = CanvasOpticalAlignment.NoSideBearings
                    };
                    Win2DCanvasTextFormatBody = new CanvasTextFormat()
                    {
                        FontFamily = setLiveTileFont, FontWeight = Win2DFontWeightBody, FontSize = 90 + setLiveTileFontSize, WordWrapping = CanvasWordWrapping.NoWrap, HorizontalAlignment = HorizontalAlignmentTime, VerticalAlignment = CanvasVerticalAlignment.Center, OpticalAlignment = CanvasOpticalAlignment.NoSideBearings
                    };

                    if (setDisplayAMPMFont)
                    {
                        Win2DCanvasTextFormatSub = new CanvasTextFormat()
                        {
                            FontFamily = setLiveTileFont, FontWeight = Win2DFontWeightSub, FontSize = 38 + setLiveTileFontSize, WordWrapping = CanvasWordWrapping.NoWrap, HorizontalAlignment = CanvasHorizontalAlignment.Left, OpticalAlignment = CanvasOpticalAlignment.NoSideBearings
                        };
                    }
                    else
                    {
                        Win2DCanvasTextFormatSub = new CanvasTextFormat()
                        {
                            FontFamily = "Segoe UI", FontWeight = Win2DFontWeightSub, FontSize = 38 + setLiveTileFontSize, WordWrapping = CanvasWordWrapping.NoWrap, HorizontalAlignment = CanvasHorizontalAlignment.Left, OpticalAlignment = CanvasOpticalAlignment.NoSideBearings
                        };
                    }

                    Win2DCanvasTextFormatTextRight = new CanvasTextFormat()
                    {
                        FontFamily = setLiveTileFont, FontWeight = Win2DFontWeightBody, FontSize = 67 + (setLiveTileFontSize / 2), WordWrapping = CanvasWordWrapping.NoWrap, HorizontalAlignment = CanvasHorizontalAlignment.Right, VerticalAlignment = CanvasVerticalAlignment.Bottom, OpticalAlignment = CanvasOpticalAlignment.NoSideBearings
                    };

                    //Live tile text positions
                    switch (setLiveTileFont)
                    {
                    case "Segoe UI": { TimeHeight1 = -82; break; }

                    case "/Assets/Fonts/Gothic720-Light.ttf#Gothic720 Lt BT": { TimeHeight1 = -90; break; }

                    case "/Assets/Fonts/HelveticaNeue-UltraLight.ttf#Helvetica Neue": { TimeHeight1 = -95; break; }

                    case "/Assets/Fonts/Existence-Light.ttf#Existence": { TimeHeight1 = -94; break; }

                    case "/Assets/Fonts/OneDay-Light.ttf#ONE DAY": { TimeHeight1 = -103; break; }

                    case "/Assets/Fonts/Pier-Regular.ttf#Pier Sans": { TimeHeight1 = -78; break; }

                    case "/Assets/Fonts/Panama-Light.ttf#Panama": { TimeHeight1 = -89; break; }

                    case "/Assets/Fonts/Bellota-Light.ttf#Bellota": { TimeHeight1 = -80; break; }

                    case "/Assets/Fonts/Nooa-Semiserif.ttf#Nooa Semiserif": { TimeHeight1 = -99; break; }

                    case "/Assets/Fonts/Modeka-Light.ttf#Modeka": { TimeHeight1 = -97; break; }

                    case "/Assets/Fonts/Rawengulk-Light.ttf#Rawengulk": { TimeHeight1 = -105; break; }

                    case "/Assets/Fonts/Dense-Regular.ttf#Dense": { TimeHeight1 = -101; break; }

                    case "/Assets/Fonts/DigitalDisplay.ttf#digital display tfb": { TimeHeight1 = -104; break; }
                    }
                    switch (setLiveTileFont)
                    {
                    case "Segoe UI": { BottomTextHeight1 = -1; break; }

                    case "/Assets/Fonts/Gothic720-Light.ttf#Gothic720 Lt BT": { BottomTextHeight1 = -9; break; }

                    case "/Assets/Fonts/HelveticaNeue-UltraLight.ttf#Helvetica Neue": { BottomTextHeight1 = -13; break; }

                    case "/Assets/Fonts/Existence-Light.ttf#Existence": { BottomTextHeight1 = -9; break; }

                    case "/Assets/Fonts/OneDay-Light.ttf#ONE DAY": { BottomTextHeight1 = -11; break; }

                    case "/Assets/Fonts/Pier-Regular.ttf#Pier Sans": { BottomTextHeight1 = -3; break; }

                    case "/Assets/Fonts/Panama-Light.ttf#Panama": { BottomTextHeight1 = -9; break; }

                    case "/Assets/Fonts/Bellota-Light.ttf#Bellota": { BottomTextHeight1 = 8; break; }

                    case "/Assets/Fonts/Nooa-Semiserif.ttf#Nooa Semiserif": { BottomTextHeight1 = -9; break; }

                    case "/Assets/Fonts/Modeka-Light.ttf#Modeka": { BottomTextHeight1 = -15; break; }

                    case "/Assets/Fonts/Rawengulk-Light.ttf#Rawengulk": { BottomTextHeight1 = -25; break; }

                    case "/Assets/Fonts/Dense-Regular.ttf#Dense": { BottomTextHeight1 = -23; break; }

                    case "/Assets/Fonts/DigitalDisplay.ttf#digital display tfb": { BottomTextHeight1 = -22; break; }
                    }

                    TileRenderVarsLoaded = true;
                }

                using (CanvasDrawingSession ds = Win2DCanvasRenderTarget.CreateDrawingSession())
                {
                    //Live tile content - Time
                    DrawTimeOnTileSolo(ds, 0, false, false);

                    //Live tile content - Right
                    ds.DrawText(TextAlarmClock + DisplayPosition1Text, -LiveTilePadding, BottomTextHeight1, LiveTileWidth, LiveTileHeight, Win2DFontColorCusto, Win2DCanvasTextFormatTextRight);
                }
                await ExportLiveTile();
            }
            catch { }
        }
Example #12
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.Attribute, 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)
                        );

                    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 textLayout      = new CanvasTextLayout(drawingSession, character.Char.ToString(), format, 0.0f, 0.0f);
                        var backgroundColor = GetBackgroundColor(character.Attributes, selected);
                        var foregroundColor = GetForegroundColor(character.Attributes, selected);
                        drawingSession.FillRectangle(rect, backgroundColor);

                        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.Attribute, false));
                }
            }

            if (ViewDebugging)
            {
                AnnotateView(drawingSession);
            }
        }
        private void EnsureLayout(CanvasControl sender)
        {
            if (!needsLayout)
            {
                return;
            }

            var geometry = GetLayoutGeometry(sender);

            string text;

            if (CurrentTextOption == TextOption.English)
            {
                text =
                    "Win2D is an easy-to-use Windows Runtime API for immediate mode 2D graphics rendering with GPU acceleration. " +
                    "It is available to C# and C++ developers writing Windows apps for Windows 8.1, Windows Phone 8.1 and Windows " +
                    "10. It utilizes the power of Direct2D, and integrates seamlessly with XAML and CoreWindow. The CanvasTextAnalyzer " +
                    "class identifies what glyphs are needed to render a piece of text, including the font fallbacks to properly " +
                    "handle different languages.  Example Gallery uses it to create this Custom Text Layouts example, which wordwraps text " +
                    "to fill an arbitrary geometric shape.";
            }
            else
            {
                //
                // Storing bi-directional text as a contiguous literal causes problems in VS; it will attempt to reorder the bi-di levels
                // in the script, and it reorders them wrongly (doesn't match Word, Outlook, other programs). This works around it
                // by separating some of them out.
                //
                // This text string contains control characters around 'C#' and C++' to ensure they are drawn with the correct
                // directionality. Higher-level editors like Word use this same mechanism, since a full, correct Bidi ordering
                // isn't sufficient for them.
                //
                text =
                    "Win2D هو API  لنظام التشغيل ويندوز سهل الاستخدام لتقديم الرسومات الثنائية الابعاد " + "(2D)" +
                    "مع تسارع المعالج الجرافيك. متاح للمطورين \u202aC#\u202c و \u202aC+ +\u202c لتطوير تطبيقات الويندوز لإصدارات " +
                    "8.1،   10 و هاتف الويندوز إصدار 8.1. فإنه يستخدم قوة Direct2D، ويدمج بسهولة مع XAML وCoreWindows ." +
                    "الفئة CanvasTextAnalyzer يحدد ما هي الرموز المطلوبة لتقديم قطعة من " +
                    "النص، بما في ذلك أساسات الخط إلى التعامل مع لغات مختلفة. Example Gallery يستخدم هذه الطقنيه لعرض كيفية التعامل مع النصوص.";
            }

            // Duplicate the text, so that it fills more reading space.
            text = text + text;

            var textFormat = new CanvasTextFormat();

            textFormat.FontFamily = fontPicker.CurrentFontFamily;

            var textDirection = CurrentTextDirection == TextDirection.LeftToRight ?
                                CanvasTextDirection.LeftToRightThenTopToBottom : CanvasTextDirection.RightToLeftThenTopToBottom;

            CanvasTextAnalyzer textAnalyzer = new CanvasTextAnalyzer(text, textDirection);

            //
            // Figure out what fonts to use.
            //
            var fontResult = textAnalyzer.GetFonts(textFormat);

            //
            // Perform a script analysis on the text.
            //
            var scriptAnalysis = textAnalyzer.GetScript();

            //
            // Perform bidi analysis.
            //
            var bidiAnalysis = textAnalyzer.GetBidi();

            float maxLineSpacing = 0;
            List <FormattingSpan> formattingSpans = EvaluateFormattingSpans(textAnalyzer, fontResult, scriptAnalysis, bidiAnalysis, out maxLineSpacing);

            //
            // Perform line break analysis.
            //
            var breakpoints = textAnalyzer.GetBreakpoints();

            //
            // Get the rectangles to layout text into.
            //
            layoutRectangles = SplitGeometryIntoRectangles(geometry, maxLineSpacing, sender);

            //
            // Insert glyph runs into the layout boxes.
            //
            layoutBoxes = CreateGlyphRuns(layoutRectangles, formattingSpans, breakpoints);

            if (ShouldJustify)
            {
                Justify(textAnalyzer, layoutBoxes);
            }

            needsLayout = false;
        }
Example #14
0
        public async Task <Point> DrawWeather(CanvasDrawingSession ds, CanvasDevice device, CanvasBitmap canvasBitmap, Point drawPoint, bool isBackground = false)
        {
            #region Init & Get Weather Informations

            Size   screenSize = SettingManager.GetWindowsResolution();
            var    width      = screenSize.Width;
            var    height     = screenSize.Height;
            float  space      = (float)width - (float)drawPoint.X;
            Rect   textSize;
            var    newWidth     = width - space;
            double tempWidth    = 0;
            var    oldDrawPoint = drawPoint.Y;

            if (drawPoint.Y >= height)
            {
                drawPoint.Y = drawPoint.Y > height ? drawPoint.Y - height - height * 22 / 100 : height - height * 25 / 100;
            }

            if (!SettingsHelper.GetSetting <bool>(SettingKey.IsDisplayWeather.ToString()))
            {
                return(drawPoint);
            }

            //Get Weather condition in the 1st time
            if (CurrentWeatherInfo.Temp == null)
            {
                if (CurrentWeather?.Main == null)
                {
                    //If FixedLocation Mode is ON then get weather with FixedLocation
                    if (IsFixedLocation)
                    {
                        await GetWeather(false);
                    }
                    else
                    {
                        await GetWeather();
                    }
                }
            }
            else
            {
                //If the final state is dif then get new WeatherCondition
                if (IsFixedLocation == IsNormalMode)
                {
                    if (IsFixedLocation)
                    {
                        if (!string.IsNullOrEmpty(UserLocation))
                        {
                            await GetWeather(false);
                        }

                        //Update Mode status & IconSaved
                        StartVm.IsIconSaved = false;
                        IsNormalMode        = false;
                    }
                    else
                    {
                        await GetWeather();

                        StartVm.IsIconSaved = false;
                        IsNormalMode        = true;
                    }
                }
            }

            var isFahrenheit = SettingsHelper.GetSetting <bool>(SettingKey.IsFahrenheit.ToString());

            //If CurrentWeather isn't loaded then draw with temporary template
            //Avoid step out DrawWeather method when haven't drawn and make User think Weather Function is broken
            if (CurrentWeather?.Main == null)
            {
                CurrentWeatherInfo.Temp = isFahrenheit ? "? °F" : "? °C";
                if (string.IsNullOrEmpty(CurrentWeatherInfo.Address))
                {
                    CurrentWeatherInfo.Address       = "???";
                    CurrentWeatherInfo.Condition     = "clouds";
                    CurrentWeatherInfo.MainCondition = "??";
                }

                //Update final state to get WeatherCondition in the next time
                IsNormalMode = IsFixedLocation;
            }
            else
            {
                if (isFahrenheit)
                {
                    CurrentWeatherInfo.Temp = Math.Round(CurrentWeather.Main.Temp * 1.8 + 32) + "°F";
                }
                else
                {
                    CurrentWeatherInfo.Temp = Math.Round(CurrentWeather.Main.Temp) + "°C";
                }

                CurrentWeatherInfo.MainCondition = CurrentWeather.Weather[0].Main;
                CurrentWeatherInfo.Condition     = CurrentWeather.Weather[0].Description;
            }

            var address = CurrentWeatherInfo.Address;

            #endregion

            #region Get Address & Caculate area size, position

            if (address != null)
            {
                var strArr = address.Split(',');

                if (strArr.Count() >= 2)
                {
                    CurrentWeatherInfo.Address = string.Format("{0},{1}", strArr[strArr.Length - 2],
                                                               strArr[strArr.Length - 1]);
                }
                else
                {
                    CurrentWeatherInfo.Address = strArr[0];
                }

                var textFormat = new CanvasTextFormat
                {
                    FontFamily   = "Segoe UI Light",
                    FontSize     = (float)(height * 4 / 100),
                    WordWrapping = CanvasWordWrapping.NoWrap
                };

                textSize = BitmapHelper.TextRect(CurrentWeatherInfo.Address, textFormat, ds);

                if (string.IsNullOrEmpty(CurrentWeatherInfo.MainCondition))
                {
                    CurrentWeatherInfo.Condition     = "clouds";
                    CurrentWeatherInfo.MainCondition = "??";
                }

                //Caculate WeatherCondition text length for drawing AntiBright & Weather
                var conditionSize = BitmapHelper.TextRect(CurrentWeatherInfo.MainCondition, new CanvasTextFormat()
                {
                    FontSize     = (float)(height * 4.5 / 100),
                    FontFamily   = "Segoe UI Light",
                    FontWeight   = FontWeights.Thin,
                    WordWrapping = CanvasWordWrapping.NoWrap
                }, ds);

                var tempSize = BitmapHelper.TextRect(CurrentWeatherInfo.Temp, new CanvasTextFormat()
                {
                    FontSize     = (float)(height * 7.5 / 100),
                    WordWrapping = CanvasWordWrapping.NoWrap,
                    FontFamily   = "Segoe UI Light",
                    FontWeight   = FontWeights.Thin
                }, ds);

                //Check if CenterX + WeatherCondition(or Temperature if Temp>WeatherCon) > Address to update CenterX(use for draw WeatherCondition)
                tempWidth = tempSize.Width > conditionSize.Width ? tempSize.Width : conditionSize.Width;

                DrawPoint = new Point(newWidth - textSize.Width, drawPoint.Y);

                if (DrawPoint.X + textSize.Width + height / 100 >= newWidth)
                {
                    newWidth -= height / 100;
                    DrawPoint = new Point(newWidth - textSize.Width, drawPoint.Y);
                }

                if (drawPoint.X == 0)
                {
                    newWidth = textSize.Width > tempWidth + height * 15 / 100 + width / 100 ? textSize.Width + height * 3 / 100 : tempWidth + height * 15 / 100 + width / 100 + height * 3 / 100;

                    DrawPoint = new Point(newWidth - textSize.Width, drawPoint.Y);
                }


                //Check if WeatherIcon + TempWidth > Address to update DrawPoint
                if (DrawPoint.X + tempWidth + height * 15 / 100 + width / 100 + height / 100 >= newWidth)
                {
                    var x = DrawPoint.X - (tempWidth + DrawPoint.X + width / 100 + height * 15 / 100 + height / 100 - newWidth);
                    DrawPoint = new Point(x, drawPoint.Y);
                }

                if (Math.Abs(drawPoint.X - width / 2) < 0.5)
                {
                    var leftToCenter = width / 2 - DrawPoint.X + height * 2 / 100;
                    var haftWidth    = (newWidth - DrawPoint.X + height * 2 / 100) / 2;
                    var tempSpace    = leftToCenter - haftWidth;
                    DrawPoint = new Point(DrawPoint.X + tempSpace, DrawPoint.Y);
                    newWidth += tempSpace;
                }
            }

            #endregion

            #region Draw Methods

            if ((DrawPoint.X == 0) && (DrawPoint.Y == 0))
            {
                return(drawPoint);
            }
            {
                //Check and draw transparent black rectangle if necessary
                if (BitmapHelper.IsBrightArea(canvasBitmap,
                                              (int)(DrawPoint.X - height * 2 / 100),
                                              (int)(DrawPoint.Y - height / 100),
                                              (int)(newWidth - DrawPoint.X + height * 2 / 100),
                                              (int)height * 22 / 100))
                {
                    ds.FillRoundedRectangle(
                        new Rect(DrawPoint.X - height * 2 / 100,
                                 (int)DrawPoint.Y - height / 100,
                                 newWidth - DrawPoint.X + height * 2 / 100,
                                 height * 22 / 100), 20, 20,
                        new CanvasSolidColorBrush(device, Colors.Black)
                    {
                        Opacity = 0.4F
                    });
                }



                var strArr = CurrentWeatherInfo.Address?.Split(',');
                if (strArr?.Length > 2)
                {
                    CurrentWeatherInfo.Address = strArr[strArr.Length - 2] + "," + strArr[strArr.Length - 1];
                }

                if (CurrentWeatherInfo.Address != null)
                {
                    ds.DrawText(CurrentWeatherInfo.Address, (float)(newWidth - height * 1.5 / 100), (float)DrawPoint.Y,
                                Colors.White,
                                new CanvasTextFormat
                    {
                        FontSize            = (float)(height * 4 / 100),
                        HorizontalAlignment = CanvasHorizontalAlignment.Right,
                        FontFamily          = "Segoe UI Light",
                        FontWeight          = FontWeights.Thin
                    });
                }

                var centerX = (float)(DrawPoint.X + (newWidth - DrawPoint.X) / 2);

                //Config Area position for better Draw design
                if (tempWidth + centerX + width * 2 / 100 >= newWidth)
                {
                    centerX -= (float)tempWidth + centerX + (float)(width * 2 / 100) - (float)newWidth;
                }
                else
                {
                    if ((tempWidth + height * 15 / 100 >= textSize.Width) &&
                        (tempWidth + height * 15 / 100 + (newWidth - (float)width * 2 / 100) - textSize.Width) <= newWidth)
                    {
                        centerX = (float)((newWidth - (float)width * 2 / 100) - textSize.Width);
                    }
                }

                if (CurrentWeatherInfo.Temp != null)
                {
                    ds.DrawText(CurrentWeatherInfo.Temp, centerX, (float)(DrawPoint.Y + height * 4.5 / 100), Colors.White,
                                new CanvasTextFormat
                    {
                        FontSize            = (float)(height * 7.5 / 100),
                        HorizontalAlignment = CanvasHorizontalAlignment.Left,
                        FontFamily          = "Segoe UI Light",
                        FontWeight          = FontWeights.Thin
                    });
                }

                if (CurrentWeatherInfo.MainCondition != null)
                {
                    ds.DrawText(CurrentWeatherInfo.MainCondition, centerX, (float)(DrawPoint.Y + height * 13 / 100),
                                Colors.White,
                                new CanvasTextFormat
                    {
                        FontSize            = (float)(height * 4.5 / 100),
                        HorizontalAlignment = CanvasHorizontalAlignment.Left,
                        FontFamily          = "Segoe UI Light",
                        FontWeight          = FontWeights.Thin
                    });
                }

                if (CurrentWeatherInfo.Condition != null)
                {
                    if (isBackground)
                    {
                        var weatherIcon = PickWeatherIcon(CurrentWeatherInfo.Condition);
                        var iconSizeStr = weatherIcon.Substring(0, 3);
                        var iconSize    = int.Parse(iconSizeStr);
                        var iconBitmap  = new CanvasRenderTarget(device, iconSize, iconSize, 500);
                        using (var ds1 = iconBitmap.CreateDrawingSession())
                        {
                            var file =
                                await
                                StorageFile.GetFileFromApplicationUriAsync(
                                    new Uri("ms-appx:///ShareClass/Assets/WeatherIcon/" + weatherIcon + ".svg"));

                            using (var stream = await file.OpenStreamForReadAsync())
                                using (var reader = new StreamReader(stream))
                                {
                                    var xml = new XmlDocument();
                                    xml.LoadXml(reader.ReadToEnd(), new XmlLoadSettings {
                                        ProhibitDtd = false
                                    });

                                    var svgDocument = SvgDocument.Parse(xml);


                                    using (var renderer = new Win2dRenderer(iconBitmap, svgDocument))
                                        renderer.Render(iconSize, iconSize, ds1);

                                    ds.DrawImage(iconBitmap, new Rect(centerX - height * 15 / 100,
                                                                      DrawPoint.Y + height * 5.5 / 100, height * 13 / 100, height * 13 / 100));
                                }
                        }
                    }
                    else
                    {
                        if (!StartVm.IsIconSaved)
                        {
                            var weatherIcon = PickWeatherIcon(CurrentWeatherInfo.Condition);
                            var iconSizeStr = weatherIcon.Substring(0, 3);
                            var iconSize    = int.Parse(iconSizeStr);
                            var iconBitmap  = new CanvasRenderTarget(device, iconSize, iconSize, 500);
                            using (var ds1 = iconBitmap.CreateDrawingSession())
                            {
                                var file =
                                    await
                                    StorageFile.GetFileFromApplicationUriAsync(
                                        new Uri("ms-appx:///ShareClass/Assets/WeatherIcon/" + weatherIcon + ".svg"));

                                using (var stream = await file.OpenStreamForReadAsync())
                                    using (var reader = new StreamReader(stream))
                                    {
                                        var xml = new XmlDocument();
                                        xml.LoadXml(reader.ReadToEnd(), new XmlLoadSettings {
                                            ProhibitDtd = false
                                        });

                                        var svgDocument = SvgDocument.Parse(xml);


                                        using (var renderer = new Win2dRenderer(iconBitmap, svgDocument))
                                            renderer.Render(iconSize, iconSize, ds1);

                                        StartVm.IconBitmap  = new CanvasRenderTarget(device, iconSize, iconSize, 500);
                                        StartVm.IconBitmap  = iconBitmap;
                                        StartVm.IsIconSaved = true;

                                        ds.DrawImage(iconBitmap, new Rect(centerX - height * 15 / 100,
                                                                          DrawPoint.Y + height * 5.5 / 100, height * 13 / 100, height * 13 / 100));
                                    }
                            }
                        }
                        else
                        {
                            ds.DrawImage(StartVm.IconBitmap,
                                         new Rect(centerX - height * 15 / 100, DrawPoint.Y + height * 5.5 / 100, height * 13 / 100, height * 13 / 100));
                        }
                    }
                }


                if (oldDrawPoint >= screenSize.Height)
                {
                    var temp = DrawPoint.Y - height * 1.5 / 100;
                    if (temp + screenSize.Height <= screenSize.Height * 2)
                    {
                        return(new Point(drawPoint.X, temp + screenSize.Height));
                    }
                    return(new Point(-1, -1));
                }
                else
                {
                    var temp = DrawPoint.Y - height * 2 / 100 + height * 22 / 100;
                    if (temp <= screenSize.Height)
                    {
                        return(new Point(drawPoint.X, temp));
                    }
                    return(new Point(-1, -1));
                }
            }

            #endregion
        }
Example #15
0
 internal virtual void setFont(CanvasTextFormat font)
 {
     this.font = font;
     //font.FontFamily = "Arial";
 }
        public CodeEditBox()
        {
            InitializeComponent();
            Unloaded += CodeEditBox_Unloaded;

            _textFormat = new CanvasTextFormat
            {
                FontFamily = "Consolas",
                FontSize   = 14
            };

            // Make the control focusable
            IsTabStop = true;

            // The CoreTextEditContext processes text input, but other keys are
            // the apps's responsibility.
            _coreWindow                 = CoreWindow.GetForCurrentThread();
            _coreWindow.KeyDown        += CoreWindow_KeyDown;
            _coreWindow.PointerPressed += CoreWindow_PointerPressed;

            // Create a CoreTextEditContext for our custom edit control.
            CoreTextServicesManager manager = CoreTextServicesManager.GetForCurrentView();

            _editContext = manager.CreateEditContext();

            // Create a TextDocument where we will store the text data
            _textDocument                   = new TextDocument(_editContext);
            _textDocument.TextChanged      += TextDocument_TextChanged;
            _textDocument.SelectionChanged += TextDocument_SelectionChanged;

            //! Automatic hide and show the Input Pane. Note that on Desktop, you will need to
            //! implement the UIA text pattern to get expected automatic behavior.
            _editContext.InputPaneDisplayPolicy = CoreTextInputPaneDisplayPolicy.Automatic;
            // Set the input scope to inform software keyboard layout and text behavior.
            _editContext.InputScope = CoreTextInputScope.Default;

            // The system raises this event when it wants the edit control to remove focus.
            _editContext.FocusRemoved += EditContext_FocusRemoved;
            // The system raises this event to request layout information.
            // This is used to help choose a position for the IME candidate window.
            _editContext.LayoutRequested += EditContext_LayoutRequested;
            // The system raises this event to notify the edit control
            // that the string composition has started.
            _editContext.CompositionStarted += EditContext_CompositionStarted;
            // The system raises this event to notify the edit control
            // that the string composition is finished.
            _editContext.CompositionCompleted += EditContext_CompositionCompleted;
            // The system raises this event when the NotifyFocusLeave operation has
            // completed.
            // _editContext.NotifyFocusLeaveCompleted += EditContext_NotifyFocusLeaveCompleted;

            // Focus state reporter
            // TODO: remove this

            GotFocus  += CodeEditBox_FocusChanged;
            LostFocus += CodeEditBox_FocusChanged;
            CodeEditBox_FocusChanged(this, null);

            // Update rendertargets
            TextDisplay.SizeChanged += TextDisplay_SizeChanged;
            TextDisplay_SizeChanged(this, null);

            // Set our initial UI.
            UpdateUI();
        }
Example #17
0
 public TextInfo(ICanvasResourceCreator rc, String text)
 {
     format     = RendererSettings.getInstance().getLabelFont();
     textLayout = new CanvasTextLayout(rc, text, format, 0.0f, 0.0f);
     bounds     = getTextBounds();
 }
        protected void DrawString(Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs canvasArgs, CanvasTextFormat textFormat, double x, double y, string text, Color textColor,
                                  bool leftAligned,
                                  bool horizontallyCentered, bool verticallyCentered)
        {
            CanvasTextFormat ctf = new CanvasTextFormat()
            {
                FontSize            = textFormat.FontSize,
                FontFamily          = textFormat.FontFamily,
                HorizontalAlignment = CanvasHorizontalAlignment.Left,
                VerticalAlignment   = CanvasVerticalAlignment.Top
            };

            if (horizontallyCentered)
            {
                ctf.HorizontalAlignment = CanvasHorizontalAlignment.Center;
            }
            if (verticallyCentered)
            {
                ctf.VerticalAlignment = CanvasVerticalAlignment.Center;;
            }
            if (!leftAligned && !horizontallyCentered)
            {
                ctf.HorizontalAlignment = CanvasHorizontalAlignment.Right;
            }

            canvasArgs.DrawingSession.DrawText(text, new Vector2((float)x, (float)y), textColor, ctf);
        }
Example #19
0
        //Draw Wide Big Live Tile
        async Task ClockTileWideBig()
        {
            try
            {
                //Load Tile Render Variables
                if (!TileRenderVarsLoaded)
                {
                    CanvasHorizontalAlignment HorizontalAlignmentTime = CanvasHorizontalAlignment.Center;
                    switch (setDisplayHorizontalAlignmentTime)
                    {
                    case 1: { HorizontalAlignmentTime = CanvasHorizontalAlignment.Left; break; }

                    case 2: { HorizontalAlignmentTime = CanvasHorizontalAlignment.Center; break; }

                    case 3: { HorizontalAlignmentTime = CanvasHorizontalAlignment.Right; break; }
                    }

                    //Live tile font styles
                    Win2DCanvasTextFormatTitle = new CanvasTextFormat()
                    {
                        FontFamily = setLiveTileFont, FontWeight = Win2DFontWeightTitle, FontSize = 170 + setLiveTileFontSize, WordWrapping = CanvasWordWrapping.NoWrap, HorizontalAlignment = HorizontalAlignmentTime, OpticalAlignment = CanvasOpticalAlignment.NoSideBearings
                    };
                    Win2DCanvasTextFormatBody = new CanvasTextFormat()
                    {
                        FontFamily = setLiveTileFont, FontWeight = Win2DFontWeightBody, FontSize = 170 + setLiveTileFontSize, WordWrapping = CanvasWordWrapping.NoWrap, HorizontalAlignment = HorizontalAlignmentTime, OpticalAlignment = CanvasOpticalAlignment.NoSideBearings
                    };

                    if (setDisplayAMPMFont)
                    {
                        Win2DCanvasTextFormatSub = new CanvasTextFormat()
                        {
                            FontFamily = setLiveTileFont, FontWeight = Win2DFontWeightSub, FontSize = 45 + setLiveTileFontSize, WordWrapping = CanvasWordWrapping.NoWrap, OpticalAlignment = CanvasOpticalAlignment.NoSideBearings
                        };
                    }
                    else
                    {
                        Win2DCanvasTextFormatSub = new CanvasTextFormat()
                        {
                            FontFamily = "Segoe UI", FontWeight = Win2DFontWeightSub, FontSize = 45 + setLiveTileFontSize, WordWrapping = CanvasWordWrapping.NoWrap, OpticalAlignment = CanvasOpticalAlignment.NoSideBearings
                        };
                    }

                    Win2DCanvasTextFormatTextCenter = new CanvasTextFormat()
                    {
                        FontFamily = "Segoe UI", FontWeight = Win2DFontWeightBody, FontSize = 67 + (setLiveTileFontSize / 2), WordWrapping = CanvasWordWrapping.NoWrap, HorizontalAlignment = CanvasHorizontalAlignment.Center, VerticalAlignment = CanvasVerticalAlignment.Bottom
                    };

                    //Live tile text positions
                    switch (setLiveTileFont)
                    {
                    case "Segoe UI": { TimeHeight1 = -30; break; }

                    case "/Assets/Fonts/Gothic720-Light.ttf#Gothic720 Lt BT": { TimeHeight1 = -31; break; }

                    case "/Assets/Fonts/HelveticaNeue-UltraLight.ttf#Helvetica Neue": { TimeHeight1 = -36; break; }

                    case "/Assets/Fonts/Existence-Light.ttf#Existence": { TimeHeight1 = -45; break; }

                    case "/Assets/Fonts/OneDay-Light.ttf#ONE DAY": { TimeHeight1 = -41; break; }

                    case "/Assets/Fonts/Pier-Regular.ttf#Pier Sans": { TimeHeight1 = -29; break; }

                    case "/Assets/Fonts/Panama-Light.ttf#Panama": { TimeHeight1 = -28; break; }

                    case "/Assets/Fonts/Bellota-Light.ttf#Bellota": { TimeHeight1 = -32; break; }

                    case "/Assets/Fonts/Nooa-Semiserif.ttf#Nooa Semiserif": { TimeHeight1 = -34; break; }

                    case "/Assets/Fonts/Modeka-Light.ttf#Modeka": { TimeHeight1 = -37; break; }

                    case "/Assets/Fonts/Rawengulk-Light.ttf#Rawengulk": { TimeHeight1 = -48; break; }

                    case "/Assets/Fonts/Dense-Regular.ttf#Dense": { TimeHeight1 = -38; break; }

                    case "/Assets/Fonts/DigitalDisplay.ttf#digital display tfb": { TimeHeight1 = -54; break; }
                    }

                    TileRenderVarsLoaded = true;
                }

                using (CanvasDrawingSession ds = Win2DCanvasRenderTarget.CreateDrawingSession())
                {
                    //Live tile content - Time
                    DrawTimeOnTileSolo(ds, 0, false, true);

                    //Live tile content - Center
                    ds.DrawText(DisplayPosition1Text, 0, BottomTextCenterHeight4, LiveTileWidth, LiveTileHeight, Win2DFontColorTrans, Win2DCanvasTextFormatTextCenter);
                }
                await ExportLiveTile();
            }
            catch { }
        }
        private void DrawText(InkRecognitionUnit recoUnit, CanvasControl sender, CanvasDrawEventArgs args)
        {
            var childIds = recoUnit.childIds;
            var initialTransformation = args.DrawingSession.Transform;

            // Points of bounding rectangle to align drawn text
            float floatX = (float)recoUnit.boundingRectangle.topX;
            float floatY = (float)recoUnit.boundingRectangle.topY;

            // Rotated bounding rectangle points to get correct angle of text being drawn
            float topLeftX = (float)recoUnit.rotatedBoundingRectangle[0].x;
            float topLeftY = (float)recoUnit.rotatedBoundingRectangle[0].y;

            float topRightX = (float)recoUnit.rotatedBoundingRectangle[1].x;
            float topRightY = (float)recoUnit.rotatedBoundingRectangle[1].y;

            float bottomRightX = (float)recoUnit.rotatedBoundingRectangle[2].x;
            float bottomRightY = (float)recoUnit.rotatedBoundingRectangle[2].y;

            float bottomLeftX = (float)recoUnit.rotatedBoundingRectangle[3].x;
            float bottomLeftY = (float)recoUnit.rotatedBoundingRectangle[3].y;

            // Height and width of bounding rectangle to get font size and width for text layout
            float height = GetDistanceBetweenPoints(topRightX, bottomRightX, topRightY, bottomRightY) * dipsPerMm;
            float width  = GetDistanceBetweenPoints(bottomLeftX, bottomRightX, bottomLeftY, bottomRightY) * dipsPerMm;

            if (height < 45)
            {
                height = 45;
            }

            // Transform to get correct angle of text
            float centerPointX = ((topLeftX + topRightX) / 2) * dipsPerMm;
            float centerPointY = ((topLeftY + bottomLeftY) / 2) * dipsPerMm;
            var   centerPoint  = new Vector2(centerPointX, centerPointY);

            Matrix3x2 angle = GetRotationAngle(bottomLeftX, bottomRightX, bottomLeftY, bottomRightY, centerPoint);

            args.DrawingSession.Transform = angle;

            var textFormat = new CanvasTextFormat()
            {
                FontSize     = height - 5,
                WordWrapping = CanvasWordWrapping.NoWrap,
                FontFamily   = "Ink Free"
            };

            // Build string to be drawn to canvas
            string textLine = string.Empty;

            foreach (var item in childIds)
            {
                int id = int.Parse(item.ToString());

                // Deconstruct the tuple to get the recognized text from it
                (string text, _) = recoText[id];

                textLine += text + " ";
            }

            var textLayout = new CanvasTextLayout(sender.Device, textLine, textFormat, width, height);

            // Associate correct color with each word in string
            int index = 0;

            foreach (var item in childIds)
            {
                int id = int.Parse(item.ToString());

                // Deconstruct the tuple to get the recognized text and color from it
                (string text, Color color) = recoText[id];

                textLayout.SetColor(index, text.Length, color);

                index += text.Length + 1;
            }

            args.DrawingSession.DrawTextLayout(textLayout, floatX * dipsPerMm, floatY * dipsPerMm, Colors.Black);
            args.DrawingSession.Transform = initialTransformation;
        }