Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DrawRect has wrong top and left values after rotation and movement

    SmartClient Version: v10.0p_2015-10-13/PowerEdition Deployment (built 2015-10-13)
    Tested with IE11 and Chrome Version 46.0.2490.80 m (64-bit)

    Code:
    package at.qwf.test1.client;
    
    import at.qwf.test1.client.exception.ClientExceptionHandler;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.core.client.GWT;
    import com.google.gwt.core.client.Scheduler;
    import com.google.gwt.core.client.Scheduler.ScheduledCommand;
    import com.smartgwt.client.types.KnobType;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.drawing.DrawPane;
    import com.smartgwt.client.widgets.drawing.DrawRect;
    import com.smartgwt.client.widgets.drawing.events.ClickEvent;
    import com.smartgwt.client.widgets.drawing.events.ClickHandler;
    
    public class Test1 implements EntryPoint {
    
        @Override
        public void onModuleLoad() {
            GWT.setUncaughtExceptionHandler(new ClientExceptionHandler());
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
    
                @Override
                public void execute() {
                    DrawPane drawPane = new DrawPane();
                    drawPane.setWidth(800);
                    drawPane.setHeight(800);
    
                    DrawRect drawRect = new DrawRect();
                    drawRect.setKnobs(KnobType.RESIZE, KnobType.MOVE);
                    drawRect.setDrawPane(drawPane);
                    drawRect.setRect(100, 100, 200, 100);
                    drawRect.rotateTo(45.00);
    
                    drawRect.addClickHandler(new ClickHandler() {
    
                        @Override
                        public void onClick(ClickEvent event) {
                            DrawRect rect = (DrawRect) event.getSource();
                            SC.say(("Left/Top is " + rect.getLeft() + "/" + rect.getTop()));
                        }
                    });
    
                    drawPane.draw();
                }
            });
        }
    }
    Rotated rectangles have wrong top and left coordinates when they are moved.
    Please see the testcase.
    Click on the rectangle when initially drawn. Left/top should be 100/100.
    Then move the rectangle to the right. The top value is negative now.

    Doing the same test without drawRect.rotateTo(45.00) gives a correct result.



    #2
    It's complicated to explain, but the final position of the moved DrawRect can be expressed in multiple ways as a series of original coordinates and transforms, so it's not surprising, nor necessarily incorrect, that a rotated shape reports a top coordinate that doesn't obviously match the on-screen result. This is because you're accessing the top coordinate pre-transform.

    Depending on what you're trying to do, you may want instead the bounding box of the shape. This you can get with DrawItem.getResizeBoundingBox() (DrawPane-relative coordinates) or DrawItem.getPageLeft()/getPageTop() (page-relative coordinates).

    Comment


      #3
      What I'd like to do is to get the position of a drawRect relative to it's drawPane, to save it into a database and later recreate the item at the same position.

      I've tested DrawItem.getResizeBoundingBox() and DrawItem.getPageLeft()/getPageTop(), but none of them provides coordinates which I can use with setLeft() or setTop() to get the same drawItem's position for a rotated rectangle.

      The docu of getTop() says: Top coordinate in pixels relative to the DrawPane, same for getLeft(), and this is what I need.



      Comment


        #4
        Hi Isomorphic,
        anything new on this topic ?

        Comment


          #5
          Hi Isomorphic,
          20 days have passed and we still need a solution or workaround to the problem above.

          John

          Comment


            #6
            Originally posted by john_austria View Post
            What I'd like to do is to get the position of a drawRect relative to it's drawPane, to save it into a database and later recreate the item at the same position.
            In order to capture the state of a DrawItem, you'll need to store the 5 properties: rotation, scale, translate, xShearFactor and yShearFactor. The stored values can then be supplied when creating a new DrawItem to restore that state. If you choose to move to SC 10.1p, we will provide the API DrawItem.getShapeData() which returns an opaque JavaScript object representing the state (instead of having to capture all 5 properties). It can then be passed in as DrawItem.shapeData when creating a new DrawItem. (This will be in the next nightly builds of SC 10.1p and newer.)

            Any extra state specific to a DrawItem subclass, such as DrawRect.left|top|width|height, will have to be captured in addition to the DrawItem state, and also supplied when creating the DrawRect.

            The docu of getTop() says: Top coordinate in pixels relative to the DrawPane, same for getLeft(), and this is what I need.
            This should state, "relative to the local coordinate system," where the local coordinate system is described here. Sorry for the confusion - we'll fix the docs.

            Comment

            Working...
            X