Permalink
Browse files

Fix draggable/pinachable weird offsets

  • Loading branch information...
koenbok committed Jan 27, 2016
1 parent 75a62be commit c420611952e8827b2f5bce405394973cbcfc944e
Showing with 24 additions and 12 deletions.
  1. +24 −12 framer/LayerPinchable.coffee
@@ -41,28 +41,40 @@ class exports.LayerPinchable extends BaseClass
@layer.on(Gestures.PinchStart, @_pinchStart)
@layer.on(Gestures.Pinch, @_pinch)
@layer.on(Gestures.PinchEnd, @_pinchEnd)
@layer.on(Gestures.TapStart, @_tapStart)
_reset: ->
@_scaleStart = null
@_rotationStart = null
@_rotationOffset = null
_pinchStart: (event) =>
_tapStart: (event) ->
#@_centerOrigin(event) if @centerOrigin
@_reset()
_centerOrigin: (event) =>
topInSuperBefore = Utils.convertPoint({}, @layer, @layer.superLayer)
pinchLocation = Utils.convertPointFromContext(event.touchCenter, @layer, true, true)
@layer.originX = pinchLocation.x / @layer.width
@layer.originY = pinchLocation.y / @layer.height
if @centerOrigin
topInSuperAfter = Utils.convertPoint({}, @layer, @layer.superLayer)
xDiff = topInSuperAfter.x - topInSuperBefore.x
yDiff = topInSuperAfter.y - topInSuperBefore.y
@layer.x -= xDiff
@layer.y -= yDiff
topInSuperBefore = Utils.convertPoint({}, @layer, @layer.superLayer)
pinchLocation = Utils.convertPointFromContext(event.touchCenter, @layer, true, true)
@layer.originX = pinchLocation.x / @layer.width
@layer.originY = pinchLocation.y / @layer.height
# This is not a great fix, we should add this in the draggable. Basically
# we need to account in the draggable for a change of origin relative to
# the dragging start offset.
if @layer._draggable
@layer.draggable._layerStartPoint.x -= xDiff
@layer.draggable._layerStartPoint.y -= yDiff

This comment has been minimized.

@koenbok

koenbok Jan 27, 2016

Owner

@jonastreub this is the fix! Do you have a good idea how we could add this to the draggable? Basically we need to store the start origin and correct the start offset if we notice the origin has been changed.

topInSuperAfter = Utils.convertPoint({}, @layer, @layer.superLayer)
xDiff = topInSuperAfter.x - topInSuperBefore.x
yDiff = topInSuperAfter.y - topInSuperBefore.y
@layer.x -= xDiff
@layer.y -= yDiff
_pinchStart: (event) =>
@_reset()
@_centerOrigin(event) if @centerOrigin
_pinch: (event) =>

0 comments on commit c420611

Please sign in to comment.