Right Click Position When Zoomed

4 posts, 0 answers
  1. Don
    Don avatar
    40 posts
    Member since:
    Apr 2009

    Posted 01 Sep 2014 Link to this post

    When a user right clicks in the diagram when it is zoomed, the mouse position does not match the coordinates of the diagram.

    Point p = context.MousePosition;
    pastePoint = new Point(zoomFact * p.X, zoomFact * p.Y);
    Point mfTestPoint = Application.Current.RootVisual.TransformToVisual(currentDiagram.DocumentPlane).Transform(pastePoint);
     
    DiagramNode clickedItem3 = currentDiagram.GetNodeAt(pastePoint, false, true);
    CustomDiagramLink clickedItem4 = (CustomDiagramLink)currentDiagram.GetLinkAt(pastePoint, 5, true);

    I tried using the zoom factor as a modifier to find the object on the diagram but that doesn't work either. The original version of this method just used the mouse position as the pastePoint and that works fine when not zoomed. How should I handle finding the object that is right clicked so that the context menu can be modified depending on what the user clicks on.

    PS this is a deployed application and the version can't be changed. It is currently using version 2.3.0.16766.
  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 02 Sep 2014 Link to this post

    Hi Donald,

    The coordinate system of the RadDiagram is not directly related to the application's coordinates. When the diagram is not zoomed the coordinates match but when you zoom there is a noticeable difference based on the zoom factor.

    However, the diagram exposes GetTransformedPoint() method that transforms a Point from the screen to a Point from the diagram. 

    Point p = context.MousePosition;
    var transformedPoint = this.diagram.GetTransformedPoint(mousePos);

    A possible approach for finding the object that is right clicked is to listen for the MouseRightButtonDown event of the diagram and in its handler to get the shape that has its IsMouseOver property set to True. Here is an example:

    var shapeUnderMouse = this.diagram.Shapes.FirstOrDefault(x => x.IsMouseOver);
    if (shape != null)
    {
        // execute your logic here
    }

    Please let me know if this helps.

    Regards,
    Martin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. DevCraft banner
  4. Don
    Don avatar
    40 posts
    Member since:
    Apr 2009

    Posted 02 Sep 2014 in reply to Martin Link to this post

    Can you tell me what version of the control GetTransformedPoint was implemented in? The version that is deployed in that application does not have that method. The version of control we are using is 2.3.0.16766. (Yea I know but it is out of my hands)
  5. Don
    Don avatar
    40 posts
    Member since:
    Apr 2009

    Posted 02 Sep 2014 Link to this post

    Never mind. I figured it out and the control does have the method. It appears to work. Thank you.
Back to Top