Ejemplo n.º 1
0
  /** If mouse is inside the component's area then this will return it's depth. -1 otherwise. */
  public UIContainer checkForMouseFocus(float mouseX, float mouseY) {
    UIContainer currentTopFocus = null;

    if (active) {
      if ((mouseX > blX)
          && (mouseX < (blX + width))
          && (mouseY > blY)
          && (mouseY < (blY + height))) {
        currentTopFocus = this;
      } else {
        if (hovered) {
          hovered = false;
          onHoverOff();
        }
      }

      UIContainer childFocus = null;
      for (UIContainer c : children) {
        childFocus = c.checkForMouseFocus(mouseX - blX, mouseY - blY);

        if (childFocus != null) {
          if (currentTopFocus == null) {
            currentTopFocus = childFocus;
          } else {
            if (childFocus.getZOrder() <= currentTopFocus.getZOrder()) {
              currentTopFocus = childFocus;
            }
          }
        }
      }
    }

    return currentTopFocus;
  }