dialect "rtobjectdraw"

def betterDrag: GraphicApplication = object {
    inherit graphicApplicationSize (400 @ 400)

    // location and size of block
    def upperLeft: Point = 100 @ 120
    def dimensions: Point = 60 @ 60
  
    // create the block to be dragged
    def block:Graphic2D = 
                framedRectAt (upperLeft) size (dimensions) on (canvas)
   
    var lastPoint: Point
   
    method onMousePress (pt: Point) -> Done {
        lastPoint := pt
    }
   
    method onMouseDrag(point: Point) -> Done {
        if (block.contains (lastPoint)) then {
            block.moveBy (point.x - lastPoint.x, point.y - lastPoint.y)
            lastPoint := point
        }
    }
   
    startGraphics
}
