当前位置: 首页>>代码示例>>C#>>正文


C# Size.ToVector2方法代码示例

本文整理汇总了C#中Windows.Foundation.Size.ToVector2方法的典型用法代码示例。如果您正苦于以下问题:C# Size.ToVector2方法的具体用法?C# Size.ToVector2怎么用?C# Size.ToVector2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.Foundation.Size的用法示例。


在下文中一共展示了Size.ToVector2方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Draw

        //int count;
        public void Draw(CanvasDrawingSession ds, Size sizeRender, float totalTimeSeconds)
        {
            //count++;
            //ds.DrawText(count.ToString(), new Vector2(10.0f, 10.0f), Colors.Red);
            SetupText(ds);
            ConfigureEffect(totalTimeSeconds);

            ds.DrawImage(composite, sizeRender.ToVector2() / 2);
        }
开发者ID:clarkezone,项目名称:BUILD2015-Talk-2-672,代码行数:10,代码来源:BurningTextExample.xaml.cs

示例2: Draw

        void Draw(CanvasDrawingSession drawingSession, string text, Size size)
        {
            // Background gradient.
            using (var brush = CanvasRadialGradientBrush.CreateRainbow(drawingSession, 0))
            {
                brush.Center = size.ToVector2() / 2;

                brush.RadiusX = (float)size.Width;
                brush.RadiusY = (float)size.Height;

                drawingSession.FillRectangle(0, 0, (float)size.Width, (float)size.Height, brush);
            }

            // Text label.
            var label = string.Format("{0}\n{1:0} x {2:0}", text, size.Width, size.Height);

            drawingSession.DrawText(label, size.ToVector2() / 2, Colors.Black, textLabelFormat);
        }
开发者ID:fengweijp,项目名称:Win2D,代码行数:18,代码来源:ControlTransforms.xaml.cs

示例3: CreateSurfaceImagesAsync

        /// <summary>
        /// Creates the SurfaceImages based on the ItemsSource
        /// </summary>
        /// <returns>Task</returns>
        private async Task CreateSurfaceImagesAsync()
        {
            if (_surfaceImagesCreated)
                return;

            var padding = Padding;
            // Clear previous visuals
            _surfaceVisuals.Clear();
            _fluidItems.Clear();
            _bgLayer.Children.RemoveAll();
            _topLayer.Children.RemoveAll();
            _selectedVisual = null;
            // Dispose the surface images
            for (var i = 0; i < _surfaceImages.Count; i++)
            {
                var surfaceImage = _surfaceImages.ElementAt(i);
                surfaceImage.Dispose();
            }
            _surfaceImages.Clear();

            if ((ItemsSource == null) || !ItemsSource.Any())
                return;

            var options = ImageSurfaceOptions.Default;
            options.SurfaceBackgroundColor = Colors.Transparent;

            var availableSize = new Size(_availableWidth, _availableHeight);
            for (var i = 0; i < ItemsSource.Count(); i++)
            {
                // Create the surface image
                var surfaceImage = await _generator.CreateImageSurfaceAsync(ItemsSource.ElementAt(i), availableSize, options);
                _surfaceImages.Add(surfaceImage);

                // Add a visual for the background
                var containerVisual = _compositor.CreateSpriteVisual();
                containerVisual.Size = availableSize.ToVector2();
                containerVisual.Brush = _compositor.CreateColorBrush(ItemBackground);
                containerVisual.Offset = new Vector3((float)padding.Left, (float)padding.Top, 0);

                // Create the visual for the content
                var contentVisual = _compositor.CreateSpriteVisual();
                contentVisual.Size = availableSize.ToVector2();
                var surfaceBrush = _compositor.CreateSurfaceBrush(surfaceImage.Surface);
                surfaceBrush.UpdateSurfaceBrushOptions(Stretch, AlignX, AlignY);
                contentVisual.Brush = surfaceBrush;

                // Calculate the Inset Clip
                var left = i * (_itemWidth + ItemGap.Single());
                var right = _availableWidth - (left + _itemWidth);
                containerVisual.Properties.InsertScalar("LeftInset", left);
                containerVisual.Properties.InsertScalar("RightInset", right);
                containerVisual.Clip = _compositor.CreateInsetClip(left, 0, right, 0);

                // Center Point
                containerVisual.CenterPoint = new Vector3(left + (_itemWidth / 2f), (float)padding.Top + (_itemHeight / 2f), 0);
                contentVisual.CenterPoint = containerVisual.CenterPoint;
                containerVisual.ImplicitAnimations = _implicitAnimationCollection;
                contentVisual.ImplicitAnimations = _implicitAnimationCollection;

                // Set the container content
                containerVisual.Children.InsertAtTop(contentVisual);

                // Add to Background Layer
                _bgLayer.Children.InsertAtTop(containerVisual);

                // Add Visual to the fluid items
                _fluidItems[containerVisual] = new Rect(padding.Left + left, padding.Top, _itemWidth, _itemHeight);
                _surfaceVisuals[surfaceImage] = containerVisual;
            }
        }
开发者ID:RareNCool,项目名称:CompositionProToolkit,代码行数:74,代码来源:FluidBanner.cs

示例4: ArrangeOverride

        /// <summary>
        /// Handles the Arrange pass during Layout
        /// </summary>
        /// <param name="finalSize">Final Size of the control</param>
        /// <returns>Total size occupied by all the Children</returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            if ((ItemsSource == null) || !ItemsSource.Any())
                return finalSize;

            // Resize the rootContainer
            _rootContainer.Size = finalSize.ToVector2();

            var padding = Padding;

            var paddingSize = padding.CollapseThickness();
            var width = finalSize.Width;
            var height = finalSize.Height;
            _itemCount = ItemsSource.Count();

            _availableWidth = (width - paddingSize.Width).Single();
            _availableHeight = (height - paddingSize.Height).Single();
            var gapCount = _itemCount - 1;
            var totalGap = (gapCount * ItemGap).Single();
            var availableNonGapWidth = _availableWidth - totalGap;
            var availableNonGapHeight = _availableHeight;

            _itemWidth = availableNonGapWidth / _itemCount;
            _itemHeight = availableNonGapHeight;
            _bannerBounds = new Rect(padding.Left, padding.Top, _availableWidth, _availableHeight);

            // Update Visual sizes and surfaceImages
            var availableSize = new Vector2(_availableWidth, _availableHeight);
            _rootContainer.Size = availableSize;
            _bgLayer.Size = availableSize;
            _bgLayer.CenterPoint = new Vector3(_bgLayer.Size * 0.5f, 0);
            _topLayer.Size = availableSize;

            // Check if any visual is currently selected. If yes then obtain its index.
            // The new visual at that index should be selected and added to the toplayer
            var selectedVisualIndex = -1;
            if (_selectedVisual != null)
            {
                foreach (var item in _fluidItems)
                {
                    selectedVisualIndex++;
                    if (ReferenceEquals(item.Key, _selectedVisual))
                        break;
                }
            }

            for (var index = 0; index < _surfaceImages.Count; index++)
            {
                // Get the surfaceImage
                var surfaceImage = _surfaceImages.ElementAt(index);

                // Get the visual corresponding to this surfaceImage
                var itemVisual = _surfaceVisuals[surfaceImage];

                if (itemVisual == null)
                    continue;

                itemVisual.Size = availableSize;
                itemVisual.CenterPoint = new Vector3(itemVisual.Size * 0.5f, 0);
                var contentVisual = itemVisual.Children.ElementAt(0) as SpriteVisual;
                if (contentVisual == null)
                    continue;

                contentVisual.Size = availableSize;
                contentVisual.CenterPoint = itemVisual.CenterPoint;
                (contentVisual.Brush as CompositionSurfaceBrush)?.UpdateSurfaceBrushOptions(Stretch, AlignX, AlignY);

                // Calculate the Inset Clip
                var left = index * (_itemWidth + ItemGap.Single());
                var right = _availableWidth - (left + _itemWidth);
                itemVisual.Properties.InsertScalar("LeftInset", left);
                itemVisual.Properties.InsertScalar("RightInset", right);
                itemVisual.Clip = (index == selectedVisualIndex)
                    ? _compositor.CreateInsetClip(0, 0, 0, 0)
                    : _compositor.CreateInsetClip(left, 0, right, 0);

                // Center Point
                itemVisual.CenterPoint = new Vector3(left + (_itemWidth / 2f), (float)padding.Top + (_itemHeight / 2f), 0);
                contentVisual.CenterPoint = itemVisual.CenterPoint;

                // Update Fluid Items
                _fluidItems[itemVisual] = new Rect(padding.Left + left, padding.Top, _itemWidth, _itemHeight);
            }

            // Update Animations' keyframes
            _expandRightInset.InsertKeyFrame(1f, _availableWidth - _itemWidth);
            _collapseInsetClip.InsertKeyFrame(1f, _availableWidth - _itemWidth);

            return finalSize;
        }
开发者ID:RareNCool,项目名称:CompositionProToolkit,代码行数:95,代码来源:FluidBanner.cs

示例5: CalculateGameToScreenTransform

            private Matrix3x2 CalculateGameToScreenTransform(Size screenSize)
            {
                var scaleToScreen = Matrix3x2.CreateScale(screenSize.ToVector2());

                var scaleVerticalRegion = Matrix3x2.CreateScale(1, verticalRegion);
                var offsetVerticalRegion = Matrix3x2.CreateTranslation(0, 0.5f - (verticalRegion / 2.0f));

                var transform = scaleVerticalRegion * offsetVerticalRegion * scaleToScreen;
                return transform;
            }
开发者ID:fengweijp,项目名称:Win2D,代码行数:10,代码来源:KeyboardInputExample.xaml.cs

示例6: Update

            public void Update(Size controlSize)
            {
                // Move the ball.
                Position += Velocity;

                // Bounce if we hit the edge.
                Vector2 topLeft = new Vector2(Radius);
                Vector2 bottomRight = controlSize.ToVector2() - new Vector2(Radius);

                float bounceX = (Position.X < topLeft.X || Position.X > bottomRight.X) ? -1 : 1;
                float bounceY = (Position.Y < topLeft.Y || Position.Y > bottomRight.Y) ? -1 : 1;

                Velocity *= new Vector2(bounceX, bounceY);

                Position = Vector2.Clamp(Position, topLeft, bottomRight);

                // Gradually fade in and out.
                FadeAge += FadeSpeed;
            }
开发者ID:jiatingxiu,项目名称:Win2D,代码行数:19,代码来源:LayersExample.xaml.cs

示例7: UpdateVisualPosition

        void UpdateVisualPosition(Visual visual, Size size)
        {
            var oldOffset = visual.Offset;
            var newOffset = new Vector3(
                (float)(rnd.NextDouble() * (window.Bounds.Width - size.Width)),
                (float)(rnd.NextDouble() * (window.Bounds.Height - size.Height)),
                0);

            visual.Offset = newOffset;
            visual.Size = size.ToVector2();

            AnimateOffset(visual, oldOffset, newOffset);
        }
开发者ID:fengweijp,项目名称:Win2D,代码行数:13,代码来源:App.cs


注:本文中的Windows.Foundation.Size.ToVector2方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。