/// <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> /// Create and show a new error /// </summary> /// <param Name="error">The text to display to the user</param> /// <param Name="camera">The camera to display the error on</param> /// <param Name="duration">How long to display the error for</param> public Error(string error, PCamera camera, int duration = 3000) { //Slightly shade the background to bring attention to the error PPath background = PPath.CreateRectangle(0, 0, camera.ViewBounds.Width, camera.ViewBounds.Height); background.Brush = new SolidBrush(Color.FromArgb(30, 220, 220, 220)); AddChild(background); //Add the error text to the center of the screen PText errorText = new PText(error); errorText.ConstrainWidthToTextWidth = false; errorText.Font = new Font("Century Gothic", 18); errorText.TextAlignment = StringAlignment.Center; float height = errorText.Font.Height; float width = camera.Canvas.FindForm().Width; float y = (camera.Canvas.FindForm().Height - height) / 2; errorText.Bounds = new RectangleF(0, y, width, height); AddChild(errorText); //Display the error camera.AddChild(this); //Remove the error after the required time PActivity dissapear = new PActivity(duration); dissapear.ActivityFinished += activityFinished; camera.Canvas.Root.AddActivity(dissapear); }
protected void ActivityStepped(PActivity activity) { PRoot root = Canvas.Root; if (root.PaintInvalid || root.ChildPaintInvalid) { PNodeList cameraChildren = Canvas.Camera.ChildrenReference; foreach(PNode each in cameraChildren) { if (each is PHandle) { PHandle handle = (PHandle) each; handle.RelocateHandle(); } } } }
/// <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(); } }
public override void Initialize() { PCanvas c = Canvas; PActivity updateHandles = new PActivity(-1, 0); updateHandles.ActivityStepped = new ActivitySteppedDelegate(ActivityStepped); PPath rect = PPath.CreateRectangle(0, 0, 100, 100); rect.Brush = Brushes.Red; c.Layer.AddChild(rect); c.Camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateNorthEastLocator(rect))); c.Camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateNorthWestLocator(rect))); c.Camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateSouthEastLocator(rect))); c.Camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateSouthWestLocator(rect))); c.Root.ActivityScheduler.AddActivity(updateHandles, true); }
public override void Initialize() { Canvas.RegionManagement = true; PLayer layer = Canvas.Layer; PRoot root = Canvas.Root; Random r = new Random(); for (int i = 0; i < 400; i++) { PNode n = PPath.CreateRectangle(0, 0, 100, 80); n.TranslateBy(10000 * (float)r.NextDouble(), 10000 * (float)r.NextDouble()); n.Brush = new SolidBrush(Color.FromArgb((int)(255 * r.NextDouble()), (int)(255 * r.NextDouble()), (int)(255 * r.NextDouble()))); layer.AddChild(n); } Canvas.Camera.AnimateViewToCenterBounds(layer.GlobalFullBounds, true, 0); PActivity a = new PActivity(-1, 20); a.ActivityStepped = new ActivitySteppedDelegate(ActivityStepped); root.AddActivity(a); }
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 = PPath.CreateRectangle(0, 0, 100, 80); 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.AnimateToPositionScaleRotation(0f, 0f, 0.5f, 0f, 5000); PActivity a2 = aNode.AnimateToPositionScaleRotation(100f, 0f, 1.5f, 110f, 5000); PActivity a3 = aNode.AnimateToPositionScaleRotation(200f, 100f, 1f, 0f, 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); }
/// <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) { // In some cases, starting another timer or setting its interval can // cause ProcessActivities to get re-called. So, we need to catch re-entrances here. if (processActivitiesRecur > 0) { return; } processActivitiesRecur++; 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); } } processActivitiesRecur--; }
/// <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> /// Called when the drag activity stops running. /// </summary> /// <param name="activity">The drag activity.</param> public void ActivityFinished(PActivity activity) { OnDragActivityFinalStep(source, dragEvent); }
/// <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> /// 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> /// 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); }
public void ActivityStepped(PActivity activity) { RotateNodes(); }
/// <summary> /// When the hilite animation finishes, put the slide back in its proper place /// </summary> protected void HiliteActivityFinished(PActivity activity) { PTransformActivity transformActivity = activity as PTransformActivity; PNode.PNodeTransformTarget nodeTarget = (PNode.PNodeTransformTarget)transformActivity.ActivityTarget; PNode slide = nodeTarget.Target; slideBar.AddChild((int)slide.Tag, slide); // Reinsert slide in the right slot }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
//Toggle the Carat'start visibility each time the animation iterates protected void ActivityStepped(PActivity activity) { Visible = !Visible; }
/// <summary> /// Start the blinking animation /// </summary> /// <returns>The PActivity driving the blinking</returns> public PActivity Blink() { //Create an activity that runs forever PActivity blink = new PActivity(-1, BlinkDuration); //Hook active method to ActivityStepped so it knows what to do blink.ActivityStepped = new ActivitySteppedDelegate(ActivityStepped); //Add the activity to Root, so that it can start Root.AddActivity(blink); return blink; }
/// <summary> /// Wait for all the specified activity to finish before returning from /// this method. This will freeze out user input, and so it is generally /// recommended that you use <c>PActivity.StartTime</c> and /// <c>PActivity.StartAfter</c> to offset activities instead of using /// this method. /// </summary> public virtual void WaitForActivity(PActivity activity) { while (activityScheduler.ActivitiesReference.Contains(activity)) { ProcessActivitiesNow(); } }
/// <summary> /// When the focus animation finishes, show the hires version of the slide /// </summary> protected void FocusActivityFinished(PActivity activity) { PTransformActivity transformActivity = activity as PTransformActivity; PNode.PNodeTransformTarget nodeTarget = (PNode.PNodeTransformTarget)transformActivity.ActivityTarget; PNode slide = nodeTarget.Target; ((PMultiSizeImage)slide).ShowThumb = false; }
/// <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; }
/// <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; }
/// <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(); } }
//**************************************************************** // 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; }
/// <summary> /// Once the time has expired, automatically remove the error /// </summary> protected void activityFinished(PActivity activity) { closeMessage(); }
/// <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)) { navigationActivity = aCamera.AnimateViewToMatrix(aMatrix, duration); ((PTransformActivity)navigationActivity).SlowInSlowOut = !wasOldAnimation; return navigationActivity; } return null; }
/// <summary> /// Sets the view position of the scrollDirector. /// </summary> /// <param name="point">The new position.</param> /// <param name="animate">Indicates whether or not to animate the transition.</param> protected virtual void SetViewPosition(Point point, bool animate) { if (view == null) { return; } float oldX = 0, oldY = 0, x = point.X, y = point.Y; PointF vp = this.ViewPosition; oldX = vp.X; oldY = vp.Y; // Send the scroll director the exact view position and let it // interpret it as needed float newX = x; float newY = y; if ((oldX != newX) || (oldY != newY)) { if (animate) { scroll = new ScrollActivity(ViewPosition, point, scrollDirector, animateScrollDuration); Canvas.Root.AddActivity(scroll); } else { scrollDirector.SetViewPosition(newX, newY); } } }
/// <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); }