Profile Picture

When Moving a Shape, highlight the Shapes It Passes Over?

Posted By Jason Irby 14 Years Ago

When Moving a Shape, highlight the Shapes It Passes Over?

Author
Message
Jason Irby
Posted 14 Years Ago
View Quick Profile
Forum Member

Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)

Group: Forum Members
Last Active: 3 Years Ago
Posts: 59, Visits: 77

Greeting,

Say I have a simple diagram with 2 shapes on it a circle and a square.

I’m going to grab the circle and drag it over and drop it onto the square.

When that happens, I’m going to do some interesting stuff like linking them, etc. 

That’s fine.  You’ve helped me work out many of the issues up to this point.

However there is one additional behaviour that I am having trouble implementing.

As I am dragging the circle across the drawing surface, as the mouse position passed over the square, I want to highlight the square in such a way as to let the user know “hey, you can drop the circle here and we’ll do something cool”.  (I’ll probably change the fill or stroke color as an indicator.)

The problem I have is detecting when the mouse passes over the square while dragging the circle.

Since the 2 shapes were already on the drawing, Nevron does not see this as “dragOver” so that event doesn’t fire.

I guess since the preview/ghost shape of the circle is considered top z order, I don’t seem to get a mouseMove, mouseEnter event on the square underneath.

Of course this example is highly simplified but you get the general idea.  Can you give me any suggestions on how I could approach this?

 

Thanks in advance.

Jason



Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi,

Yes, you can accomplish this. Here’s a sample source code:

 

private NNodeList shapes;

 

private void CreateDiagram()

{

shapes = new List<NShape>();

      NBasicShapesFactory f = new NBasicShapesFactory(document);

      f.DefaultSize = new NSizeF(100, 100);

 

      NShape square = f.CreateShape(BasicShapes.Rectangle);

      square.Location = new NPointF(0, 0);

      document.ActiveLayer.AddChild(square);

 

      NShape circle = f.CreateShape(BasicShapes.Circle);

      circle.Location = new NPointF(0, 200);

      document.ActiveLayer.AddChild(circle);

 

      document.EventSinkService.NodeBoundsChanged += new NodeEventHandler(EventSinkService_NodeBoundsChanged);

 

      document.SizeToContent();

      shapes = document.Descendants(NFilters.Shape2D, -1);

}

 

private void EventSinkService_NodeBoundsChanged(NNodeEventArgs args)

{

      if (args.Node is NShape)

      {

            NShape draggedShape = (NShape)args.Node;

            if (draggedShape.ShapeType == ShapeType.Shape1D)

                  return;

 

            NRectangleF bounds = draggedShape.Bounds;

            bounds = view.SceneToDevice.TransformBounds(bounds);

            NHitTestContext hitTestContext = view.ProvideDocumentHitTestContext();

 

            for (int i = 0; i < shapes.Count; i++)

            {

                  NShape shape = (NShape)shapes[i];

                  if (shape == draggedShape)

                        continue;

 

                  if (shape.HitTest(bounds, hitTestContext))

                  {

                        NStyle.SetFillStyle(shape, new NColorFillStyle(KnownArgbColorValue.Red));

                  }

                  else

                  {

                        shape.Style.FillStyle = null;

                  }

            }

      }

}

 



Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic