Skip to content

Commit

Permalink
fix origin when pinch starts
Browse files Browse the repository at this point in the history
  • Loading branch information
J.P.P Treub committed Jan 21, 2016
1 parent 56b653a commit f985fbb
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions framer/LayerPinchable.coffee
Expand Up @@ -34,7 +34,6 @@ class exports.LayerPinchable extends BaseClass


constructor: (@layer) -> constructor: (@layer) ->
super super

@_attach() @_attach()


_attach: -> _attach: ->
Expand All @@ -53,6 +52,18 @@ class exports.LayerPinchable extends BaseClass
@emit(Events.ScaleStart, event) if @scale @emit(Events.ScaleStart, event) if @scale
@emit(Events.RotateStart, event) if @rotate @emit(Events.RotateStart, event) if @rotate


if @setOrigin

topInSuperBefore = Utils.convertPoint({}, @layer, @layer.superLayer)
pinchLocation = Utils.convertPointFromContext(event.center, @layer, true, true)
@layer.originX = pinchLocation.x / @layer.width
@layer.originY = pinchLocation.y / @layer.height
topInSuperAfter = Utils.convertPoint({}, @layer, @layer.superLayer)
xDiff = topInSuperAfter.x - topInSuperBefore.x
yDiff = topInSuperAfter.y - topInSuperBefore.y
@layer.x -= xDiff
@layer.y -= yDiff

_pinchMove: (event) => _pinchMove: (event) =>


return unless event.pointers.length is 2 return unless event.pointers.length is 2
Expand All @@ -68,9 +79,6 @@ class exports.LayerPinchable extends BaseClass


return unless Utils.pointTotal(Utils.pointAbs(Utils.pointSubtract(pointA, pointB))) > @threshold return unless Utils.pointTotal(Utils.pointAbs(Utils.pointSubtract(pointA, pointB))) > @threshold


# TODO
# if @setOrigin

if @scale if @scale
@_scaleStart ?= @layer.scale @_scaleStart ?= @layer.scale
scale = event.scale * @_scaleStart scale = event.scale * @_scaleStart
Expand Down

0 comments on commit f985fbb

Please sign in to comment.