public TextInfo(ICanvasResourceCreator rc, String text)
 {
     
     format = RendererSettings.getInstance().getLabelFont();
     textLayout = new CanvasTextLayout(rc, text, format, 0.0f, 0.0f);
     bounds = getTextBounds();
 }
        private void DrawRegion(CanvasVirtualImageSource sender, Rect region)
        {
            var tryPanningOrZoomingLayout = new CanvasTextLayout(sender.Device, "Try panning or zooming.", format, 500, 0);

            var infoLayout = new CanvasTextLayout(sender.Device,
                "In this demo, each time a region is updated, it is cleared to a different background color.  " +
                "This is to make it possible to see which regions get redrawn.",
                format, 500, 0);

            var youMadeIt = new CanvasTextLayout(sender.Device,
                "You made it to the end!", endFormat, 1000, 0);

            using (var ds = sender.CreateDrawingSession(NextColor(), region))
            {
                var left = ((int)(region.X / gridSize) - 1) * gridSize;
                var top = ((int)(region.Y / gridSize) - 1) * gridSize;
                var right = ((int)((region.X + region.Width) / gridSize) + 1) * gridSize;
                var bottom = ((int)((region.Y + region.Height) / gridSize) + 1) * gridSize;

                for (var x = left; x <= right; x += gridSize)
                {
                    for (var y = top; y <= bottom; y += gridSize)
                    {
                        var pos = new Vector2((float)x, (float)y);
                        ds.DrawCircle(pos, 10, Colors.White);

                        ds.DrawText(string.Format("{0}\n{1}", x, y), pos, Colors.DarkBlue, coordFormat);
                    }
                }

                DrawTextWithBackground(ds, tryPanningOrZoomingLayout, gridSize / 2, gridSize / 2);
                DrawTextWithBackground(ds, infoLayout, gridSize * 3.5, gridSize * 5.5);
                DrawTextWithBackground(ds, youMadeIt, width - youMadeIt.RequestedSize.Width, height - youMadeIt.RequestedSize.Height);
            }
        }
        public win2d_TextboxCursor(CanvasDevice device, Color color)
        {
            Color = color;
            LastUpdate = TimeSpan.Zero;

            CursorCharacter = new CanvasTextLayout(device, "|", Statics.DefaultFontNoWrap, 0, 0);
        }
 public win2d_Button(CanvasDevice device, Vector2 position, int width, int height, string text)
     : base(position, width, height)
 {
     Color = Colors.Gray;
     TextLayout = new CanvasTextLayout(device, text, Statics.DefaultFontNoWrap, 0, 0);
     RecalculateLayout();
 }
        private IEnumerable<ITextRender2MeasureMapLine> AnalyzeMap(CanvasTextLayout tl, string allText)
        {
            var lines = tl.LineMetrics;
            int idx = 0;
            var formatChanges = ToRanges(tl.GetFormatChangeIndices(), allText.Length).ToArray();
            for (int i = 0; i < lines.Length; i++)
            {
                var line = lines[i];
                //var regions = tl.GetCharacterRegions(idx, line.CharacterCount);
                var regions = GetRegions(tl, idx, line, formatChanges).ToArray();

                var resMap = new List<TextRender2MeasureMapElement>();

                foreach (var region in regions)
                {
                    var attr = tl.GetCustomBrush(region.CharacterIndex) as ITextRenderAttributeState;
                    var subStr = allText.Substring(region.CharacterIndex, region.CharacterCount).Replace("\n", "");
                    if (subStr.Length > 0)
                    {
                        resMap.Add(new TextRender2MeasureMapElement()
                        {
                            Command = new TextRenderCommand(attr ?? new TextRenderAttributeState(), new TextRenderTextContent(subStr)),
                            Placement = new Point(region.LayoutBounds.X, region.LayoutBounds.Y),
                            Size = new Size(region.LayoutBounds.Width, region.LayoutBounds.Height)
                        });
                    }
                }

                yield return new MeasureMapLine(resMap.ToArray(), i, line.Height);
                idx += line.CharacterCount;
            }
        }
        public void Draw(CanvasAnimatedDrawEventArgs args, Vector2 position, CanvasTextFormat font)
        {
            if (LastFont == null || LastFont.FontFamily != font.FontFamily || LastFont.FontSize != font.FontSize)
            {
                Widths.Clear();

                // recalculate widths
                for(int i = 0; i < Parts.Count; i++)
                {
                    CanvasTextLayout layoutTemp = new CanvasTextLayout(args.DrawingSession, Parts[i].String.Replace(' ', '.'), font, 0, 0);
                    Widths.Add((float)layoutTemp.LayoutBounds.Width);
                }

                LastFont = font;
            }

            float fOffsetX = 0.0f;
            for (int i = 0; i < Parts.Count; i++)
            {
                // draw string part
                args.DrawingSession.DrawText(Parts[i].String, new Vector2(position.X + fOffsetX, position.Y), Parts[i].Color, font);

                // add to offset
                fOffsetX += Widths[i];
            }
        }
        /// <summary>
        /// Создать карту.
        /// </summary>
        /// <param name="program">Программа.</param>
        /// <param name="width">Ширина.</param>
        /// <param name="fontSize">Размер шрифта.</param>
        /// <param name="maxLines">Максимальное число линий.</param>
        /// <returns>Карта.</returns>
        public ITextRender2MeasureMap CreateMap(ITextRender2RenderProgram program, double width, double fontSize, int? maxLines)
        {
            if (program == null) throw new ArgumentNullException(nameof(program));
            var interProgram = CreateIntermediateProgram(program).ToArray();
            var allText = interProgram.Aggregate(new StringBuilder(), (sb, s) => sb.Append(s.RenderString)).ToString();
            using (var tf = new CanvasTextFormat())
            {
                tf.FontFamily = "Segoe UI";
                tf.FontSize = (float)fontSize;
                tf.WordWrapping = CanvasWordWrapping.Wrap;
                tf.Direction = CanvasTextDirection.LeftToRightThenTopToBottom;
                tf.Options = CanvasDrawTextOptions.Default;

                var screen = DisplayInformation.GetForCurrentView();
                using (var ds = new CanvasRenderTarget(CanvasDevice.GetSharedDevice(), (float) width, 10f, screen.LogicalDpi))
                {
                    using (var tl = new CanvasTextLayout(ds, allText, tf, (float)width, 10f))
                    {
                        var helperArgs = interProgram.OfType<MappingHelperArg>().ToList();
                        mappingHelper.ApplyAttributes(tl, helperArgs, fontSize);
                        var map = AnalyzeMap(tl, allText).ToArray();
                        var result = new MeasureMap(map, width, maxLines, StrikethrougKoef);
                        return result;
                    }
                }
            }
        }
Beispiel #8
0
        void EnsureResources(ICanvasResourceCreatorWithDpi resourceCreator, Size targetSize)
        {
            if (resourceRealizationSize == targetSize && !needsResourceRecreation)
                return;

            float canvasWidth = (float)targetSize.Width;
            float canvasHeight = (float)targetSize.Height;
            sizeDim = Math.Min(canvasWidth, canvasHeight);

            if (!defaultFontSizeSet)
            {
                CurrentFontSize = sizeDim / 1.3f;
                CurrentFontSize = Math.Max((float)fontSizeSlider.Minimum, CurrentFontSize);
                CurrentFontSize = Math.Min((float)fontSizeSlider.Maximum, CurrentFontSize);
                fontSizeSlider.Value = CurrentFontSize;
                defaultFontSizeSet = true;
            }

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

            if (!UniformStyle)
            {
                textLayout.SetFontSize(0, 1, CurrentUppercaseFontSize);
                textLayout.SetFontFamily(0, 1, uppercaseFontPicker.CurrentFontFamily);

                textLayout.SetFontSize(1, 2, CurrentLowercaseFontSize);
                textLayout.SetFontFamily(1, 2, lowercaseFontPicker.CurrentFontFamily);
            }

            needsResourceRecreation = false;
            resourceRealizationSize = targetSize;
        }
        public RichListBox(CanvasDevice device, Vector2 position, int width, int height, string title, CanvasTextFormat titleFont, CanvasTextFormat stringsFont, int maxStrings = 0)
        {
            // base(device, position, width, 0, title, titleFont)
            Position = position;

            // title
            Title = new CanvasTextLayout(device, title, titleFont, 0, 0);
            TitlePosition = new Vector2(Position.X + Padding, Position.Y + Padding);

            // width is derived from title bounds
            Width = width;  //(int)Title.LayoutBounds.Width + Padding * 2;
            Height = height;

            // bar under title
            BarUnderTitleLeft = new Vector2(Position.X, Position.Y + Padding * 2 + (float)Title.LayoutBounds.Height);
            BarUnderTitleRight = new Vector2(Position.X + Width, Position.Y + Padding * 2 + (float)Title.LayoutBounds.Height);

            // strings
            StringsFont = stringsFont;
            StringsTextLayout = new CanvasTextLayout(device, "THIS IS A PRETTY GOOD TEMP STRING", StringsFont, 0, 0);
            StringsPosition = new Vector2(Position.X + Padding, BarUnderTitleRight.Y + Padding);

            MaxStrings = maxStrings == 0 ? 1000 : maxStrings;

            BorderRectangle = new Rect(Position.X, Position.Y, Width, Height);
        }
 public FeedItemLayoutData(CanvasDevice device, FeedItem feedItem, float fRequestedWidth)
 {
     FeedDataTitleLayout = new CanvasTextLayout(device, feedItem.FeedDataTitle, Statics.DefaultFont, fRequestedWidth, 20);
     PublicationDateLayout = new CanvasTextLayout(device, feedItem.PublicationDate.ToString("MM/dd/yy"), Statics.DefaultFont, fRequestedWidth, 20); // MMMM dd, yyyy - h:mm
     TitleLayout = new CanvasTextLayout(device, feedItem.Title, Statics.DefaultFont, fRequestedWidth, 20);
     AuthorLayout = new CanvasTextLayout(device, feedItem.Author, Statics.DefaultFont, fRequestedWidth, 20);
     if (feedItem.Title != feedItem.Content) { ContentLayout = new CanvasTextLayout(device, feedItem.Content, Statics.DefaultFont, fRequestedWidth, 20); }
     LinkLayout = new CanvasTextLayout(device, feedItem.Link.ToString(), Statics.DefaultFont, fRequestedWidth, 20);
 }
Beispiel #11
0
        public static void Initialize(CanvasDevice device)
        {
            LoadCharacterWidths(device);

            UpArrow = new CanvasTextLayout(device, "\u2191", Statics.DefaultFontNoWrap, 0, 0);
            DoubleUpArrow = new CanvasTextLayout(device, "\u219f", Statics.DefaultFontNoWrap, 0, 0);
            DownArrow = new CanvasTextLayout(device, "\u2193", Statics.DefaultFontNoWrap, 0, 0);
            DoubleDownArrow = new CanvasTextLayout(device, "\u21a1", Statics.DefaultFontNoWrap, 0, 0);
        }
        public win2d_Button(CanvasDevice device, Vector2 position, int width, int height, string text)
            : base(position, width, height)
        {
            ButtonRectangle = new Rect(Position.X, Position.Y, Width, Height);

            TextLayout = new CanvasTextLayout(device, text, Statics.DefaultFontNoWrap, 0, 0);
            TextLayoutPosition = new Vector2(Position.X + (Width - (float)TextLayout.LayoutBounds.Width) / 2, Position.Y + (Height - (float)TextLayout.LayoutBounds.Height) / 2);

            Color = Colors.Gray;
        }
        public win2d_Slider(CanvasDevice device, Vector2 position, int width, string text, int minValue, int maxValue, int startingValue)
            : base(position, width, -1)
        {
            _device = device;
            _minValue = minValue;
            _maxValue = maxValue;

            _textlayout = new CanvasTextLayout(_device, text, Statics.DefaultFontNoWrap, 0, 0);

            _sliderbarrect = new Rect(Position.X, Position.Y + _textlayout.LayoutBounds.Height + Statics.Padding, Width, 10);
            Height = (int)_textlayout.LayoutBounds.Height + Statics.Padding + 10;
        }
        public win2d_Textbox(CanvasDevice device, Vector2 position, int width)
            : base(position, width, -1)
        {
            _device = device;

            CanvasTextLayout layout = new CanvasTextLayout(_device, "TEST!", Statics.DefaultFontNoWrap, 0, 0);
            Height = (int)layout.LayoutBounds.Height + PaddingY * 2;
            Color = Colors.White;

            Cursor = new win2d_TextboxCursor(_device, Colors.White);
            CursorStringIndex = 0;

            RecalculateLayout();
        }
        public RichListBoxLeaderboard(CanvasDevice device, Vector2 position, int width, int height, string title, CanvasTextFormat titleFont, CanvasTextFormat stringsFont, CanvasTextFormat leadersFont)
            : base(device, position, width, height, title, titleFont, stringsFont, 0)
        {
            LeadersFont = leadersFont;

            // calculate leaders text layout (for text height)
            LeadersTextLayout = new CanvasTextLayout(device, "ABCDEFG", LeadersFont, 0, 0);

            // calculate leaders position Y (X is calculated for each string)
            LeadersPosition = new Vector2(StringsPosition.X, StringsPosition.Y);

            // leaders position is dynamic
            // strings position is dynamic

            MaxY = (int)Position.Y + Height - Padding;
        }
        public win2d_Textbox(CanvasDevice device, Vector2 position, int width)
            : base(position, width, -1)
        {
            CanvasTextLayout layout = new CanvasTextLayout(device, "TEST!", Statics.DefaultFontNoWrap, 0, 0);

            Position = position;
            Width = width;
            Height = (int)layout.LayoutBounds.Height + PaddingY * 2;
            Color = Colors.White;

            TextPosition = new Vector2(position.X + PaddingX, position.Y + PaddingY);
            Border = new Rect(position.X, position.Y, width, Height);

            Cursor = new win2d_TextboxCursor(device, Colors.White);
            CursorStringIndex = 0;
            bRecalculateLayout = true;
        }
        public static void SetProgress(CanvasDevice device, Tuple<string, float> progress)
        {
            ProgressPhaseTextLayout = new CanvasTextLayout(device, progress.Item1, Statics.FontMedium, 0, 0);
            float x = (float)(Statics.CanvasWidth - ProgressPhaseTextLayout.LayoutBounds.Width) / 2;
            float y = (float)(Statics.CanvasHeight - ProgressPhaseTextLayout.LayoutBounds.Height) / 2;
            ProgressPhaseTextLayoutPosition = new Vector2(x, y);

            ProgressPercentage = progress.Item2;
            ProgressPercentageRect = new Rect((Statics.CanvasWidth - ProgressBarWidth) / 2,
                                                      ProgressPhaseTextLayoutPosition.Y + ProgressPhaseTextLayout.LayoutBounds.Height + 10,
                                                      ProgressBarWidth * ProgressPercentage,
                                                      20);
            ProgressPercentageBorderRect = new Rect((Statics.CanvasWidth - ProgressBarWidth) / 2,
                                                            ProgressPhaseTextLayoutPosition.Y + ProgressPhaseTextLayout.LayoutBounds.Height + 10,
                                                            ProgressBarWidth,
                                                            20);
        }
        void canvas_CreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            // Create the Direct3D teapot model.
            teapot = new TeapotRenderer(sender);

            // Create Win2D resources for drawing the scrolling text.
            var textFormat = new CanvasTextFormat
            {
                FontSize = fontSize,
                HorizontalAlignment = CanvasHorizontalAlignment.Center
            };

            textLayout = new CanvasTextLayout(sender, scrollingText, textFormat, textRenderTargetSize - textMargin * 2, float.MaxValue);

            textRenderTarget = new CanvasRenderTarget(sender, textRenderTargetSize, textRenderTargetSize);

            // Set the scrolling text rendertarget (a Win2D object) as
            // source texture for our 3D teapot model (which uses Direct3D).
            teapot.SetTexture(textRenderTarget);
        }
        public static void Initialize(CanvasDevice device)
        {
            _device = device;
            BackgroundRect = new Rect(0, 0, Statics.CanvasWidth, Statics.CanvasHeight);

            TitleLayout = new CanvasTextLayout(device, Title, Statics.FontLarge, 0, 0);
            TitlePosition = new Vector2(
                (float)(Statics.CanvasWidth - TitleLayout.LayoutBounds.Width) / 2,
                (float)((Statics.CanvasHeight / 4) - (TitleLayout.LayoutBounds.Height / 2)));

            int nRectWidth = 200;
            int nRectHeight = 200;
            int nPadding = 10;
            int nX = (Statics.CanvasWidth - nRectWidth) / 2;
            int nY = Statics.CanvasHeight * 3 / 4 - nRectHeight / 2;
            MenuItemsBorderRect = new Rect(nX, nY, nRectWidth, nRectHeight);
            MenuItemsPosition = new Vector2(nX + nPadding, nY + nPadding);

            fNextMenuItemPositionY = MenuItemsPosition.Y;
            AddMainMenuItems();
        }
        public RichListBoxProminent(CanvasDevice device, Vector2 position, int width, string title, CanvasTextFormat titleFont, int maxStrings, CanvasTextFormat stringsFont, CanvasTextFormat prominentStringFont)
            : base(device, position, width, 0, title, titleFont, stringsFont, maxStrings)
        {
            // strings height
            double dStringsHeight = StringsTextLayout.LayoutBounds.Height * (MaxStrings - 1);

            // bar under strings
            BarUnderStringsLeft = new Vector2(Position.X, StringsPosition.Y + (float)dStringsHeight + Padding);
            BarUnderStringsRight = new Vector2(Position.X + Width, StringsPosition.Y + (float)dStringsHeight + Padding);

            // prominent string
            ProminentStringPosition = new Vector2(Position.X + Padding, BarUnderStringsRight.Y + Padding);
            ProminentStringFont = prominentStringFont;
            ProminentStringLayout = new CanvasTextLayout(device, "THIS IS A PRETTY GOOD TEMP STRING", ProminentStringFont, 0, 0);

            // total height
            Height = (int)(Title.LayoutBounds.Height + Padding * 6 + dStringsHeight + ProminentStringLayout.LayoutBounds.Height);

            // border
            BorderRectangle = new Rect(Position.X, Position.Y, Width, Height);
        }
        private async void TextBlock_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            var textblock = sender as TextBlock;
            utextblock = new UniversalElement(sender);

            var textformat = new CanvasTextFormat()
            {
                FontFamily = textblock.FontFamily.Source,
                FontSize = (float)textblock.FontSize,
                FontStretch = textblock.FontStretch,
                FontWeight = textblock.FontWeight
            };

            var textlayout = new CanvasTextLayout(utextblock.Masker.Device, textblock.Text, textformat, (float)textblock.ActualWidth + 6, (float)textblock.ActualHeight + 6);

            var geometry = CanvasGeometry.CreateText(textlayout);

            await utextblock.CreateMaskBrush(geometry.Stroke(3), Colors.Blue);

            var first = (utextblock.Element.Parent as Panel).Children.First();
            ElementCompositionPreview.SetElementChildVisual(first, utextblock.Visual);
        }
Beispiel #22
0
        void EnsureResources(ICanvasResourceCreatorWithDpi resourceCreator, Size targetSize)
        {
            if (resourceRealizationSize != targetSize && !needsResourceRecreation)
                return;

            float canvasWidth = (float)targetSize.Width;
            float canvasHeight = (float)targetSize.Height;

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

            textLayout = CreateTextLayout(resourceCreator, canvasWidth, canvasHeight);
            textGeometry = CanvasGeometry.CreateText(textLayout);

            needsResourceRecreation = false;
            resourceRealizationSize = targetSize;
        }
Beispiel #23
0
        private CanvasTextLayout CreateTextLayout(ICanvasResourceCreator resourceCreator, float canvasWidth, float canvasHeight)
        {
            string testString;

            if (CurrentTextLengthOption == TextLengthOption.Short)
            {
                testString = "one two";
            }
            else
            {
                testString = "This is some text which demonstrates Win2D's text-to-geometry option; there are sub-options of this test which apply lining options such as underline or strike-through. Additionally,  this example applies different text directions to ensure glyphs are transformed correctly.";
            }

            if(ThumbnailGenerator.IsDrawingThumbnail)
            {
                testString = "a";
            }

            for (int i = 0; i < testString.Length; ++i)
            {
                if (testString[i] == ' ')
                {
                    int nextSpace = testString.IndexOf(' ', i + 1);
                    int limit = nextSpace == -1 ? testString.Length : nextSpace;

                    WordBoundary wb = new WordBoundary();
                    wb.Start = i + 1;
                    wb.Length = limit - i - 1;
                    everyOtherWordBoundary.Add(wb);
                    i = limit;
                }
            }

            float sizeDim = Math.Min(canvasWidth, canvasHeight);

            CanvasTextFormat textFormat = new CanvasTextFormat()
            {
                FontSize = CurrentTextLengthOption == TextLengthOption.Paragraph? sizeDim * 0.09f : sizeDim * 0.3f,
                Direction = CurrentTextDirection,
            };

            if (ThumbnailGenerator.IsDrawingThumbnail)
            {
                textFormat.FontSize = sizeDim * 0.75f;
            }

            CanvasTextLayout textLayout = new CanvasTextLayout(resourceCreator, testString, textFormat, canvasWidth, canvasHeight);

            if(CurrentTextEffectOption == TextEffectOption.UnderlineEveryOtherWord)
            {
                foreach(WordBoundary wb in everyOtherWordBoundary)
                {
                    textLayout.SetUnderline(wb.Start, wb.Length, true);
                }
            }
            else if (CurrentTextEffectOption == TextEffectOption.StrikeEveryOtherWord)
            {
                foreach (WordBoundary wb in everyOtherWordBoundary)
                {
                    textLayout.SetStrikethrough(wb.Start, wb.Length, true);
                }
            }

            textLayout.VerticalGlyphOrientation = CurrentVerticalGlyphOrientation;

            return textLayout;
        }
Beispiel #24
0
        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);
        }
Beispiel #25
0
        private void DrawPage(CanvasPrintDocument sender, CanvasDrawingSession ds, uint pageNumber, Rect imageableRect)
        {
            var cellAcross = new Vector2(cellSize.X, 0);
            var cellDown = new Vector2(0, cellSize.Y);

            var totalSize = cellAcross * columns + cellDown * rows;
            Vector2 topLeft = (pageSize - totalSize) / 2;

            int bitmapIndex = ((int)pageNumber - 1) * bitmapsPerPage;

            var labelFormat = new CanvasTextFormat()
            {
                FontFamily = "Comic Sans MS",
                FontSize = 12,
                VerticalAlignment = CanvasVerticalAlignment.Bottom,
                HorizontalAlignment = CanvasHorizontalAlignment.Left
            };

            var numberFormat = new CanvasTextFormat()
            {
                FontFamily = "Comic Sans MS",
                FontSize = 18,
                VerticalAlignment = CanvasVerticalAlignment.Top,
                HorizontalAlignment = CanvasHorizontalAlignment.Left
            };

            var pageNumberFormat = new CanvasTextFormat()
            {
                FontFamily = "Comic Sans MS",
                FontSize = 10,
                VerticalAlignment = CanvasVerticalAlignment.Bottom,
                HorizontalAlignment = CanvasHorizontalAlignment.Center
            };

            var titleFormat = new CanvasTextFormat()
            {
                FontFamily = "Comic Sans MS",
                FontSize = 24,
                VerticalAlignment = CanvasVerticalAlignment.Top,
                HorizontalAlignment = CanvasHorizontalAlignment.Left
            };


            if (pageNumber == 1)
                ds.DrawText("Win2D Printing Example", imageableRect, Colors.Black, titleFormat);

            ds.DrawText(string.Format("Page {0} / {1}", pageNumber, pageCount),
                imageableRect,
                Colors.Black,
                pageNumberFormat);

            DrawGrid(ds, cellAcross, cellDown, topLeft);

            for (int row = 0; row < rows; ++row)
            {
                for (int column = 0; column < columns; ++column)
                {
                    var cellTopLeft = topLeft + (cellAcross * column) + (cellDown * row);

                    var paddedTopLeft = cellTopLeft + textPadding / 2;
                    var paddedSize = cellSize - textPadding;

                    var bitmapInfo = bitmaps[bitmapIndex % bitmaps.Count];

                    // Center the bitmap in the cell
                    var bitmapPos = cellTopLeft + (cellSize - bitmapInfo.Bitmap.Size.ToVector2()) / 2;

                    ds.DrawImage(bitmapInfo.Bitmap, bitmapPos);

                    using (var labelLayout = new CanvasTextLayout(sender, bitmapInfo.Name, labelFormat, paddedSize.X, paddedSize.Y))
                    using (var numberLayout = new CanvasTextLayout(sender, (bitmapIndex + 1).ToString(), numberFormat, paddedSize.X, paddedSize.Y))
                    {
                        DrawTextOverWhiteRectangle(ds, paddedTopLeft, labelLayout);
                        DrawTextOverWhiteRectangle(ds, paddedTopLeft, numberLayout);
                    }

                    bitmapIndex++;
                }
            }
        }
Beispiel #26
0
        public void Draw(ref CanvasAnimatedDrawEventArgs drawArgs, ref List<Txt> txts)
        {
            if (!initialized)
            {
                if (TextLayout == null)
                {
                    TextLayout = new CanvasTextLayout(drawArgs.DrawingSession, Content, Format, 0.0f, 0.0f)
                    {
                        WordWrapping = CanvasWordWrapping.NoWrap
                    };
                }
                
                switch (Format.Direction)
                {
                    case CanvasTextDirection.LeftToRightThenTopToBottom:
                        posX = -(float)TextLayout.DrawBounds.Width;
                        break;
                    case CanvasTextDirection.RightToLeftThenTopToBottom:
                        posX = (float)((float)MetroSlideshow.WindowWidth + TextLayout.DrawBounds.Width);
                        break;
                }
                posY = ComputePosY(ref txts);
                initialized = true;
            }

            if (needToRecomputePosY)
            {
                posY = ComputePosY(ref txts);
                needToRecomputePosY = false;
            }

            switch (Format.Direction)
            {
                case CanvasTextDirection.LeftToRightThenTopToBottom:
                    if (posX < (MetroSlideshow.WindowWidth / 4) || posX > (MetroSlideshow.WindowWidth * (float)(3.0 / 4)))
                    {
                        posX += 3;
                    }
                    else
                    {
                        posX++;
                    }

                    if (posX > MetroSlideshow.WindowWidth || posY > MetroSlideshow.WindowHeight)
                    {
                        initialized = false;
                    }
                    break;
                case CanvasTextDirection.RightToLeftThenTopToBottom:
                    if (posX < (MetroSlideshow.WindowWidth / 4) || posX > (MetroSlideshow.WindowWidth * (float)(3.0 / 4)))
                    {
                        posX -= 3;
                    }
                    else
                    {
                        posX--;
                    }

                    if (posX < 0 || posY > MetroSlideshow.WindowHeight)
                    {
                        initialized = false;
                    }
                    break;
            }

            drawArgs.DrawingSession.DrawTextLayout(TextLayout, new Microsoft.Graphics.Canvas.Numerics.Vector2()
            {
                X = posX,
                Y = posY
            }, Color);
        }
        protected virtual void Dispose(Boolean disposing)
        {
            if (!disposed)
            {
                if (disposing == true && textLayout != null)
                {

                    textLayout.Dispose();
                    textLayout = null;
                }
                disposed = true;
            }
        }
Beispiel #28
0
        void EnsureResources(ICanvasResourceCreatorWithDpi resourceCreator, Size targetSize)
        {
            if (!needsResourceRecreation)
                return;

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

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

            needsResourceRecreation = false;
        }
 internal virtual void drawString(string str, int x, int y)
 {
     CanvasTextLayout l = new CanvasTextLayout(graphics, str, font, 0.0f, 0.0f);
     graphics.DrawTextLayout(l, x, y, c);
 }
 public void SetLayout(CanvasTextLayout layout)
 {
     size = layout.DefaultFontSize;
 }