Пример #1
0
        /// <summary>
        /// Helper for slider value changes; updates ninegrid visual to correct x/y size with animation.
        /// </summary>
        private void AnimateXYSliderChangeHelper(ValueTimer <float> sender, string direction)
        {
            // For animated case, animate from the current to the released values using a keyframe animation
            if (IsAnimatedInterpolation)
            {
                var percentSliderValue = (float)sender.Value / 100.0f;

                float defaultSizeValue;
                switch (direction)
                {
                case "x":
                    defaultSizeValue = _defaultSize.X;
                    break;

                case "y":
                    defaultSizeValue = _defaultSize.Y;
                    break;

                default:
                    throw new ArgumentException("Parameter must be 'x' or 'y'", direction);
                }

                // Define keyframe animation
                var animation = _compositor.CreateScalarKeyFrameAnimation();
                animation.InsertExpressionKeyFrame(1, direction + " * p");
                animation.SetScalarParameter(direction, defaultSizeValue);
                animation.SetScalarParameter("p", percentSliderValue);
                animation.Duration = _duration;

                // Start animation
                _ninegridVisual.StartAnimation("Size." + direction.ToUpper(), animation);
            }
        }
Пример #2
0
 private void LevelCodeGen_Load(object sender, EventArgs e)
 {
     timer1.Start();
     timer2.Start();
     ValueTimer.Start();
     i = 0;
 }
Пример #3
0
 /// <summary>
 /// Callback for value timer to execute value changed.
 /// </summary>
 private void OnYSliderValueChanged(ValueTimer <float> sender, ValueChangedEventArgs <float> args)
 {
     if (_valueTimerYSlider.IntervalMilliseconds != 0 && IsAnimatedInterpolation)
     {
         this.AnimateXYSliderChangeHelper(sender, "y");
     }
     else if (!IsAnimatedInterpolation)
     {
         // For non-animated case, change Size.Y based on the percentage value from the slider
         var x = _ninegridVisual.Size.X;
         var p = (float)args.Value / 100.0f;
         var y = _defaultSize.Y;
         _ninegridVisual.Size = new Vector2(x, y * p);
     }
 }
Пример #4
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;
        }
Пример #5
0
        /// <summary>
        /// Callback for value timer to execute value changed.
        /// </summary>
        private void OnScaleSliderValueChanged(ValueTimer <float> sender, ValueChangedEventArgs <float> args)
        {
            if (_valueTimerScaleSlider.IntervalMilliseconds != 0 && IsAnimatedInterpolation)
            {
                // For animated case, animate from the current to the released values using a keyframe animation
                var scaleValue = (float)args.Value;

                // Define keyframe animation
                var scaleAnimation = _compositor.CreateVector3KeyFrameAnimation();
                scaleAnimation.InsertKeyFrame(1, new Vector3(scaleValue / 100.0f, scaleValue / 100.0f, 1));
                scaleAnimation.Duration = _duration;

                // Start animations
                _ninegridVisual.StartAnimation("Scale", scaleAnimation);
            }
            else if (!IsAnimatedInterpolation)
            {
                // For non-animated case, change Scale based on the percentage value from the slider
                var s = (float)args.Value;
                _ninegridVisual.Scale = new Vector3(s / 100.0f, s / 100.0f, 1);
            }
        }