Permalink
Browse files

Fix layer.point

- Make defaults a copy
- Always set x, y, etc over frame, point, etc

# Conflicts:
#	framer/Layer.coffee
  • Loading branch information...
koenbok committed May 1, 2016
1 parent 1dbda74 commit e0f6509d7c993bf14c80c4a31824d28b74cf5a3b
Showing with 57 additions and 38 deletions.
  1. +10 −2 framer/Align.coffee
  2. +2 −0 framer/Defaults.coffee
  3. +45 −36 framer/Layer.coffee
View
@@ -1,10 +1,17 @@
center = (layer, property, offset=0) ->
parent = Screen
parent = layer.parent if layer.parent
borderWidth = parent.borderWidth
borderWidth ?= 0
return (parent.width / 2) - (layer.width / 2) - borderWidth + offset if property is "x"
return (parent.height / 2) - (layer.height / 2) - borderWidth + offset if property is "y"
x = (parent.width / 2) - (layer.width / 2) - borderWidth + offset
y = (parent.height / 2) - (layer.height / 2) - borderWidth + offset
return x if property is "x"
return y if property is "y"
return {x:x, y:y} if property is "point"
return 0
left = (layer, property, offset=0) ->
@@ -35,6 +42,7 @@ bottom = (layer, property, offset=0) ->
borderWidth ?= 0
return parent.height - (2 * borderWidth) - layer.height + offset
# Helper to see if we are dealing with a function or result of a function
wrapper = (f) ->
return (a, b) ->
return ((l, p) -> f(l, p, a)) if not a? or _.isNumber(a)
View
@@ -80,6 +80,8 @@ exports.Defaults =
return {} unless Originals.hasOwnProperty(className)
return {} unless Framer.Defaults.hasOwnProperty(className)
options = _.clone options
# Always start with the originals
defaults = _.clone Originals[className]
View
@@ -45,6 +45,7 @@ layerProperty = (obj, name, cssProperty, fallback, validator, transformer, optio
layerValueTypeError(name, value)
@_properties[name] = value
if cssProperty != null
@_element.style[cssProperty] = LayerStyle[cssProperty](@)
@@ -84,12 +85,7 @@ class exports.Layer extends BaseClass
# We have to create the element before we set the defaults
@_createElement()
if options.hasOwnProperty "frame"
options = _.extend(options, options.frame)
options = Defaults.getDefaults "Layer", options
super options
super Defaults.getDefaults("Layer", options)
# Add this layer to the current context
@_context.addLayer(@)
@@ -106,12 +102,15 @@ class exports.Layer extends BaseClass
else
@parent = options.parent
# If an index was set, we would like to use that one
if options.hasOwnProperty("index")
@index = options.index
# Set some calculated properties
for p in ["index", "point", "size", "frame"]
if options.hasOwnProperty(p)
@[p] = options[p]
@x = options.x if options.hasOwnProperty("x")
@y = options.y if options.hasOwnProperty("y")
# x and y always win from point, frame or size
for p in ["x", "y", "width", "height"]
if options.hasOwnProperty(p)
@[p] = options[p]
@_context.emit("layer:create", @)
@@ -303,37 +302,13 @@ class exports.Layer extends BaseClass
##############################################################
# Geometry
# @define "point",
# get: -> _.pick(@, ["x", "y"])
# set: (point) ->
# return if not point
# point = {x: point, y: point} if _.isNumber(point)
# for k in ["x", "y"]
# @[k] = point[k] if point.hasOwnProperty(k)
# @define "size",
# get: -> _.pick(@, ["width", "height"])
# set: (size) ->
# return if not size
# size = {width: size, height: size} if _.isNumber(size)
# for k in ["width", "height"]
# @[k] = size[k] if size.hasOwnProperty(k)
# @define "frame",
# get: -> _.pick(@, ["x", "y", "width", "height"])
# set: (frame) ->
# return if not frame
# for k in ["x", "y", "width", "height"]
# @[k] = frame[k] if frame.hasOwnProperty(k)
_setGeometryValues: (input, keys) ->
# If this is a number, we set everything to that number
if _.isNumber(input)
for k in keys
@[k] = input
else
# If there is nothing to work with we exit
return unless input
@@ -343,7 +318,9 @@ class exports.Layer extends BaseClass
@define "point",
get: -> Utils.point(@)
set: (input) -> @_setGeometryValues(input, ["x", "y"])
set: (input) ->
input = layerPropertyPointTransformer(input, @, "point")
@_setGeometryValues(input, ["x", "y"])
@define "size",
get: -> Utils.size(@)
@@ -1137,6 +1114,38 @@ class exports.Layer extends BaseClass
onRotateStart:(cb) -> @on(Events.RotateStart, cb)
onRotateEnd:(cb) -> @on(Events.RotateEnd, cb)
##############################################################
## HINT
shouldShowHint: ->
return true if @ignoreEvents is false
return false
showHint: ->
if not @shouldShowHint()
return _.invoke(@children, "showHint")
color = new Color(40, 175, 250)
layer = new Layer
frame: @canvasFrame
backgroundColor: new Color(40, 175, 250, 0.4)
borderColor: new Color("white").alpha(.5)
borderRadius: @borderRadius * Utils.average([@canvasScaleX(), @canvasScaleY()])
borderWidth: 1
animation = layer.animate
properties:
opacity: 0
time: 0.4
animation.onAnimationEnd ->
layer.destroy()
_.invoke(@children, "showHint")
##############################################################
## DESCRIPTOR

0 comments on commit e0f6509

Please sign in to comment.