Updated CoordinateDisplay styles; fixed #10.

This commit is contained in:
Nick Winter 2014-03-28 11:55:24 -07:00
parent ff7e2d5d47
commit 62f2fe80c3

View file

@ -23,9 +23,11 @@ module.exports = class CoordinateDisplay extends createjs.Container
build: -> build: ->
@mouseEnabled = @mouseChildren = false @mouseEnabled = @mouseChildren = false
@addChild @label = new createjs.Text("", "40px Arial", "#003300") @addChild @background = new createjs.Shape()
@label.name = 'position text' @addChild @label = new createjs.Text("", "bold 32px Arial", "#FFFFFF")
@label.shadow = new createjs.Shadow("#FFFFFF", 1, 1, 0) @label.name = 'Coordinate Display Text'
@label.shadow = new createjs.Shadow("#000000", 1, 1, 0)
@background.name = "Coordinate Display Background"
onMouseOver: (e) -> @mouseInBounds = true onMouseOver: (e) -> @mouseInBounds = true
onMouseOut: (e) -> @mouseInBounds = false onMouseOut: (e) -> @mouseInBounds = false
@ -57,17 +59,34 @@ module.exports = class CoordinateDisplay extends createjs.Container
hide: -> hide: ->
return unless @label.parent return unless @label.parent
@removeChild @label @removeChild @label
@removeChild @background
@uncache() @uncache()
updateSize: ->
margin = 6
radius = 5
width = @label.getMeasuredWidth() + 2 * margin
height = @label.getMeasuredHeight() + 2 * margin
@label.regX = @background.regX = width / 2 - margin
@label.regY = @background.regY = height / 2 - margin
@background.graphics
.clear()
.beginFill("rgba(0, 0, 0, 0.4)")
.beginStroke("rgba(0, 0, 0, 0.6)")
.setStrokeStyle(1)
.drawRoundRect(0, 0, width, height, radius)
.endFill()
.endStroke()
[width, height]
show: => show: =>
return unless @mouseInBounds and @lastPos and not @destroyed return unless @mouseInBounds and @lastPos and not @destroyed
@label.text = "(#{@lastPos.x}, #{@lastPos.y})" @label.text = "(#{@lastPos.x}, #{@lastPos.y})"
[width, height] = [@label.getMeasuredWidth(), @label.getMeasuredHeight()] [width, height] = @updateSize()
@label.regX = width / 2
@label.regY = height / 2
sup = @camera.worldToSurface @lastPos sup = @camera.worldToSurface @lastPos
@x = sup.x @x = sup.x
@y = sup.y - 7 @y = sup.y - 5
@addChild @background
@addChild @label @addChild @label
@cache -width / 2, -height / 2, width, height @cache -width / 2, -height / 2, width, height
Backbone.Mediator.publish 'surface:coordinates-shown', {} Backbone.Mediator.publish 'surface:coordinates-shown', {}