Exemplo n.º 1
0
  public boolean checkContainsPolygon(
      RectangularShape myShape, float[][] arrPointer, int numberPointer, float pX, float pY) {

    float myShapeX = myShape.getX();
    float myShapeY = myShape.getY();
    float arrPoiterTemp[][] = new float[2][numberPointer + 1];

    for (int j = 0; j <= 1; j++) {
      for (int i = 0; i < numberPointer; i++) {
        if (j == 0) {
          arrPoiterTemp[j][i] = arrPointer[j][i] + myShapeX;
        }
        if (j == 1) {
          arrPoiterTemp[j][i] = arrPointer[j][i] + myShapeY;
        }
      }
    }

    boolean c = false;
    int i, j = 0;
    for (i = 0, j = numberPointer - 1; i < numberPointer; j = i++) {
      if (((arrPoiterTemp[1][i] > pY) != (arrPoiterTemp[1][j] > pY))
          && (pX
              < (arrPoiterTemp[0][j] - arrPoiterTemp[0][i])
                      * (pY - arrPoiterTemp[1][i])
                      / (arrPoiterTemp[1][j] - arrPoiterTemp[1][i])
                  + arrPoiterTemp[0][i])) c = !c;
    }

    return c;
  }
Exemplo n.º 2
0
  /**
   * Method check Touch Point Contains A Rectangle
   *
   * @myShap: A Sprite Or AnimatedSprite on Scene
   * @x1: Axis coordinates 1 as compared to myShape
   * @x2: Axis coordinates 2 as compared to myShape
   * @y1: Axis coordinates 2 as compared to myShape
   * @y2: Axis coordinates 2 as compared to myShape
   * @pX, pY: Point Touch
   */
  public boolean checkContains(
      RectangularShape myShape, int x1, int y1, int x2, int y2, int pX, int pY) {
    boolean c = false;
    if (myShape != null) {
      int myShapeX = (int) myShape.getX();
      int myShapeY = (int) myShape.getY();

      int polyX[] = new int[] {myShapeX + x1, myShapeX + x1, myShapeX + x2, myShapeX + x2};
      int polyY[] = new int[] {myShapeY + y1, myShapeY + y2, myShapeY + y2, myShapeY + y1};

      int i, j = 0;
      for (i = 0, j = 3; i < 4; j = i++) {
        if (((polyY[i] > pY) != (polyY[j] > pY))
            && (pX < (polyX[j] - polyX[i]) * (pY - polyY[i]) / (polyY[j] - polyY[i]) + polyX[i]))
          c = !c;
      }
    }
    return c;
  }
Exemplo n.º 3
0
  private void setItem(
      final ItemType pType, final int pRow, final int pCol, RectangularShape pItem) {

    if (pItem != null)
      if (pItem.getParent() != null)
        throw new IllegalArgumentException("pItem already has a parent!");

    switch (pType) {
      case CAPTION:
        if (mCaption != null) {
          if (mCaption instanceof IMenuItem) mMenuItems.remove(mCaption);
          else detachChild(this.mCaption);
          mCaption = null;
        }
        break;
      case HEADER:
        if (mHeader[pCol] != null) {
          if (mHeader[pCol] instanceof IMenuItem) mMenuItems.remove(mHeader[pCol]);
          else detachChild(mHeader[pCol]);
          mHeader[pCol] = null;
        }
        break;
      case CELL:
        if (mCell[pRow][pCol] != null) {
          if (mCell[pRow][pCol] instanceof IMenuItem) mMenuItems.remove(mCell[pRow][pCol]);
          else detachChild(mCell[pRow][pCol]);
          mCell[pRow][pCol] = null;
        }
        break;
      case FOOTER:
        if (mFooter[pCol] != null) {
          if (mFooter[pCol] instanceof IMenuItem) mMenuItems.remove(mFooter[pCol]);
          else detachChild(mFooter[pCol]);
          mFooter[pCol] = null;
        }
        break;
    }

    if (pItem != null) {
      final GridPanelOptions opt = mOptions;

      final float paddingLeft = opt.getPanelPadding().getLeft();
      final float paddingTop = opt.getPanelPadding().getTop();

      final Margin cellMargin = opt.getCellMargin();
      final float marginLeft = cellMargin.getLeft();
      final float marginTop = cellMargin.getTop();

      final float captionHeight =
          opt.isHasCaption() ? opt.getCaptionMargin().calcOuterHeight(opt.getCaptionHeight()) : 0f;
      final float headerHeight =
          opt.isHasHeader() ? opt.getHeaderMargin().calcOuterHeight(opt.getHeaderHeight()) : 0f;

      final float colWidth = opt.getColWidth();
      final float rowHeight = opt.getRowHeight();

      final float x = paddingLeft + marginLeft + (cellMargin.calcOuterWidth(colWidth)) * pCol;
      float y = paddingTop;

      if (pType == ItemType.HEADER) y += captionHeight;
      if (pType == ItemType.CELL)
        y +=
            captionHeight
                + headerHeight
                + marginTop
                + (cellMargin.calcOuterHeight(rowHeight)) * pRow;
      if (pType == ItemType.FOOTER)
        y +=
            captionHeight
                + headerHeight
                + cellMargin.calcOuterHeight(rowHeight) * opt.getRowCount()
                + opt.getFooterMargin().getTop();

      pItem.setPosition(x, y);

      // TODO scale util
      if (pType == ItemType.CAPTION)
        if (pItem.getHeight() > opt.getCaptionHeight()) {
          pItem.setScale(opt.getCaptionHeight() / pItem.getHeight());
        }
      if (pType == ItemType.HEADER)
        if (pItem.getWidth() != colWidth || pItem.getHeight() != opt.getHeaderHeight()) {
          final float xScaleFactor = colWidth / pItem.getWidth();
          final float yScaleFactor = opt.getHeaderHeight() / pItem.getHeight();

          final float scaleFactor = Math.max(xScaleFactor, yScaleFactor);
          pItem.setScale(scaleFactor);
        }
      if (pType == ItemType.CELL)
        if (pItem.getWidth() != colWidth || pItem.getHeight() != rowHeight) {
          final float xScaleFactor = colWidth / pItem.getWidth();
          final float yScaleFactor = rowHeight / pItem.getHeight();

          final float scaleFactor = Math.max(xScaleFactor, yScaleFactor);
          pItem.setScale(scaleFactor);
        }
      if (pType == ItemType.FOOTER)
        if (pItem.getWidth() != colWidth || pItem.getHeight() != opt.getFooterHeight()) {
          final float xScaleFactor = colWidth / pItem.getWidth();
          final float yScaleFactor = opt.getFooterHeight() / pItem.getHeight();

          final float scaleFactor = Math.max(xScaleFactor, yScaleFactor);
          pItem.setScale(scaleFactor);
        }

      // TODO check skew effect
      final float angle = this.getRotation();
      this.setRotation(0);

      if (pItem instanceof IMenuItem) this.addMenuItem((IMenuItem) pItem);
      else this.attachChild(pItem);

      this.setRotation(angle);

      switch (pType) {
        case CAPTION:
          this.mCaption = pItem;
          break;
        case HEADER:
          this.mHeader[pCol] = pItem;
          break;
        case CELL:
          this.mCell[pRow][pCol] = pItem;
          break;
        case FOOTER:
          this.mFooter[pCol] = pItem;
          break;
      }
    }
  }