Permalink
Browse files

Add maxDragRect to draggable

  • Loading branch information...
koenbok committed May 18, 2014
1 parent d7c2135 commit 20decd2397ccae507a9dee4f34c4164bbfb0624b
Showing with 41 additions and 18 deletions.
  1. +11 −11 extras/CactusFramer/static/app.coffee
  2. +30 −7 framer/LayerDraggable.coffee
@@ -1,17 +1,17 @@
layerA = new Layer
width: 250
height: 300
midX: 200
clip: true
layerA.states.add "hello", {x:500}
layerA.y = 300
layerA.states.add "other", layerA.properties
layerA.states.switchInstant "hello"
layerA.states.switch "other"
layerA = new Layer
width: 100
height: 100
layerB = new Layer
width: 20
height: 20
superLayer: layerA
layerB.draggable.enabled = true
layerB.draggable.maxDragFrame = layerA.frame
# console.log typeof layerA.properties.visible
@@ -1,4 +1,4 @@
_ = require "./Underscore"
{_} = require "./Underscore"
Utils = require "./Utils"
{EventEmitter} = require "./EventEmitter"
@@ -27,14 +27,18 @@ class exports.LayerDraggable extends EventEmitter
constructor: (@layer) ->
# @speed = {x:1.0, y:1.0}
@speedX = 1.0
@speedY = 1.0
@_deltas = []
@_isDragging = false
@enabled = true
@speedX = 1.0
@speedY = 1.0
@maxDragFrame = null
# @resistancePointX = null
# @resistancePointY = null
# @resistanceDistance = null
@attach()
@@ -92,10 +96,29 @@ class exports.LayerDraggable extends EventEmitter
y: delta.y * @speedY
t: event.timeStamp
newX = @_start.x + correctedDelta.x - @_offset.x
newY = @_start.y + correctedDelta.y - @_offset.y
if @maxDragFrame
maxDragFrame = @maxDragFrame
maxDragFrame = maxDragFrame() if _.isFunction maxDragFrame
minX = Utils.frameGetMinX(@maxDragFrame)
maxX = Utils.frameGetMaxX(@maxDragFrame) - @layer.width
minY = Utils.frameGetMinY(@maxDragFrame)
maxY = Utils.frameGetMaxY(@maxDragFrame) - @layer.height
newX = minX if newX < minX
newX = maxX if newX > maxX
newY = minY if newY < minY
newY = maxY if newY > maxY
# We use the requestAnimationFrame to update the position
window.requestAnimationFrame =>
@layer.x = @_start.x + correctedDelta.x - @_offset.x
@layer.y = @_start.y + correctedDelta.y - @_offset.y
@layer.x = newX
@layer.y = newY
@_deltas.push correctedDelta

0 comments on commit 20decd2

Please sign in to comment.