Zoom-aware, ratio-based edge avoidance (polish for #1448).

This commit is contained in:
Nick Winter 2014-08-18 14:08:54 -07:00
parent 86ba46b64c
commit 8ca9374de0
2 changed files with 5 additions and 9 deletions

View file

@ -150,12 +150,6 @@ module.exports = class Camera extends CocoClass
#zv = Math.min(Math.max(0, worldPos.z - 5), cPos.z - 5) / (cPos.z - 5) #zv = Math.min(Math.max(0, worldPos.z - 5), cPos.z - 5) / (cPos.z - 5)
#zv * ratioWithY + (1 - zv) * ratioWithoutY #zv * ratioWithY + (1 - zv) * ratioWithoutY
distanceToTopEdge: (y) ->
@worldViewport.y - y
distanceToRightEdge: (x) ->
(@worldViewport.x + @worldViewport.width) - x
# SUBSCRIPTIONS # SUBSCRIPTIONS
onZoomIn: (e) -> @zoomTo @target, @zoom * 1.15, 300 onZoomIn: (e) -> @zoomTo @target, @zoom * 1.15, 300

View file

@ -84,7 +84,7 @@ module.exports = class CoordinateDisplay extends createjs.Container
totalHeight = contentHeight + contributionsToTotalSize.reduce (a, b) -> a + b totalHeight = contentHeight + contributionsToTotalSize.reduce (a, b) -> a + b
if @isNearTopEdge() if @isNearTopEdge()
verticalEdge = verticalEdge =
startPos: -fullPointMarkerLength startPos: -fullPointMarkerLength
posShift: -contentHeight + 4 posShift: -contentHeight + 4
else else
@ -104,10 +104,12 @@ module.exports = class CoordinateDisplay extends createjs.Container
@orient verticalEdge, horizontalEdge, totalHeight, totalWidth @orient verticalEdge, horizontalEdge, totalHeight, totalWidth
isNearTopEdge: -> isNearTopEdge: ->
@camera.distanceToTopEdge(@lastPos.y) <= 1 yRatio = 1 - (@camera.worldViewport.y - @lastPos.y) / @camera.worldViewport.height
yRatio > 0.9
isNearRightEdge: -> isNearRightEdge: ->
@camera.distanceToRightEdge(@lastPos.x) <= 4 xRatio = (@lastPos.x - @camera.worldViewport.x) / @camera.worldViewport.width
xRatio > 0.85
orient: (verticalEdge, horizontalEdge, totalHeight, totalWidth) -> orient: (verticalEdge, horizontalEdge, totalHeight, totalWidth) ->
@label.regY = @background.regY = verticalEdge.posShift @label.regY = @background.regY = verticalEdge.posShift