<commit_before>Event = require './event'

findZones = (zones, x, y) ->
  result = {}
  result[name] = $ for name, $ of zones when (
    $[0] <= x <= ($[0] + $[2]) and $[1] <= y <= ($[1] + $[3])
  )
  return result

module.exports = class Shape extends require './element'
  constructor: (args = {}) ->
    super
    (@zones ||= {}) and @zones[key] = value for key, value of args.zones

    for name in ['draw']
      do (name) => @addListener name, ((e) -> e.stop() unless @events?[name]), yes

  mousemoveListener: (event) ->
    super
    event.zones = findZones @zones, event.localX, event.localY
    return this

  mousedownListener: (event) ->
    super
    event.zones = findZones @zones, event.localX, event.localY
    return this

  mouseupListener: (event) ->
    super
    event.zones = findZones @zones, event.localX, event.localY
    return this

  draw: (context, args) ->
    if @events?.draw then @broadcastEvent new Event
      type:'draw', target:this, context:context, args:args
    return this<commit_msg>figure out the zones in the shape<commit_after>Event = require './event'

findPointZones = (x, y, zones) ->
  result = {}
  result[name] = $ for name, $ of zones when (
    $[0] <= x <= ($[0] + $[2]) and $[1] <= y <= ($[1] + $[3])
  )
  return result

module.exports = class Shape extends require './element'
  constructor: (args = {}) ->
    super
    (@zones ||= {}) and @zones[key] = value for key, value of args.zones

    for name in ['draw']
      do (name) =>
        @addListener name, ((e) -> e.stop() unless @events?[name]), yes
        @addListener name, ((e) -> e.stop() unless @events?[name]), no

  mousemoveCaptureListener: (event) ->
    super
    if zones = findPointZones event.localX, event.localY, @zones
      event.zones = zones
      for name in ['active', 'hover', 'normal'] when zones[name]
        state = name
        break
      if (@state = state or null) then event.target = this
    return this

  mousedownCaptureListener: (event) ->
    super
    if zones = findPointZones event.localX, event.localY, @zones
      event.zones = zones
      for name in ['active', 'hover', 'normal'] when zones[name]
        state = name
        break
      if (@state = state or null) then event.target = this
    return this

  mouseupCaptureListener: (event) ->
    super
    if zones = findPointZones event.localX, event.localY, @zones
      event.zones = zones
      for name in ['active', 'hover', 'normal'] when zones[name]
        state = name
        break
      if (@state = state or null) then event.target = this
    return this

  draw: (context, args) ->
    if @events?.draw then @broadcastEvent new Event
      type:'draw', target:this, context:context, args:args
    return this
{'fraction_non_alphanumeric': 0.1485003657644477, 'fraction_numerical': 0.0043891733723482075, 'mean_word_length': 2.7880886426592797, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 20, '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': '2096822', 'n_tokens_mistral': 881, 'n_tokens_neox': 872, 'n_words': 280}