Skip to content

Instantly share code, notes, and snippets.

@masterkrang
Created July 12, 2012 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masterkrang/3101450 to your computer and use it in GitHub Desktop.
Save masterkrang/3101450 to your computer and use it in GitHub Desktop.
aslkfj
#= require ./widget
class App.Builder.Widgets.TextWidget extends App.Builder.Widgets.Widget
@newFromHash: (hash) ->
widget = super
widget.setString(hash.string) if hash.string
return widget
constructor: (options={}) ->
super
@_string = options.string
@_selection_border = null
@label = cc.LabelTTF.labelWithString(@_string, 'Arial', 24)
@label.setColor(new cc.Color3B(255, 0, 0))
@addChild(@label)
@setContentSize(@label.getContentSize())
@on('dblclick', @handleDoubleClick)
highlight: ->
super()
console.log "text widget highlight"
@drawSelection()
draw: ->
if @isHighlighted() then @drawSelection()
drawSelection: ->
console.log "text widget draw selection"
cc.renderContext.strokeStyle = "rgba(255,0,255,1)";
cc.renderContext.lineWidth = "2";
#s = @contentSize()
vertices = [cc.ccp(0, 0), cc.ccp(100, 0), cc.ccp(100, 10), cc.ccp(0, 10)]
@_selection_border = cc.drawingUtil.drawPoly(vertices, 4, true)
update: ->
console.log "update"
getString: ->
@_string
setString: (string) ->
@_string = string
@label.setString(@_string)
@setContentSize(@label.getContentSize())
@trigger('change', 'string')
handleDoubleClick: (touch, event) =>
@setString($('#font_settings').show())
#input = $('<textarea>')
#$(cc.canvas.parentNode).append(input)
#r = @rect()
#input.css(
# position: 'absolute'
# top: 100 + $(cc.canvas).position().top
# left: r.origin.x + $(cc.canvas).position().left
#)
toHash: ->
hash = super
hash.string = @_string
hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment