Пример #1
0
        /// <summary>
        /// Add this activity to the scheduler.
        /// </summary>
        /// <param name="activity">The activity to be added.</param>
        /// <param name="processLast">
        /// Specifies whether the activity should be run last.
        /// </param>
        /// <remarks>
        /// Adding an activity schedules that activity to run at some point in the
        /// future.
        /// <para>
        /// Sometimes it's useful to make sure that an activity is run after all other
        /// activities have been run. To do this set processLast to true when adding the
        /// activity.
        /// </para>
        /// </remarks>
        public virtual void AddActivity(PActivity activity, bool processLast)
        {
            if (activities.Contains(activity))
            {
                return;
            }

            activitiesChanged = true;

            if (processLast)
            {
                activities.Insert(0, activity);
            }
            else
            {
                activities.Add(activity);
            }

            activity.ActivityScheduler = this;

            if (!ActivityTimer.Enabled)
            {
                StartActivityTimer();
            }
        }
Пример #2
0
        /// <summary>
        /// Process all scheduled activities for the given time. Each activity is
        /// given one "step", equivalent to one frame of animation.
        /// </summary>
        /// <param name="currentTime">The time for which to process each activity.</param>
        public virtual void ProcessActivities(long currentTime)
        {
            int size = activities.Count;

            if (size > 0)
            {
                processingActivities.Clear();
                processingActivities.AddRange(activities);
                for (int i = size - 1; i >= 0; i--)
                {
                    PActivity each = processingActivities[i];
                    each.ProcessStep(currentTime);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Remove this activity from the scheduler.
        /// </summary>
        /// <param name="activity">The activity to be removed.</param>
        /// <remarks>
        /// Once an activity has been removed from the scheduler, it will no longer be
        /// run.
        /// </remarks>
        public virtual void RemoveActivity(PActivity activity)
        {
            if (!activities.Contains(activity))
            {
                return;
            }

            activitiesChanged = true;
            activities.Remove(activity);

            if (activities.Count == 0)
            {
                StopActivityTimer();
            }
        }
Пример #4
0
 /// <summary>
 /// Adds a activity to the list.
 /// </summary>
 /// <param name="activity">The activity to add.</param>
 /// <returns>The position into which the new activity was inserted.</returns>
 public int Add(PActivity activity)
 {
     return List.Add(activity);
 }
Пример #5
0
 /// <summary>
 /// Removes the first occurrence of a specific activity from the list.
 /// </summary>
 /// <param name="activity">The activity to remove from the list.</param>
 public void Remove(PActivity activity)
 {
     List.Remove(activity);
 }
Пример #6
0
 /// <summary>
 /// Inserts a activity to the list at the specified position.
 /// </summary>
 /// <param name="index">
 /// The zero-based index at which the activity should be inserted.
 /// </param>
 /// <param name="activity">The activity to insert into the list.</param>
 public void Insert(int index, PActivity activity)
 {
     List.Insert(index, activity);
 }
Пример #7
0
        /// <summary>
        /// Add this activity to the scheduler.
        /// </summary>
        /// <param name="activity">The activity to be added.</param>
        /// <param name="processLast">
        /// Specifies whether the activity should be run last.
        /// </param>
        /// <remarks>
        /// Adding an activity schedules that activity to run at some point in the
        /// future.
        /// <para>
        /// Sometimes it's useful to make sure that an activity is run after all other
        /// activities have been run. To do this set processLast to true when adding the
        /// activity.
        /// </para>
        /// </remarks>
        public virtual void AddActivity(PActivity activity, bool processLast)
        {
            if (activities.Contains(activity)) return;

            activitiesChanged = true;

            if (processLast) {
                activities.Insert(0, activity);
            } else {
                activities.Add(activity);
            }

            activity.ActivityScheduler = this;

            if (!ActivityTimer.Enabled) {
                StartActivityTimer();
            }
        }
        /// <summary>
        /// Animate the camera's view matrix from its current value when the activity
        /// starts to the new destination matrix value.
        /// </summary>
        /// <param name="aCamera">The camera whose view matrix will be animated.</param>
        /// <param name="aMatrix">The final matrix value.</param>
        /// <param name="duration">
        /// The amount of time that the animation should take.
        /// </param>
        /// <returns>
        /// The newly scheduled activity, if the duration is greater than 0; else null.
        /// </returns>
        protected virtual PActivity AnimateCameraViewMatrixTo(PCamera aCamera, PMatrix aMatrix, int duration)
        {
            bool wasOldAnimation = false;

            // first stop any old animations.
            if (navigationActivity != null) {
                navigationActivity.Terminate();
                wasOldAnimation = true;
            }

            if (duration == 0) {
                aCamera.ViewMatrix = aMatrix;
                return null;
            }

            PMatrix source = aCamera.ViewMatrixReference;

            //if (!source.MatrixReference.Equals(aMatrix.MatrixReference)) {
            if (!source.Equals(aMatrix)) {
                navigationActivity = aCamera.AnimateViewToMatrix(aMatrix, duration);
                ((PTransformActivity)navigationActivity).SlowInSlowOut = !wasOldAnimation;
                return navigationActivity;
            }

            return null;
        }
Пример #9
0
        protected void ActivityStepped(PActivity activity)
        {
            if (fRed) {
                aNode.Brush = new SolidBrush(Color.Red);
            } else {
                aNode.Brush = new SolidBrush(Color.Green);
            }

            fRed = !fRed;
        }
 /// <summary>
 /// Stops the drag activity.
 /// </summary>
 /// <param name="e">A PInputEventArgs that contains the event data.</param>
 private void StopDragActivity(PInputEventArgs e)
 {
     dragActivity.Terminate();
     dragActivity = null;
 }
        /// <summary>
        /// Schedules the drag activity to run.
        /// </summary>
        /// <param name="e">A PInputEventArgs that contains the event data.</param>
        protected virtual void StartDragActivity(PInputEventArgs e)
        {
            dragActivity = new PActivity(-1, PUtil.DEFAULT_ACTIVITY_STEP_RATE);
            dragActivity.ActivityDelegate = this;

            e.Camera.Root.AddActivity(dragActivity);
        }
 /// <summary>
 /// Called when the drag activity is running.
 /// </summary>
 /// <param name="activity">The drag activity.</param>
 public void ActivityStepped(PActivity activity)
 {
     OnDragActivityStep(source, dragEvent);
 }
 /// <summary>
 /// Called when the drag activity starts running.
 /// </summary>
 /// <param name="activity">The drag activity.</param>
 public void ActivityStarted(PActivity activity)
 {
     OnDragActivityFirstStep(source, dragEvent);
 }
 /// <summary>
 /// Called when the drag activity stops running.
 /// </summary>
 /// <param name="activity">The drag activity.</param>
 public void ActivityFinished(PActivity activity)
 {
     OnDragActivityFinalStep(source, dragEvent);
 }
Пример #15
0
        /// <summary>
        /// Remove this activity from the scheduler.
        /// </summary>
        /// <param name="activity">The activity to be removed.</param>
        /// <remarks>
        /// Once an activity has been removed from the scheduler, it will no longer be
        /// run.
        /// </remarks>
        public virtual void RemoveActivity(PActivity activity)
        {
            if (!activities.Contains(activity)) return;

            activitiesChanged = true;
            activities.Remove(activity);

            if (activities.Count == 0) {
                StopActivityTimer();
            }
        }
Пример #16
0
 /// <summary>
 /// Schedules this activity to start after the first activity has finished.
 /// </summary>
 /// <param name="first">The activity to start after.</param>
 /// <remarks>
 /// Note that no link is created between these activities, if the startTime or duration
 /// of the first activity is later changed this activities start time will not be updated
 /// to reflect that change.
 /// </remarks>
 public virtual void StartAfter(PActivity first)
 {
     StartTime = first.StartTime + first.Duration;
 }
Пример #17
0
 //****************************************************************
 // Activities - Methods for scheduling activities to run.
 //****************************************************************
 /// <summary>
 /// Overridden.  Add an activity to the activity scheduler associated with
 /// this root.
 /// </summary>
 /// <param name="activity">The new activity to scheduled.</param>
 /// <returns>
 /// True if the activity is successfully scheduled; otherwise, false.
 /// </returns>
 /// <remarks>
 /// Activities are given a chance to run during each call to the root's
 /// <c>ProcessInputs</c> method. When the activity has finished running it
 /// will automatically get removed.
 /// </remarks>
 public override bool AddActivity(PActivity activity)
 {
     ActivityScheduler.AddActivity(activity);
     return true;
 }
Пример #18
0
        public override void Initialize()
        {
            long currentTime = PUtil.CurrentTimeMillis;

            // Create a new node that we will apply different activities to, and
            // place that node at location 200, 200.
            aNode = new PNode();  //PPath.CreateRectangle(0, 0, 100, 80);
            aNode.SetBounds(0, 0, 100, 80);
            aNode.Brush = new SolidBrush(Color.Blue);
            PLayer layer = Canvas.Layer;
            layer.AddChild(aNode);
            aNode.SetOffset(200, 200);

            // Create a new custom "flash" activity. This activity will start running in
            // five seconds, and while it runs it will flash aNode's brush color between
            // red and green every half second.  The same effect could be achieved by
            // extending PActivity and override OnActivityStep.
            PActivity flash = new PActivity(-1, 500, currentTime + 5000);
            flash.ActivityStepped = new ActivitySteppedDelegate(ActivityStepped);

            Canvas.Root.AddActivity(flash);

            // Use the PNode animate methods to create three activities that animate
            // the node's position. Since our node already descends from the root node the
            // animate methods will automatically schedule these activities for us.
            PActivity a1 = aNode.AnimateToPositionScale(0f, 0f, 0.5f, 5000);
            PActivity a2 = aNode.AnimateToPositionScale(100f, 0f, 1.5f, 5000);
            //PActivity a3 = aNode.AnimateToPositionScale(200f, 100f, 1f, 5000);
            PActivity a3 = aNode.AnimateToPositionScale(20f, 200f, 1f, 5000);

            // the animate activities will start immediately (in the next call to PRoot.processInputs)
            // by default. Here we set their start times (in PRoot global time) so that they start
            // when the previous one has finished.
            a1.StartTime = currentTime;

            a2.StartAfter(a1);
            a3.StartAfter(a2);

            // or the previous three lines could be replaced with these lines for the same effect.
            //a2.setStartTime(currentTime + 5000);
            //a3.setStartTime(currentTime + 10000);

            base.Initialize ();
        }
Пример #19
0
 /// <summary>
 /// Schedule the given activity with the root.
 /// </summary>
 /// <param name="activity">The new activity to schedule.</param>
 /// <returns>True if the activity is successfully scheduled.</returns>
 /// <remarks>
 /// Note that only scheduled activities will be stepped. If the activity is
 /// successfully added true is returned, else false. 
 /// </remarks>
 public virtual bool AddActivity(PActivity activity)
 {
     PRoot r = Root;
     if (r != null) {
         return r.AddActivity(activity);
     }
     return false;
 }
Пример #20
0
 /// <summary>
 /// Schedules this activity to start after the first activity has finished.
 /// </summary>
 /// <param name="first">The activity to start after.</param>
 /// <remarks>
 /// Note that no link is created between these activities, if the startTime or duration
 /// of the first activity is later changed this activities start time will not be updated
 /// to reflect that change.
 /// </remarks>
 public virtual void StartAfter(PActivity first)
 {
     StartTime = first.StartTime + first.Duration;
 }
Пример #21
0
 /// <summary>
 /// Determines whether the list contains a specific activity.
 /// </summary>
 /// <param name="activity">The activity to locate in the list.</param>
 /// <returns>
 /// True if the activity is found in the list; otherwise, false.
 /// </returns>
 public bool Contains(PActivity activity)
 {
     return List.Contains(activity);
 }
Пример #22
0
 /// <summary>
 /// Determines the index of a specific activity in the list.
 /// </summary>
 /// <param name="activity">The activity to locate in the list.</param>
 /// <returns>
 /// The index of the activity if found in the list; otherwise, -1.
 /// </returns>
 public int IndexOf(PActivity activity)
 {
     return List.IndexOf(activity);
 }
Пример #23
0
 /// <summary>
 /// Add this activity to the scheduler.
 /// </summary>
 /// <param name="activity">The activity to be added.</param>
 /// <remarks>
 /// Adding an activity schedules that activity to run at some point in the
 /// future.
 /// </remarks>
 public virtual void AddActivity(PActivity activity)
 {
     AddActivity(activity, false);
 }
Пример #24
0
 /// <summary>
 /// Add this activity to the scheduler.
 /// </summary>
 /// <param name="activity">The activity to be added.</param>
 /// <remarks>
 /// Adding an activity schedules that activity to run at some point in the
 /// future.
 /// </remarks>
 public virtual void AddActivity(PActivity activity)
 {
     AddActivity(activity, false);
 }