/// <summary>
        /// Set up Continuity by hooking continuing Visuals to root Frame and getting global co-ordinates so that Visual seems to remain on the same location even though pages change and local coordinate space changes as well. 
        /// </summary>
        /// <param name="containerVisual">Container Visual which contains visual that needs to continue between pages</param>
        /// <param name="hostElement">UIElement which the Visual is hosted in</param>
        /// <param name="newContainerVisual">new ContainerVisual after re-parent of sprite Visual to root.</param>
        public static void SetupContinuity(ContainerVisual containerVisual,UIElement HostElement, out ContainerVisual newContainerVisual)
        {
            if (null == containerVisual || null == HostElement)
            {
                newContainerVisual = null;
                return;
            }
            Frame rootFrame = Window.Current.Content as Frame;
            Visual rootVisual = ElementCompositionPreview.GetElementVisual(rootFrame);
            Compositor compositor = rootVisual.Compositor;
            //remove element from current tree 
            var visualChild = containerVisual.Children.FirstOrDefault();
            containerVisual.Children.Remove(visualChild);

            //create temp container to add the visual to the root 
            ContainerVisual tempContainer = compositor.CreateContainerVisual();
            tempContainer.Children.InsertAtTop(visualChild);
            //Get location of visual as compared to root frame. 
            var coordinate = HostElement.TransformToVisual(rootFrame);
            var position = coordinate.TransformPoint(new Point(0, 0));
            //set the location of container visual to same visual location but now root as the parent.
            tempContainer.Offset = new System.Numerics.Vector3((float)position.X, (float)position.Y, 0);
            visualChild.Offset = new System.Numerics.Vector3(0, 0, 0);

            //add container with sprite to the window of app
            ElementCompositionPreview.SetElementChildVisual(rootFrame, tempContainer);
            containerVisual = null;
            newContainerVisual = tempContainer;
        }
Example #2
0
        public void Parallax_Expression()
        {
            _compositor = new Compositor();
            _root = (ContainerVisual)ElementCompositionPreview.GetContainerVisual(Container);
            _compositor = _root.Compositor;

            // Create the Blue Square
            var blueSquareVisual = _compositor.CreateSolidColorVisual();
            blueSquareVisual.Color = Colors.Blue;
            blueSquareVisual.Size = new System.Numerics.Vector2(100.0f, 100.0f);
            blueSquareVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f);

            // Create the Green Square
            var greenSquareVisual = _compositor.CreateSolidColorVisual();
            greenSquareVisual.Color = Colors.Green;
            greenSquareVisual.Size = new System.Numerics.Vector2(50.0f, 50.0f);
            greenSquareVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f);


            // Add the Blue and Green square visuals to the tree
            _root.Children.InsertAtTop(blueSquareVisual);
            _root.Children.InsertAtTop(greenSquareVisual);

            _foreground = greenSquareVisual;
            _background = blueSquareVisual;
        }
Example #3
0
        public async Task Create(ContainerVisual rootContainer)
        {
            // Create a panning Visual that will be the entire size of all photos.

            _rootContainer = rootContainer;
            _compositor = rootContainer.Compositor;

            _panningContainer = _compositor.CreateContainerVisual();
            _rootContainer.Children.InsertAtTop(_panningContainer);


            // Configure the photo database and create the initial layout.

            _random = new Random();
            _allTiles = new List<Tile>();
            _farTileHistory = new List<Tile>();
            _nearTileHistory = new List<Tile>();
            _photoDatabase = new PhotoDatabase();
            await _photoDatabase.Create(_compositor.DefaultGraphicsDevice);

            CreatePlaceholderLayout();


            // Start pictures loading:
            // - Don't load all of the pictures at once, as this will create threadpool threads for
            //   each and will hammer the IO system, delaying everything.
            // - As each image arrives, connect it with a tile and start loading the next photo
            //   until all tiles have photos.

            for (int i = 0; i < ConcurrentDecodeThreads; i++)
            {
                LoadNextPhoto();
            }
        }
        public DetailsPage()
        {
            this.InitializeComponent();

           _mainGridVisual = ElementCompositionPreview.GetElementVisual(Window.Current.Content) as ContainerVisual;
            _compositor = _mainGridVisual.Compositor;
        }
Example #5
0
        public Tile(ContainerVisual parent, float border)
        {
            _parent = parent;
            _border = border;


            // Create a placeholder picture frame:
            // - This is the parent of the actual image.
            // - Configure with a center-point in the middle to allow easy rotation.
            // - Don't add it to the parent yet.  This enables the caller to specify more
            //   properties (such as offset) without animating them before making the Tile visible.

            _frame = s_compositor.CreateSolidColorVisual();
            _frame.Color = s_unselectedFrameColor;
            _frame.Opacity = 1.0f;


            // Since we can't currently animate colors, need to animate opacity instead.
            // At the least, we should be able to make this an effect and animate that.
            // - Start with opacity = 0 and fade in when selected.

            _selectedFrame = s_compositor.CreateSolidColorVisual();
            _selectedFrame.Offset = new Vector3();
            _selectedFrame.Color = s_selectedFrameColor;
            _selectedFrame.Opacity = 0.0f;
            _frame.Children.InsertAtBottom(_selectedFrame);
            

            // Begin a default animation for the rotation.

            StartNewRotationAnimation();
        }
        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();
        }
Example #7
0
        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();
        }
Example #8
0
        public void SetupVisuals()
        {
            // Intialize the Compositor
            _compositor = new Compositor();
            _root = (ContainerVisual)ElementCompositionPreview.GetContainerVisual(Container);
            _compositor = _root.Compositor;

            // Create the Blue Square
            var blueSquareVisual = _compositor.CreateSolidColorVisual();
            blueSquareVisual.Color = Colors.Blue;
            blueSquareVisual.Size = new System.Numerics.Vector2(50.0f, 50.0f);
            blueSquareVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f);

            // Create the Green Square with 20% opacity
            var greenSquareVisual = _compositor.CreateSolidColorVisual();
            greenSquareVisual.Color = Colors.Green;
            greenSquareVisual.Size = new System.Numerics.Vector2(50.0f, 50.0f);
            greenSquareVisual.Offset = new Vector3(150.00f, 100.00f, 0.00f);
            greenSquareVisual.Opacity = 0.20f;

            // Add the Visuals to the tree
            _root.Children.InsertAtTop(greenSquareVisual);
            _root.Children.InsertAtTop(blueSquareVisual);

            _source = greenSquareVisual;
            _target = blueSquareVisual;
        }
        public async Task Create(ContainerVisual topContainer)
        {
            var compositor = topContainer.Compositor;
            Tile.Initialize(compositor);
            CommonAnimations.Initialize(compositor);

            _layoutManager = new LayoutManager();
            await _layoutManager.Create(topContainer);

            _transitionLibrary = new TransitionLibrary(compositor, _layoutManager);
            _random = new Random();

            NearSlideEntry = new TransitionEntry(
                TransitionKind.NearSlide,
                _layoutManager.GetNearNeighbor,
                _transitionLibrary.CreateNearSlideTransition,
                TransitionOptions.Select,
                TransitionDesaturationMode.None);

            FarSlideEntry = new TransitionEntry(
                TransitionKind.FarSlide,
                _layoutManager.GetFarNeighbor,
                _transitionLibrary.CreateFarSlideTransition,
                TransitionOptions.Select,
                TransitionDesaturationMode.ColorFlashlight);

            ZoomEntry = new TransitionEntry(
                TransitionKind.Zoom,
                _layoutManager.GetFarNeighbor,
                _transitionLibrary.CreateZoomAndPanTransition,
                TransitionOptions.Select,
                TransitionDesaturationMode.Regular);

            StackEntry = new TransitionEntry(
                TransitionKind.Stack,
                _layoutManager.GetCurrentPictureFrame,
                _transitionLibrary.CreateStackTransition,
                TransitionOptions.Select,
                TransitionDesaturationMode.None);

            UnstackEntry = new TransitionEntry(
                TransitionKind.Stack,
                _layoutManager.GetCurrentPictureFrame,
                _transitionLibrary.CreateUnstackTransition,
                TransitionOptions.Select,
                TransitionDesaturationMode.None);

            _entries = new TransitionEntry[]
            {
                NearSlideEntry,
                FarSlideEntry,
                ZoomEntry,
                StackEntry,
                UnstackEntry,
            };
        }
        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;

        }
Example #11
0
        // Define and setup the Green Square Visual that will be animated 
        public void SetupVisual()
        {
            // Intialize the Compositor
            _compositor = new Compositor();
            _root = (ContainerVisual)ElementCompositionPreview.GetElementVisual(Container);
            _compositor = _root.Compositor;

            _linear = _compositor.CreateLinearEasingFunction();

            // Create Green Square
            var colorVisual = _compositor.CreateSpriteVisual();
            colorVisual.Brush = _compositor.CreateColorBrush(Colors.Green);
            colorVisual.Size = new Vector2(150.0f, 150.0f);
            colorVisual.Offset = new Vector3(250.0f, 50.0f, 0.0f);
            colorVisual.CenterPoint = new Vector3(75.0f, 75.0f, 0.0f);
            _target = colorVisual;

            // Create Blue Square
            var colorVisual2 = _compositor.CreateSpriteVisual();
            colorVisual2.Brush = _compositor.CreateColorBrush(Colors.Aqua);
            colorVisual2.Size = new Vector2(200.0f, 150.0f);
            colorVisual2.Offset = new Vector3(25.0f, 50.0f, 0.0f);
            colorVisual2.IsVisible = false; 
            _target2 = colorVisual2;

            // Add the Blue and Green square visuals to the tree
            _mainContainer = _compositor.CreateContainerVisual();
            ElementCompositionPreview.SetElementChildVisual(Container, _mainContainer);
            _mainContainer.Children.InsertAtTop(_target);
            _mainContainer.Children.InsertAtTop(_target2);

            // Create Scoped batch for animations
            _batch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            // Add Animation1 to the batch
            Animation1(_target);

            // Suspend the batch to exclude an animation
            _batch.Suspend();

            // Exluding Animation2 from batch
            Animation2(_target);

            // Resuming the batch to collect additional animations
            _batch.Resume();

            // Add Animation3 to the batch
            Animation3(_target);

            // Batch is ended an no objects can be added
            _batch.End();

            // Method triggered when batch completion event fires
            _batch.Completed += OnBatchCompleted;
        }
        public virtual void InitializeComposition(Vector2 bounds)
        {
            Visual = MainElement.GetContainerVisual();
            Compositor = Visual.Compositor;

            float halfwidth = (float)MainElement.Width / 2.0f;
            float halfheight = (float)MainElement.Height / 2.0f;

            Visual.CenterPoint = new Vector3(halfwidth, halfwidth, 0);
            UpdateComposition(bounds);
        }
Example #13
0
        private void Host_Loaded(object sender, RoutedEventArgs e)
        {
            this.container = (ContainerVisual)ElementCompositionPreview.GetContainerVisual(this.Host);
            this.compositor = container.Compositor;

            this.background = this.compositor.CreateSolidColorVisual();
            this.background.Color = Colors.LightGreen;

            this.container.Children.InsertAtBottom(background);
            UpdateSize();
        }
Example #14
0
        public MyContainerVisualHost(DrawingVisual border, DrawingVisual text)
        {
            // Create a ContainerVisual to hold DrawingVisual children.
            _containerVisual = new ContainerVisual();

            // Add children to ContainerVisual in reverse z-order (bottom to top).
            _containerVisual.Children.Add(border);
            _containerVisual.Children.Add(text);

            // Create parent-child relationship with host visual and ContainerVisual.
            this.AddVisualChild(_containerVisual);
        }
Example #15
0
        ContainerVisual GetContainerVisual(ContainerVisual obj)
        {
            if (GetExisting(obj, out ContainerVisual result))
            {
                return(result);
            }

            result = CacheAndInitializeVisual(obj, _c.CreateContainerVisual());
            InitializeContainerVisual(obj, result);
            StartAnimationsAndFreeze(obj, result);
            return(result);
        }
        public override DocumentPage GetPage(int pageNumber)
        {
            DocumentPage    originalPage = _originalPaginator.GetPage(pageNumber);
            ContainerVisual fixedPage    = new ContainerVisual();

            fixedPage.Children.Add(originalPage.Visual);
            fixedPage.Transform = new TranslateTransform(_pageMargin.Width, _pageMargin.Height);
            Rect bleedBox   = AdjustForMargins(originalPage.BleedBox);
            Rect contentBox = AdjustForMargins(originalPage.ContentBox);

            return(new DocumentPage(fixedPage, _pageSize, bleedBox, contentBox));
        }
Example #17
0
        IEnumerable <XObject> GetContainerVisualContents(ContainerVisual obj)
        {
            foreach (var item in GetVisualContents(obj))
            {
                yield return(item);
            }

            foreach (var item in obj.Children.SelectMany(FromCompositionObject))
            {
                yield return(item);
            }
        }
Example #18
0
        private void PositionOhlcDataPointVisual(ContainerVisual parentVisual, int index, Vector3 offset, Vector2 size, SolidColorBrush brush, float angle = 0)
        {
            ContainerVisual childVisual = parentVisual.Children.ElementAt(index) as ContainerVisual;

            if (childVisual != null)
            {
                childVisual.Offset = offset;
                childVisual.Size   = size;
                childVisual.RotationAngleInDegrees = angle;
                this.SetCompositionColorBrush(childVisual, brush);
            }
        }
Example #19
0
        public void ValuesChanged(InteractionTracker sender, InteractionTrackerValuesChangedArgs args)
        {
            if (_indicator == null && ApiInfo.CanUseDirectComposition && (_tracker.Position.X > 0.0001f || _tracker.Position.X < -0.0001f) /*&& Math.Abs(e.Cumulative.Translation.X) >= 45*/)
            {
                var sprite = _visual.Compositor.CreateSpriteVisual();
                sprite.Size        = new Vector2(30, 30);
                sprite.CenterPoint = new Vector3(15);

                var surface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/Images/Reply.png"));
                surface.LoadCompleted += (s, e) =>
                {
                    sprite.Brush = _visual.Compositor.CreateSurfaceBrush(s);
                };

                var ellipse = _visual.Compositor.CreateEllipseGeometry();
                ellipse.Radius = new Vector2(15);

                var ellipseShape = _visual.Compositor.CreateSpriteShape(ellipse);
                ellipseShape.FillBrush = _visual.Compositor.CreateColorBrush((Windows.UI.Color)App.Current.Resources["MessageServiceBackgroundColor"]);
                ellipseShape.Offset    = new Vector2(15);

                var shape = _visual.Compositor.CreateShapeVisual();
                shape.Shapes.Add(ellipseShape);
                shape.Size = new Vector2(30, 30);

                _indicator = _visual.Compositor.CreateContainerVisual();
                _indicator.Children.InsertAtBottom(shape);
                _indicator.Children.InsertAtTop(sprite);
                _indicator.Size        = new Vector2(30, 30);
                _indicator.CenterPoint = new Vector3(15);
                _indicator.Scale       = new Vector3();

                _container.Children.InsertAtTop(_indicator);

                //ElementCompositionPreview.SetElementChildVisual(this, _indicator);
                //ElementCompositionPreview.SetElementChildVisual(this, _container);
            }

            var offset = (_tracker.Position.X > 0 && !_reply) || (_tracker.Position.X <= 0 && !_forward) ? 0 : Math.Max(0, Math.Min(72, Math.Abs(_tracker.Position.X)));

            var abs     = Math.Abs(offset);
            var percent = abs / 72f;

            var width  = (float)ActualWidth;
            var height = (float)ActualHeight;

            if (_indicator != null)
            {
                _indicator.Offset  = new Vector3(_tracker.Position.X > 0 ? width - percent * 60 : -30 + percent * 55, (height - 30) / 2, 0);
                _indicator.Scale   = new Vector3(_tracker.Position.X > 0 ? 0.8f + percent * 0.2f : -(0.8f + percent * 0.2f), 0.8f + percent * 0.2f, 1);
                _indicator.Opacity = percent;
            }
        }
Example #20
0
            // The root of the composition.
            ContainerVisual Root()
            {
                var result      = _root = _c.CreateContainerVisual();
                var propertySet = result.Properties;

                propertySet.InsertScalar("Progress", 0F);
                propertySet.InsertScalar("t0", 0F);
                // Layer aggregator
                result.Children.InsertAtTop(ShapeVisual_0());
                StartProgressBoundAnimation(propertySet, "t0", t0ScalarAnimation_0_to_1(), _rootProgress);
                return(result);
            }
        private void AddImageSpriteVisual(
            CompositionSurfaceBrush brush,
            Vector2 size,
            ContainerVisual parent)
        {
            var imageSpriteVisual = _compositor.CreateSpriteVisual();

            brush.Stretch           = CompositionStretch.UniformToFill;
            imageSpriteVisual.Brush = brush;
            imageSpriteVisual.Size  = size;
            parent.Children.InsertAtTop(imageSpriteVisual);
        }
        private bool IsTable(ContainerVisual visual)
        {
            foreach (Visual child in visual.Children)
            {
                if (child.GetType().Name == "RowVisual")
                {
                    return(true);
                }
            }

            return(false);
        }
Example #23
0
        public void StartEntranceEffect()
        {
            ContainerVisual container  = (ContainerVisual)ElementCompositionPreview.GetElementChildVisual(BasePage);
            Compositor      compositor = container.Compositor;

            // 设置缩放和动画
            const float               ScaleFactor = 20f;
            TimeSpan                  duration    = TimeSpan.FromMilliseconds(1200);
            LinearEasingFunction      linearEase  = compositor.CreateLinearEasingFunction();
            CubicBezierEasingFunction easeInOut   = compositor.CreateCubicBezierEasingFunction(new Vector2(.38f, 0f), new Vector2(.45f, 1f));

            // 创建淡出动画
            ScalarKeyFrameAnimation fadeOutAnimation = compositor.CreateScalarKeyFrameAnimation();

            fadeOutAnimation.InsertKeyFrame(1, 0);
            fadeOutAnimation.Duration = duration;

            // Grid的动画
            Vector2KeyFrameAnimation scaleUpGridAnimation = compositor.CreateVector2KeyFrameAnimation();

            scaleUpGridAnimation.InsertKeyFrame(0.1f, new Vector2(1 / ScaleFactor, 1 / ScaleFactor));
            scaleUpGridAnimation.InsertKeyFrame(1, new Vector2(1, 1));
            scaleUpGridAnimation.Duration = duration;

            // 初始屏动画
            Vector2KeyFrameAnimation scaleUpSplashAnimation = compositor.CreateVector2KeyFrameAnimation();

            scaleUpSplashAnimation.InsertKeyFrame(0, new Vector2(1, 1));
            scaleUpSplashAnimation.InsertKeyFrame(1, new Vector2(ScaleFactor, ScaleFactor));
            scaleUpSplashAnimation.Duration = duration;

            // 设置Grid的中心缩放视觉
            Visual gridVisual = ElementCompositionPreview.GetElementVisual(UIToShow);

            gridVisual.Size        = UIToShow.ActualSize;
            gridVisual.CenterPoint = new Vector3(gridVisual.Size.X, gridVisual.Size.Y, 0) * .5f;

            // 创建一个视觉组,当改组所有视觉执行完后不再显示
            CompositionScopedBatch batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            container.StartAnimation("Opacity", fadeOutAnimation);
            container.StartAnimation("Scale.XY", scaleUpSplashAnimation);
            gridVisual.StartAnimation("Scale.XY", scaleUpGridAnimation);

            batch.Completed += (s, a) =>
            {
                ElementCompositionPreview.SetElementChildVisual(BasePage, null);
                SurfaceLoader.Uninitialize();
                AnimationCompleted?.Invoke(this, null);
            };
            batch.End();
        }
Example #24
0
        /// <summary>
        /// Start animations and re-parent to destination UI Elmenent to finish the operations
        /// </summary>
        /// <param name="destinationElement">Destination UIElement where Visual should show up after page has loaded</param>
        /// <param name="containerVisual">ContainerVisual that contains Visual which needs to show in UIElement</param>
        /// <param name="newContainerVisual">ContainerVisual after visual is parented to UIElement</param>
        public static void InitiateContinuity(FrameworkElement destinationElement, ContainerVisual containerVisual, out ContainerVisual newContainerVisual)
        {
            if (null == containerVisual || null == destinationElement)
            {
                newContainerVisual = null;
                return;
            }
            //Get the frame of Window
            var        rootFrame  = AppShell.Current;
            Visual     rootVisual = ElementCompositionPreview.GetElementVisual(AppShell.Current);
            Compositor compositor = rootVisual.Compositor;
            //Create Temporary Container. this will be added to final UIElement
            ContainerVisual tempContainer = compositor.CreateContainerVisual();
            // Get Sprite Visual from incoming container
            var spriteHeroImage = containerVisual.Children.FirstOrDefault();

            //Create animation scoped batch to track animation completion and to complete re-parenting
            CompositionScopedBatch scopeBatch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            //Get coordinates of UIElement in reference to root so that it can be used for animations final value
            var coordinate = destinationElement.TransformToVisual(rootFrame);
            var position   = coordinate.TransformPoint(new Point(0, 0));

            //Create offset animation to make visual move on screen
            Vector3KeyFrameAnimation offsetAnimation = compositor.CreateVector3KeyFrameAnimation();

            offsetAnimation.InsertKeyFrame(1f, new System.Numerics.Vector3((float)position.X, (float)position.Y, 0));
            offsetAnimation.Duration = TimeSpan.FromMilliseconds(600);

            //Create size animation to change size of the visuals
            Vector2KeyFrameAnimation sizeAnimation = compositor.CreateVector2KeyFrameAnimation();

            sizeAnimation.InsertKeyFrame(1f, new System.Numerics.Vector2((float)destinationElement.ActualWidth, (float)destinationElement.ActualHeight));
            sizeAnimation.Duration = TimeSpan.FromMilliseconds(600);

            //Start Animations
            spriteHeroImage.StartAnimation("size", sizeAnimation);
            containerVisual.StartAnimation("offset", offsetAnimation);
            //Scoped batch completed event.
            scopeBatch.Completed += (o, e) =>
            {
                //Re-parent SpriteVisual to temp container and add temp container to UIElement as animations are finished.
                spriteHeroImage.Offset = new System.Numerics.Vector3(0, 0, 2000);
                containerVisual.Children.Remove(spriteHeroImage);
                tempContainer.Children.InsertAtTop(spriteHeroImage);
                ElementCompositionPreview.SetElementChildVisual(destinationElement, tempContainer);
                containerVisual = null;
            };
            newContainerVisual = tempContainer;

            scopeBatch.End();
        }
Example #25
0
        private void HideCustomSplashScreen()
        {
            ContainerVisual container  = (ContainerVisual)ElementCompositionPreview.GetElementChildVisual(this);
            Compositor      compositor = container.Compositor;

            // Setup some constants for scaling and animating
            const float               ScaleFactor = 20f;
            TimeSpan                  duration    = TimeSpan.FromMilliseconds(1200);
            LinearEasingFunction      linearEase  = compositor.CreateLinearEasingFunction();
            CubicBezierEasingFunction easeInOut   = compositor.CreateCubicBezierEasingFunction(new Vector2(.38f, 0f), new Vector2(.45f, 1f));

            // Create the fade animation which will target the opacity of the outgoing splash screen
            ScalarKeyFrameAnimation fadeOutAnimation = compositor.CreateScalarKeyFrameAnimation();

            fadeOutAnimation.InsertKeyFrame(1, 0);
            fadeOutAnimation.Duration = duration;

            // Create the scale up animation for the grid
            Vector2KeyFrameAnimation scaleUpGridAnimation = compositor.CreateVector2KeyFrameAnimation();

            scaleUpGridAnimation.InsertKeyFrame(0.1f, new Vector2(1 / ScaleFactor, 1 / ScaleFactor));
            scaleUpGridAnimation.InsertKeyFrame(1, new Vector2(1, 1));
            scaleUpGridAnimation.Duration = duration;

            // Create the scale up animation for the Splash screen visuals
            Vector2KeyFrameAnimation scaleUpSplashAnimation = compositor.CreateVector2KeyFrameAnimation();

            scaleUpSplashAnimation.InsertKeyFrame(0, new Vector2(1, 1));
            scaleUpSplashAnimation.InsertKeyFrame(1, new Vector2(ScaleFactor, ScaleFactor));
            scaleUpSplashAnimation.Duration = duration;

            // Configure the grid visual to scale from the center
            Visual gridVisual = ElementCompositionPreview.GetElementVisual(MainFrame);

            gridVisual.Size        = new Vector2((float)MainFrame.ActualWidth, (float)MainFrame.ActualHeight);
            gridVisual.CenterPoint = new Vector3(gridVisual.Size.X, gridVisual.Size.Y, 0) * .5f;


            //
            // Create a scoped batch for the animations.  When the batch completes, we can dispose of the
            // splash screen visuals which will no longer be visible.
            //

            CompositionScopedBatch batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            container.StartAnimation("Opacity", fadeOutAnimation);
            container.StartAnimation("Scale.XY", scaleUpSplashAnimation);
            gridVisual.StartAnimation("Scale.XY", scaleUpGridAnimation);

            batch.Completed += Batch_Completed;
            batch.End();
        }
Example #26
0
 public DryingDrawingVisual([NotNull] ContainerVisual containerVisual, [NotNull] List <DrawingVisual> dryingDrawingVisualList)
 {
     if (containerVisual == null)
     {
         throw new ArgumentNullException("containerVisual");
     }
     if (dryingDrawingVisualList == null)
     {
         throw new ArgumentNullException("dryingDrawingVisualList");
     }
     ContainerVisual         = containerVisual;
     DryingDrawingVisualList = dryingDrawingVisualList;
 }
Example #27
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            hostElement              = GetTemplateChild("DrawHolder") as Rectangle;
            hostElement.SizeChanged += ElementCompositionVisual_SizeChanged;
            rootVisual            = Window.Current.Compositor.CreateContainerVisual();
            swapChainVisual       = Window.Current.Compositor.CreateSpriteVisual();
            swapChainVisual.Brush = Window.Current.Compositor.CreateColorBrush(Colors.Pink);
            rootVisual.Children.InsertAtTop(swapChainVisual);
            ElementCompositionPreview.SetElementChildVisual(hostElement, rootVisual);

            foregroundColor = ((SolidColorBrush)Foreground).Color;
        }
Example #28
0
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            Messenger.Default.Send(new ChildPageLoadedMessage());
            _compositor = new Compositor();
            var root = ElementCompositionPreview.GetElementVisual(MainGrid);

            _compositor = root.Compositor;

            _mainContainer = _compositor.CreateContainerVisual();
            ElementCompositionPreview.SetElementChildVisual(MainGrid, _mainContainer);

            // CreateSprite(Color.FromArgb(0x50, 0x00, 0x20, 0x90));
        }
Example #29
0
        public static string FromElement(ContainerVisual element)
        {
            var brush = ((SpriteVisual)((SpriteVisual)element.Children.First()).Children.First()).Brush as CompositionColorBrush;
            var dict  = new Dictionary <Color, string> {
                { Color.FromArgb(0xFF, 100, 150, 200), "cello" },
                { Color.FromArgb(0xFF, 130, 150, 200), "flute" },
                { Color.FromArgb(0xFF, 160, 150, 200), "guitar" },
                { Color.FromArgb(0xFF, 190, 150, 200), "oboe" },
                { Color.FromArgb(0xFF, 220, 150, 200), "violin" },
            };

            return(dict[brush.Color]);
        }
 public VisualDocumentPaginator(DocumentPaginator paginator, Size pageSize, Size margin)
 {
     m_PageSize             = pageSize;
     m_Margin               = margin;
     m_Paginator            = paginator;
     m_ContentSize          = new Size(pageSize.Width - 2 * margin.Width, pageSize.Height - 2 * margin.Height);
     m_PageCount            = (int)Ceiling(m_Paginator.PageSize.Height / m_ContentSize.Height);
     m_Paginator.PageSize   = m_ContentSize;
     m_PageContent          = new ContainerVisual();
     m_SmallerPage          = new ContainerVisual();
     m_NewPage              = new ContainerVisual();
     m_SmallerPageContainer = new ContainerVisual();
 }
Example #31
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            Size result = base.ArrangeOverride(finalSize);

            ContainerVisual _container = GetVisualChild(0) as ContainerVisual;

            foreach (Visual child in _container.Children)
            {
                ((UIElement)child).Arrange(new Rect(new Point(), result));
            }

            return(result);
        }
        /// <summary>
        /// Prepares the <see cref="ContainerVisual"/> used for the visualization of the ticks by setting its Size, Color and Offset.
        /// </summary>
        /// <param name="containerVisual">The <see cref="ContainerVisual"/> that is used by the Composition API.</param>
        /// <param name="layoutSlot"> A Rectangle in the Euclidean plane geometry used for the Size and Offset of the <see cref="ContainerVisual"/>.</param>
        protected internal virtual ContainerVisual PrepareTickVisual(ContainerVisual containerVisual, RadRect layoutSlot)
        {
            if (containerVisual.Size.X != layoutSlot.Width || containerVisual.Size.Y != layoutSlot.Height)
            {
                containerVisual.Size = new Vector2((float)layoutSlot.Width, (float)layoutSlot.Height);
            }

            this.ChangeBrushesAccordingToAppTheme();
            this.SetCompositionColorBrush(containerVisual, this.telerikChartAxisBorderBrush);
            containerVisual.Offset = new Vector3((float)layoutSlot.Location.X, (float)layoutSlot.Location.Y, 0);

            return(containerVisual);
        }
        /// <summary>
        /// Prepares the <see cref="ContainerVisual"/> used for the visualization of the <see cref="BarIndicatorBase"/> by setting its Size, Color and Offset.
        /// </summary>
        /// <param name="containerVisual">The <see cref="ContainerVisual"/> that is used by the <see cref="Compositor"/> API.</param>
        /// <param name="dataPoint"> The <see cref="DataPoint"/> used for the calculation of the Size and Offset of the <see cref="ContainerVisual"/>.</param>
        protected internal virtual ContainerVisual PrepareBarIndicatorVisual(ContainerVisual containerVisual, DataPoint dataPoint)
        {
            containerVisual.Offset = new Vector3((float)dataPoint.LayoutSlot.Location.X, (float)dataPoint.LayoutSlot.Location.Y, 0);

            if (containerVisual.Size.X != dataPoint.LayoutSlot.Width || containerVisual.Size.Y != dataPoint.LayoutSlot.Height)
            {
                containerVisual.Size = new System.Numerics.Vector2((float)dataPoint.LayoutSlot.Width, (float)dataPoint.LayoutSlot.Height);
            }

            this.SetCompositionColorBrush(containerVisual, this.telerikChartStrokeBrush);

            return(containerVisual);
        }
Example #34
0
 private void CreateImageFactory(UIElement element)
 {
     if (visual == null)
     {
         visual = GetVisual(element);
     }
     compositor = GetCompositor(visual);
     //visual.Clip = compositor.CreateInsetClip(0, 0, 0, 0);
     if (imageFactory == null)
     {
         imageFactory = CreateCompositionImageFactory(compositor);                        //<=== this causes a hige growth in memory footprint
     }
 }
        /// <summary>
        /// Start animations and re-parent to destination UI Elmenent to finish the operations
        /// </summary>
        /// <param name="destinationElement">Destination UIElement where Visual should show up after page has loaded</param>
        /// <param name="containerVisual">ContainerVisual that contains Visual which needs to show in UIElement</param>
        /// <param name="newContainerVisual">ContainerVisual after visual is parented to UIElement</param>
        public static void InitiateContinuity(FrameworkElement destinationElement, ContainerVisual containerVisual, out ContainerVisual newContainerVisual)
        {
            if (null == containerVisual || null == destinationElement)
            {
                newContainerVisual = null;
                return;
            }
            //Get the frame of Window
            Frame rootFrame = Window.Current.Content as Frame;
            Visual rootVisual = ElementCompositionPreview.GetElementVisual(rootFrame);
            Compositor compositor = rootVisual.Compositor;
            //Create Temporary Container. this will be added to final UIElement 
            ContainerVisual _TempContainer = compositor.CreateContainerVisual();
            // Get Sprite Visual from incoming container
            var spriteHeroImage = containerVisual.Children.FirstOrDefault();

            //Create animation scoped batch to track animation completion and to complete re-parenting
            CompositionScopedBatch scopeBatch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            //Get coordinates of UIElement in reference to root so that it can be used for animations final value
            var coordinate = destinationElement.TransformToVisual(rootFrame);
            var position = coordinate.TransformPoint(new Point(0, 0));
            
            //Create offset animation to make visual move on screen
            Vector3KeyFrameAnimation offsetAnimation = compositor.CreateVector3KeyFrameAnimation();
            offsetAnimation.InsertKeyFrame(1f, new System.Numerics.Vector3((float)position.X, (float)position.Y, 0));
            offsetAnimation.Duration = TimeSpan.FromMilliseconds(600);

            //Create size animation to change size of the visuals 
            Vector2KeyFrameAnimation sizeAnimation = compositor.CreateVector2KeyFrameAnimation();
            sizeAnimation.InsertKeyFrame(1f, new System.Numerics.Vector2((float)destinationElement.ActualWidth, (float)destinationElement.ActualHeight));
            sizeAnimation.Duration = TimeSpan.FromMilliseconds(600);

            //Start Animations 
            spriteHeroImage.StartAnimation("size", sizeAnimation);
            containerVisual.StartAnimation("offset", offsetAnimation);
            //Scoped batch completed event. 
            scopeBatch.Completed += (o, e) =>
            {
                //Re-parent SpriteVisual to temp container and add temp container to UIElement as animations are finished.
                spriteHeroImage.Offset = new System.Numerics.Vector3(0, 0, 0);
                containerVisual.Children.Remove(spriteHeroImage);
                _TempContainer.Children.InsertAtTop(spriteHeroImage);
                ElementCompositionPreview.SetElementChildVisual(destinationElement, _TempContainer);
                containerVisual = null;

            };
            newContainerVisual = _TempContainer;

            scopeBatch.End();
        }
Example #36
0
        /// <inheritdoc/>
        protected override async void OnApplyTemplate()
        {
            var strategy = Strategy;

            var rootElement = _rootElement;

            if (rootElement != null)
            {
                rootElement.SizeChanged -= RootElement_SizeChanged;
            }

            // Gets the XAML root element
            rootElement = GetTemplateChild("RootElement") as FrameworkElement;

            _rootElement = rootElement;

            if (rootElement != null)
            {
                rootElement.SizeChanged += RootElement_SizeChanged;

                if (strategy == UIStrategy.Composition)
                {
                    // Get the Visual of the root element
                    Visual rootVisual = ElementCompositionPreview.GetElementVisual(rootElement);

                    if (rootVisual != null)
                    {
                        // We create a ContainerVisual to insert SpriteVisual with a brush
                        var container = rootVisual.Compositor.CreateContainerVisual();

                        // the containerVisual is now a child of rootVisual
                        ElementCompositionPreview.SetElementChildVisual(rootElement, container);

                        _containerVisual = container;
                        _rootVisual      = rootVisual;

                        await CreateModuloExpression();
                    }
                }
                else
                {
                    _containerElement   = rootElement.FindName("ContainerElement") as Canvas;
                    _containerTranslate = new TranslateTransform();
                    _containerElement.RenderTransform = _containerTranslate;
                }

                await LoadImageBrush(ImageSource);
            }

            base.OnApplyTemplate();
        }
Example #37
0
        public void Create()
        {
            var uri    = new Uri("pack://application:,,,/ypi_client_order.xps");
            var stream = System.Windows.Application.GetResourceStream(uri).Stream;

            System.IO.Packaging.Package package1 = System.IO.Packaging.Package.Open(stream);
            System.IO.Packaging.PackageStore.AddPackage(uri, package1);
            var xpsDoc = new XpsDocument(package1, System.IO.Packaging.CompressionOption.Maximum, uri.AbsoluteUri);
            var fixedDocumentSequenceO = xpsDoc.GetFixedDocumentSequence();

            MemoryStream xpsStream       = new MemoryStream();
            Package      package2        = Package.Open(xpsStream, FileMode.Create);
            string       memoryStreamUri = "memorystream://printstream";
            Uri          packageUri      = new Uri(memoryStreamUri);

            PackageStore.AddPackage(packageUri, package2);
            XpsDocument       doc    = new XpsDocument(package2, CompressionOption.Fast, memoryStreamUri);
            XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);

            System.Windows.Documents.Serialization.SerializerWriterCollator vxpsd = writer.CreateVisualsCollator();
            int pageno = 1;

            foreach (System.Windows.Documents.DocumentReference r in fixedDocumentSequenceO.References)
            {
                System.Windows.Documents.FixedDocument d = r.GetDocument(false);
                foreach (System.Windows.Documents.PageContent pc in d.Pages)
                {
                    System.Windows.Documents.FixedPage fixedPage = pc.GetPageRoot(false);
                    double width           = fixedPage.Width;
                    double height          = fixedPage.Height;
                    System.Windows.Size sz = new System.Windows.Size(width, height);
                    fixedPage.Measure(sz);
                    fixedPage.Arrange(new System.Windows.Rect(new System.Windows.Point(), sz));
                    fixedPage.UpdateLayout();
                    ContainerVisual newpage = new ContainerVisual();
                    newpage.Children.Add(fixedPage);
                    newpage.Children.Add(CreateWatermark(400, 400, "hello world"));
                    pageno++;
                    vxpsd.Write(newpage);

                    //PackageStore.RemovePackage(packageUri);
                    //doc.Close();
                }
            }

            doc.Close();
            xpsStream.Position = 0;
            Package     finalPackage          = Package.Open(xpsStream, FileMode.Open);
            XpsDocument finalDoc              = new XpsDocument(finalPackage, CompressionOption.Fast, memoryStreamUri);
            var         fixedDocumentSequence = xpsDoc.GetFixedDocumentSequence();
        }
        public override DocumentPage GetPage(int pageNumber)
        {
            _pageNumber = pageNumber + 1;
            DocumentPage    page          = _paginator.GetPage(pageNumber);
            ContainerVisual printedPage   = new ContainerVisual();
            ContainerVisual pageContainer = new ContainerVisual();

            pageContainer.Children.Add(page.Visual);
            pageContainer.Transform = new TranslateTransform(_margin.Left, _margin.Top);
            printedPage.Children.Add(pageContainer);
            AddHeader(printedPage);
            AddFooter(printedPage);
            return(new DocumentPage(printedPage, _pageSize, _pageBox, _contentBox));
        }
Example #39
0
            // The root of the composition.
            ContainerVisual Root()
            {
                if (_root != null)
                {
                    return(_root);
                }
                var result      = _root = _c.CreateContainerVisual();
                var propertySet = result.Properties;

                propertySet.InsertScalar("Progress", 0F);
                // Shape tree root for layer: Shape
                result.Children.InsertAtTop(ShapeVisual_0());
                return(result);
            }
        /// <inheritdoc />
        public override DocumentPage GetPage(int pageNumber)
        {
            // Get the requested page.
            var page = _flowDocumentPaginator.GetPage(pageNumber);

            // Wrap the page in a Visual. You can then add a transformation and extras.
            var newVisual = new ContainerVisual();

            newVisual.Children.Add(page.Visual);
            newVisual.Children.Add(CreateHeader(pageNumber)); // Add the title to the visual.
            var newPage = new DocumentPage(newVisual);        // Wrap the visual in a new page.

            return(newPage);
        }
Example #41
0
 public void MapSight(Sight sight, ContainerVisual containerVisual, Rectangle rectImage)
 {
     if (_map.ContainsKey(sight))
     {
         _map[sight].ImageContainerVisual = containerVisual;
         _map[sight].RectImage            = rectImage;
     }
     else
     {
         _map.Add(sight, new SightVisual {
             ImageContainerVisual = containerVisual, RectImage = rectImage
         });
     }
 }
 private void Test_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     if (AllowBoidPlacement)
     {
         Point            p       = e.GetPosition(BoidViewBox);
         SpeciesViewModel species = (SpeciesViewModel)availableSpecies.SelectedItem;
         ContainerVisual  child   = VisualTreeHelper.GetChild(BoidViewBox, 0) as ContainerVisual;
         ScaleTransform   scale   = child.Transform as ScaleTransform;
         species.CreateBoidOnCoords(p.X / scale.ScaleX, p.Y / scale.ScaleY);
     }
     else
     {
     }
 }
Example #43
0
        // Intended for transient visual objects (such as the selection-rectangle)
        public void PutTransientVisual(string Key, ContainerVisual Graphic)
        {
            var Index = this.OwnerView.ViewChildren.IndexOfMatch(child => child.Key.IsEqual(Key));

            if (Index >= 0)
            {
                this.OwnerView.ViewChildren[Index] = ViewChild.Create(Key, Graphic);
            }
            else
            {
                this.OwnerView.ViewChildren.Add(ViewChild.Create(Key, Graphic));
                this.TransientObjectsCount++;
            }
        }
 public void CreateVisuals(Compositor compositor)
 {
     layerVisual         = compositor.CreateLayerVisual();
     itemContainerVisual = compositor.CreateContainerVisual();
     layerVisual.Children.InsertAtTop(itemContainerVisual);
     for (int i = 0; i < items.Count; ++i)
     {
         var item       = items[i];
         var itemVisual = item.CreateVisual(compositor);
         itemVisual.Size   = new Vector2(300, 200);
         itemVisual.Offset = new Vector3((i % 2 - 1) * itemVisual.Size.X, (i / 2 - 1) * itemVisual.Size.Y, 0);
         itemContainerVisual.Children.InsertAtTop(itemVisual);
     }
 }
Example #45
0
 public MainPage()
 {
     this.InitializeComponent();
     
     //Get the root Frame of Window. 
     Frame rootFrame = Window.Current.Content as Frame;
     _root = ElementCompositionPreview.GetElementVisual(rootFrame) as ContainerVisual;
     
     //Get compositor 
     _compositor = _root.Compositor;
     
     //Set up Sample Data to load the list.
     StoreData sampleData = new StoreData();
     _sampleCollection = sampleData.Collection;
 }
        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();
        }
Example #47
0
        private void InitializeComposition()
        {
            // setup compositor and root visual
            this.compositor = new Compositor();
            this.rootVisual = this.compositor.CreateContainerVisual();

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

            // add a solid color background
            this.background = this.compositor.CreateSolidColorVisual();
            this.background.Color = Colors.LightGreen;
            this.rootVisual.Children.InsertAtBottom(this.background);

            UpdateSize();
        }
        /// <summary>
        /// Creates an instance of the ColorBloomTransitionHelper. 
        /// Any visuals to be later created and animated will be hosted within the specified UIElement.
        /// </summary>
        public ColorBloomTransitionHelper(UIElement hostForVisual)
        {
            this.hostForVisual = hostForVisual;

            // we have an element in the XAML tree that will host our Visuals
            var visual = ElementCompositionPreview.GetElementVisual(hostForVisual);
            _compositor = visual.Compositor;

            // create a container
            // adding children to this container adds them to the live visual tree
            _containerForVisuals = _compositor.CreateContainerVisual();
            ElementCompositionPreview.SetElementChildVisual(hostForVisual, _containerForVisuals);

            // initialize the ImageLoader and create the circle mask
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
            _circleMaskSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/TransitionAnimation-ColorBloom/CircleOpacityMask.png"));
        }
        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);
        }
        /// <summary>
        /// Creates an instance of the ColorBloomTransitionHelper. 
        /// Any visuals to be later created and animated will be hosted within the specified UIElement.
        /// </summary>
        public ColorBloomTransitionHelper(UIElement hostForVisual)
        {
            this.hostForVisual = hostForVisual;

            // we have an element in the XAML tree that will host our Visuals
            var visual = ElementCompositionPreview.GetElementVisual(hostForVisual);
            _compositor = visual.Compositor;

            // create a container
            // adding children to this container adds them to the live visual tree
            _containerForVisuals = _compositor.CreateContainerVisual();
            ElementCompositionPreview.SetElementChildVisual(hostForVisual, _containerForVisuals);

            // initialize the ImageLoader and create the circle mask
            _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
            _circleMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White);
        }
Example #51
0
        private void ShowVisual_Click(object sender, RoutedEventArgs e)
        {
            // Initialize the Compositor
            _compositor = new Compositor();
            _root = (ContainerVisual)ElementCompositionPreview.GetContainerVisual(root);
            _compositor = _root.Compositor;

            // Generate the Green Square
            var colorVisual = _compositor.CreateSolidColorVisual();
            colorVisual.Color = Colors.Green;
            colorVisual.Size = new Vector2(150.0f, 150.0f);
            colorVisual.Offset = new Vector3(50.0f, 50.0f, 0.0f);

            // Add the image to the tree
            _root.Children.InsertAtTop(colorVisual);

            _target = colorVisual;
        }
Example #52
0
        public void SetupVisual()
        {
            // Intialize the Compositor
            _compositor = new Compositor();
            _root = (ContainerVisual)ElementCompositionPreview.GetContainerVisual(Container);
            _compositor = _root.Compositor;

            // Generate the Green Square
            var colorVisual = _compositor.CreateSolidColorVisual();
            colorVisual.Color = Colors.Green;
            colorVisual.Size = new System.Numerics.Vector2(50.0f, 50.0f);
            colorVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f);

            // Add the Visual to the tree
            _root.Children.InsertAtTop(colorVisual);

            _target = colorVisual;
        }
        /// <summary>
        /// Creates an instance of the ColorSlideTransitionHelper. 
        /// Any visuals to be later created and animated will be hosted within the specified UIElement.
        /// </summary>
        public ColorSlideTransitionHelper(UIElement hostForVisual)
        {


            this.hostForVisual = hostForVisual;

            // we have an element in the XAML tree that will host our Visuals
            var visual = ElementCompositionPreview.GetElementVisual(hostForVisual);
            _compositor = visual.Compositor;

            // create a container
            // adding children to this container adds them to the live visual tree
            _containerForVisuals = _compositor.CreateContainerVisual();

            InitializeSlideAnimation();


            ElementCompositionPreview.SetElementChildVisual(hostForVisual, _containerForVisuals);
        }
        async 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;

            // load the background image
            var image = _compositor.DefaultGraphicsDevice.CreateImageFromUri(new Uri("ms-appx:///Assets/White.png"));
            await image.CompleteLoadAsync();

            // todo: not sure why GaussianBlurEffect doesn't work??
            // Got a feeling it might have something to do with the Source setting, 
            // maybe it's just not supported yet?
            var effectDefination = new SaturationEffect // new GaussianBlurEffect
            {
                //BorderMode = EffectBorderMode.Soft,
                //BlurAmount = 5f,
                //Optimization = EffectOptimization.Quality,
                Source = new CompositionEffectSourceParameter("Overlay")
            };

            // create the actual effect
            var effectFactory = _compositor.CreateEffectFactory(effectDefination);
            var effect = effectFactory.CreateEffect();
            effect.SetSourceParameter("Overlay", image);

            // create the effect visual
            _effectVisual = _compositor.CreateEffectVisual();
            _effectVisual.Effect = effect;
            _effectVisual.Opacity = 0.8f;
            _effectVisual.Size = new Vector2((float)this.ImagePanel.ActualWidth, (float)this.ImagePanel.ActualHeight);

            // place the effect visual onto the UI
            imagePanelVisual.Children.InsertAtTop(_effectVisual);
        }
        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;
        }
Example #56
0
        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();
        }
 private void AddImageSpriteVisual(
     CompositionSurfaceBrush brush,
     Vector2 size,
     ContainerVisual parent)
 {
     var imageSpriteVisual = _compositor.CreateSpriteVisual();
     brush.Stretch = CompositionStretch.UniformToFill;
     imageSpriteVisual.Brush = brush;
     imageSpriteVisual.Size = size;
     parent.Children.InsertAtTop(imageSpriteVisual);
 }
 private void AddColorSpriteVisual(
     Color color,
     Vector2 size,
     ContainerVisual parent)
 {
     var colorSpriteVisual = _compositor.CreateSpriteVisual();
     colorSpriteVisual.Brush = _compositor.CreateColorBrush(color);
     colorSpriteVisual.Size = size;
     parent.Children.InsertAtTop(colorSpriteVisual);
 }
        private ContainerVisual AddLayerVisual(
            CompositionEffectBrush effectBrush,
            Vector2 size,
            Vector3 offset,
            ContainerVisual parent)
        {
            var layerVisual = _compositor.CreateLayerVisual();
            layerVisual.Effect = effectBrush;
            layerVisual.Size = size;
            layerVisual.Offset = offset;
            parent.Children.InsertAtTop(layerVisual);

            return layerVisual;
        }
Example #60
0
        public void CreateUnstackTransition(ContainerVisual targetVisual)
        {
            Debug.Assert((_stackedTiles != null) && (_stackedTiles.Count > 0));
            
            for (int i = 0; i < _stackedTiles.Count; i++)
            {
                Vector3 offset = _stackedTiles[i].Frame.Offset - _stackVisual.Offset;
                Vector3 direction = offset / offset.Length();
                Vector3 delta = direction * Math.Max(_windowWidth, _windowHeight);

                _stackFlyOutAnimation.SetVector3Parameter("delta", delta);
                _stackFlyOutAnimation.SetVector3Parameter("originalOffset", _stackedTiles[i].Offset);
                _stackFlyOutAnimation.DelayTime = TimeSpan.FromMilliseconds(1500 + (_stackedTiles.Count - i) * 100);

                _stackedTiles[i].Frame.StartAnimation("Offset", _stackFlyOutAnimation);
            }

            _stackedTiles.Clear();
            _stackedTiles = null;
        }