コード例 #1
0
        public void Initialize(UIElement host, CompositionImage sourceElement, object payload)
        {
            _host = host;
            _parent = host;
            _payload = payload;

            // Make a copy of the sourceElement's sprite so we can hand it off to the next page
            SpriteVisual sourceSprite = sourceElement.SpriteVisual;
            Compositor compositor = sourceSprite.Compositor;
            _sprite = compositor.CreateSpriteVisual();
            _sprite.Size = sourceSprite.Size;
            _sprite.Brush = sourceElement.SurfaceBrush;

            // We're going to use the backing surface, make sure it doesn't get released
            sourceElement.SharedSurface = true;

            // Determine the offset from the host to the source element used in the transition
            GeneralTransform coordinate = sourceElement.TransformToVisual(_parent);
            Point position = coordinate.TransformPoint(new Point(0, 0));

            // Set the sprite to that offset relative to the host
            _sprite.Offset = new Vector3((float)position.X, (float)position.Y, 0);

            // Set the sprite as the content under the host
            ElementCompositionPreview.SetElementChildVisual(_parent, _sprite);
        }
コード例 #2
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            ThumbnailList.ItemsSource = Model.Items;

            // Populate the Effect combobox
            IList<ComboBoxItem> effectList = new List<ComboBoxItem>();
            foreach (EffectTypes type in Enum.GetValues(typeof(EffectTypes)))
            {
                ComboBoxItem item = new ComboBoxItem();
                item.Tag = type;
                item.Content = type.ToString();
                effectList.Add(item);
            }

            EffectSelection.ItemsSource = effectList;
            EffectSelection.SelectedIndex = 0;

            // Get the current compositor
            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

            // Create the destinatio sprite, sized to cover the entire list
            _destinationSprite = _compositor.CreateSpriteVisual();
            _destinationSprite.Size = new Vector2((float)ThumbnailList.ActualWidth, (float)ThumbnailList.ActualHeight);

            // Start out with the destination layer invisible to avoid any cost until necessary
            _destinationSprite.IsVisible = false;

            ElementCompositionPreview.SetElementChildVisual(ThumbnailList, _destinationSprite);

            // Update the effect to set the appropriate brush 
            UpdateEffect();

        }
コード例 #3
0
        private void Clock_Loaded(object sender, RoutedEventArgs e)
        {
            _root = Container.GetVisual();
            _compositor = _root.Compositor;

            // Background
            _background = _compositor.CreateSpriteVisual();
            _background.Size = new Vector2(200.0f, 200.0f);
            var _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
            CompositionImageOptions options = new CompositionImageOptions()
            {
                DecodeWidth = 400,
                DecodeHeight = 400,
            };
            var _image = _imageFactory.CreateImageFromUri(FaceImage, options);
            _background.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _root.Children.InsertAtTop(_background);

            // Hour Hand
            options = new CompositionImageOptions()
            {
                DecodeWidth = 72,
                DecodeHeight = 240,
            };

            _hourhand = _compositor.CreateSpriteVisual();
            _hourhand.Size = new Vector2(24.0f, 80.0f);
            _image = _imageFactory.CreateImageFromUri(HourHandImage, options);
            _hourhand.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _hourhand.CenterPoint = new Vector3(12.0f, 70.0f, 0);
            _hourhand.Offset = new Vector3(88.0f, 30.0f, 0);
            _root.Children.InsertAtTop(_hourhand);

            // Minute Hand
            options = new CompositionImageOptions()
            {
                DecodeWidth = 48,
                DecodeHeight = 270,
            };
            _image = _imageFactory.CreateImageFromUri(MinuteHandImage, options);
            _minutehand = _compositor.CreateSpriteVisual();
            _minutehand.Size = new Vector2(16.0f, 90.0f);
            _minutehand.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _minutehand.CenterPoint = new Vector3(8.0f, 85.0f, 0);
            _minutehand.Offset = new Vector3(92.0f, 15.0f, 0);
            _root.Children.InsertAtTop(_minutehand);

            SetHoursAndMinutes();

            // Second Hand
            _secondhand = _compositor.CreateSpriteVisual();
            _secondhand.Size = new Vector2(1.0f, 90.0f);
            _secondhand.Brush = _compositor.CreateColorBrush(Colors.Red);
            _secondhand.CenterPoint = new Vector3(0.5f, 90.0f, 0);
            _secondhand.Offset = new Vector3(99.5f, 10.0f, 0);
            _root.Children.InsertAtTop(_secondhand);
            _secondhand.RotationAngleInDegrees = (float)(int)DateTime.Now.TimeOfDay.TotalSeconds * 6;

            _timer.Start();
        }
        public void SetupDestinationEffect(Compositor compositor)
        {
            // Create SpriteVisual for blur effect
            _destVisual = compositor.CreateSpriteVisual();
            _destVisual.Size = new Vector2(0, 0);

            // Create graphics effect for blur
            var graphicsEffect = new GaussianBlurEffect
            {
                Name = "GB",
                Source = new CompositionEffectSourceParameter("destinationSource"),
                BlurAmount = 10f,
                BorderMode = EffectBorderMode.Hard,
                Optimization = EffectOptimization.Balanced

            };

            var effectFactory = compositor.CreateEffectFactory(graphicsEffect);

            var blurEffect = effectFactory.CreateBrush();
            var destinationBrush = compositor.CreateBackdropBrush();

            blurEffect.SetSourceParameter("destinationSource", destinationBrush);

            // Set the SpriteVisual's brush as blur effect
            _destVisual.Brush = blurEffect;

            // Insert the destination visual as child of the BlurRect UIElement.
            // Since the BlurRect is between the text of the flyout and the content of the page,
            // the destination visual will blur the content of the page.
            ElementCompositionPreview.SetElementChildVisual(BlurRect, _destVisual);
        }
コード例 #5
0
        private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Get backing visual from shadow container and interop compositor
            _shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer);
            _compositor = _shadowContainer.Compositor;

            // Get CompositionImage, its sprite visual
            _image = VisualTreeHelperExtensions.GetFirstDescendantOfType<CompositionImage>(ShadowContainer);
            _imageVisual = _image.SpriteVisual;

            // Load mask asset onto surface using helpers in SamplesCommon
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
            _imageMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White);

            // Create surface brush for mask
            CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush();
            mask.Surface = _imageMaskSurface.Surface;
            
            // Get surface brush from composition image
            CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush;

            // Create mask brush for toggle mask functionality
            _maskBrush = _compositor.CreateMaskBrush();
            _maskBrush.Mask = mask;
            _maskBrush.Source = source;

            // Initialize toggle mask
            _isMaskEnabled = false;
        }
コード例 #6
0
ファイル: MainView.cs プロジェクト: blinds52/intense
        private void InitializeComposition()
        {
            // setup compositor and root visual
            this.compositor = new Compositor();
            this.root = this.compositor.CreateContainerVisual();

            // associate with the CoreWindow
            this.compositionTarget = this.compositor.CreateTargetForCurrentView();
            this.compositionTarget.Root = this.root;

            // add a solid color background
            this.background = this.compositor.CreateSpriteVisual();
            this.background.Brush = this.compositor.CreateColorBrush(Colors.LightGreen);
            this.root.Children.InsertAtBottom(this.background);

            // create green square
            var colorVisual = this.compositor.CreateSpriteVisual();
            colorVisual.Brush = this.compositor.CreateColorBrush(Colors.Green);
            colorVisual.Size = new Vector2(150.0f, 150.0f);
            colorVisual.CenterPoint = new Vector3(75.0f, 75.0f, 0.0f);
            this.target = colorVisual;
            this.root.Children.InsertAtTop(this.target);

            // animate square
            Animate(this.target);

            UpdateSize();
        }
コード例 #7
0
        public BackDrop()
        {
            m_rootVisual = ElementCompositionPreview.GetElementVisual(this as UIElement);
            Compositor = m_rootVisual.Compositor;

            m_blurVisual = Compositor.CreateSpriteVisual();

#if SDKVERSION_INSIDER
            m_noiseBrush = Compositor.CreateSurfaceBrush();

            CompositionEffectBrush brush = BuildBlurBrush();
            brush.SetSourceParameter("source", m_compositor.CreateBackdropBrush());
            m_blurBrush = brush;
            m_blurVisual.Brush = m_blurBrush;

            BlurAmount = 9;
            TintColor = Colors.Transparent;
#else
            m_blurBrush = Compositor.CreateColorBrush(Colors.White);
            m_blurVisual.Brush = m_blurBrush;
#endif
            ElementCompositionPreview.SetElementChildVisual(this as UIElement, m_blurVisual);

            this.Loading += OnLoading;
            this.Unloaded += OnUnloaded;
        }
コード例 #8
0
        private void CompImage_Loading(FrameworkElement sender, object args)
        {
            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
            _sprite = _compositor.CreateSpriteVisual();
            _sprite.Size = new Vector2((float)ActualWidth, (float)ActualHeight);

            ElementCompositionPreview.SetElementChildVisual(this, _sprite);
        }
コード例 #9
0
ファイル: Shadow.cs プロジェクト: h82258652/SoftwareKobo.UI
        internal Shadow()
        {
            DefaultStyleKey = typeof(Shadow);

            var compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
            _shadowVisual = compositor.CreateSpriteVisual();
            _dropShadow = compositor.CreateDropShadow();
            _shadowVisual.Shadow = _dropShadow;
        }
コード例 #10
0
        public DrawingSurfaceRenderer(Compositor compositor, CompositionGraphicsDevice compositionGraphicsDevice)
        {
            drawingSurfaceVisual = compositor.CreateSpriteVisual();
            drawingSurface = compositionGraphicsDevice.CreateDrawingSurface(new Size(256, 256), DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);
            drawingSurfaceVisual.Brush = compositor.CreateSurfaceBrush(drawingSurface);
            DrawDrawingSurface();

            compositionGraphicsDevice.RenderingDeviceReplaced += CompositionGraphicsDevice_RenderingDeviceReplaced;
        }
コード例 #11
0
        private void CompImage_Unloaded(object sender, RoutedEventArgs e)
        {
            _unloaded = true;

            if (_sprite != null)
            {
                _sprite.Dispose();
                _sprite = null;
            }
        }
コード例 #12
0
        private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Acquire Compositor and set up basic visual tree structure
            _xamlRoot = ElementCompositionPreview.GetElementVisual(MainGrid);
            _compositor = _xamlRoot.Compositor;
            _root = _compositor.CreateContainerVisual();
            _mainImage = Image.SpriteVisual;

            ElementCompositionPreview.SetElementChildVisual(ImageContainer, _root);
            _root.Children.InsertAtTop(_mainImage);


            // Add visual indicators to show the position of AnchorPoint and CenterPoint
            _indicatorContainer = _compositor.CreateContainerVisual();

            _apIndicator = _compositor.CreateSpriteVisual();
            _apIndicator.Size = new Vector2(10, 10);
            _apIndicator.AnchorPoint = new Vector2(0.5f, 0.5f);
            _apIndicator.Brush = _compositor.CreateColorBrush(Windows.UI.Colors.Red);

            _cpIndicator = _compositor.CreateSpriteVisual();
            _cpIndicator.Size = new Vector2(10, 10);
            _cpIndicator.AnchorPoint = new Vector2(0.5f, 0.5f);
            _cpIndicator.Brush = _compositor.CreateColorBrush(Windows.UI.Colors.Green);

            _root.Children.InsertAtTop(_indicatorContainer);
            _indicatorContainer.Children.InsertAtTop(_cpIndicator);
            _indicatorContainer.Children.InsertAtTop(_apIndicator);


            // Specify a clip to prevent image from overflowing into the sliders list
            Visual containerGrid = ElementCompositionPreview.GetElementVisual(ContentGrid);
            containerGrid.Size = new Vector2((float)ContentGrid.ActualWidth, (float)ContentGrid.ActualHeight);
            ContentGrid.SizeChanged += (s, a) =>
            {
                containerGrid.Size = new Vector2((float)ContentGrid.ActualWidth, (float)ContentGrid.ActualHeight);
            };
            containerGrid.Clip = _compositor.CreateInsetClip();


            // Create list of properties to add as sliders
            var list = new List<TransformPropertyModel>();
            list.Add(new TransformPropertyModel(AnchorPointXAction) { PropertyName = "AnchorPoint - X (Red)", MinValue = -1, MaxValue = 2, StepFrequency = 0.01f, Value = _mainImage.AnchorPoint.X });
            list.Add(new TransformPropertyModel(AnchorPointYAction) { PropertyName = "AnchorPoint - Y (Red)", MinValue = -1, MaxValue = 2, StepFrequency = 0.01f, Value = _mainImage.AnchorPoint.Y });
            list.Add(new TransformPropertyModel(CenterPointXAction) { PropertyName = "CenterPoint - X (Green)", MinValue = -600, MaxValue = 600, StepFrequency = 1f, Value = _mainImage.CenterPoint.X });
            list.Add(new TransformPropertyModel(CenterPointYAction) { PropertyName = "CenterPoint - Y (Green)", MinValue = -600, MaxValue = 600, StepFrequency = 1f, Value = _mainImage.CenterPoint.Y });
            list.Add(new TransformPropertyModel(RotationAction) { PropertyName = "Rotation (in Degrees)", MinValue = 0, MaxValue = 360, StepFrequency = 1f, Value = _mainImage.RotationAngleInDegrees });
            list.Add(new TransformPropertyModel(ScaleXAction) { PropertyName = "Scale - X", MinValue = 0, MaxValue = 3, StepFrequency = 0.01f, Value = _mainImage.Scale.X });
            list.Add(new TransformPropertyModel(ScaleYAction) { PropertyName = "Scale - Y", MinValue = 0, MaxValue = 3, StepFrequency = 0.01f, Value = _mainImage.Scale.Y });
            list.Add(new TransformPropertyModel(OffsetXAction) { PropertyName = "Offset - X", MinValue = -200, MaxValue = 200, StepFrequency = 1f, Value = _mainImage.Offset.X });
            list.Add(new TransformPropertyModel(OffsetYAction) { PropertyName = "Offset - Y", MinValue = -200, MaxValue = 200, StepFrequency = 1f, Value = _mainImage.Offset.Y });

            XamlItemsControl.ItemsSource = list;

        }
コード例 #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DropShadowPanel"/> class.
        /// </summary>
        public DropShadowPanel()
        {
            this.DefaultStyleKey = typeof(DropShadowPanel);

            Compositor compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

            _shadowVisual = compositor.CreateSpriteVisual();

            if (IsSupported)
            {
                _dropShadow          = compositor.CreateDropShadow();
                _shadowVisual.Shadow = _dropShadow;
            }

            SizeChanged += OnSizeChanged;
        }
コード例 #14
0
        private void AddShadowChild()
        {
            var canvas = new Canvas();
            var compositor = ElementCompositionPreview.GetElementVisual(canvas).Compositor;
            _spriteVisual = compositor.CreateSpriteVisual();

            var dropShadow = compositor.CreateDropShadow();
            dropShadow.Offset = new Vector3(-ShadowWidth, -ShadowWidth, 0);
            dropShadow.Color = Colors.Black;
            dropShadow.Opacity = 0.6f;
            _spriteVisual.Shadow = dropShadow;

            ElementCompositionPreview.SetElementChildVisual(canvas, _spriteVisual);

            Children.Add(canvas);
        }
コード例 #15
0
        /// <summary>
        /// Runs the animation
        /// </summary>
        private void TriggerBloomAnimation(SpriteVisual colorVisual)
        {
            // animate the Scale of the visual within a scoped batch
            // this gives us transactionality and allows us to do work once the transaction completes
            var batchTransaction = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            // as with all animations on Visuals, these too will run independent of the UI thread
            // so if the UI thread is busy with app code or doing layout on state/page transition,
            // these animations still run uninterruped and glitch free
            colorVisual.StartAnimation("Scale.X", _bloomAnimation);
            colorVisual.StartAnimation("Scale.Y", _bloomAnimation);

            batchTransaction.Completed += BloomAnimationCompleted;

            batchTransaction.End();
        }
コード例 #16
0
        private static void Initialize()
        {
            Compositor = ElementCompositionPreview.GetElementVisual(UiElement).Compositor;

            ContainerVisual = Compositor.CreateContainerVisual();

            SpriteVisual       = Compositor.CreateSpriteVisual();
            SpriteVisual.Size  = new Vector2((float)Window.Current.Bounds.Width, (float)Window.Current.Bounds.Height);
            SpriteVisual.Brush = CreateBackdropBrush();

            ContainerVisual.Children.InsertAtTop(SpriteVisual);

            ElementCompositionPreview.SetElementChildVisual(UiElement, ContainerVisual);

            Page.SizeChanged += OnSizeChanged;
        }
コード例 #17
0
        public void AnimationUnfocusTreatment(SpriteVisual target)
        {
            if (FocusedVisuals.Contains(target))
            {
                if (target.Shadow != null && _reversedShadowAnimationGroup != null)
                {
                    target.Shadow.StartAnimationGroup(_reversedShadowAnimationGroup);
                }
                if (_reversedVisualAnimationGroup != null)
                {
                    target.StartAnimationGroup(_reversedVisualAnimationGroup);
                }

                FocusedVisuals.Remove(target);
            }
        }
コード例 #18
0
        void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            // get visuals from xaml object
            _touchAreaVisual = GetVisual(this.TouchArea);
            var imagePanelVisual = GetVisual(this.ImagePanel);

            // get compositor
            _compositor = imagePanelVisual.Compositor;

            var width  = (float)this.ImagePanel.ActualWidth;
            var height = (float)this.ImagePanel.ActualHeight;

            // load the background image
            var uri          = new Uri("ms-appx:///Assets/White.png");
            var imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
            var options      = new CompositionImageOptions
            {
                DecodeWidth  = (int)width,
                DecodeHeight = (int)height
            };
            var image = imageFactory.CreateImageFromUri(uri, options);

            // currently GaussianBlurEffect is not supported in Composition
            var effectDefination = new SaturationEffect // new GaussianBlurEffect
            {
                //BorderMode = EffectBorderMode.Soft,
                //BlurAmount = 5f,
                //Optimization = EffectOptimization.Quality,
                Source = new CompositionEffectSourceParameter("Overlay")
            };

            // create the actual effect
            var surfaceBrush  = _compositor.CreateSurfaceBrush(image.Surface);
            var effectFactory = _compositor.CreateEffectFactory(effectDefination);
            var effectBrush   = effectFactory.CreateBrush();

            effectBrush.SetSourceParameter("Overlay", surfaceBrush);

            // create the visual with the effect
            _visual         = _compositor.CreateSpriteVisual();
            _visual.Brush   = effectBrush;
            _visual.Opacity = 0.8f;
            _visual.Size    = new Vector2(width, height);

            // place the effect visual onto the UI
            imagePanelVisual.Children.InsertAtTop(_visual);
        }
コード例 #19
0
        public NineGridResizing()
        {
            this.InitializeComponent();

            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

            // Add page loaded event listener
            this.Loaded += NineGridResizing_Loaded;

            // Set data context for data binding
            DataContext = this;

            // Sprite visual to be painted
            _ninegridVisual = _compositor.CreateSpriteVisual();

            // Create ninegridbrush and paint on visual;
            _ninegridBrush        = _compositor.CreateNineGridBrush();
            _ninegridVisual.Brush = _ninegridBrush;
            _ninegridSurface      = ImageLoader.Instance.LoadFromUri(new Uri("ms-appx:///Samples/SDK 14393/NineGridResizing/RoundedRect.png"));

            // Clip compgrid
            var compGrid = ElementCompositionPreview.GetElementVisual(CompGrid);

            compGrid.Clip = _compositor.CreateInsetClip();

            // Scene container to be scaled
            _backgroundContainer = ElementCompositionPreview.GetElementVisual(bkgHost);

            // Insert Composition island
            ElementCompositionPreview.SetElementChildVisual(ngHost, _ninegridVisual);

            // Instatiate brush scenario list and fill with created brush scenarios
            _nineGridBrushScenarios = new ObservableCollection <INineGridScenario>(CreateBrushes(_compositor, _ninegridSurface, _ninegridVisual.Size));

            // Set default combo box selection to first item
            BrushScenarioSelected = _nineGridBrushScenarios.FirstOrDefault();

            // Value timer initialization for sliders
            _valueTimerXSlider = new ValueTimer <float>();
            _valueTimerXSlider.ValueChanged += OnXSliderValueChanged;

            _valueTimerYSlider = new ValueTimer <float>();
            _valueTimerYSlider.ValueChanged += OnYSliderValueChanged;

            _valueTimerScaleSlider = new ValueTimer <float>();
            _valueTimerScaleSlider.ValueChanged += OnScaleSliderValueChanged;
        }
コード例 #20
0
        private void GridView_Loaded(object sender, RoutedEventArgs e)
        {
            var scroll = List.Descendants <ScrollViewer>().FirstOrDefault() as ScrollViewer;

            if (scroll != null)
            {
                _scrollingHost = scroll;
                _scrollingHost.ChangeView(null, 0, null, true);
                scroll.ViewChanged += Scroll_ViewChanged;
                Scroll_ViewChanged(scroll, null);

                var brush = App.Current.Resources["SystemControlBackgroundChromeMediumLowBrush"] as SolidColorBrush;
                var props = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scroll);

                if (_backgroundVisual == null)
                {
                    _backgroundVisual = ElementCompositionPreview.GetElementVisual(BackgroundPanel).Compositor.CreateSpriteVisual();
                    ElementCompositionPreview.SetElementChildVisual(BackgroundPanel, _backgroundVisual);
                }

                _backgroundVisual.Brush = _backgroundVisual.Compositor.CreateColorBrush(brush.Color);
                _backgroundVisual.Size  = new System.Numerics.Vector2((float)BackgroundPanel.ActualWidth, (float)BackgroundPanel.ActualHeight);
                _backgroundVisual.Clip  = _backgroundVisual.Compositor.CreateInsetClip();

                _expression = _expression ?? _backgroundVisual.Compositor.CreateExpressionAnimation("Max(Maximum, Scrolling.Translation.Y)");
                _expression.SetReferenceParameter("Scrolling", props);
                _expression.SetScalarParameter("Maximum", -(float)BackgroundPanel.Margin.Top + 1);
                _backgroundVisual.StopAnimation("Offset.Y");
                _backgroundVisual.StartAnimation("Offset.Y", _expression);

                _expressionClip = _expressionClip ?? _backgroundVisual.Compositor.CreateExpressionAnimation("Min(0, Maximum - Scrolling.Translation.Y)");
                _expressionClip.SetReferenceParameter("Scrolling", props);
                _expressionClip.SetScalarParameter("Maximum", -(float)BackgroundPanel.Margin.Top + 1);
                _backgroundVisual.Clip.StopAnimation("Offset.Y");
                _backgroundVisual.Clip.StartAnimation("Offset.Y", _expressionClip);
            }

            var panel = List.ItemsPanelRoot as ItemsWrapGrid;

            if (panel != null)
            {
                panel.SizeChanged += (s, args) =>
                {
                    Scroll_ViewChanged(scroll, null);
                };
            }
        }
コード例 #21
0
        private void Clock_Loaded(object sender, RoutedEventArgs e)
        {
            _root = Container.GetVisual();
            _compositor = _root.Compositor;

            // Background
            _background = _compositor.CreateSpriteVisual();
            _background.Size = new Vector2(800.0f, 800.0f);
            var _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
            var options = new CompositionImageOptions()
            {
                DecodeWidth = 740,
                DecodeHeight = 740
            };
            var _image = _imageFactory.CreateImageFromUri(FaceImage, options);
            _background.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _root.Children.InsertAtTop(_background);

            // Hour Hand
            _hourhand = _compositor.CreateSpriteVisual();
            _hourhand.Size = new Vector2(800.0f, 800.0f);
            _image = _imageFactory.CreateImageFromUri(HourHandImage, options);
            _hourhand.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _hourhand.Offset = new Vector3(0.0f, 0.0f, 0);
            _hourhand.CenterPoint = new Vector3(400.0f, 400.0f, 0);
            _root.Children.InsertAtTop(_hourhand);

            // Minute Hand
            _minutehand = _compositor.CreateSpriteVisual();
            _minutehand.Size = new Vector2(800.0f, 800.0f);
            _image = _imageFactory.CreateImageFromUri(MinuteHandImage, options);
            _minutehand.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _minutehand.Offset = new Vector3(0.0f, 0.0f, 0);
            _minutehand.CenterPoint = new Vector3(400.0f, 400.0f, 0);
            _root.Children.InsertAtTop(_minutehand);

            // Foreground
            _foreground = _compositor.CreateSpriteVisual();
            _foreground.Size = new Vector2(800.0f, 800.0f);
            _image = _imageFactory.CreateImageFromUri(FrontImage, options);
            _foreground.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
            _root.Children.InsertAtTop(_foreground);

            SetHoursAndMinutes();

            _timer.Start();
        }
コード例 #22
0
        /// <summary>
        /// Show Compositon effects on image
        /// </summary>
        /// <param name="imageURL">Image to effect</param>
        private void SetupComposition(Uri imageURL)
        {
            try
            {
                CompositionSurfaceBrush _imageBrush;

                Compositor _compositor = Window.Current.Compositor;

                _imageBrush         = _compositor.CreateSurfaceBrush();
                _imageBrush.Stretch = CompositionStretch.UniformToFill;


                LoadedImageSurface _loadedSurface = LoadedImageSurface.StartLoadFromUri(imageURL);
                _loadedSurface.LoadCompleted += _loadedSurface_LoadCompleted;
                _imageBrush.Surface           = _loadedSurface;

                // Saturate
                var saturationEffect = new SaturationEffect
                {
                    Saturation = 1,
                    Source     = new CompositionEffectSourceParameter("image")
                };
                var effectFactory = _compositor.CreateEffectFactory(saturationEffect);
                var effectBrush   = effectFactory.CreateBrush();
                effectBrush.SetSourceParameter("image", _imageBrush);

                // Blur
                var blurEffect = new GaussianBlurEffect
                {
                    BlurAmount = 8,
                    Source     = new CompositionEffectSourceParameter("image")
                };
                var effectFactory2 = _compositor.CreateEffectFactory(blurEffect);
                var effectBrush2   = effectFactory2.CreateBrush();
                effectBrush2.SetSourceParameter("image", effectBrush);

                _imageVisual       = _compositor.CreateSpriteVisual();
                _imageVisual.Brush = effectBrush2;
                _imageVisual.Size  = new Vector2(Convert.ToSingle(BackgroundContainer.ActualWidth), Convert.ToSingle(BackgroundContainer.ActualHeight));

                ElementCompositionPreview.SetElementChildVisual(BackgroundContainer, _imageVisual);
            }
            catch
            {
                // I guess it'll just look meh
            }
        }
コード例 #23
0
        protected override void OnApplyTemplate()
        {
            var ease      = Window.Current.Compositor.CreateLinearEasingFunction();
            var animation = Window.Current.Compositor.CreateVector3KeyFrameAnimation();

            animation.InsertKeyFrame(0, new Vector3(-1, 0, 0), ease);
            animation.InsertKeyFrame(1, new Vector3(0, 0, 0), ease);
            animation.IterationBehavior = AnimationIterationBehavior.Forever;
            animation.Duration          = TimeSpan.FromSeconds(1);

            var backgroundColor = GetColor(BorderBrushProperty);
            var foregroundColor = GetColor(BackgroundProperty);

            var gradient = Window.Current.Compositor.CreateLinearGradientBrush();

            gradient.ColorStops.Add(Window.Current.Compositor.CreateColorGradientStop(0, Color.FromArgb(0x00, backgroundColor.R, backgroundColor.G, backgroundColor.B)));
            gradient.ColorStops.Add(Window.Current.Compositor.CreateColorGradientStop(0.67f, Color.FromArgb(0x67, backgroundColor.R, backgroundColor.G, backgroundColor.B)));
            gradient.ColorStops.Add(Window.Current.Compositor.CreateColorGradientStop(1, Color.FromArgb(0x00, backgroundColor.R, backgroundColor.G, backgroundColor.B)));
            gradient.StartPoint = new Vector2(0, 0);
            gradient.EndPoint   = new Vector2(0.5f, 0);
            gradient.ExtendMode = CompositionGradientExtendMode.Wrap;

            var background = Window.Current.Compositor.CreateSpriteVisual();

            background.RelativeSizeAdjustment = Vector2.One;
            background.Brush = Window.Current.Compositor.CreateColorBrush(foregroundColor);

            _foreground = Window.Current.Compositor.CreateSpriteVisual();
            _foreground.RelativeSizeAdjustment = new Vector2(2, 1);
            _foreground.Brush = gradient;
            _foreground.StartAnimation("RelativeOffsetAdjustment", animation);

            _placeholder = GetTemplateChild("Placeholder") as TextBlock;
            _presenter   = GetTemplateChild("Presenter") as TextBlock;

            _skeleton = Window.Current.Compositor.CreateContainerVisual();
            _skeleton.Children.InsertAtTop(background);
            _skeleton.Children.InsertAtTop(_foreground);
            _skeleton.Opacity = 0.67f;

            _skeleton.AnchorPoint = new Vector2(IsPlaceholderRightToLeft ? 1 : 0, 0);
            _skeleton.RelativeOffsetAdjustment = new Vector3(IsPlaceholderRightToLeft ? 1 : 0, 0, 0);

            ElementCompositionPreview.SetElementChildVisual(_placeholder, _skeleton);

            base.OnApplyTemplate();
        }
コード例 #24
0
        private void InitializeDropShadow()
        {
            var compositor = ElementCompositionPreview.GetElementVisual(this.shadowView).Compositor;

            this.shadowVisual = compositor.CreateSpriteVisual();
            this.dropShadow   = compositor.CreateDropShadow();

            this.OnColorPropertyChanged();
            this.OnOffsetPropertyChanged();
            this.OnBlurRadiusPropertyChanged();
            this.OnShadowOpacityPropertyChanged();
            this.OnShadowCornerRadiusPropertyChanged();

            this.shadowVisual.Shadow = this.dropShadow;

            ElementCompositionPreview.SetElementChildVisual(this.shadowView, this.shadowVisual);
        }
コード例 #25
0
        XElement FromSpriteVisual(SpriteVisual obj)
        {
            return(new XElement(GetCompositionObjectName(obj), GetContents()));

            IEnumerable <XObject> GetContents()
            {
                foreach (var item in GetVisualContents(obj))
                {
                    yield return(item);
                }

                if (obj.Brush != null)
                {
                    yield return(new XElement(nameof(obj.Brush), FromCompositionObject(obj.Brush)));
                }
            }
        }
コード例 #26
0
        public ScrollViewerBackground()
        {
            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                return;
            }

            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
            _visual     = _compositor.CreateSpriteVisual();

            ElementCompositionPreview.SetElementChildVisual(this, _visual);

            Loaded      += OnLoaded;
            SizeChanged += OnSizeChanged;

            RegisterPropertyChangedCallback(BackgroundProperty, OnBackgroundChanged);
        }
コード例 #27
0
        private void AnimateOffset(SpriteVisual target)
        {
            float endPoint   = target.Size.X;
            float startPoint = target.Size.X - target.Size.X;

            if (target.Offset.X == startPoint)
            {
                target.AnchorPoint = new Vector2(1f, 0f);
                _offsetAnim.InsertKeyFrame(1, endPoint);
            }
            else if (target.Offset.X == endPoint)
            {
                target.AnchorPoint = new Vector2(0f, 0f);
                _offsetAnim.InsertKeyFrame(1, startPoint);
            }
            target.StartAnimation("Offset.X", _offsetAnim);
        }
コード例 #28
0
        private void TurnOffGlass()
        {
            if (!IsGlassOn)
            {
                return;
            }

            ElementCompositionPreview.SetElementChildVisual(GlassHost, null); //turn off the glass

            if (glassVisual != null)
            {
                glassVisual.Dispose();
                glassVisual = null;
            }

            IsGlassOn = false;
        }
コード例 #29
0
        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {
            // Dispose the sprite and unparent it
            ElementCompositionPreview.SetElementChildVisual(ThumbnailList, null);

            if (_destinationSprite != null)
            {
                _destinationSprite.Dispose();
                _destinationSprite = null;
            }

            if (_maskSurface != null)
            {
                _maskSurface.Dispose();
                _maskSurface = null;
            }
        }
コード例 #30
0
        void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            // get visuals from xaml object
            _touchAreaVisual = GetVisual(this.TouchArea);
            var imagePanelVisual = GetVisual(this.ImagePanel);

            // get compositor
            _compositor = imagePanelVisual.Compositor;

            var width = (float)this.ImagePanel.ActualWidth;
            var height = (float)this.ImagePanel.ActualHeight;

            // load the background image
            var uri = new Uri("ms-appx:///Assets/White.png");
            var imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
            var options = new CompositionImageOptions
            {
                DecodeWidth = (int)width,
                DecodeHeight = (int)height
            };
            var image = imageFactory.CreateImageFromUri(uri, options);

            // currently GaussianBlurEffect is not supported in Composition
            var effectDefination = new SaturationEffect // new GaussianBlurEffect
            {
                //BorderMode = EffectBorderMode.Soft,
                //BlurAmount = 5f,
                //Optimization = EffectOptimization.Quality,
                Source = new CompositionEffectSourceParameter("Overlay")
            };

            // create the actual effect
            var surfaceBrush = _compositor.CreateSurfaceBrush(image.Surface);
            var effectFactory = _compositor.CreateEffectFactory(effectDefination);
            var effectBrush = effectFactory.CreateBrush();
            effectBrush.SetSourceParameter("Overlay", surfaceBrush);

            // create the visual with the effect
            _visual = _compositor.CreateSpriteVisual();
            _visual.Brush = effectBrush;
            _visual.Opacity = 0.8f;
            _visual.Size = new Vector2(width, height);

            // place the effect visual onto the UI
            imagePanelVisual.Children.InsertAtTop(_visual);
        }
コード例 #31
0
        private void Favorites_Loaded(object sender, RoutedEventArgs e)
        {
            if (BuildInfo.BeforeAprilUpdate)
            {
                return;
            }

            selectionLabelBackground.Opacity = 0.5;

            BlendEffectMode blendmode = BlendEffectMode.Overlay;

            // Create a chained effect graph using a BlendEffect, blending color and blur
            var graphicsEffect = new BlendEffect
            {
                Mode       = blendmode,
                Background = new ColorSourceEffect()
                {
                    Name  = "Tint",
                    Color = Colors.Transparent,
                },

                Foreground = new GaussianBlurEffect()
                {
                    Name       = "Blur",
                    Source     = new CompositionEffectSourceParameter("Backdrop"),
                    BlurAmount = 18.0f,
                    BorderMode = EffectBorderMode.Hard,
                }
            };

            var blurEffectFactory = _compositor.CreateEffectFactory(graphicsEffect,
                                                                    new[] { "Blur.BlurAmount", "Tint.Color" });

            // Create EffectBrush, BackdropBrush and SpriteVisual
            _brush = blurEffectFactory.CreateBrush();

            var destinationBrush = _compositor.CreateBackdropBrush();

            _brush.SetSourceParameter("Backdrop", destinationBrush);

            selectionBlurSprite       = _compositor.CreateSpriteVisual();
            selectionBlurSprite.Size  = new Vector2((float)0, (float)0);
            selectionBlurSprite.Brush = _brush;

            ElementCompositionPreview.SetElementChildVisual(selectionBlur, selectionBlurSprite);
        }
コード例 #32
0
        private void InitializeFrostedGlass(float width, float height, Color color, float blurAmout, byte alpha, float multiply, float backAmout, float frontAmout)
        {
            Visual             hostedVisual = ElementCompositionPreview.GetElementVisual(glassGrid);
            Compositor         compositor   = hostedVisual.Compositor;
            GaussianBlurEffect blurEffect   = new GaussianBlurEffect()
            {
                BlurAmount = blurAmout,
                BorderMode = EffectBorderMode.Hard,
                Source     = new ArithmeticCompositeEffect()
                {
                    MultiplyAmount = multiply,
                    Source1Amount  = backAmout,
                    Source2Amount  = frontAmout,
                    Source1        = new CompositionEffectSourceParameter("BackBrush"),
                    Source2        = new ColorSourceEffect()
                    {
                        Color = Color.FromArgb(alpha, color.R, color.G, color.B)
                    }
                }
            };

            CompositionEffectFactory factory = compositor.CreateEffectFactory(blurEffect);
            CompositionBackdropBrush backdropBrush;

            if (Hosted)
            {
                backdropBrush = compositor.CreateHostBackdropBrush();
            }
            else
            {
                backdropBrush = compositor.CreateBackdropBrush();
            }
            CompositionEffectBrush brush = factory.CreateBrush();

            brush.SetSourceParameter("BackBrush", backdropBrush);

            SpriteVisual glassVisual = compositor.CreateSpriteVisual();

            glassVisual.Size = new Vector2()
            {
                X = width,
                Y = height
            };
            glassVisual.Brush = brush;
            ElementCompositionPreview.SetElementChildVisual(glassGrid, glassVisual);
        }
コード例 #33
0
ファイル: CandlestickSeries.cs プロジェクト: sk8tz/UI-For-UWP
        internal override void ApplyPaletteToContainerVisual(SpriteVisual visual, DataPoint point)
        {
            int   index              = this.ActualPaletteIndex;
            var   ohlcDataPoint      = point as OhlcDataPoint;
            Brush paletteFill        = this.chart.GetPaletteBrush(index, PaletteVisualPart.Fill, this.Family, point.isSelected);
            Brush paletteSpecialFill = this.chart.GetPaletteBrush(index, PaletteVisualPart.SpecialFill, this.Family, point.isSelected);
            Brush stroke             = this.chart.GetPaletteBrush(index, PaletteVisualPart.Stroke, this.Family, point.isSelected);

            if (paletteFill != null && stroke != null && ohlcDataPoint != null)
            {
                for (int i = 0; i < visual.Children.Count; i++)
                {
                    var childVisual = visual.Children.ElementAt(i) as SpriteVisual;
                    if (childVisual != null)
                    {
                        if (i + 1 != visual.Children.Count)
                        {
                            this.chart.ContainerVisualsFactory.SetCompositionColorBrush(childVisual, stroke, true);
                        }
                        else
                        {
                            if (ohlcDataPoint.IsFalling && paletteSpecialFill != null)
                            {
                                this.chart.ContainerVisualsFactory.SetCompositionColorBrush(childVisual, paletteSpecialFill, true);
                            }
                            else
                            {
                                this.chart.ContainerVisualsFactory.SetCompositionColorBrush(childVisual, paletteFill, true);
                            }
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < visual.Children.Count; i++)
                {
                    var childVisual = visual.Children.ElementAt(i) as SpriteVisual;
                    if (childVisual != null)
                    {
                        this.chart.ContainerVisualsFactory.SetCompositionColorBrush(childVisual, null, true);
                    }
                }
            }
        }
コード例 #34
0
ファイル: Sun.cs プロジェクト: DanieleScipioni/TestApp
        public async Task DrawShadow(FrameworkElement shadowSource, FrameworkElement shadowHost,
                                     Color color, float?offsetX = null, float?offsetY = null)
        {
            Compositor compositor = ElementCompositionPreview.GetElementVisual(shadowHost).Compositor;

            SpriteVisual spriteVisual = compositor.CreateSpriteVisual();

            _spriteVisualByUiElement.Add(shadowSource, spriteVisual);

            List <FrameworkElement> frameworkElements;
            ContainerVisual         shadowHostContainerVisual;

            if (_shadowSourceByShadowHost.ContainsKey(shadowHost))
            {
                frameworkElements         = _shadowSourceByShadowHost[shadowHost];
                shadowHostContainerVisual = (ContainerVisual)ElementCompositionPreview.GetElementChildVisual(shadowHost);
            }
            else
            {
                frameworkElements = new List <FrameworkElement>();
                _shadowSourceByShadowHost.Add(shadowHost, frameworkElements);
                shadowHostContainerVisual = compositor.CreateContainerVisual();
                ElementCompositionPreview.SetElementChildVisual(shadowHost, shadowHostContainerVisual);
                shadowHost.SizeChanged += ShadowHostOnSizeChanged;
            }

            frameworkElements.Add(shadowSource);

            shadowSource.SizeChanged += ShadowSourceOnSizeChanged;

            DropShadow dropShadow = compositor.CreateDropShadow();

            dropShadow.BlurRadius = 5;
            dropShadow.Offset     = new Vector3(offsetX ?? _offsetX, offsetY ?? _offsetY, 0);
            dropShadow.Color      = color;
            dropShadow.Mask       = await ShadowMask(shadowSource, compositor);

            dropShadow.SourcePolicy = CompositionDropShadowSourcePolicy.Default;

            spriteVisual.Size   = new Vector2((float)shadowSource.ActualWidth, (float)shadowSource.ActualHeight);
            spriteVisual.Shadow = dropShadow;
            spriteVisual.Offset = VisualOffset(shadowSource, shadowHost);

            shadowHostContainerVisual.Children.InsertAtTop(spriteVisual);
        }
コード例 #35
0
        public BackDrop()
        {
            m_rootVisual = ElementCompositionPreview.GetElementVisual(this as UIElement);
            Compositor   = m_rootVisual.Compositor;

            m_blurVisual = Compositor.CreateSpriteVisual();

            CompositionEffectBrush brush = BuildBlurBrush();

            brush.SetSourceParameter("source", m_compositor.CreateBackdropBrush());
            m_blurBrush        = brush;
            m_blurVisual.Brush = m_blurBrush;

            ElementCompositionPreview.SetElementChildVisual(this as UIElement, m_blurVisual);

            this.Loading  += OnLoading;
            this.Unloaded += OnUnloaded;
        }
コード例 #36
0
        private void ThumbnailList_ItemClick(object sender, ItemClickEventArgs e)
        {
            ListViewItem     listItem = (ListViewItem)ThumbnailList.ContainerFromItem(e.ClickedItem);
            CompositionImage image    = listItem.ContentTemplateRoot.GetFirstDescendantOfType <CompositionImage>();

            // Flip each thumbnail as it's clicked
            SpriteVisual sprite = image.SpriteVisual;

            sprite.RotationAxis = new Vector3(1, 0, 0);
            sprite.CenterPoint  = new Vector3(sprite.Size.X / 2, sprite.Size.Y / 2, 0);

            ScalarKeyFrameAnimation rotateAnimation = _compositor.CreateScalarKeyFrameAnimation();

            rotateAnimation.InsertKeyFrame(0, 0);
            rotateAnimation.InsertKeyFrame(1, 360);
            rotateAnimation.Duration = TimeSpan.FromSeconds(2);
            sprite.StartAnimation("RotationAngleInDegrees", rotateAnimation);
        }
コード例 #37
0
ファイル: BackDrop.cs プロジェクト: h82258652/SoftwareKobo.UI
        public Backdrop()
        {
            DefaultStyleKey = typeof(Backdrop);

            SizeChanged += (sender, e) =>
            {
                UpdateVisualSize();
            };

            var rootVisual = ElementCompositionPreview.GetElementVisual(this);
            _compositor = rootVisual.Compositor;
            _blurVisual = _compositor.CreateSpriteVisual();
            var brush = CreateBlurBrush();
            brush.SetSourceParameter("Source", _compositor.CreateBackdropBrush());
            _blurVisual.Brush = brush;

            ElementCompositionPreview.SetElementChildVisual(this, _blurVisual);
        }
コード例 #38
0
        public Layer(Compositor compositor, int identifier, Vector3 offset, Vector2 size,
                     ContainerVisual parent, CompositionColorBrush layerColor)
        {
            _compositor     = compositor;
            LayerColor      = layerColor;
            FocusedVisuals  = new List <Visual>();
            ElevatedVisuals = new List <Visual>();

            SpriteVisual x = _compositor.CreateSpriteVisual();

            x.Size     = new Vector2(size.X, size.Y);
            x.Offset   = Offset = offset;
            Identifier = identifier;
            x.Comment  = Identifier.ToString();

            _backingVisual = x;
            parent.Children.InsertAtTop(x);
        }
コード例 #39
0
ファイル: acrylic.cs プロジェクト: colinkiama/Mango
        private SpriteVisual CreateExclusionBlendVisual()
        {
            SpriteVisual blendVisual = _compositor.CreateSpriteVisual();

            blendVisual.Opacity = 1f;

            IGraphicsEffect exclusionBlendEffect = new Microsoft.Graphics.Canvas.Effects.BlendEffect
            {
                Mode = BlendEffectMode.Exclusion
            };

            CompositionEffectFactory exclusionBlendFactory = _compositor.CreateEffectFactory(exclusionBlendEffect);
            CompositionEffectBrush   exlcusionBrush        = exclusionBlendFactory.CreateBrush();

            blendVisual.Brush = exlcusionBrush;

            return(blendVisual);
        }
コード例 #40
0
        public InteractiveShadowBase()
        {
            this.DefaultStyleKey = typeof(InteractiveShadowBase);

            compositor = this.GetVisual().Compositor;

            shadow = compositor.CreateDropShadow();

            shadow.Opacity    = 0.9f;
            shadow.BlurRadius = 95.0f;

            baseVisual = compositor.CreateSpriteVisual();

            baseVisual.Size   = new Vector2(50);
            baseVisual.Brush  = compositor.CreateColorBrush(Colors.AliceBlue);
            baseVisual.Offset = new Vector3(100, 100, 0);
            baseVisual.Shadow = shadow;
        }
コード例 #41
0
        SpriteVisual GetSpriteVisual(SpriteVisual obj)
        {
            if (GetExisting(obj, out SpriteVisual result))
            {
                return(result);
            }

            result = CacheAndInitializeVisual(obj, _c.CreateSpriteVisual());

            if (obj.Brush != null)
            {
                result.Brush = GetCompositionBrush(obj.Brush);
            }

            InitializeContainerVisual(obj, result);
            StartAnimationsAndFreeze(obj, result);
            return(result);
        }
コード例 #42
0
ファイル: BarSeries.cs プロジェクト: sk8tz/UI-For-UWP
        internal override void ApplyPaletteToContainerVisual(SpriteVisual visual, DataPoint point)
        {
            int index = this.paletteModeCache == SeriesPaletteMode.Series ? this.ActualPaletteIndex : point.CollectionIndex;

            if (index > 0)
            {
                SolidColorBrush paletteFill = this.chart.GetPaletteBrush(index, PaletteVisualPart.Fill, this.Family, point.isSelected) as SolidColorBrush;

                if (paletteFill != null)
                {
                    this.chart.ContainerVisualsFactory.SetCompositionColorBrush(visual, paletteFill, true);
                }
                else
                {
                    this.chart.ContainerVisualsFactory.SetCompositionColorBrush(visual, null, true);
                }
            }
        }
コード例 #43
0
        private void Timer_Tick(object sender, object e)
        {
            if (_timer != null)
            {
                Debug.Assert(_sprite.Children.Count == 0, "Should not be any children");

                // Create a second sprite to show while the image is still loading
                SpriteVisual loadingSprite = _compositor.CreateSpriteVisual();
                loadingSprite       = _compositor.CreateSpriteVisual();
                loadingSprite.Size  = new Vector2((float)ActualWidth, (float)ActualHeight);
                loadingSprite.Brush = _placeholderBrush != null ? _placeholderBrush : _defaultPlaceholderBrush;
                _sprite.Children.InsertAtTop(loadingSprite);

                // Stop and null out the time, no more need for it.
                _timer.Stop();
                _timer = null;
            }
        }
コード例 #44
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            _compositor = Window.Current.Compositor;
            _generator  = _compositor.CreateCompositionGenerator();

            _imageVisual      = _compositor.CreateSpriteVisual();
            _imageVisual.Size = new Vector2(RenderGrid.Width.ToSingle(), RenderGrid.Height.ToSingle());
            _imageOptions     = ImageSurfaceOptions.DefaultOptimized;
            _imageOptions.SurfaceBackgroundColor = Colors.Black;
            _imageSurface      = _generator.CreateImageSurface(null, _imageVisual.Size.ToSize(), _imageOptions);
            _imageVisual.Brush = _compositor.CreateSurfaceBrush(_imageSurface);
            ElementCompositionPreview.SetElementChildVisual(RenderGrid, _imageVisual);

            ImageCB.SelectedIndex   = 0;
            StretchCB.SelectedIndex = 0;
            AlignXCB.SelectedIndex  = 1;
            AlignYCB.SelectedIndex  = 1;
        }
コード例 #45
0
        /// <summary>
        /// Creates a Visual using the specific color and constraints
        /// </summary>
        private SpriteVisual CreateVisualWithColorAndPosition(Windows.UI.Color color,
                                                              Windows.Foundation.Rect initialBounds,
                                                              Windows.Foundation.Rect finalBounds)
        {
            // init the position and dimensions for our visual
            var width     = (float)initialBounds.Width;
            var height    = (float)initialBounds.Height;
            var positionX = initialBounds.X;
            var positionY = initialBounds.Y;

            // we want our visual (a circle) to completely fit within the bounding box
            var circleColorVisualDiameter = (float)Math.Min(width, height);

            // the diameter of the circular visual is an essential bit of information
            // in initializing our bloom animation - a one-time thing
            if (_bloomAnimation == null)
            {
                InitializeBloomAnimation(circleColorVisualDiameter / 2, finalBounds); // passing in the radius
            }
            // we are going to some lengths to have the visual precisely placed
            // such that the center of the circular visual coincides with the center of the AppBarButton.
            // it is important that the bloom originate there
            var diagonal       = Math.Sqrt(2 * (circleColorVisualDiameter * circleColorVisualDiameter));
            var deltaForOffset = (diagonal - circleColorVisualDiameter) / 2;

            // now we have everything we need to calculate the position (offset) and size of the visual
            var offset = new Vector3((float)positionX + (float)deltaForOffset + circleColorVisualDiameter / 2,
                                     (float)positionY + circleColorVisualDiameter / 2,
                                     0f);
            var size = new Vector2(circleColorVisualDiameter);

            // create the visual with a solid colored circle as brush
            SpriteVisual coloredCircleVisual = _compositor.CreateSpriteVisual();

            coloredCircleVisual.Brush  = CreateCircleBrushWithColor(color);
            coloredCircleVisual.Offset = offset;
            coloredCircleVisual.Size   = size;

            // we want our scale animation to be anchored around the center of the visual
            coloredCircleVisual.AnchorPoint = new Vector2(0.5f, 0.5f);


            return(coloredCircleVisual);
        }
コード例 #46
0
        private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Get backing visual from shadow container and interop compositor
            _shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer);
            _compositor = _shadowContainer.Compositor;

            // Get CompositionImage, its sprite visual
            _image = VisualTreeHelperExtensions.GetFirstDescendantOfType<CompositionImage>(ShadowContainer);
            _imageVisual = _image.SpriteVisual;
           
            // Add drop shadow to image visual
            _shadow = _compositor.CreateDropShadow();
            _imageVisual.Shadow = _shadow;

            // Initialize sliders to shadow defaults - with the exception of offset
            BlurRadiusSlider.Value  = _shadow.BlurRadius;   //defaults to 9.0f
            OffsetXSlider.Value     = _shadow.Offset.X;     //defaults to 0
            OffsetYSlider.Value     = _shadow.Offset.Y;     //defaults to 0
            RedSlider.Value         = _shadow.Color.R;      //defaults to 0 (black.R)
            GreenSlider.Value       = _shadow.Color.G;      //defaults to 0 (black.G) 
            BlueSlider.Value        = _shadow.Color.B;      //defaults to 0 (black.B) 

            // Load mask asset onto surface using helpers in SamplesCommon
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
            _imageMaskSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Assets/CircleMask.png"));

            // Create surface brush for mask
            CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush();
            mask.Surface = _imageMaskSurface.Surface;
            
            // Get surface brush from composition image
            CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush;

            // Create mask brush for toggle mask functionality
            _maskBrush = _compositor.CreateMaskBrush();
            _maskBrush.Mask = mask;
            _maskBrush.Source = source;

            // Initialize toggle mask and animation to false
            _isMaskEnabled = false;
            _isAnimationEnabled = false;
          
        }
コード例 #47
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _thumb = _compositor.CreateSpriteVisual();

            var _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
            CompositionImageOptions options = new CompositionImageOptions()
            {
                DecodeWidth = 21,
                DecodeHeight = 36,
            };

            Uri thumbImageUri = new Uri("ms-appx:///Resources/Images/FaderThumb.png");
            var thumbImage = _imageFactory.CreateImageFromUri(thumbImageUri, options);

            _thumb.Brush = _compositor.CreateSurfaceBrush(thumbImage.Surface);
            _thumb.Size = new Vector2(21, 36);
            _thumb.Offset = new Vector3(-10, 0, 0);
            _root.Children.InsertAtTop(_thumb);
        }
コード例 #48
0
        private async void BusyIndicator_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
            generator = CompositionMaskFactory.GetCompositionMaskGenerator(compositor);

            container = compositor.CreateContainerVisual();
            container.Size = new Vector2(60, 60);
            container.Offset = new Vector3(-30, -30, 0);

            float size = 30;

            var color = Color.FromArgb(255, 0xD2, 0x42, 0x29);

            ellipse_0 = await CreateEllipseVisual(color, size, size);
            ellipse_1 = await CreateEllipseVisual(color, size, size);
            ellipse_2 = await CreateEllipseVisual(color, size, size);
            ellipse_3 = await CreateEllipseVisual(color, size, size);

            container.Children.InsertAtBottom(ellipse_0);
            container.Children.InsertAtBottom(ellipse_1);
            container.Children.InsertAtBottom(ellipse_2);
            container.Children.InsertAtBottom(ellipse_3);

            ElementCompositionPreview.SetElementChildVisual(this, container);

            animations.Add(AnimateScale(ellipse_0));
            animations.Add(AnimateScale(ellipse_1, true));
            animations.Add(AnimateScale(ellipse_2));
            animations.Add(AnimateScale(ellipse_3, true));

            animations.Add(AnimateRotation(ellipse_0, 0));
            animations.Add(AnimateRotation(ellipse_1, 0.25f * (float)Math.PI));
            animations.Add(AnimateRotation(ellipse_2, 0.5f * (float)Math.PI));
            animations.Add(AnimateRotation(ellipse_3, 0.75f * (float)Math.PI));

            IsReady = true;
        }
コード例 #49
0
ファイル: MainPage.xaml.cs プロジェクト: blinds52/intense
        private void Host_Loaded(object sender, RoutedEventArgs e)
        {
            var visual = ElementCompositionPreview.GetElementVisual(this.Host);
            this.compositor = visual.Compositor;

            // create root container
            this.root = this.compositor.CreateContainerVisual();
            ElementCompositionPreview.SetElementChildVisual(this.Host, this.root);

            // create background
            this.background = this.compositor.CreateSpriteVisual();
            this.background.Brush = this.compositor.CreateColorBrush(Colors.LightGreen);
            this.root.Children.InsertAtBottom(this.background);

            // create green square
            var colorVisual = this.compositor.CreateSpriteVisual();
            colorVisual.Brush = this.compositor.CreateColorBrush(Colors.Green);
            colorVisual.Size = new Vector2(150.0f, 150.0f);
            colorVisual.CenterPoint = new Vector3(75.0f, 75.0f, 0.0f);
            this.target = colorVisual;
            this.root.Children.InsertAtTop(this.target);

            UpdateSize();
        }
コード例 #50
0
ファイル: CompositionImage.cs プロジェクト: liquidboy/X
        private void CompImage_Unloaded(object sender, RoutedEventArgs e)
        {
            _unloaded = true;

            // TODO: Remove this workaround after 14332
            ReleaseSurface();

            if (_sprite != null)
            {
                // TODO: Remove this workaround after 14332
                ElementCompositionPreview.SetElementChildVisual(this, null);

                _sprite.Dispose();
                _sprite = null;
            }
        }
コード例 #51
0
        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {
            // Dispose the sprite and unparent it
            ElementCompositionPreview.SetElementChildVisual(ThumbnailList, null);

            if (_destinationSprite != null)
            {
                _destinationSprite.Dispose();
                _destinationSprite = null;
            }
        }
コード例 #52
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _trackBackground = GetTemplateChild("PART_TrackBackground") as Rectangle;
            _root = GetVisual(_trackBackground);
            _compositor = _root.Compositor;

            _track = _compositor.CreateSpriteVisual();

            _track.Brush = _compositor.CreateColorBrush(Color.FromArgb(255, 0, 120, 215));
            _root.Children.InsertAtTop(_track);
            //_track.getV
            //_trackBackground
            //
            //_thumb = GetTemplateChild("PART_Thumb") as ContentControl;
            //if (_thumb != null)
            //{
            //    _thumb.PointerPressed += (s, e) => { TouchSliderDragValueHandler.OnPointerPressed(s as UIElement, this, e); };
            //    _thumb.PointerMoved += (s, e) => { TouchSliderDragValueHandler.OnPointerMoved(this, e); };
            //    _thumb.PointerReleased += (s, e) => { TouchSliderDragValueHandler.OnPointerReleased(s as UIElement, this, e); };
            //}
        }
コード例 #53
0
 private void CreateSpriteVisual()
 {
     spriteVisual = compositor.CreateSpriteVisual();
     spriteVisual.Brush = effectBrush;
     spriteVisual.Size = new Vector2(GetElementWidth(), GetElementHeight());
 }
コード例 #54
0
        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {
            // Dispose the sprite and unparent it
            // TODO: Remove this workaround after 14332
            //ElementCompositionPreview.SetElementChildVisual(ThumbnailList, null);

            if (_destinationSprite != null)
            {
                // TODO: Remove this workaround after 14332
                //_destinationSprite.Dispose();
                _destinationSprite = null;
            }
        }
コード例 #55
0
        private void CreateTextAndBlendEffect(Vector2 sizeLightBounds)
        {
            //
            // Crete the effect graph, doing a hard light blend of the text over the 
            // content already drawn into the backbuffer
            //

            IGraphicsEffect graphicsEffect = new BlendEffect()
            {
                Mode = BlendEffectMode.HardLight,
                Foreground = new CompositionEffectSourceParameter("Text"),
                Background = new CompositionEffectSourceParameter("Destination"),
            };

            CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(graphicsEffect, null);
            CompositionEffectBrush brush = effectFactory.CreateBrush();

            // Bind the destination brush
            brush.SetSourceParameter("Destination", _compositor.CreateBackdropBrush());


            //
            // Create the text surface which we'll scroll over the image with the lighting effect
            //

            // Pick a nice size font depending on target size
            const float maxFontSize = 72;
            const float scaleFactor = 12;
            float fontSize = Math.Min(sizeLightBounds.X / scaleFactor, maxFontSize);

            // Create the text format description, then the surface
            CanvasTextFormat textFormat = new CanvasTextFormat
                    {
                        FontFamily = "Segoe UI",
                        FontSize = fontSize,
                        FontWeight = FontWeights.Bold,
                        WordWrapping = CanvasWordWrapping.WholeWord,
                        HorizontalAlignment = CanvasHorizontalAlignment.Center,
                        VerticalAlignment = CanvasVerticalAlignment.Center
                    };

            string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec efficitur, eros sit amet laoreet scelerisque, " +
                          "nunc odio ultricies metus, ut consectetur nulla massa eu nibh.Phasellus in lorem id nunc euismod tempus.Phasellus et nulla non turpis tempor blandit ut eget turpis." +
                          "Phasellus ac ornare elit, ut scelerisque dolor. Nam vel finibus lorem. Aenean malesuada pulvinar eros id ornare. Fusce blandit ante eget dolor efficitur suscipit." +
                          "Phasellus ac lacus nibh. Aenean eget blandit risus, in lacinia mi. Proin fermentum ante eros, non sollicitudin mi pretium eu. Curabitur suscipit lectus arcu, eget" +
                          "pretium quam sagittis non. Mauris purus mauris, condimentum nec laoreet sit amet, imperdiet sit amet nisi. Sed interdum, urna et aliquam porta, elit velit tincidunt orci," +
                          "vitae vestibulum risus lacus at nulla.Phasellus sapien ipsum, pellentesque varius enim nec, iaculis aliquet enim. Nulla id dapibus ante. Sed hendrerit sagittis leo, commodo" +
                          "fringilla ligula rutrum ut. Nullam sodales, ex ut pellentesque scelerisque, sapien nulla mattis lectus, vel ullamcorper leo enim ac mi.Sed consectetur vitae velit in consequat." +
                          "Pellentesque ac condimentum justo, at feugiat nulla. Sed ut congue neque. Nam gravida quam ac urna porttitor, ut bibendum ante mattis.Cras viverra cursus sapien, et sollicitudin" +
                          "risus fringilla eget. Nulla facilisi. Duis pellentesque scelerisque nisi, facilisis malesuada massa gravida et. Vestibulum ac leo sed orci tincidunt feugiat.Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nunc id leo vestibulum, vulputate ipsum sit amet, scelerisque velit. Curabitur imperdiet justo et tortor dignissim, sit amet volutpat sem ullamcorper. Nam mollis ullamcorper tellus vitae convallis. Aliquam eleifend elit nec tincidunt pharetra. Aliquam turpis eros, mollis et nunc quis, porta molestie justo. Etiam ultrices sem non turpis imperdiet dictum.Aliquam molestie elit in urna sodales, nec luctus dui laoreet.Curabitur molestie risus vel ligula efficitur, non fringilla urna iaculis.Curabitur neque tortor, facilisis quis dictum facilisis, facilisis et ante. Sed nisl erat, semper vitae efficitur ut, congue vitae quam. Ut auctor lacus sit amet varius placerat.Sed ac tellus tempus, ultricies est quis, tempor felis.Nulla vel faucibus elit, eu tincidunt eros. Nulla blandit id nisl ut porta. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Etiam suscipit tellus a mattis pulvinar. Sed et libero vel ligula elementum suscipit.Ut elementum libero at sagittis pharetra. Fusce ultrices odio sapien, a posuere est consectetur ut.";

            // Make the surface twice the height to give us room to scroll
            Vector2 surfaceSize = new Vector2(sizeLightBounds.X, 2f * sizeLightBounds.Y);
            CompositionDrawingSurface textSurface = SurfaceLoader.LoadText(text, surfaceSize.ToSize(),
                                                                           textFormat, Colors.White, Colors.Transparent);
            brush.SetSourceParameter("Text", _compositor.CreateSurfaceBrush(textSurface));

            // Create the sprite and parent it to the panel with the clip
            _textSprite = _compositor.CreateSpriteVisual();
            _textSprite.Size = surfaceSize;
            _textSprite.Brush = brush;

            ElementCompositionPreview.SetElementChildVisual(MyPanel, _textSprite);

            // Lastly, setup the slow scrolling animation of the text
            LinearEasingFunction linear = _compositor.CreateLinearEasingFunction();
            Vector3KeyFrameAnimation offsetAnimation = _compositor.CreateVector3KeyFrameAnimation();
            offsetAnimation.InsertKeyFrame(0f, new Vector3(0, 0, 0), linear);
            offsetAnimation.InsertKeyFrame(1f, new Vector3(0, -_textSprite.Size.Y * .5f, 0), linear);
            offsetAnimation.Duration = TimeSpan.FromMilliseconds(30000);
            offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            _textSprite.StartAnimation("Offset", offsetAnimation);
        }
コード例 #56
0
        /// <summary>
        /// Runs the animation
        /// </summary>
        private void TriggerBloomAnimation(SpriteVisual colorVisual)
        {

            // animate the Scale of the visual within a scoped batch
            // this gives us transactionality and allows us to do work once the transaction completes
            var batchTransaction = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            // as with all animations on Visuals, these too will run independent of the UI thread
            // so if the UI thread is busy with app code or doing layout on state/page transition,
            // these animations still run uninterruped and glitch free
            colorVisual.StartAnimation("Scale.X", _bloomAnimation);
            colorVisual.StartAnimation("Scale.Y", _bloomAnimation);

            batchTransaction.Completed += (sender, args) =>
            {
                // remove this visual from visual tree
                _containerForVisuals.Children.Remove(colorVisual);

                // notify interested parties
                ColorBloomTransitionCompleted(this, EventArgs.Empty);
            };
            
            batchTransaction.End();

        }
コード例 #57
0
        /// <summary>
        /// Creates the visual tree that will house the video.
        /// </summary>
        /// <param name="videoContentGrid"></param>
        private void EnsureComposition(Grid videoContentGrid)
        {
            if (_videoVisual == null)
            {
                // Create a ContainerVisual that we'll attach lights to, as well as our video.
                _videoRootVisual = _compositor.CreateContainerVisual();

                // Create a SpriteVisual to host the video content.
                _videoVisual = _compositor.CreateSpriteVisual();
                _videoVisual.Size = new Vector2((float)videoContentGrid.ActualWidth, (float)videoContentGrid.ActualHeight);

                // Make sure our visual stays in sync with our host.
                videoContentGrid.SizeChanged += (s, a) =>
                {
                    _videoVisual.Size = new Vector2((float)videoContentGrid.ActualWidth, (float)videoContentGrid.ActualHeight);
                };

                // Attach our visuals to the tree.
                _videoRootVisual.Children.InsertAtTop(_videoVisual);
                ElementCompositionPreview.SetElementChildVisual(videoContentGrid, _videoRootVisual);
            }
        }
コード例 #58
0
        /// <summary>
        /// Runs the animation
        /// </summary>
        private void TriggerSlideAnimation(SpriteVisual colorVisual)
        {

            // animate the Scale of the visual within a scoped batch
            // this gives us transactionality and allows us to do work once the transaction completes
            var batchTransaction = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            // as with all animations on Visuals, these too will run independent of the UI thread
            // so if the UI thread is busy with app code or doing layout on state/page transition,
            // this animation still run uninterruped and glitch free.
            colorVisual.StartAnimation("Offset.X", _slideAnimation);

            batchTransaction.Completed += SlideAnimationCompleted;

            batchTransaction.End();

        }
コード例 #59
0
        private void SetVideoSurface(VideoSurface canvas)
        {
            var size = new Size(canvas.ActualWidth, canvas.ActualHeight);
            _player.SetSurfaceSize(size);

            var compositor = ElementCompositionPreview.GetElementVisual(canvas).Compositor;
            var surface = _player.GetSurface(compositor);

            _spriteVisual = compositor.CreateSpriteVisual();
            _spriteVisual.Size =
                new Vector2((float) canvas.ActualWidth, (float) canvas.ActualHeight);

            CompositionBrush brush = compositor.CreateSurfaceBrush(surface.CompositionSurface);
            _spriteVisual.Brush = brush;

            var container = compositor.CreateContainerVisual();
            container.Children.InsertAtTop(_spriteVisual);

            ElementCompositionPreview.SetElementChildVisual(canvas, container);
        }
コード例 #60
0
ファイル: GrayscaleEffect.cs プロジェクト: liquidboy/X
        public void Dispose()
        {
            imageFactory = null;
            imageSource = null;


            if (effect != null)
            {
                effect.Dispose();
                effect = null;
            }

            if (surfaceBrush != null)
            {
                surfaceBrush.Surface = null;
                surfaceBrush.Dispose();
                surfaceBrush = null;
            }

            //if (visual != null)
            //{
            //    if(spriteVisual!=null) visual.Children.Remove(spriteVisual);
            //    visual.Dispose();
            //    visual = null;
            //}
            
            if (effectBrush != null)
            {
                effectBrush.SetSourceParameter(EffectSource, null);
                effectBrush.Dispose();
                effectBrush = null;
            }

            if (spriteVisual != null) {
                spriteVisual.Brush = null;
                spriteVisual.Dispose();
                spriteVisual = null;
            }
            
        }