module.exports = class Shape extends require './element'
module.exports = class Shape extends require './element'
constructor: ->
super
Copy the element regions if they were set from named arguments
if regions = @regions
@regions = {}
@regions[name] = region for name, region of regions
draw: -> this
Helper method, to get element regions that match the event.
getEventRegions: (event) ->
result = null
Proceed only if event coordinates are localized
if event and (x = event.localX)? and (y = event.localY)?
Walk through the element regions
for name, $ of @regions
and add the region to the result if event localized coordinates are within the region rectangle.
if $[0] <= x <= ($[0] + $[2]) and $[1] <= y <= ($[1] + $[3])
Initialize result only if at least one region matches
result or= {}
result[name] = $
return result
Capture mousemove events passing through this shape
mousemoveCaptureListener: (event) ->
super
Proceed only for valid event
if event
Check if there are any regions that match the event, store them in the event and set this shape as event target
event.target = this if event.regions = @getEventRegions event
return this
mousedownCaptureListener: (event) ->
super
Proceed only for valid event
if event
Check if there are any regions that match the event, store them in the event and set this shape as event target
event.target = this if event.regions = @getEventRegions event
return this
mouseupCaptureListener: (event) ->
super
Proceed only for valid event
if event
Check if there are any regions that match the event, store them in the event and set this shape as event target
event.target = this if event.regions = @getEventRegions event
return this