Beispiel #1
0
        private async void HandleCapabilitiesChangedAsync(CompositionCapabilities sender, object args)
        {
            _areEffectsSupported = _capabilities.AreEffectsSupported();
            _areEffectsFast      = _capabilities.AreEffectsFast();

            GalleryUI.NotifyCompositionCapabilitiesChanged(_areEffectsSupported, _areEffectsFast);

            SampleDefinitions.RefreshSampleList();


            //
            // Let the user know that the display config has changed and some samples may or may
            // not be available
            //

            if (!_areEffectsSupported || !_areEffectsFast)
            {
                string message;

                if (!_areEffectsSupported)
                {
                    message = "Your display configuration may have changed.  Your current graphics hardware does not support effects.  Some samples will not be available";
                }
                else
                {
                    message = "Your display configuration may have changed. Your current graphics hardware does not support advanced effects.  Some samples will not be available";
                }

                var messageDialog = new MessageDialog(message);
                messageDialog.Commands.Add(new UICommand("Close"));

                // Show the message dialog
                await messageDialog.ShowAsync();
            }
        }
        public MainPage(Rect imageBounds)
        {
            _instance = this;

            // Get hardware capabilities and register changed event listener
#if SDKVERSION_INSIDER
            _capabilities          = CompositionCapabilities.GetForCurrentView();
            _capabilities.Changed += HandleCapabilitiesChangedAsync;
            _areEffectsSupported   = _capabilities.AreEffectsSupported();
            _areEffectsFast        = _capabilities.AreEffectsFast();
#else
            _areEffectsSupported = true;
            _areEffectsFast      = true;
#endif
            _runtimeCapabilities = new RuntimeSupportedSDKs();
            this.InitializeComponent();

            // Initialize the image loader
            ImageLoader.Initialize(ElementCompositionPreview.GetElementVisual(this).Compositor);

            // Show the custome splash screen
            ShowCustomSplashScreen(imageBounds);

            SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
        }
        private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
        {
            ToggleSwitch toggleSwitch = sender as ToggleSwitch;

            if (toggleSwitch != null && SimulatorDropdown != null)
            {
                if (toggleSwitch.IsOn == true)
                {
                    // Show simulation options
                    SimulatorDropdown.Visibility = Visibility.Visible;

                    // Simulate capabilities
                    _activeCapabilityWrapper = (CapabilityWrapper)SimulatorDropdown.SelectedItem;
                }
                else
                {
                    // Hide simulation options
                    SimulatorDropdown.Visibility = Visibility.Collapsed;

                    // Update to use actual capabilities
                    _activeCapabilityWrapper = new CapabilityWrapper("", _liveCapabilities.AreEffectsSupported(), _liveCapabilities.AreEffectsFast());
                }

                UpdateAlbumArt();
            }
        }
        /// <summary>
        /// Handles hardware capabilities changed updates
        /// </summary>
        private void HandleCapabilitiesChanged(CompositionCapabilities sender, object args)
        {
            _liveCapabilities = sender;

            if (ToggleSwitch.IsOn == false)
            {
                // If not in simulate mode, update to wrapper to use live capabilities and update view
                _activeCapabilityWrapper = new CapabilityWrapper("", _liveCapabilities.AreEffectsSupported(), _liveCapabilities.AreEffectsFast());
                UpdateAlbumArt();
            }
        }
        public MainPage(Rect imageBounds)
        {
            _instance            = this;
            _runtimeCapabilities = new RuntimeSupportedSDKs();
            _currentFrame        = null;

            // Get hardware capabilities and register changed event listener only when targeting the
            // appropriate SDK version and the runtime supports this version
            if (_runtimeCapabilities.IsSdkVersionRuntimeSupported(RuntimeSupportedSDKs.SDKVERSION._15063))
            {
#if SDKVERSION_15063
                _capabilities          = CompositionCapabilities.GetForCurrentView();
                _capabilities.Changed += HandleCapabilitiesChangedAsync;
                _areEffectsSupported   = _capabilities.AreEffectsSupported();
                _areEffectsFast        = _capabilities.AreEffectsFast();
#endif
            }
            else
            {
                _areEffectsSupported = true;
                _areEffectsFast      = true;
            }
            this.InitializeComponent();
            _mainNavigation = new MainNavigationViewModel();

            // Initialize the image loader
            ImageLoader.Initialize(ElementCompositionPreview.GetElementVisual(this).Compositor);

            // Show the custome splash screen
            ShowCustomSplashScreen(imageBounds);

            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false;

#if SDKVERSION_16299
            // Apply acrylic styling to the navigation and caption
            if (_runtimeCapabilities.IsSdkVersionRuntimeSupported(RuntimeSupportedSDKs.SDKVERSION._16299))
            {
                // Extend the app into the titlebar so that we can apply acrylic
                CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
                ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;
                titleBar.ButtonBackgroundColor         = Colors.Transparent;
                titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
                titleBar.ButtonForegroundColor         = Colors.Black;

                // Apply a customized control template to the pivot
                MainPivot.Template = (ControlTemplate)Application.Current.Resources["PivotControlTemplate"];

                // Apply acrylic to the main navigation
                TitleBarRow.Height      = new GridLength(31);
                TitleBarGrid.Background = (Brush)Application.Current.Resources["SystemControlChromeMediumLowAcrylicWindowMediumBrush"];
            }
#endif
        }
Beispiel #6
0
        /// <summary>
        /// Updates the effects applied and visuals shown based on information retrieved from
        /// calling the capabilities API
        /// </summary>
        private void UpdateAlbumArt()
        {
            if (_capabilities.AreEffectsSupported())
            {
                //
                // If effects are supported, add effects to the background image and
                // add a masked circle image in the center for better visual appearance.
                //

                if (!_containsCircleImage)
                {
                    // Create circle mask
                    var circleMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White);

                    // Create image visual to use as the circle-masked center image
                    _circleImageVisual      = _compositor.CreateSpriteVisual();
                    _circleImageVisual.Size = new Vector2((float)ImageCanvas.ActualWidth / 2, (float)ImageCanvas.ActualHeight / 2);
                    var xOffset = (float)(ImageCanvas.ActualWidth / 2 - _circleImageVisual.Size.X / 2);
                    var yOffset = (float)(ImageCanvas.ActualHeight / 2 - _circleImageVisual.Size.Y / 2);
                    _circleImageVisual.Offset = new Vector3(xOffset, yOffset, 0);

                    // Create circle image surface
                    CompositionSurfaceBrush circleSurfaceBrush = _compositor.CreateSurfaceBrush();
                    circleSurfaceBrush.Surface = circleMaskSurface.Surface;
                    circleSurfaceBrush.Stretch = CompositionStretch.Uniform;

                    // Apply mask to visual
                    CompositionMaskBrush maskBrush = _compositor.CreateMaskBrush();
                    maskBrush.Source = _imageSurfaceBrush;
                    maskBrush.Mask   = circleSurfaceBrush;

                    _circleImageVisual.Brush = maskBrush;

                    _imageContainer.Children.InsertAtTop(_circleImageVisual);
                    _containsCircleImage = true;
                }

                //
                // Create saturation effect, which will be either used alone if effects are slow, or chained
                // with blur if effects are fast
                //
                var saturationEffect = new SaturationEffect
                {
                    Saturation = 0.3f,
                    Source     = new CompositionEffectSourceParameter("SaturationSource")
                };

                if (_capabilities.AreEffectsFast())
                {
                    // Create blur effect and chain with saturation effect
                    GaussianBlurEffect chainedEffect = new GaussianBlurEffect()
                    {
                        Name         = "Blur",
                        Source       = saturationEffect, //takes saturation effect as input
                        BlurAmount   = 6.0f,
                        BorderMode   = EffectBorderMode.Hard,
                        Optimization = EffectOptimization.Balanced
                    };

                    CompositionEffectFactory chainedEffectFactory = _compositor.CreateEffectFactory(chainedEffect);
                    CompositionEffectBrush   effectBrush          = chainedEffectFactory.CreateBrush();

                    effectBrush.SetSourceParameter("SaturationSource", _imageSurfaceBrush);

                    _backgroundImageVisual.Brush = effectBrush;

                    CapabilityText = "Effects are supported and fast. Background image is blurred and desaturated.";
                }
                else
                {
                    // If effects are slow but supported use desaturation effect since it is less expensive than blur
                    CompositionEffectFactory saturationEffectFactory = _compositor.CreateEffectFactory(saturationEffect);
                    CompositionEffectBrush   saturationBrush         = saturationEffectFactory.CreateBrush();

                    saturationBrush.SetSourceParameter("SaturationSource", _imageSurfaceBrush);

                    _backgroundImageVisual.Brush = saturationBrush;

                    CapabilityText = "Effects are supported but not fast. Background image is desaturated.";
                }
            }
            else
            {
                //
                // If effects are not supported, just use the image as the background with no effects
                // and remove the center circle image to declutter the UI.
                //

                if (_containsCircleImage)
                {
                    _imageContainer.Children.Remove(_circleImageVisual);
                    _containsCircleImage = false;
                }

                _backgroundImageVisual.Brush = _imageSurfaceBrush;

                CapabilityText = "Effects not supported. No effects are applied.";
            }
        }