<commit_before>###
The Drawable module is used to provide a simple draw method to the including
object.

Binds a default draw listener to draw a rectangle or a sprite, if one exists.

Binds a step listener to update the transform of the object.

Autoloads the sprite specified in I.spriteName, if any.

@name Drawable
@module
@constructor

@param {Object} I Instance variables
@param {Object} self Reference to including object
###
Drawable = (I, self) ->
  I ||= {}

  $.reverseMerge I,
    color: "#196"
    spriteName: null
    zIndex: 0

  if I.sprite?.isString?()
    I.sprite = Sprite(I.sprite, (sprite) ->
      I.width = sprite.width
      I.height = sprite.height
    )
  else if I.spriteName
    I.sprite = Sprite(I.spriteName, (sprite) ->
      I.width = sprite.width
      I.height = sprite.height
    )

  self.bind 'draw', (canvas) ->
    #TODO: Not sure if setting the transform here is the best
    # but we want to make sure it's adjusted after *all* the updates
    center = self.center()

    if I.rotation
      I.transform = Matrix.translation(center.x, center.y)
        .concat(Matrix.rotation(I.rotation))
        .concat(Matrix.translation(-I.width/2, -I.height/2))
    else
      # Assumes I.x and I.y are top-left
      I.transform = Matrix.translation(I.x, I.y)

    if I.sprite
      I.sprite.draw(canvas, 0, 0)
    else
      canvas.fillColor(I.color)
      canvas.fillRect(0, 0, I.width, I.height)

  return {}
<commit_msg>Modified in browser at pixie.strd6.com<commit_after>###
The Drawable module is used to provide a simple draw method to the including
object.

Binds a default draw listener to draw a rectangle or a sprite, if one exists.

Binds a step listener to update the transform of the object.

Autoloads the sprite specified in I.spriteName, if any.

@name Drawable
@module
@constructor

@param {Object} I Instance variables
@param {Object} self Reference to including object
###
Drawable = (I, self) ->
  I ||= {}

  $.reverseMerge I,
    color: "#196"
    spriteName: null
    zIndex: 0

  if I.sprite?.isString?()
    I.sprite = Sprite.loadByName(I.sprite, (sprite) ->
      I.width = sprite.width
      I.height = sprite.height
    )
  else if I.spriteName
    I.sprite = Sprite.loadByName(I.spriteName, (sprite) ->
      I.width = sprite.width
      I.height = sprite.height
    )

  self.bind 'draw', (canvas) ->
    #TODO: Not sure if setting the transform here is the best
    # but we want to make sure it's adjusted after *all* the updates
    center = self.center()

    if I.rotation
      I.transform = Matrix.translation(center.x, center.y)
        .concat(Matrix.rotation(I.rotation))
        .concat(Matrix.translation(-I.width/2, -I.height/2))
    else
      # Assumes I.x and I.y are top-left
      I.transform = Matrix.translation(I.x, I.y)

    if I.sprite
      I.sprite.draw(canvas, 0, 0)
    else
      canvas.fillColor(I.color)
      canvas.fillRect(0, 0, I.width, I.height)

  return {}

{'fraction_non_alphanumeric': 0.11235194585448392, 'fraction_numerical': 0.007106598984771574, 'mean_word_length': 2.746514575411914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1160127', 'n_tokens_mistral': 1003, 'n_tokens_neox': 969, 'n_words': 314}