Announcement

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

    DrawImage resize by mouse - BUG or wrong expectations?

    Hello!

    For
    - smartGWT 5.1p - v10.0p_2014-10-07/LGPL Development Only (built 2014-10-07)
    - FF 31.5.0 (didn't test on other browsers)

    Problem
    When I'm resizing an Image by mouse drag, the new dimensions of the image are wrong when releasing the mouse button.

    Description
    To show what happens I created a class which adds an Image with two handlers that I need in my real code (DragResizeStop and Resized - in both these I will need to run some logic in my actual code). After DragResizeStop fires the Resized is fired and new values (different from what I would expect) for Width/Height are automatically applied to the object. To force the correct dimensions to be applied I set the Width/Height in the DragResizeStop with the values I take from the "event" object but they are overwritten automatically when the Resized triggers. The visual appearance of the Image is not modified but it's dimensions in pixels are wrong.

    To exemplify I created the class below:
    - Local image
    - both handlers (DragResizeStop and Resized)
    - added some logs
    - in DragResizeStop I set the new Width and new Height from the "event" object to the Image and I print them in the logs
    - when entering the Resized I just print the values from the Image object and they are different from the above ones.

    What I would expect is that the Image's width/height are updated with the correct values when I release the mouse button - event.getNewWidth() and event.getNewHeight().
    It seems that when the Resized is fired, some old (intermediate) values for W/H are applied and not the ones corresponding to the position where the mouse button was released.

    Any thoughts? Have I misunderstand they way this works?

    Thanks in advance!

    P.S: same goes for DrawRect (I haven't tested for other draw items)


    Running the code below, after a resize by mouse this is what I see in the logs:

    Code:
    11:39:13.332:MUP2:INFO:Log:+++++DragResizeStop (image): WxH - 346x203
    11:39:13.332:MUP2:INFO:Log:+++++DragResizeStop (event): WxH - 346x203
    11:39:13.338:MUP2:INFO:Log:*****Resized (image): WxH - 442x234
    Code:
    public class TestResize {
    	
    	public void drawDesign() {
    
    		Layout mainLayout = new Layout();
    		mainLayout.setBorder("1px solid black");
    		
    		DrawPane shapesPane = new DrawPane();
    		shapesPane.setCanDrag(true);
    		shapesPane.setTop(0);
    		shapesPane.setLeft(0);
    		shapesPane.setWidth(1200);
    		shapesPane.setHeight(800);
    		shapesPane.setOverflow(Overflow.HIDDEN);
    
    		final DrawImage image = new DrawImage();
    		image.setSrc("cow.jpg");
    		image.setTop(50);
    		image.setLeft(50);
    		image.setWidth(200);
    		image.setHeight(200);
    		image.showAllKnobs();
    		image.setDrawPane(shapesPane);
    		image.setCanDrag(true);
    		image.setShowResizeOutline(true);
    		
    		image.addDragResizeStopHandler(new DragResizeStopHandler() {
    			@Override
    			public void onDragResizeStop(DragResizeStopEvent event) {
    				image.setWidth(event.getNewWidth());
    				image.setHeight(event.getNewHeight());
    				// here the correct values are applied on the Image
    				SC.logInfo("+++++DragResizeStop (image): WxH - " + image.getWidth() + "x" + image.getHeight());
    				SC.logInfo("+++++DragResizeStop (event): WxH - " + event.getNewWidth() + "x" + event.getNewHeight());
    			}
    		});
    		
    		image.addResizedHandler(new ResizedHandler() {
    			@Override
    			public void onResized(ResizedEvent event) {
    				// here some other values are present (old or intermediate ones)
    				SC.logInfo("*****Resized (image): WxH - " + image.getWidth() + "x" + image.getHeight());
    			}
    		});
    		
    		image.draw();
    	
    		shapesPane.draw();
    
    		mainLayout.addMember(shapesPane);
    	}
    }

    #2
    You are simply seeing the original dimensions of the DrawImage, since in dragResizeStop, the change in size is not yet permanent - the drag can still be cancelled.

    Comment


      #3
      Well, I can tell you they are definitely not the original ones, but some intermediate values that always have the same incremental steps in one go (for example, for one process of resizing the Height is increased/decreased once the mouse goes over 43 pixels until the button is released. If another resize starts, then this value is changed but the same pattern is applied for the whole period of that drag-resize, the H is increased/decreased in steps of, let's say 83 pixels). I hope it is not too bad explained (english isn't my native language, sorry) :)

      Anyhow, if I understand correctly your answer (though I'm not really sure what you mean by "the drag can still be cancelled" if it is from the code point of view, or user point of view), shouldn't this mean that if the drag is successfully ended let's say, the real new dimensions (where the mouse is released) will be applied at some point? Where/when is that point?

      Thanks!

      Comment


        #4
        We do see an issue while running your sample code and are analyzing the best way to address it.

        Comment


          #5
          Thank you! I'll make sure to watch the thread closely for news.

          Have to say just that the same applies to DrawRect (and possibly other Draw Items, I didn't test all of them)

          Comment


            #6
            This should be fixed for SC 10.0p/SGWT 5.0p and newer in the nightly builds marked 4-25-15. If there are still issues remaining you'll have to post sample code.

            Comment


              #7
              Great stuff! It works fine for DrawImage now. Still issues for Rect/Oval/Triangle, but I'll get back to you with a complete code to include all of them for testing.

              Thanks again!

              Comment


                #8
                Hi again!

                Seems that some issues are present with DrawRect and DrawOval as well. Not sure how to interpret this, to be honest :)

                This is with the new version - v10.0p_2015-04-27/LGPL Development Only (built 2015-04-27)

                What happens is that when resizing one of those items by mouse, after releasing the button, the correct width/height are automatically applied, but the "event" object in the last event triggered (DragResizeStop) contains slightly different values than the ones applied on the DrawItem.

                Code:
                11:53:47.602:MUP0:INFO:Log:+++++DragResizeStop (rectangle): WxH - 547x236
                11:53:47.602:MUP0:INFO:Log:+++++DragResizeStop (event): WxH - 551x240
                The "547x236" are the correct values, but the event.getNewWidth() and event.getNewHeight() in the same event return "551x240". If I were to use these values for something (I don't in my code example, but there might be situations where they would be needed) they would be wrong.

                Here you have a code sample that contains both items (oval and rectangle). Hope this helps.

                Thanks!

                Code:
                public class TestResize {
                	
                	public void drawDesign() {
                
                		Layout mainLayout = new Layout();
                		mainLayout.setBorder("1px solid black");
                		
                		DrawPane shapesPane = new DrawPane();
                		shapesPane.setCanDrag(true);
                		shapesPane.setTop(0);
                		shapesPane.setLeft(0);
                		shapesPane.setWidth(1200);
                		shapesPane.setHeight(800);
                		shapesPane.setOverflow(Overflow.HIDDEN);
                		
                		//============================= RECTANGLE
                		
                		final DrawRect rect = new DrawRect();
                		rect.setTop(130);
                		rect.setLeft(0);
                		rect.setWidth(100);
                		rect.setHeight(100);
                		rect.showAllKnobs();
                		rect.setDrawPane(shapesPane);
                		rect.setCanDrag(true);
                		rect.setShowResizeOutline(true);
                		
                		rect.addDragResizeStopHandler(new DragResizeStopHandler() {
                			@Override
                			public void onDragResizeStop(DragResizeStopEvent event) {
                				SC.logInfo("+++++DragResizeStop (rectangle): WxH - " + rect.getWidth() + "x" + rect.getHeight());
                				SC.logInfo("+++++DragResizeStop (event): WxH - " + event.getNewWidth() + "x" + event.getNewHeight());
                			}
                		});
                		
                		rect.addResizedHandler(new ResizedHandler() {
                			@Override
                			public void onResized(ResizedEvent event) {
                				SC.logInfo("*****Resized (rectangle): WxH - " + rect.getWidth() + "x" + rect.getHeight());
                			}
                		});
                		
                		//============================= OVAL
                		
                		final DrawOval oval = new DrawOval();
                		oval.setTop(300);
                		oval.setLeft(0);
                		oval.setWidth(100);
                		oval.setHeight(100);
                		oval.showAllKnobs();
                		oval.setDrawPane(shapesPane);
                		oval.setCanDrag(true);
                		oval.setShowResizeOutline(true);
                		
                		oval.addDragResizeStopHandler(new DragResizeStopHandler() {
                			@Override
                			public void onDragResizeStop(DragResizeStopEvent event) {
                				SC.logInfo("+++++DragResizeStop (oval): WxH - " + oval.getWidth() + "x" + oval.getHeight());
                				SC.logInfo("+++++DragResizeStop (event): WxH - " + event.getNewWidth() + "x" + event.getNewHeight());
                			}
                		});
                		
                		oval.addResizedHandler(new ResizedHandler() {
                			@Override
                			public void onResized(ResizedEvent event) {
                				SC.logInfo("*****Resized (oval): WxH - " + oval.getWidth() + "x" + oval.getHeight());
                			}
                		});
                		
                		shapesPane.draw();
                
                		mainLayout.addMember(shapesPane);
                	}
                }

                Comment


                  #9
                  We're looking into this, but it does appear that at the moment you're not being impacted by the issue.

                  Comment


                    #10
                    Hi,

                    well, in my actual code I am setting manually the dimensions using the ones from "event" object. I did this because of the bug you already solved (dimensions were not updated and only the "event" object had the final ones). Now I have to change that and let the framework handle the values. But yes, you can say it doesn't have such a big impact.

                    But, I have a question though, as I understand this will be a lower prio for you, is there a way for me to find out when it gets solved?

                    Thank you!

                    Comment


                      #11
                      We'll update this thread when the issue is resolved.

                      Comment


                        #12
                        That's great! Thanks!

                        Comment

                        Working...
                        X