Esempio n. 1
0
        /// <summary>
        /// Recalculates the position of the squad member's information.
        /// </summary>
        /// <param name="position">The new position of the squad member.</param>
        public override void Recalculate(PointF position)
        {
            base.Recalculate(position);

            float infoWidth = showBigHealth ? big : small;

            infoBackground.Size = new SizeF(infoWidth, 50);

            name.Position = new PointF(infoBackground.Position.X + 4, infoBackground.Position.Y + 5);

            health.Position = new PointF(infoBackground.Position.X + 8, infoBackground.Position.Y + 34);
            health.Size     = new SizeF(infoWidth - healthOffset, 4);

            for (int i = 0; i < separators.Count; i++)
            {
                const float     width     = 2;
                const float     height    = 8;
                ScaledRectangle separator = separators[i];
                separator.Size     = new SizeF(width, height);
                separator.Position = new PointF(health.Position.X + (health.Size.Width / (separators.Count - 1) * i), health.Position.Y + (health.Size.Height * 0.5f) - (height * 0.5f));
            }
        }
        /// <summary>
        /// Internal render method
        /// </summary>
        /// <param name="pageNumber"></param>
        /// <param name="rotationAngle"></param>
        /// <returns></returns>
        private async Task BackgroundPageRenderAsync()
        {
            using (PdfPage page = RenderedDocument.GetPage(renderedPageIndex))
            {
                var renderOptions = new PdfPageRenderOptions();
                renderOptions.BackgroundColor = Windows.UI.Colors.Transparent;
                double          actualWidth = PreviewArea.ActualWidth - PreviewBorder.Margin.Left - PreviewBorder.Margin.Right - 4;
                ScaledRectangle displayedPageDimension;

                if (RenderedRotationAngle % 180 == 0)
                {
                    // Raw page orientation matches displayed page orientation
                    displayedPageDimension = new ScaledRectangle(page.Size.Height, page.Size.Width);
                }
                else
                {
                    // Raw page orientation does not match the displayed page orientation
                    displayedPageDimension = new ScaledRectangle(page.Size.Width, page.Size.Height);
                }

                double stretchedHeight = displayedPageDimension.GetScaledHeight(actualWidth);

                if (stretchedHeight > MaxHeight)
                {
                    renderOptions.DestinationHeight = (uint)(MaxHeight);
                    renderOptions.DestinationWidth  = (uint)displayedPageDimension.GetScaledWidth(MaxHeight);
                }
                else
                {
                    renderOptions.DestinationHeight = (uint)stretchedHeight;
                    renderOptions.DestinationWidth  = (uint)actualWidth;
                }

                // update decent border around the previewed page
                PreviewBorder.Height = renderOptions.DestinationHeight;
                PreviewBorder.Width  = renderOptions.DestinationWidth;

                var stream = new InMemoryRandomAccessStream();
                await page.RenderToStreamAsync(stream, renderOptions);

                BitmapImage src = new BitmapImage();
                await src.SetSourceAsync(stream);

                Preview.Source = src;

                RotateTransform rotationTransform = new RotateTransform()
                {
                    Angle   = RenderedRotationAngle,
                    CenterX = (PreviewBorder.Width - 4) / 2,
                    CenterY = (PreviewBorder.Height - 4) / 2
                };

                ScaleTransform scaleTransform;
                if (RenderedRotationAngle % 180 == 0)
                {
                    scaleTransform = new ScaleTransform()
                    {
                        ScaleX = 1,
                        ScaleY = 1,
                    };
                }
                else
                {
                    scaleTransform = new ScaleTransform()
                    {
                        CenterX = (PreviewBorder.Width - 4) / 2,
                        CenterY = (PreviewBorder.Height - 4) / 2,
                        ScaleX  = displayedPageDimension.AspectRatio,
                        ScaleY  = 1 / displayedPageDimension.AspectRatio,
                    };
                }

                TransformGroup renderTransform = new TransformGroup();
                renderTransform.Children.Add(rotationTransform);
                renderTransform.Children.Add(scaleTransform);

                Preview.RenderTransform = renderTransform;
                SetBorderStyle();
            }
        }