Exemple #1
0
        public void SamplesMorePointsUntilPassLimitReached()
        {
            var tester = new TestRenderer();

            tester.AddSample(new SubPixel(0, 0, 1, 0, 0), Colors.White);
            var delta = 0.1f;
            var aaa   = new AdaptiveRenderer(3, 0.001f, tester);
            var c     = aaa.Render(SubPixel.ForPixelCenter(0, 0));

            c.Red.Should().BeApproximately(0.0f, delta);
            c.Blue.Should().BeApproximately(0.0f, delta);
            c.Green.Should().BeApproximately(0.0f, delta);
            tester.ProbeCount().Should().Be(14);
        }
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            string str = value as string;

            if (str != null)
            {
                var parseResult = new XmlTemplateParser().ParseAdaptiveContent(str, FeatureSet.GetExperimental());
                if (parseResult.IsOkForRender())
                {
                    return(AdaptiveRenderer.Render(parseResult.AdaptiveContent, new Thickness(0)));
                }
            }

            return(null);
        }
Exemple #3
0
        public void SamplesMorePointsUntilToleranceReached()
        {
            var tester = new TestRenderer();

            tester.AddSample(new SubPixel(0, 0, 2, 1, 1), new Color(0.01f, 0.01f, 0.01f));
            tester.AddSample(new SubPixel(0, 0, 2, 0, 1), new Color(0.01f, 0.01f, 0.01f));
            tester.AddSample(new SubPixel(0, 0, 2, 1, 0), new Color(0.01f, 0.01f, 0.01f));
            tester.AddSample(new SubPixel(0, 0, 1, 0, 0), new Color(0.02f, 0.02f, 0.02f));
            var delta = 0.1f;
            var aaa   = new AdaptiveRenderer(10, 0.08f, tester);
            var c     = aaa.Render(SubPixel.ForPixelCenter(0, 0));

            c.Red.Should().BeApproximately(0.0f, delta);
            c.Blue.Should().BeApproximately(0.0f, delta);
            c.Green.Should().BeApproximately(0.0f, delta);
            tester.ProbeCount().Should().BeInRange(14, 100);
        }
Exemple #4
0
        /// <summary>
        /// This should only be called once. For new tile notification content, create a new instance of this element.
        /// </summary>
        /// <param name="tileSize"></param>
        /// <param name="tilePixelSize"></param>
        /// <param name="visualElements"></param>
        /// <param name="isBrandingVisible"></param>
        /// <param name="binding"></param>
        public void InitializeFromXml(TileSize tileSize, PreviewTileVisualElements visualElements, bool isBrandingVisible, AdaptiveBinding binding)
        {
            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }

            _binding  = binding;
            _tileSize = tileSize;

            // Set the background color
            TileContentContainer.Background = new SolidColorBrush(visualElements.BackgroundColor);

            UsingPeek = false;


            if (binding.Container != null)
            {
                var container = binding.Container;

                // Calculate the tile margin
                Thickness margin = new Thickness(GetExternalMargin());

                if (isBrandingVisible)
                {
                    switch (tileSize)
                    {
                    case TileSize.Small:
                        margin.Bottom = BRANDING_HEIGHT - 4;
                        break;

                    default:
                        margin.Bottom = BRANDING_HEIGHT;
                        break;
                    }
                }

                // Render the adaptive
                TileContent.Child = AdaptiveRenderer.Render(container, margin);


                // Background image
                var allImages       = container.GetAllDescendants().OfType <AdaptiveImage>();
                var backgroundImage = allImages.FirstOrDefault(i => i.Placement == Placement.Background);
                var peekImage       = allImages.FirstOrDefault(i => i.Placement == Placement.Peek);

                // If we don't support both peek and background, then just peek is used
                if (!binding.SupportedFeatures.BackgroundAndPeekImage && backgroundImage != null && peekImage != null)
                {
                    backgroundImage = null;
                }


                // Calculate overlays
                double backgroundOverlay = 0;

                if (backgroundImage != null)
                {
                    if (backgroundImage.HintOverlay != null)
                    {
                        backgroundOverlay = backgroundImage.HintOverlay.Value;
                    }
                    else if (binding.HintOverlay != null)
                    {
                        backgroundOverlay = binding.HintOverlay.Value;
                    }

                    else
                    {
                        // If there's text on the tile, defaults to 20
                        if (container.GetAllDescendants().OfType <AdaptiveTextField>().Any())
                        {
                            backgroundOverlay = 20;
                        }

                        // Else defaults to no overlay
                        else
                        {
                            backgroundOverlay = 0;
                        }
                    }

                    // If we're ignoring the dev specified background when there's no text on the tile
                    if (!binding.SupportedFeatures.RespectDevSpecifiedBackgroundOverlayEvenWhenNoTextOnTile)
                    {
                        if (!container.GetAllDescendants().OfType <AdaptiveTextField>().Any())
                        {
                            backgroundOverlay = 0;
                        }
                    }
                }

                double peekOverlay = 0;

                if (peekImage != null)
                {
                    if (peekImage.HintOverlay != null)
                    {
                        peekOverlay = peekImage.HintOverlay.Value;
                    }

                    // New in TH2: Binding overlay applies to both peek and background
                    else if (binding.HintOverlay != null && binding.SupportedFeatures.OverlayForBothBackgroundAndPeek)
                    {
                        peekOverlay = binding.HintOverlay.Value;
                    }

                    // Defaults to 0
                    else
                    {
                        peekOverlay = 0;
                    }
                }


                if (backgroundImage != null)
                {
                    switch (backgroundImage.HintCrop)
                    {
                    case HintCrop.Circle:
                        BackgroundImageContainer.Child = new CircleImage()
                        {
                            Source         = ImageHelper.GetBitmap(backgroundImage.Src),
                            Margin         = tileSize == TileSize.Small ? new Thickness(4) : new Thickness(8),
                            OverlayOpacity = backgroundOverlay / 100.0
                        };
                        break;

                    default:
                        BackgroundImageContainer.Child = new Image()
                        {
                            Source  = ImageHelper.GetBitmap(backgroundImage.Src),
                            Stretch = Stretch.UniformToFill
                        };
                        BackgroundImageOverlay.Opacity    = backgroundOverlay / 100.0;
                        BackgroundImageOverlay.Visibility = Visibility.Visible;
                        break;
                    }
                }

                if (peekImage != null)
                {
                    UsingPeek = true;

                    switch (peekImage.HintCrop)
                    {
                    case HintCrop.Circle:
                        PeekImageContainer.Child = new CircleImage()
                        {
                            Source         = ImageHelper.GetBitmap(peekImage.Src),
                            Margin         = tileSize == TileSize.Small ? new Thickness(4) : new Thickness(8),
                            OverlayOpacity = peekOverlay / 100.0
                        };
                        break;

                    default:
                        PeekImageContainer.Child = new Grid()
                        {
                            Children =
                            {
                                new Image()
                                {
                                    Source  = ImageHelper.GetBitmap(peekImage.Src),
                                    Stretch = Stretch.UniformToFill
                                },

                                // Overlay
                                new Rectangle()
                                {
                                    Fill    = new SolidColorBrush(Colors.Black),
                                    Opacity = peekOverlay / 100.0
                                }
                            }
                        };
                        break;
                    }

                    PeekRow.Height = new GridLength(1, GridUnitType.Star);
                }
            }
        }