• ¶

    CLASS: Shape

    • Extends: Element
    • Parent: Index

    A drawable shape. Manages regions.


  • ¶
    module.exports = class Shape extends require './element'
  • ¶

    CONSTRUCTOR

    new Shape(args)

    Creates Shape instance.

      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
  • ¶

    PARAMETERS

    • args - named arguments

  • ¶

    PROPERTIES

    #regions

    • Type: Object - region name/value pairs
    • {REGION NAME}
      • Type: Array - [x, y, width, height]

  • ¶

    METHODS

    #draw(context, args)

    • Returns: Shape

    A draw method stub

      draw: -> this
  • ¶

  • ¶

    #getEventRegions(event)

    • Returns: Object - named set of matching regions

    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
  • ¶

  • ¶

    LISTENERS

    #mousemoveCaptureListener(event)

    • Returns: Shape

    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
  • ¶

    PARAMETERS

    event

    • Type: Event - captured event

  • ¶

    #mousedownCaptureListener(event)

    • Returns: Shape

    Capture mousedown events passing through this shape

      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
  • ¶

    PARAMETERS

    event

    • Type: Event - captured event

  • ¶

    #mouseupCaptureListener(event)

    • Returns: Event

    Capture mouseup events passing through this shape

      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
  • ¶

    PARAMETERS

    event

    • Type: Event - captured event