/// <summary> /// Called when a <see cref="PNode.MouseEnter">MouseEnter</see> event is sent to this /// listener. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> public virtual void OnMouseEnter(object sender, PInputEventArgs e) { if (MouseEnter != null) { MouseEnter(sender, e); } }
/// <summary> /// Called when a <see cref="PNode.MouseLeave">MouseLeave</see> event is sent to this /// listener. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> public virtual void OnMouseLeave(object sender, PInputEventArgs e) { if (MouseLeave != null) { MouseLeave(sender, e); } }
/// <summary> /// Called when a <see cref="PNode.MouseDrag">MouseDrag</see> event is sent to this /// listener. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> public virtual void OnMouseDrag(object sender, PInputEventArgs e) { if (MouseDrag != null) { MouseDrag(sender, e); } }
/// <summary> /// Called when a <see cref="PNode.DoubleClick">DoubleClick</see> event is sent to this /// listener. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> public virtual void OnDoubleClick(object sender, PInputEventArgs e) { if (DoubleClick != null) { DoubleClick(sender, e); } }
/// <summary> /// Called when a <see cref="PNode.KeyUp">KeyUp</see> event is sent to this /// listener. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> public virtual void OnKeyUp(object sender, PInputEventArgs e) { if (KeyUp != null) { KeyUp(sender, e); } }
/// <summary> /// Called when a <see cref="PNode.MouseWheel">MouseWheel</see> event is sent to this /// listener. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> public virtual void OnMouseWheel(object sender, PInputEventArgs e) { if (MouseWheel != null) { MouseWheel(sender, e); } }
/// <summary> /// Called when a <see cref="PNode.DragLeave">DragLeave</see> event is sent to this /// listener. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> public virtual void OnDragLeave(object sender, PInputEventArgs e) { if (DragLeave != null) { DragLeave(sender, e); } }
/// <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> /// Override this method to get notified when the drag activity stops stepping. /// </summary> /// <param name="sender">The source of the drag event.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> protected virtual void OnDragActivityFinalStep(object sender, PInputEventArgs e) { if (DragActivityFinalStep != null) { DragActivityFinalStep(sender, e); } }
/// <summary> /// Called when a <see cref="PNode.LostFocus">LostFocus</see> event is sent to this /// listener. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> public virtual void OnLostFocus(object sender, PInputEventArgs e) { if (LostFocus != null) { LostFocus(sender, e); } }
/// <summary> /// Called when a <see cref="PNode.DragDrop">DragDrop</see> event is sent to this /// listener. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> public virtual void OnDragDrop(object sender, PInputEventArgs e) { if (DragDrop != null) { DragDrop(sender, e); } }
/// <summary> /// Called when a <see cref="PNode.DragOver">DragOver</see> event is sent to this /// listener. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> public virtual void OnDragOver(object sender, PInputEventArgs e) { if (DragOver != null) { DragOver(sender, e); } }
/// <summary> /// Overridden. See <see cref="PDragSequenceEventHandler.ShouldStartDragInteraction"> /// PDragSequenceEventHandler.ShouldStartDragInteraction</see>. /// </summary> protected override bool ShouldStartDragInteraction(PInputEventArgs e) { if (base.ShouldStartDragInteraction(e)) { return(e.PickedNode != e.TopCamera); } return(false); }
//**************************************************************** // Event Filter - All event listeners can be associated with event // filters. An event filter is simply a callback that either // accepts or rejects events. Inheriters can override // DoesAcceptEvent and filter out undesirable events there. Or, // the AcceptsEvent delegate can be set directly to a method that // filters events. //**************************************************************** /// <summary> /// Returns true if the filter accepts the given event and false otherwise. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data.</param> /// <returns>True if the filter accepts the event; otherwise, false.</returns> public virtual bool DoesAcceptEvent(PInputEventArgs e) { if (this.AcceptsEvent != null) { return(AcceptsEvent(e)); } return(true); }
/// <summary> /// The filter for a PPanEventHandler. This method only accepts left mouse button /// events that have not yet been handled. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data.</param> /// <returns> /// True if the event is an unhandled left mouse button event; otherwise, false. /// </returns> protected virtual bool PPanEventHandlerAcceptsEvent(PInputEventArgs e) { if (!e.Handled && e.IsMouseEvent && e.Button == MouseButtons.Left) { return(true); } return(false); }
/// <summary> /// Overridden. See <see cref="PDragSequenceEventHandler.OnDrag"> /// PDragSequenceEventHandler.OnDrag</see>. /// </summary> protected override void OnDrag(object sender, PInputEventArgs e) { base.OnDrag(sender, e); SizeFx s = e.GetDeltaRelativeTo(draggedNode); s = draggedNode.LocalToParent(s); draggedNode.OffsetBy(s.Width, s.Height); }
/// <summary> /// Subclasses should override this method to get notified of the drag events in /// a drag sequence. /// </summary> /// <param name="sender">The source of the end drag event.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> /// <remarks> /// This method is called in the middle of a drag sequence, between the /// <see cref="OnStartDrag"/> and the <see cref="OnEndDrag"/> methods. /// <para> /// Unlike the <see cref="OnMouseDrag"/> method, this method will not get called /// until after the <see cref="MinDragStartDistance"/> has been reached. /// </para> /// <para> /// <b>Notes to Inheritors:</b> Overriding methods must still call /// <c>base.OnDrag()</c> for correct behavior. /// </para> /// </remarks> protected virtual void OnDrag(object sender, PInputEventArgs e) { dragEvent = e; if (Drag != null) { Drag(sender, e); } }
/// <summary> /// Overridden. See <see cref="PDragSequenceEventHandler.OnStartDrag"> /// PDragSequenceEventHandler.OnStartDrag</see>. /// </summary> protected override void OnStartDrag(object sender, PInputEventArgs e) { base.OnStartDrag(sender, e); draggedNode = e.PickedNode; if (moveToFrontOnPress) { draggedNode.MoveToFront(); } }
/// <summary> /// Pans the camera as the mouse is dragged. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data.</param> protected virtual void Pan(PInputEventArgs e) { PCamera c = e.Camera; Vector2 l = new Vector2(e.Position.X, e.Position.Y); if (c.ViewBounds.Contains(l)) { SizeFx s = e.Delta; c.TranslateViewBy(s.Width, s.Height); } }
/// <summary> /// Subclasses should override this method to get notified of the end event in /// a drag sequence. /// </summary> /// <param name="sender">The source of the end drag event.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> /// <remarks> /// This method is called at the end of a drag sequence. /// <para> /// </para> /// Unlike the <see cref="OnMouseDrag"/> method, this method will not get called /// until after the <see cref="MinDragStartDistance"/> has been reached. /// <para> /// <b>Notes to Inheritors:</b> Overriding methods must still call /// <c>base.OnEndDrag()</c> for correct behavior. /// </para> /// </remarks> protected virtual void OnEndDrag(object sender, PInputEventArgs e) { StopDragActivity(e); dragEvent = null; source = null; e.Canvas.Interacting = false; Dragging = false; if (EndDrag != null) { EndDrag(sender, e); } }
/// <summary> /// Overridden. See <see cref="PBasicInputEventHandler.OnMouseUp"> /// PBasicInputEventHandler.OnMouseUp</see>. /// </summary> public override void OnMouseUp(object sender, PInputEventArgs e) { base.OnMouseUp(sender, e); if (sequenceInitiatedButton == e.Button) { if (Dragging) { OnEndDrag(sender, e); } sequenceInitiatedButton = MouseButtons.None; } }
//**************************************************************** // Dragging - Methods to indicate the stages of the drag sequence. //**************************************************************** /// <summary> /// Subclasses should override this method to get notified of the start of a new /// drag sequence. /// </summary> /// <param name="sender">The source of the start drag event.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> /// <remarks> /// This method is called at the beginning of a drag sequence. /// <para> /// Unlike the <see cref="OnMouseDrag"/> method, this method will not get called /// until after the <see cref="MinDragStartDistance"/> has been reached. /// </para> /// <para> /// <b>Notes to Inheritors:</b> Overriding methods must still call /// <c>base.OnStartDrag()</c> for correct behavior. /// </para> /// </remarks> protected virtual void OnStartDrag(object sender, PInputEventArgs e) { dragEvent = e; source = sender; StartDragActivity(e); Dragging = true; e.Canvas.Interacting = true; if (StartDrag != null) { StartDrag(sender, e); } }
/// <summary> /// Overridden. See <see cref="PBasicInputEventHandler.OnMouseDrag"> /// PBasicInputEventHandler.OnMouseDrag</see>. /// </summary> public override void OnMouseDrag(object sender, PInputEventArgs e) { base.OnMouseDrag(sender, e); if (sequenceInitiatedButton != MouseButtons.None) { if (!Dragging) { if (ShouldStartDragInteraction(e)) { OnStartDrag(sender, e); } return; } OnDrag(sender, e); } }
/// <summary> /// Overridden. Do auto-panning even when the mouse is not moving. /// </summary> /// <param name="sender">The source of the drag event.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> protected override void OnDragActivityStep(object sender, PInputEventArgs e) { base.OnDragActivityStep(sender, e); if (!autopan) { return; } PCamera c = e.Camera; RectangleFx b = c.Bounds; PointFx l = e.GetPositionRelativeTo(c); PUtil.OutCode outcode = PUtil.RectangleOutCode(l, b); SizeFx delta = SizeFx.Empty; if ((outcode & PUtil.OutCode.Top) != 0) { delta.Height = ValidatePanningDelta(-1.0f - (0.5f * Math.Abs(l.Y - b.Y))); } else if ((outcode & PUtil.OutCode.Bottom) != 0) { delta.Height = ValidatePanningDelta(1.0f + (0.5f * Math.Abs(l.Y - (b.Y + b.Height)))); } if ((outcode & PUtil.OutCode.Right) != 0) { delta.Width = ValidatePanningDelta(1.0f + (0.5f * Math.Abs(l.X - (b.X + b.Width)))); } else if ((outcode & PUtil.OutCode.Left) != 0) { delta.Width = ValidatePanningDelta(-1.0f - (0.5f * Math.Abs(l.X - b.X))); } delta = c.LocalToView(delta); if (delta.Width != 0 || delta.Height != 0) { c.TranslateViewBy(delta.Width, delta.Height); } }
//**************************************************************** // Events - Subclasses should not override these methods, instead // override the appropriate drag method. //**************************************************************** /// <summary> /// Overridden. See <see cref="PBasicInputEventHandler.OnMouseDown"> /// PBasicInputEventHandler.OnMouseDown</see>. /// </summary> public override void OnMouseDown(object sender, PInputEventArgs e) { base.OnMouseDown(sender, e); if (sequenceInitiatedButton == MouseButtons.None) { sequenceInitiatedButton = e.Button; } else { return; } MousePressedCanvasPoint = e.CanvasPosition; if (!Dragging) { if (ShouldStartDragInteraction(e)) { OnStartDrag(sender, e); } } }
/// <summary> /// Overridden. See <see cref="PDragSequenceEventHandler.OnDragActivityStep"> /// PDragSequenceEventHandler.OnDragActivityStep</see>. /// </summary> protected override void OnDragActivityStep(object sender, PInputEventArgs e) { base.OnDragActivityStep(sender, e); PCamera camera = e.Camera; float dx = e.CanvasPosition.X - MousePressedCanvasPoint.X; float scaleDelta = (1.0f + (0.001f * dx)); float currentScale = camera.ViewScale; float newScale = currentScale * scaleDelta; if (newScale < minScale) { scaleDelta = minScale / currentScale; } if ((maxScale > 0) && (newScale > maxScale)) { scaleDelta = maxScale / currentScale; } camera.ScaleViewBy(scaleDelta, viewZoomPoint.X, viewZoomPoint.Y); }
/// <summary> /// Overridden. See <see cref="PDragSequenceEventHandler.OnDrag"> /// PDragSequenceEventHandler.OnDrag</see>. /// </summary> protected override void OnDrag(object sender, PInputEventArgs e) { base.OnDrag(sender, e); Pan(e); }
/// <summary> /// Returns true if a drag sequence should be initiated. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data.</param> /// <returns>True if a drag sequence should be initiated; otherwise, false.</returns> protected virtual bool ShouldStartDragInteraction(PInputEventArgs e) { return(PUtil.DistanceBetweenPoints(MousePressedCanvasPoint, e.CanvasPosition) >= MinDragStartDistance); }
/// <summary> /// Overridden. See <see cref="PDragSequenceEventHandler.OnEndDrag"> /// PDragSequenceEventHandler.OnEndDrag</see>. /// </summary> protected override void OnEndDrag(object sender, PInputEventArgs e) { base.OnEndDrag(sender, e); draggedNode = null; }
/// <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; }