Merge pull request #1448 from TheSecretSquad/issue#1213CoordinateDisplayEdgeDetection

Issue#1213 coordinate display edge detection
This commit is contained in:
Nick Winter 2014-08-18 13:42:37 -07:00
commit 9697af6b05
2 changed files with 44 additions and 10 deletions

View file

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

View file

@ -70,36 +70,64 @@ module.exports = class CoordinateDisplay extends createjs.Container
contentWidth = @label.getMeasuredWidth() + (2 * margin)
contentHeight = @label.getMeasuredHeight() + (2 * margin)
# Shift all contents up so marker is at pointer (affects container cache position)
@label.regY = @background.regY = @pointMarker.regY = contentHeight
# Shift pointmarker up so it centers at pointer (affects container cache position)
@pointMarker.regY = contentHeight
pointMarkerStroke = 2
pointMarkerLength = 8
fullPointMarkerLength = pointMarkerLength + (pointMarkerStroke / 2)
contributionsToTotalSize = []
contributionsToTotalSize = contributionsToTotalSize.concat @updateCoordinates contentWidth, contentHeight, pointMarkerLength
contributionsToTotalSize = contributionsToTotalSize.concat @updateCoordinates contentWidth, contentHeight, fullPointMarkerLength
contributionsToTotalSize = contributionsToTotalSize.concat @updatePointMarker 0, contentHeight, pointMarkerLength, pointMarkerStroke
totalWidth = contentWidth + contributionsToTotalSize.reduce (a, b) -> a + b
totalHeight = contentHeight + contributionsToTotalSize.reduce (a, b) -> a + b
@cache -pointMarkerLength, -totalHeight + pointMarkerLength, totalWidth, totalHeight
if @isNearTopEdge()
verticalEdge =
startPos: -fullPointMarkerLength
posShift: -contentHeight + 4
else
verticalEdge =
startPos: -totalHeight + fullPointMarkerLength
posShift: contentHeight
updateCoordinates: (contentWidth, contentHeight, initialXYOffset) ->
offsetForPointMarker = initialXYOffset
if @isNearRightEdge()
horizontalEdge =
startPos: -totalWidth + fullPointMarkerLength
posShift: totalWidth
else
horizontalEdge =
startPos: -fullPointMarkerLength
posShift: 0
@orient verticalEdge, horizontalEdge, totalHeight, totalWidth
isNearTopEdge: ->
@camera.distanceToTopEdge(@lastPos.y) <= 1
isNearRightEdge: ->
@camera.distanceToRightEdge(@lastPos.x) <= 4
orient: (verticalEdge, horizontalEdge, totalHeight, totalWidth) ->
@label.regY = @background.regY = verticalEdge.posShift
@label.regX = @background.regX = horizontalEdge.posShift
@cache horizontalEdge.startPos, verticalEdge.startPos, totalWidth, totalHeight
updateCoordinates: (contentWidth, contentHeight, offset) ->
# Center label horizontally and vertically
@label.x = contentWidth / 2 - (@label.getMeasuredWidth() / 2) + offsetForPointMarker
@label.y = contentHeight / 2 - (@label.getMeasuredHeight() / 2) - offsetForPointMarker
@label.x = contentWidth / 2 - (@label.getMeasuredWidth() / 2) + offset
@label.y = contentHeight / 2 - (@label.getMeasuredHeight() / 2) - offset
@background.graphics
.clear()
.beginFill('rgba(0,0,0,0.4)')
.beginStroke('rgba(0,0,0,0.6)')
.setStrokeStyle(backgroundStroke = 1)
.drawRoundRect(offsetForPointMarker, -offsetForPointMarker, contentWidth, contentHeight, radius = 2.5)
.drawRoundRect(offset, -offset, contentWidth, contentHeight, radius = 2.5)
.endFill()
.endStroke()
contributionsToTotalSize = [offsetForPointMarker, backgroundStroke]
contributionsToTotalSize = [offset, backgroundStroke]
updatePointMarker: (centerX, centerY, length, strokeSize) ->
strokeStyle = 'square'