コード例 #1
0
        /// <summary>
        /// Called when the "Text Transition" button is pressed.
        /// </summary>
        private void cmdTextTransition_Click(object sender, EventArgs e)
        {
            // We transition four properties simulataneously here:
            // - The two labels' text is changed.
            // - The two labels' colors are changed.

            // We work out the new text and colors to transition to...
            string strText1, strText2;
            Color  color1, color2;

            if (lblTextTransition1.Text == STRING_SHORT)
            {
                strText1 = STRING_LONG;
                color1   = Color.Red;
                strText2 = STRING_SHORT;
                color2   = Color.Blue;
            }
            else
            {
                strText1 = STRING_SHORT;
                color1   = Color.Blue;
                strText2 = STRING_LONG;
                color2   = Color.Red;
            }

            // We create a transition to animate all four properties at the same time...
            Transition t = new Transition(new Linear(1000));

            t.Add(lblTextTransition1, "Text", strText1);
            t.Add(lblTextTransition1, "ForeColor", color1);
            t.Add(lblTextTransition2, "Text", strText2);
            t.Add(lblTextTransition2, "ForeColor", color2);
            t.Run();
        }
コード例 #2
0
        /// <summary>
        /// Performs a random tarnsition between the two pictures.
        /// </summary>
        public void transitionPictures()
        {
            // We randomly choose where the current image is going to
            // slide off to (and where we are going to slide the inactive
            // image in from)...
            int iDestinationLeft = (m_Random.Next(2) == 0) ? Width : -Width;
            int iDestinationTop  = (m_Random.Next(3) - 1) * Height;

            // We move the inactive image to this location...
            SuspendLayout();
            m_InactivePicture.Top  = iDestinationTop;
            m_InactivePicture.Left = iDestinationLeft;
            m_InactivePicture.BringToFront();
            ResumeLayout();

            // We perform the transition which moves the active image off the
            // screen, and the inactive one onto the screen...
            Transition t = new Transition(new EaseInEaseOut(1000));

            t.Add(m_InactivePicture, "Left", 0);
            t.Add(m_InactivePicture, "Top", 0);
            t.Add(m_ActivePicture, "Left", iDestinationLeft);
            t.Add(m_ActivePicture, "Top", iDestinationTop);
            t.Run();

            // We swap over which image is active and inactive for next time
            // the function is called...
            PictureBox tmp = m_ActivePicture;

            m_ActivePicture   = m_InactivePicture;
            m_InactivePicture = tmp;
        }
コード例 #3
0
ファイル: Sharper.cs プロジェクト: oxysoft/PokeSharp
        protected override void OnLostFocus(EventArgs e)
        {
            Transition t = new Transition(transition);

            t.Add(this, "GlowIntensity", 0);
            t.Add(this, "GlowFeather", 0);
            t.Run();
            base.OnGotFocus(e);
        }
コード例 #4
0
        /// <summary>
        /// Called when the "Drop and Bounce" button is pressed.
        /// </summary>
        private void cmdDropAndBounce_Click(object sender, EventArgs e)
        {
            // We animate the button to drop and bounce twice with bounces
            // of diminishing heights. While it does this, it is moving to
            // the right, as if thrown to the right. When this animation has
            // finished, the button moves back to its original position.

            // The diminishing-bounce is not one of the built-in transition types,
            // so we create it here as a user-defined transition type. You define
            // these as a collection of TransitionElements. These define how far the
            // animated properties will have moved at various times, and how the
            // transition between different elements is to be done.

            // So in the example below:
            //  0% - 40%    The button acclerates to 100% distance (i.e. the bottom of the screen)
            // 40% - 65%    The button bounces back (decelerating) to 70% distance.
            // etc...

            IList <TransitionElement> elements = new List <TransitionElement>();

            elements.Add(new TransitionElement(40, 100, InterpolationMethod.Accleration));
            elements.Add(new TransitionElement(65, 70, InterpolationMethod.Deceleration));
            elements.Add(new TransitionElement(80, 100, InterpolationMethod.Accleration));
            elements.Add(new TransitionElement(90, 92, InterpolationMethod.Deceleration));
            elements.Add(new TransitionElement(100, 100, InterpolationMethod.Accleration));

            int iDestination = gbDropAndBounce.Height - cmdDropAndBounce.Height - 10;

            Transition.Run(cmdDropAndBounce, "Top", iDestination, new UserDefined(elements, 2000));

            // The transition above just animates the vertical bounce of the button, but not
            // the left-to-right movement. This can't use the same transition, as otherwise the
            // left-to-right movement would bounce back and forth.

            // We run the left-to-right animation as a second, simultaneous transition.
            // In fact, we run a transition chain, with the animation of the button back
            // to its starting position as the second item in the chain. The second
            // transition starts as soon as the first is complete...

            Transition t1 = new Transition(new Linear(2000));

            t1.Add(cmdDropAndBounce, "Left", cmdDropAndBounce.Left + 400);

            Transition t2 = new Transition(new EaseInEaseOut(2000));

            t2.Add(cmdDropAndBounce, "Top", 19);
            t2.Add(cmdDropAndBounce, "Left", 6);

            Transition.RunChain(t1, t2);
        }
コード例 #5
0
ファイル: FlyoutAnimator.cs プロジェクト: nikeee/HolzShots
        public Task AnimateIn(int durationMs)
        {
            _taskbarIsOnTopOrBottom = TaskbarWindow.Instance.Position == Native.Shell32.TaskbarPosition.Bottom ||
                                      TaskbarWindow.Instance.Position == Native.Shell32.TaskbarPosition.Top;

            _screenRectangle = Screen.PrimaryScreen.WorkingArea;

            var startX = _screenRectangle.X + _screenRectangle.Width - _target.Width - 10;
            var startY = _screenRectangle.Y + _screenRectangle.Height - _target.Height + (_taskbarIsOnTopOrBottom ? (TaskbarWindow.Instance.Rectangle.Height / 2) : 15);

            if (_currentVisibleFlyouts.Count == 0 || _currentVisibleFlyouts.Count > 3)
            {
                _instanceOffsetY = _screenRectangle.Y + _screenRectangle.Height - _target.Height;
            }
            else
            {
                _instanceOffsetY = _currentVisibleFlyouts.Min(s => s.Location.Y) - _target.Height;
            }

            _currentVisibleFlyouts.Add(_target);

            const int offfsetY = 8;
            var       destY    = _instanceOffsetY - offfsetY;

            _target.Location = new Point(startX, startY);
            _target.Opacity  = 0.0;
            _target.TopMost  = true;

            var transition = new Transition(new Deceleration(durationMs));

            transition.Add(this, nameof(TargetY), destY);
            transition.Add(this, nameof(TargetOpacity), 1.0);

            // TODO: Fix this in .NET 5:
            // https://stackoverflow.com/a/63372604
            var cts = new TaskCompletionSource <bool>();

            transition.TransitionCompletedEvent += (s, e) => _target.InvokeIfNeeded(() => cts.SetResult(true));

            transition.Run();

            return(cts.Task);
        }
コード例 #6
0
        /// <summary>
        /// Called when the "Swap" button is pressed.
        /// </summary>
        private void cmdSwap_Click(object sender, EventArgs e)
        {
            // We swap over the group-boxes that show the "Bounce" and
            // "Throw and Catch" transitions. The active one is animated
            // left off the screen and the inactive one is animated right
            // onto the screen...

            // We work out which box is currently on screen and
            // which is off screen...
            Control ctrlOnScreen, ctrlOffScreen;

            if (gbBounce.Left == GROUP_BOX_LEFT)
            {
                ctrlOnScreen  = gbBounce;
                ctrlOffScreen = gbThrowAndCatch;
            }
            else
            {
                ctrlOnScreen  = gbThrowAndCatch;
                ctrlOffScreen = gbBounce;
            }
            ctrlOnScreen.SendToBack();
            ctrlOffScreen.BringToFront();

            // We create a transition to animate the two boxes simultaneously. One is
            // animated onto the screen, the other off the screen.

            // The ease-in-ease-out transition acclerates the rate of change for the
            // first half of the animation, and decelerates during the second half.

            Transition t = new Transition(new EaseInEaseOut(1000));

            t.Add(ctrlOnScreen, "Left", -1 * ctrlOnScreen.Width);
            t.Add(ctrlOffScreen, "Left", GROUP_BOX_LEFT);
            t.Run();
        }
コード例 #7
0
ファイル: FlyoutAnimator.cs プロジェクト: nikeee/HolzShots
        public Task AnimateOut(int durationMs)
        {
            _currentVisibleFlyouts.Remove(_target);

            var destY = _instanceOffsetY + 20;

            _target.Opacity = 1.0;
            _target.TopMost = true;

            var transition = new Transition(new Deceleration(durationMs));

            transition.Add(this, nameof(TargetY), destY);
            transition.Add(this, nameof(TargetOpacity), 0.0);

            // TODO: Fix this in .NET 5:
            // https://stackoverflow.com/a/63372604
            var cts = new TaskCompletionSource <bool>();

            transition.TransitionCompletedEvent += (s, e) => _target.InvokeIfNeeded(() => cts.SetResult(true));

            transition.Run();

            return(cts.Task);
        }