Skip to content

Instantly share code, notes, and snippets.

@ryanwilliams
Forked from anonymous/gist:3825036
Created October 3, 2012 20:53
Show Gist options
  • Save ryanwilliams/3829773 to your computer and use it in GitHub Desktop.
Save ryanwilliams/3829773 to your computer and use it in GitHub Desktop.
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]
@whitmanc
Copy link

whitmanc commented Oct 4, 2012

  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

@whitmanc
Copy link

whitmanc commented Oct 4, 2012

  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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment