Permalink
Browse files

Merge pull request #388 from koenbok/feature/PointConversionProposal

Feature/point conversion proposal
  • Loading branch information...
jonastreub committed Jul 27, 2016
2 parents 85b6df4 + e601a53 commit f74b3cbf6c6277d55c9a79e054659d071653d6b1
Showing with 78 additions and 8 deletions.
  1. +9 −0 framer/Canvas.coffee
  2. +5 −8 framer/Layer.coffee
  3. +9 −0 framer/Screen.coffee
  4. +55 −0 test/tests/LayerTest.coffee
@@ -36,4 +36,13 @@ class Canvas extends BaseClass
toInspect: ->
return "<#{@constructor.name} #{@width}x#{@height}>"
# Point Conversion
convertPointToLayer: (point, layer) ->
return Utils.convertPointFromContext(point, layer, true, true)
convertPointToScreen: (point) ->
ctx = Framer.Device.context
return Utils.convertPointFromContext(point, ctx, true, true)
exports.Canvas = Canvas
@@ -400,18 +400,15 @@ class exports.Layer extends BaseClass
get: -> Utils.frameGetMaxY @
set: (value) -> Utils.frameSetMaxY @, value
convertPointFromScreen: (point) ->
return Utils.convertPointFromContext(point, @, false)
convertPointFromCanvas: (point) ->
return Utils.convertPointFromContext(point, @, true)
convertPointToScreen: (point) ->
convertPointToScreen: (point) =>
return Utils.convertPointToContext(point, @, false)
convertPointToCanvas: (point) ->
convertPointToCanvas: (point) =>
return Utils.convertPointToContext(point, @, true)
convertPointToLayer: (point, layer) =>
return Utils.convertPoint(point, @, layer, true)
@define "canvasFrame",
importable: true
exportable: false
@@ -24,6 +24,15 @@ class ScreenClass extends BaseClass
toInspect: ->
return "<Screen #{Utils.roundWhole(@width)}x#{Utils.roundWhole(@height)}>"
# Point Conversion
convertPointToLayer: (point, layer) ->
return Utils.convertPointFromContext(point, layer, false, true)
convertPointToCanvas: (point) ->
ctx = Framer.Device.context
return Utils.convertPointToContext(point, ctx, true, false)
# Edge Swipe
onEdgeSwipe:(cb) -> @on(Events.EdgeSwipe, cb)
@@ -1144,3 +1144,58 @@ describe "Layer", ->
a1.isAnimating.should.equal false
a2.isAnimating.should.equal false
a3.isAnimating.should.equal true
describe "Point conversion", ->
it "should correctly convert points from layer to Screen", ->
point =
x: 200
y: 300
layer = new Layer point: point
screenPoint = layer.convertPointToScreen()
screenPoint.x.should.equal point.x
screenPoint.y.should.equal point.y
it "should correctly convert points from Screen to layer", ->
point =
x: 300
y: 200
layer = new Layer point: point
layerPoint = Screen.convertPointToLayer({}, layer)
layerPoint.x.should.equal -point.x
layerPoint.y.should.equal -point.y
it "should correctly convert points from layer to layer", ->
layerBOffset =
x: 200
y: 400
layerA = new Layer
layerB = new Layer point: layerBOffset
layerAToLayerBPoint = layerA.convertPointToLayer({}, layerB)
layerAToLayerBPoint.x.should.equal -layerBOffset.x
layerAToLayerBPoint.y.should.equal -layerBOffset.y
it "should correctly convert points when layers are nested", ->
layerBOffset =
x: 0
y: 200
layerA = new Layer
layerB = new Layer
parent: layerA
point: layerBOffset
rotation: 90
originX: 0
originY: 0
layerAToLayerBPoint = layerA.convertPointToLayer({}, layerB)
layerAToLayerBPoint.x.should.equal -layerBOffset.y

0 comments on commit f74b3cb

Please sign in to comment.