/// <summary>
        /// Event handler for failures in the network during the simulation.
        /// </summary>
        /// <remarks>
        /// The effect is a viewport animation to bring the failed object into view, if it is not visible already.
        /// </remarks>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="args">Event arguments.</param>
        private async void OnNetworkFailure(object sender, EventArgs args)
        {
            IRectangle rect = null;

            if (sender is ModelNode)
            {
                // For nodes just include the node itself in the viewport
                var graphNode = modelNodeToINode[sender as ModelNode];
                rect = graphNode.Layout;
            }
            else if (sender is ModelEdge)
            {
                var modelEdge = sender as ModelEdge;
                var graphEdge = modelEdgeToIEdge[modelEdge];

                // For edges we need to get the bounding box of the end points
                // We don't need to consider bends in this demo as there are none.
                rect = new RectD(graphEdge.SourcePort.GetLocation(), graphEdge.TargetPort.GetLocation());
            }

            // Don't do anything if the failing element is visible already
            if (GraphControl.Viewport.Contains(rect))
            {
                return;
            }

            // Enlarge the viewport so that we get an overview of the neighborhood as well
            var rectD = rect.ToRectD().GetEnlarged(new InsetsD(200));

            // Animated the transition to the failed element
            await animator.Animate(new ViewportAnimation(GraphControl, rectD, TimeSpan.FromMilliseconds(1000)).CreateEasedAnimation());
        }
Ejemplo n.º 2
0
        void Update(object sender, EventArgs e)
        {
            camera.Render();
            myScene.MoveScene(controls.GetControls());
            myScene.RotateScene(controls.GetRotation());
            animator1.Animate((animator) =>
            {
                if (animator1.opts[0] == false)
                {
                    animator.position.Add(new Vector3(-0.5f, 0f, 0f));
                    if (animator.position.x < -5f)
                    {
                        animator1.opts[0] = true;
                    }
                }
                else
                {
                    animator.position.Add(new Vector3(0.5f, 0f, 0f));
                    if (animator.position.x > 5f)
                    {
                        animator1.opts[0] = false;
                    }
                }
                return(animator);
            });

            animator2.Animate((animator) =>
            {
                animator.rotation.Add(new Vector3(0.5f, 0f, 0f));
                return(animator);
            });
        }
Ejemplo n.º 3
0
        public void Remove(Control child, bool animate = false)
        {
            var div  = child.Node.ParentElement;
            var cell = div.ParentElement;
            var row  = cell.ParentElement;

            if (animate)
            {
                int height = row.MeasureOffsetHeight();
                div.Style.Overflow = "hidden";
                Animator.Animate(
                    progress =>
                {
                    var newHeight    = (int)(height * (1 - progress));
                    div.Style.Height = newHeight + "px";
                },
                    AnimationSpeed,
                    () =>
                {
                    div.Style.Overflow = "";
                    div.Style.Height   = "";
                    div.RemoveChild(child.Node);
                    table.RemoveChild(row);
                    base.RemoveChild(child);
                });
            }
            else
            {
                div.RemoveChild(child.Node);
                table.RemoveChild(row);
                base.RemoveChild(child);
            }
        }
Ejemplo n.º 4
0
        public override void Use(Player player)
        {
            if (CurrentItem != null)
            {
                if (PhotoAnimatonRunning)
                {
                    return;
                }
                if (player.Inventory.Count >= player.Inventory.Capacity)
                {
                    return;
                }

                player.Inventory.Pickup(CurrentItem);
                CurrentItem = null;
                return;
            }

            var texture = TakePhoto(player.Camera);
            var photo   = Instantiate(PhotoPrefab).GetComponent <PhotoItem>();

            photo.Image = texture;

            photo.transform.SetParent(transform, false);
            photo.transform.position = PhotoPrefab.transform.position;
            photo.transform.rotation = PhotoPrefab.transform.rotation;

            PhotoAnimatonRunning = true;

            StartCoroutine(Animator.Animate(
                               () => Animator.MoveToLocal(photo.transform, Vector3.forward * -.3f, 1f, Easing.Linear),
                               () => Animator.Action(() => PhotoAnimatonRunning = false)));

            CurrentItem = photo;
        }
Ejemplo n.º 5
0
 public void Draw(RenderTarget target, RenderStates states)
 {
     if (_animatedObject != null)
     {
         _animator.Animate(_animatedObject);
     }
     target.Draw(_sprite);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Called after the layout has been calculated.
        /// </summary>
        /// <remarks>
        /// Applies the layout in an animation and cleans up. Calls OnDone to raise the Done event after the animation has been completed.
        /// </remarks>
        /// <param name="graph">The graph to apply the layout to.</param>
        /// <param name="moduleContext">The module context.</param>
        /// <param name="compoundEdit">The undo edit which wraps the layout. It was created in <see cref="StartWithIGraph"/> and will be closed here.</param>
        protected virtual async Task LayoutDone(IGraph graph, ILookup moduleContext, ICompoundEdit compoundEdit)
        {
            if (abortDialog != null)
            {
                if (abortDialog.IsVisible)
                {
                    abortDialog.Close();
                }
                abortDialog = null;
            }
            GraphControl view = moduleContext.Lookup <GraphControl>();

            if (LayoutMorphingEnabled && view != null)
            {
                var morphingAnimation =
                    graph.CreateLayoutAnimation(layoutGraph, TimeSpan.FromSeconds(1));

                Rectangle2D box =
                    LayoutGraphUtilities.GetBoundingBox(layoutGraph, layoutGraph.GetNodeCursor(), layoutGraph.GetEdgeCursor());
                RectD             targetBounds = box.ToRectD();
                ViewportAnimation vpAnim       =
                    new ViewportAnimation(view,
                                          targetBounds, TimeSpan.FromSeconds(1))
                {
                    MaximumTargetZoom = 1.0d, TargetViewMargins = view.ContentMargins
                };

                var animations = new List <IAnimation>();
                animations.Add(morphingAnimation);
                animations.Add(CreateTableAnimations());
                if (ViewPortMorphingEnabled)
                {
                    animations.Add(vpAnim);
                }
                TableLayoutConfigurator.CleanUp(graph);

                Animator animator = new Animator(view);
                await animator.Animate(animations.CreateParallelAnimation().CreateEasedAnimation());

                try {
                    compoundEdit.Commit();
                    view.UpdateContentRect();
                } finally {
                    OnDone(new LayoutEventArgs());
                }
            }
            else
            {
                layoutGraph.CommitLayoutToOriginalGraph();
                RestoreTableLayout();
                compoundEdit.Commit();
                if (view != null)
                {
                    view.UpdateContentRect();
                }
                OnDone(new LayoutEventArgs());
            }
        }
Ejemplo n.º 7
0
    public void FadeIn(TimeSpan duration)
    {
        Opacity = 0.01;
        Rectangle lWorkingArea = CalculateTotalScreenBounds();

        Bounds = new Rectangle(lWorkingArea.X - 150, lWorkingArea.Y - 150, 100, 100);
        Show();
        Bounds = new Rectangle(Owner.PointToScreen(Point.Empty), Owner.ClientSize);
        Animator.Animate(this, "Opacity", 0.01, fFinalOpacity, duration);
    }
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            if (this.NativeView == null)
            {
                return;
            }

            //Accessing page numbers from the ScrollView abstraction renderer
            AnimatedScrollView animatedScrollView = (AnimatedScrollView)Element;

            _pages = animatedScrollView.NumberOfPage;

            nativeScrollView = (UIScrollView)this.NativeView;


            nativeScrollView.ContentSize = new CGSize(_pages * (float)this.NativeView.Frame.Width, (float)this.NativeView.Frame.Height);

            //TODO: Put these 2 parameters into the Abstraction renderer
            nativeScrollView.PagingEnabled = true;
            nativeScrollView.ShowsHorizontalScrollIndicator = false;
            //

            _isAtEnd = false;
            Animator = new Animator();

            ScrollView           = new UIScrollView(nativeScrollView.Bounds);
            ScrollView.Scrolled += (sender, args) =>
            {
                Animator.Animate(Convert.ToInt32(ScrollView.ContentOffset.X));

                _isAtEnd = ScrollView.ContentOffset.X >= MaxContentOffsetXForScrollView(ScrollView);

                //animatedScrolledService = ScrollView.Delegate;

                if (_isAtEnd && this.RespondsToSelector(new Selector("AnimatedScrollViewControllerDidScrollToEnd:")))
                {
                    //animatedScrolledService.AnimatedScrollViewControllerDidScrollToEnd(this);
                }
            };

            ScrollView.ScrollAnimationEnded += (sender, args) =>
            {
                //WeakDelegate = scrollView.Delegate;
                //animatedScrolledService =  ScrollView.Delegate;

                if (_isAtEnd && this.RespondsToSelector(new Selector("AnimatedScrollViewControllerDidEndDraggingAtEnd:")))
                {
                    //animatedScrolledService.AnimatedScrollViewControllerDidEndDraggingAtEnd(this);
                }
            };

            nativeScrollView.Add(ScrollView);
        }
Ejemplo n.º 9
0
 private void Form1_Load(object sender, EventArgs e)
 {
     Animator.Animate(150, (frame, frequency) =>
     {
         if (!Visible || IsDisposed)
         {
             return(false);
         }
         Opacity = (double)frame / frequency;
         return(true);
     });
 }
Ejemplo n.º 10
0
        protected override void OnScrollChanged(int x, int y, int oldx, int oldy)
        {
            //			if (!button1YOrigin.HasValue)
            //				button1YOrigin = _views [1].GetY ();
            //
            //			Trace.WriteLine("Scrolling", "X from ["+oldx+"] to ["+x+"]");
            //			_views[0].SetY(x);
            //			_views[1].SetY(button1YOrigin.Value-x);

            Animator.Animate(Convert.ToInt32(x));

            base.OnScrollChanged(x, y, oldx, oldy);
        }
Ejemplo n.º 11
0
        public void SlideDown()
        {
            var height = headerDiv.OffsetHeight;

            headerDiv.Style.Top      = -height + "px";
            headerDiv.Style.Position = "absolute";

            Animator.Animate(
                progress =>
            {
                var newHeight                   = Math.Min(progress * height, height);
                headerDiv.Style.Top             = (-height + newHeight) + "px";
                headerContainerDiv.Style.Height = newHeight + "px";
            },
                300,
                () =>
            {
                // Reset the style so that it fits into the normal HTML flow.  This ensure that,
                // after animating, the slid-down content will resize, refit its contents, etc.
                // if the window resizes.
                headerDiv.Style.Position        = "relative";
                headerContainerDiv.Style.Height = "inherit";
            }
                );

/*
 *          int? start = null;
 *          Action<int> step = null;
 *          step = timestamp =>
 *          {
 *              start = start ?? timestamp;
 *              var progress = Math.Min((timestamp - start.Value) / duration * height, height);
 *              headerDiv.Style.Top = (-height + progress) + "px";
 *              headerContainerDiv.Style.Height = progress + "px";
 *              if (progress < height)
 *              {
 *                  Browser.Window.RequestAnimationFrame(step);
 *              }
 *              else
 *              {
 *                  // Reset the style so that it fits into the normal HTML flow.  This ensure that,
 *                  // after animating, the slid-down content will resize, refit its contents, etc.
 *                  // if the window resizes.
 *                  headerDiv.Style.Position = "relative";
 *                  headerContainerDiv.Style.Height = "inherit";
 *              }
 *          };
 *          Browser.Window.RequestAnimationFrame(step);
 */
        }
        private void AnimateIn(Point locationToBe)
        {
            Focus();

            var animacao = Animator.Animate(this, new XLocationEffect(), EasingFunctions.QuintEaseOut, locationToBe.X, 1000, 50);

            Task.Run(() =>
            {
                while (animacao.ElapsedMilliseconds < 250)
                {
                    Thread.Sleep(50);
                }
            });
        }
Ejemplo n.º 13
0
 private void Animate()
 {
     Animator.Animate(_handle, OnAnimate(),
                      length: Duration,
                      easing: Easing,
                      repeat: IsRepeat,
                      finished: (v, c) =>
     {
         var repeat = IsRepeat();
         IsRunning  = !repeat;
         Debug.WriteLine($"Timeline Finished (plays: {_playCount + 1}, repeat: {repeat}, handle: {_handle})");
         _playCount++;
         OnFinished();
     });
 }
Ejemplo n.º 14
0
 public void UpdateTransform(Matrix3D matrix, bool animate)
 {
     if (Content != null && animate)
     {
         ContentAnimation animation = new ContentAnimation
         {
             OldMatrix = Transform.Value,
             NewMatrix = matrix,
         };
         Animator.Animate(this, animation);
     }
     else
     {
         Transform = new MatrixTransform3D(matrix);
     }
 }
        private void FadeOutIn(TimeSpan time)
        {
            var animator = Animator.Animate(this, new FormFadeEffect(), EasingFunctions.Linear, 0, Convert.ToInt32(time.TotalMilliseconds), 50);

            Task.Run(() =>
            {
                while (animator.ElapsedMilliseconds < Convert.ToInt32(time.TotalMilliseconds))
                {
                    Thread.Sleep(50);
                }

                Invoke((MethodInvoker) delegate
                {
                    Visible = false;
                    Close();
                });
            });
        }
        /// <summary>
        /// Create a new layout instance and start it in a new thread
        /// </summary>
        /// <returns></returns>
        private InteractiveOrganicLayout StartLayout()
        {
            // create the layout
            InteractiveOrganicLayout organicLayout = new InteractiveOrganicLayout {
                MaximumDuration = 2000
            };

            // use an animator that animates an infinite animation
            var animator = new Animator(GraphControl)
            {
                AutoInvalidation = false, AnimationPriority = DispatcherPriority.Input
            };

            animator.Animate(delegate {
                if (!organicLayout.Running)
                {
                    animator.Stop();
                    return;
                }
                if (organicLayout.CommitPositionsSmoothly(50, 0.05) > 0)
                {
                    GraphControl.UpdateVisual();
                }
            }, TimeSpan.MaxValue);

            // run the layout in a separate thread
            Thread thread = new Thread(new ThreadStart(delegate {
                // we run the real interactive version of the organic layout
                // previously we only calculated the initial layout using OrganicLayout
                organicLayout.ApplyLayout(copiedLayoutGraph);
                // stop the animator when the layout returns (does not normally happen at all)
                graphControl.Dispatcher.Invoke(new Action <Animator>(animator1 => animator1.Stop()), animator);
            }));

            thread.IsBackground = true;
            thread.Start();

            return(organicLayout);
        }
Ejemplo n.º 17
0
 public void FadeOut(TimeSpan duration)
 {
     Animator.Animate(this, "Opacity", Opacity, 0, duration, EndFadeOut);
 }
Ejemplo n.º 18
0
        private static void Goto(Location destination, int duration, EasingFunction easing = null)
        {
            hw.DisplayDestination(destination.GetName());

            elevator.Play(new ElevatorEffect());

            var destFloor = destination.GetFloor();

            if(easing == null)
                easing = new ExponentialEase();
            var length = new TimeSpan(0, 0, 0, duration);

            var animator = new Animator {
                InitialValue = CurrentFloor,
                FinalValue = destFloor,
                EasingFunction = easing,
                Length = length,
                Set = SetCurrentFloor
            };
            animator.Animate();
        }
 public static AnimationStatus Animate(this Control control, IEffect iAnimation,
                                       EasingDelegate easing, int valueToReach, int duration, int delay, bool reverse = false, int loops = 1)
 {
     return(Animator.Animate(control, iAnimation, easing, valueToReach, duration, delay, reverse, loops));
 }
Ejemplo n.º 20
0
        public int SolutionPart2(int steps, params string[] input)
        {
            var animator = new Animator(true, input);

            return(animator.Animate(steps));
        }
Ejemplo n.º 21
0
        public int SolutionPart2(int steps, params string[] input)
        {
            var animator = new Animator(true, input);

            return animator.Animate(steps);
        }
Ejemplo n.º 22
0
        private Element InternalAdd(Control child, HorizontalAlignment alignment, int spaceAbove, bool animate = false)
        {
            if (Count > 0)
            {
                spaceAbove += spacing;
            }

            base.AddChild(child);

            var row  = Browser.Document.CreateElement("tr");
            var cell = Browser.Document.CreateElement("td");
            var div  = Browser.Document.CreateElement("div");

            cell.AppendChild(div);

            switch (alignment)
            {
            case HorizontalAlignment.Fill:
                child.Node.Style.Width = "100%";
                div.Style.Width        = "100%";
                break;

            case HorizontalAlignment.Left:
                cell.SetAttribute("align", "left");
                break;

            case HorizontalAlignment.Center:
                cell.SetAttribute("align", "center");
                break;

            case HorizontalAlignment.Right:
                cell.SetAttribute("align", "right");
                break;
            }

            if (spaceAbove != 0)
            {
                div.Style.MarginTop = spaceAbove + "px";   // TODO!?  Shouldn't this be padding?
            }

            div.AppendChild(child.Node);
            row.AppendChild(cell);

            if (animate)
            {
                int height = row.MeasureOffsetHeight();
                row.Style.Display  = "none";
                div.Style.Overflow = "hidden";
                Animator.Animate(
                    progress =>
                {
                    var newHeight     = (int)(height * progress);
                    div.Style.Height  = newHeight + "px";
                    row.Style.Display = "";
                },
                    AnimationSpeed,
                    () =>
                {
                    div.Style.Overflow = "";
                    div.Style.Height   = "";
                });
            }

            return(row);
        }
 private async void StartAnimation()
 {
     // animates the nodes in random fashion
     Random r = new Random(DateTime.Now.TimeOfDay.Milliseconds);
     await animator.Animate(Animations.CreateGraphAnimation(graphControl.Graph, Mappers.FromDelegate <INode, IRectangle>(node => new RectD(r.NextDouble() * 800, r.NextDouble() * 800, node.Layout.Width, node.Layout.Height)), null, null, null, TimeSpan.FromSeconds(5)));
 }
Ejemplo n.º 24
0
 IEnumerator Animation(bool enabled) =>
 Animator.Animate(
     () => Animator.MoveToLocal(Lamp.transform, new Vector3(0, .007f, 0), .2f, Easing.Linear),
     () => Animator.Action(() => ToggleLights(enabled)),
     () => Animator.Wait(.05f),
     () => Animator.MoveToLocal(Lamp.transform, Vector3.zero, .2f, Easing.Linear));