public
Created — forked from /gist:3825036

  • Download Gist
gistfile1.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
widgetAtPoint: (point) ->
_widgetsInTouch = []
 
for widget,i in @widgets
continue if widget instanceof App.Views.TextWidget
 
if widget.getIsVisible() and widget.isPointInside(point)
_widgetsInTouch[i] = widget
 
_widgetsInTouch.sort (a, b) ->
compA = a.getZOrder()
compB = b.getZOrder()
 
if compB < compA then -1 else (if compB > compA then 1 else 0)
 
return _widgetsInTouch[0]
  widgetAtPoint: (point) ->
    widgetWithHighestZ =
      _.max @widgets, (widget) ->
        if widget.getIsVisible() and widget.isPointInside(point)
          return widget.getZOrder() unless typeof widget.getZOrder isnt "function"
    return widgetWithHighestZ if widgetWithHighestZ

    for widget,i in @widgets
      if widget.getIsVisible() and widget.isPointInside(point)
        return widget

    null
  widgetAtPoint: (point) ->
    widgetWithHighestZ =  @widgetWithHighestZAtPoint(point)
    return widgetWithHighestZ if widgetWithHighestZ

    for widget,i in @widgets
      widget if widget.getIsVisible() and widget.isPointInside(point)

    null


  widgetWithHighestZAtPoint: (point) ->
    _.max @widgets, (widget) =>
      if widget.getIsVisible() and widget.isPointInside(point)
        return widget.getZOrder() unless typeof widget.getZOrder isnt "function"
    widgetWithHighestZ if widgetWithHighestZ

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.