/// <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 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.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.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> /// 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> /// 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.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.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.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> /// 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.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> /// Overridden. See <see cref="PDragSequenceEventHandler.OnDrag"> /// PDragSequenceEventHandler.OnDrag</see>. /// </summary> protected override void OnDrag(object sender, PInputEventArgs e) { base.OnDrag(sender, e); SizeF s = e.GetDeltaRelativeTo(draggedNode); s = draggedNode.LocalToParent(s); draggedNode.OffsetBy(s.Width, s.Height); }
//**************************************************************** // 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> /// 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); }
/// <summary> /// The filter for a PDragEventHandler. 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 PDragEventHandlerAcceptsEvent(PInputEventArgs e) { if (!e.Handled && e.IsMouseEvent) // && e.Button == MouseButtons.Left) { { return(true); } return(false); }
/// <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> /// 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> /// The filter for a PZoomEventHandler. This method only accepts right 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 right mouse button event; otherwise, false. /// </returns> protected virtual bool PZoomEventHandlerAcceptsEvent(PInputEventArgs e) { //if (!e.Handled && e.IsMouseEvent && e.Button == MouseButtons.Right) { // return true; //} if (!e.Handled && e.IsMouseEvent) { return(true); } return(false); }
/// <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; PointF l = e.Position; //if (c.ViewBounds.Contains(l)) { if (PUtil.RectangleContainsPoint(c.ViewBounds, l)) { SizeF s = e.Delta; c.TranslateViewBy(s.Width, s.Height); } }
/// <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; RectangleF b = c.Bounds; PointF l = e.GetPositionRelativeTo(c); PUtil.OutCode outcode = PUtil.RectangleOutCode(l, b); SizeF delta = SizeF.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.OnDragActivityFirstStep"> /// PDragSequenceEventHandler.OnDragActivityFirstStep</see>. /// </summary> protected override void OnDragActivityFirstStep(object sender, PInputEventArgs e) { viewZoomPoint = e.Position; base.OnDragActivityFirstStep(sender, e); }
/// <summary> /// Raises the MouseWheel event. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data</param> /// <remarks> /// Raising an event invokes the event handler through a delegate. /// <para> /// The OnMouseWheel method also allows derived classes to handle the event /// without attaching a delegate. This is the preferred technique for handling /// the event in a derived class. /// </para> /// <para> /// <b>Notes to Inheritors:</b> When overriding OnMouseWheel in a derived class, /// be sure to call the base class's OnMouseWheel method so that registered /// delegates receive the event. /// </para> /// </remarks> public virtual void OnMouseWheel(PInputEventArgs e) { PInputEventHandler handler = (PInputEventHandler) handlers[PNode.mouseWheelEventKey]; HandleEvent(e, handler); }
/// <summary> /// Raises the KeyUp event. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data</param> /// <remarks> /// Raising an event invokes the event handler through a delegate. /// <para> /// The OnKeyUp method also allows derived classes to handle the event /// without attaching a delegate. This is the preferred technique for handling /// the event in a derived class. /// </para> /// <para> /// <b>Notes to Inheritors:</b> When overriding OnKeyUp in a derived class, /// be sure to call the base class's OnKeyUp method so that registered /// delegates receive the event. /// </para> /// </remarks> public virtual void OnKeyUp(PInputEventArgs e) { PInputEventHandler handler = (PInputEventHandler) handlers[PNode.keyUpEventKey]; HandleEvent(e, handler); }
/// <summary> /// Raises the DoubleClick event. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data</param> /// <remarks> /// Raising an event invokes the event handler through a delegate. /// <para> /// The OnDoubleClick method also allows derived classes to handle the event /// without attaching a delegate. This is the preferred technique for handling /// the event in a derived class. /// </para> /// <para> /// <b>Notes to Inheritors:</b> When overriding OnDoubleClick in a derived class, /// be sure to call the base class's OnDOubleClick method so that registered /// delegates receive the event. /// </para> /// </remarks> public virtual void OnDoubleClick(PInputEventArgs e) { PInputEventHandler handler = (PInputEventHandler) handlers[PNode.doubleClickEventKey]; HandleEvent(e, handler); }
/// <summary> /// Overridden. This gets called continuously during the drag, and is used /// to animate the marquee. /// </summary> /// <param name="sender">The source of the PInputEvent.</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 (marquee != null) { float origPenNum = penNum; penNum = (penNum + 0.5f) % NUM_PENS; // Increment by partial steps to slow down animation if ((int)penNum != (int)origPenNum && !SetSafeMarqueePen(marquee.Width, marquee.Height)) { marquee.Pen = pens[(int)penNum]; } } }
protected override void OnStartDrag(object sender, PInputEventArgs e) { base.OnStartDrag (sender, e); squiggle = new PPath(); lastPoint = e.Position; //squiggle.Pen = new Pen(Brushes.Black, (float)(1/ e.Camera.ViewScale)); layer.AddChild(squiggle); }
public override bool DoesAcceptEvent(PInputEventArgs e) { return (base.DoesAcceptEvent(e) && e.IsMouseEvent && e.Button == MouseButtons.Left); }
/// <summary> /// Starts a standard selection sequence. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data.</param> /// <remarks> /// <b>Notes to Inheritors:</b> Subclasses can override this method to be notified at /// the beginning of a standard selection sequence. /// <para> /// Overriding methods must still call <c>base.StartStandardSelection()</c> for correct /// behavior. /// </para> /// </remarks> protected virtual void StartStandardSelection(PInputEventArgs e) { // Option indicator not down - clear selection, and start fresh if (!IsSelected(pressNode)) { UnselectAll(); if (IsSelectable(pressNode)) { Select(pressNode); } } }
/// <summary> /// Starts an option selection sequence (i.e. a selection sequence where the /// <c>Shift</c> key was pressed). /// </summary> /// <param name="e">A PInputEventArgs that contains the event data.</param> /// <remarks> /// <b>Notes to Inheritors:</b> Subclasses can override this method to be notified at /// the beginning of an option selection sequence. /// <para> /// Overriding methods must still call <c>base.StartStandardOptionSelection()</c> for /// correct behavior. /// </para> /// </remarks> protected virtual void StartStandardOptionSelection(PInputEventArgs e) { // Option indicator is down, toggle selection if (IsSelectable(pressNode)) { if (IsSelected(pressNode)) { Unselect(pressNode); } else { Select(pressNode); } } }
/// <summary> /// Starts an option marquee selection sequence (i.e. a marquee selection /// sequence where the <c>Shift</c> key was pressed). /// </summary> /// <param name="e">A PInputEventArgs that contains the event data.</param> /// <remarks> /// <b>Notes to Inheritors:</b> Subclasses can override this method to be notified at /// the beginning of an option marquee selection sequence. /// <para> /// Overriding methods must still call <c>base.StartOptionMarqueeSelection()</c> for /// correct behavior. /// </para> /// </remarks> protected virtual void StartOptionMarqueeSelection(PInputEventArgs e) { }
/// <summary> /// Starts a marquee selection sequence. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data.</param> /// <remarks> /// <b>Notes to Inheritors:</b> Subclasses can override this method to be notified /// at the beginning of a marquee selection sequence. /// <para> /// Overriding methods must still call <c>base.StartMarqueeSelection()</c> for correct /// behavior. /// </para> /// </remarks> protected virtual void StartMarqueeSelection(PInputEventArgs e) { UnselectAll(); }
//**************************************************************** // Dragging - Overridden methods from PDragSequenceEventHandler //**************************************************************** /// <summary> /// Overridden. See <see cref="PDragSequenceEventHandler.OnStartDrag"> /// PDragSequenceEventHandler.OnStartDrag</see>. /// </summary> protected override void OnStartDrag(object sender, PInputEventArgs e) { base.OnStartDrag (sender, e); InitializeSelection(e); if (IsMarqueeSelection(e)) { InitializeMarquee(e); if (!IsOptionSelection(e)) { StartMarqueeSelection(e); } else { StartOptionMarqueeSelection(e); } } else { if (!IsOptionSelection(e)) { StartStandardSelection(e); } else { StartStandardOptionSelection(e); } } }
/// <summary> /// Raises the DragOver event. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data</param> /// <remarks> /// Raising an event invokes the event handler through a delegate. /// <para> /// The OnDragOver method also allows derived classes to handle the event /// without attaching a delegate. This is the preferred technique for handling /// the event in a derived class. /// </para> /// <para> /// <b>Notes to Inheritors:</b> When overriding OnDragOver in a derived class, /// be sure to call the base class's OnDragOver method so that registered /// delegates receive the event. /// </para> /// </remarks> public virtual void OnDragOver(PInputEventArgs e) { PInputEventHandler handler = (PInputEventHandler) handlers[PNode.dragOverEventKey]; HandleEvent(e, handler); }
/// <summary> /// The filter for a PDragEventHandler. 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 PDragEventHandlerAcceptsEvent(PInputEventArgs e) { if (!e.Handled && e.IsMouseEvent) { // && e.Button == MouseButtons.Left) { return true; } return false; }
/// <summary> /// Raises the LostFocus event. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data</param> /// <remarks> /// Raising an event invokes the event handler through a delegate. /// <para> /// The OnLostFocus method also allows derived classes to handle the event /// without attaching a delegate. This is the preferred technique for handling /// the event in a derived class. /// </para> /// <para> /// <b>Notes to Inheritors:</b> When overriding OnLostFocus in a derived class, /// be sure to call the base class's OnLostFocus method so that registered /// delegates receive the event. /// </para> /// </remarks> public virtual void OnLostFocus(PInputEventArgs e) { PInputEventHandler handler = (PInputEventHandler) handlers[PNode.lostFocusEventKey]; HandleEvent(e, handler); }
/// <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; }
/// <summary> /// Raise the given input event. /// </summary> /// <param name="e">The arguments for this input event.</param> /// <param name="handler">The delegate to dispatch this event to.</param> /// <remarks> /// If an event has been set as handled, and the delegate is not a member of a listener /// class, then the event is consumed. If the delegate is a member of a listener class /// the decision of consumption is left up to the filter associated with that class. /// </remarks> protected virtual void HandleEvent(PInputEventArgs e, PInputEventHandler handler) { if (handler != null) { Delegate[] list = handler.GetInvocationList(); for (int i = list.Length - 1; i >= 0; i--) { Delegate each = list[i]; //if (each.Target is PInputEventListener) { Object obj = PUtil.GetTarget(each); if (obj is PInputEventListener) { // PInputEventListener listener = (PInputEventListener)each.Target; PInputEventListener listener = (PInputEventListener)obj; if (listener.DoesAcceptEvent(e)) { // The source is the node from which the event originated, not the // picked node. ((PInputEventHandler)each)(this, e); } } else if (!e.Handled) { // The source is the node from which the event originated, not the // picked node. ((PInputEventHandler)each)(this, e); } } } }
/// <summary> /// Check if the mouse has entered or exited a node during a mouse move or drag /// operation and, if so, dispatch the appropriate event. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data.</param> public virtual void CheckForMouseEnteredAndExited(PInputEventArgs e) { PNode c = (mouseOver != null) ? mouseOver.PickedNode : null; PNode p = (previousMouseOver != null) ? previousMouseOver.PickedNode : null; if (c != p) { DispatchToPath(e, PInputType.MouseLeave, previousMouseOver); DispatchToPath(e, PInputType.MouseEnter, mouseOver); previousMouseOver = mouseOver; } }
/// <summary> /// Overridden. See <see cref="PDragSequenceEventHandler.OnDrag"> /// PDragSequenceEventHandler.OnDrag</see>. /// </summary> protected override void OnDrag(object sender, PInputEventArgs e) { base.OnDrag (sender, e); if (IsMarqueeSelection(e)) { UpdateMarquee(e); if (!IsOptionSelection(e)) { ComputeMarqueeSelection(e); } else { ComputeOptionMarqueeSelection(e); } } else { DragStandardSelection(e); } }
/// <summary> /// Dispatch the given event to the appropriate focus node. /// </summary> /// <param name="e">An PInputEventArgs that contains the event data.</param> public virtual void Dispatch(PInputEventArgs e) { switch (e.Type) { case PInputType.KeyDown: DispatchToPath(e, PInputType.KeyDown, KeyboardFocus); break; case PInputType.KeyPress: DispatchToPath(e, PInputType.KeyPress, KeyboardFocus); break; case PInputType.KeyUp: DispatchToPath(e, PInputType.KeyUp, KeyboardFocus); break; case PInputType.Click: //The click event occurs before the MouseRelease so we can //dispatch to the current focused node as opposed to the //previously focused node DispatchToPath(e, PInputType.Click, MouseFocus); break; case PInputType.DoubleClick: //The double click event occurs before the MouseRelease so we can //dispatch to the current focused node as opposed to the //previously focused node DispatchToPath(e, PInputType.DoubleClick, MouseFocus); break; case PInputType.MouseDown: MouseFocus = MouseOver; DispatchToPath(e, PInputType.MouseDown, MouseFocus); break; case PInputType.MouseUp: CheckForMouseEnteredAndExited(e); DispatchToPath(e, PInputType.MouseUp, MouseFocus); mouseFocus = null; break; case PInputType.MouseDrag: CheckForMouseEnteredAndExited(e); DispatchToPath(e, PInputType.MouseDrag, MouseFocus); break; case PInputType.MouseMove: CheckForMouseEnteredAndExited(e); DispatchToPath(e, PInputType.MouseMove, MouseOver); break; case PInputType.MouseWheel: MouseFocus = MouseOver; DispatchToPath(e, PInputType.MouseWheel, MouseOver); break; case PInputType.DragOver: CheckForMouseDragEnteredAndExited(e); DispatchToPath(e, PInputType.DragOver, MouseOver); break; case PInputType.DragDrop: CheckForMouseDragEnteredAndExited(e); DispatchToPath(e, PInputType.DragDrop, MouseOver); break; } }
/// <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> /// Dispatch the given PInputEvent to the given pick path. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data.</param> /// <param name="type">The type of PInputEvent being dispatched.</param> /// <param name="path">The pick path to which the PInputEvent will be dispatched.</param> public virtual void DispatchToPath(PInputEventArgs e, PInputType type, PPickPath path) { if (path != null) { //set the type and clear the handled bit since the same event object is //used to send multiple events such as mouseEntered/mouseExited and mouseMove. e.Type = type; e.Handled = false; path.ProcessEvent(e); } }
/// <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; }
//**************************************************************** // Event Handling - Methods for handling events // // The dispatch manager updates the focus nodes based on the // incoming events, and dispatches those events to the appropriate // focus nodes. //**************************************************************** /// <summary> /// Create a new PInputEvent based on the next windows event and dispatch it to Piccolo. /// </summary> public virtual void ProcessInput() { if (nextInput == null) return; PInputEventArgs e = new PInputEventArgs(this, nextInput, nextType); //The EventArgs object for a Click event does not provide the position, so //we just ignore it here. //if (e.IsMouseEvent || e.IsDragDropEvent) { if (e.IsMouseEvent) { lastCanvasPosition = currentCanvasPosition; //if (e.IsMouseEvent) { currentCanvasPosition = new PointF(((MouseEventArgs)nextInput).X, ((MouseEventArgs)nextInput).Y); //} else { // Point pt = new Point((int)((DragEventArgs)nextInput).X, (int)((DragEventArgs)nextInput).Y); // currentCanvasPosition = nextWindowsSource.PointToClient(pt); //} //if (e.Type == PInputType.MouseMove || e.Type == PInputType.MouseDrag || e.Type == PInputType.DragOver){ PPickPath pickPath = nextInputSource.Pick(currentCanvasPosition.X, currentCanvasPosition.Y, 1); MouseOver = pickPath; //} } nextInput = null; nextInputSource = null; Dispatch(e); }
/// <summary> /// Overridden. Determines if this bounds handle or any of it's siblings need to be /// flipped. /// </summary> /// <param name="sender">The source of this handle drag event.</param> /// <param name="size">The drag delta relative to the handle.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> /// <remarks> /// While dragging the bounds handles, the node being resized may cross over itself and /// become reversed (if it is dragged through zero-width or zero-height). In this case, /// the locators for some of the bounds handles will have to be flipped to the opposite /// side. /// </remarks> public override void OnHandleDrag(object sender, SizeF size, PInputEventArgs e) { base.OnHandleDrag(sender, size, e); PBoundsLocator l = (PBoundsLocator) Locator; PNode n = l.Node; RectangleF b = n.Bounds; PNode parent = Parent; if (parent != n && parent is PCamera) { size = ((PCamera)parent).LocalToView(size); } size = LocalToGlobal(size); size = n.GlobalToLocal(size); float dx = size.Width; float dy = size.Height; switch (l.Side) { case Direction.North: b = new RectangleF(b.X, b.Y + dy, b.Width, b.Height - dy); break; case Direction.South: b = new RectangleF(b.X, b.Y, b.Width, b.Height + dy); break; case Direction.East: b = new RectangleF(b.X, b.Y, b.Width + dx, b.Height); break; case Direction.West: b = new RectangleF(b.X + dx, b.Y, b.Width - dx, b.Height); break; case Direction.NorthWest: b = new RectangleF(b.X + dx, b.Y + dy, b.Width - dx, b.Height - dy); break; case Direction.SouthWest: b = new RectangleF(b.X + dx, b.Y, b.Width - dx, b.Height + dy); break; case Direction.NorthEast: b = new RectangleF(b.X, b.Y + dy, b.Width + dx, b.Height - dy); break; case Direction.SouthEast: b = new RectangleF(b.X, b.Y, b.Width + dx, b.Height + dy); break; } bool flipX = false; bool flipY = false; if (b.Width < 0) { flipX = true; b.Width = -b.Width; b.X -= b.Width; } if (b.Height < 0) { flipY = true; b.Height = -b.Height; b.Y -= b.Height; } if (flipX || flipY) { FlipSiblingBoundsHandles(flipX, flipY); } n.Bounds = b; }
/// <summary> /// Overridden. Notifies the node whose bounds this handle is locating itself on that /// <c>SetBounds</c> will be repeatedly called. /// </summary> /// <param name="sender">The source of this handle drag event.</param> /// <param name="point">The drag position relative to the handle.</param> /// <param name="e">A PInputEventArgs that contains the event data.</param> public override void OnStartHandleDrag(object sender, PointF point, PInputEventArgs e) { base.OnStartHandleDrag(sender, point, e); PBoundsLocator l = (PBoundsLocator) Locator; l.Node.StartResizeBounds(); }
/// <summary> /// Update the marquee bounds based on the given event data. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data.</param> protected virtual void UpdateMarquee(PInputEventArgs e) { RectangleF r = RectangleF.Empty; if (marqueeParent is PCamera) { r = PUtil.AddPointToRect(r, canvasPressPt); r = PUtil.AddPointToRect(r, e.CanvasPosition); } else { r = PUtil.AddPointToRect(r, presspt); r = PUtil.AddPointToRect(r, e.Position); } marquee.Reset(); SetSafeMarqueePen(r.Width, r.Height); marquee.SetPathToRectangle(r.X, r.Y, r.Width, r.Height); r = RectangleF.Empty; r = PUtil.AddPointToRect(r, presspt); r = PUtil.AddPointToRect(r, e.Position); allItems.Clear(); PNodeFilter filter = CreateNodeFilter(r); foreach (PNode parent in selectableParents) { PNodeList items; if (parent is PCamera) { items = new PNodeList(); PCamera cameraParent = (PCamera)parent; for(int i=0; i<cameraParent.LayerCount; i++) { cameraParent.GetLayer(i).GetAllNodes(filter,items); } } else { items = parent.GetAllNodes(filter, null); } foreach (PNode node in items) { allItems.Add(node, true); } } }
/// <summary> /// Overridden. See <see cref="PDragSequenceEventHandler.OnEndDrag"> /// PDragSequenceEventHandler.OnEndDrag</see>. /// </summary> protected override void OnEndDrag(object sender, PInputEventArgs e) { base.OnEndDrag (sender, e); if (IsMarqueeSelection(e)) { EndMarqueeSelection(e); } else { EndStandardSelection(e); } }
protected override void OnEndDrag(object sender, PInputEventArgs e) { base.OnEndDrag (sender, e); UpdateSquiggle(e); squiggle = null; }
protected void UpdateSquiggle(PInputEventArgs e) { PointF p = e.Position; if (p.X != lastPoint.X || p.Y != lastPoint.Y) { squiggle.AddPoint(p); //squiggle.AddLine(lastPoint.X, lastPoint.Y, p.X, p.Y); } lastPoint = p; }
/// <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; }