/// <summary> /// Overridden. Notifies the node whose bounds this handle is locating itself on that /// the resize bounds sequence is finisheed. /// </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 OnEndHandleDrag(object sender, PointF point, PInputEventArgs e) { base.OnEndHandleDrag(sender, point, e); PBoundsLocator l = (PBoundsLocator)Locator; l.Node.EndResizeBounds(); }
/// <summary> /// Adds sticky bounds handles (with respect to the given camera) to the specified node. /// </summary> /// <param name="aNode">The node to add sticky bounds handles to.</param> /// <param name="camera">The camera to stick the bounds handles to.</param> /// <remarks> /// Sticky bounds handles are not affected by the view transform of the camera. That /// is, they will remain a constant size as the view is zoomed in and out. /// </remarks> public static void AddStickyBoundsHandlesTo(PNode aNode, PCamera camera) { camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateEastLocator(aNode))); camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateWestLocator(aNode))); camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateNorthLocator(aNode))); camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateSouthLocator(aNode))); camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateNorthEastLocator(aNode))); camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateNorthWestLocator(aNode))); camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateSouthEastLocator(aNode))); camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateSouthWestLocator(aNode))); }
/// <summary> /// Adds bounds handles to the given node. /// </summary> /// <param name="aNode">The node to add bounds handles to.</param> public static void AddBoundsHandlesTo(PNode aNode) { aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateEastLocator(aNode))); aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateWestLocator(aNode))); aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateNorthLocator(aNode))); aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateSouthLocator(aNode))); aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateNorthEastLocator(aNode))); aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateNorthWestLocator(aNode))); aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateSouthEastLocator(aNode))); aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateSouthWestLocator(aNode))); }
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 = Color.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); }
/// <summary> /// Flips this bounds handle if necessary. /// </summary> /// <param name="flipX"> /// True if this bounds handle should be flipped in the x-direction. /// </param> /// <param name="flipY"> /// True if this bounds handle should be flipped in the y-direction. /// </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 virtual void FlipHandleIfNeeded(bool flipX, bool flipY) { PBoundsLocator l = (PBoundsLocator)Locator; if (flipX || flipY) { switch (l.Side) { case Direction.North: { if (flipY) { l.Side = Direction.South; } break; } case Direction.South: { if (flipY) { l.Side = Direction.North; } break; } case Direction.East: { if (flipX) { l.Side = Direction.West; } break; } case Direction.West: { if (flipX) { l.Side = Direction.East; } break; } case Direction.NorthWest: { if (flipX && flipY) { l.Side = Direction.SouthEast; } else if (flipX) { l.Side = Direction.NorthEast; } else if (flipY) { l.Side = Direction.SouthWest; } break; } case Direction.SouthWest: { if (flipX && flipY) { l.Side = Direction.NorthEast; } else if (flipX) { l.Side = Direction.SouthEast; } else if (flipY) { l.Side = Direction.NorthWest; } break; } case Direction.NorthEast: { if (flipX && flipY) { l.Side = Direction.SouthWest; } else if (flipX) { l.Side = Direction.NorthWest; } else if (flipY) { l.Side = Direction.SouthEast; } break; } case Direction.SouthEast: { if (flipX && flipY) { l.Side = Direction.NorthWest; } else if (flipX) { l.Side = Direction.SouthWest; } else if (flipY) { l.Side = Direction.NorthEast; } break; } } } // reset locator to update layout Locator = l; }
/// <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; }