public void drawRect(float l, float t, float r, float b, Paint paint) {
   final int tilel = max(0, (int) FloatMath.floor((l - INVALIDATE_PADDING) / mTileSize));
   final int tilet = max(0, (int) FloatMath.floor((t - INVALIDATE_PADDING) / mTileSize));
   final int tiler = min(mTilesX - 1, (int) FloatMath.floor((r + INVALIDATE_PADDING) / mTileSize));
   final int tileb = min(mTilesY - 1, (int) FloatMath.floor((b + INVALIDATE_PADDING) / mTileSize));
   for (int tiley = tilet; tiley <= tileb; tiley++) {
     for (int tilex = tilel; tilex <= tiler; tilex++) {
       final Tile tile = mTiles[tiley * mTilesX + tilex];
       getDrawingCanvas(tile).drawRect(l, t, r, b, paint);
       tile.dirty = true;
     }
   }
 }
 public void drawCircle(float x, float y, float r, Paint paint) {
   final float invalR = r + INVALIDATE_PADDING;
   final int tilel = max(0, (int) FloatMath.floor((x - invalR) / mTileSize));
   final int tilet = max(0, (int) FloatMath.floor((y - invalR) / mTileSize));
   final int tiler = min(mTilesX - 1, (int) FloatMath.floor((x + invalR) / mTileSize));
   final int tileb = min(mTilesY - 1, (int) FloatMath.floor((y + invalR) / mTileSize));
   for (int tiley = tilet; tiley <= tileb; tiley++) {
     for (int tilex = tilel; tilex <= tiler; tilex++) {
       final Tile tile = mTiles[tiley * mTilesX + tilex];
       getDrawingCanvas(tile).drawCircle(x, y, r, paint);
       tile.dirty = true;
     }
   }
 }
  private boolean handleOnTouch(View v, MotionEvent event) {
    int action = event.getAction() & MotionEvent.ACTION_MASK;
    int x1 = 0;
    int y1 = 0;
    int x2 = 0;
    int y2 = 0;
    switch (action) {
        // define the region the touch event is beginning in
      case MotionEvent.ACTION_DOWN:
        {
          motorHandler.calcMotorSpeeds(x1, y1, x2, y2);
          break;
        }
        // touch has left screen - take note of this
      case MotionEvent.ACTION_UP:
        {
          motorHandler.calcMotorSpeeds(x1, y1, x2, y2);
          break;
        }

        // define the region the touch event is beginning in
      case MotionEvent.ACTION_POINTER_DOWN:
        {
          motorHandler.calcMotorSpeeds(x1, y1, x2, y2);
          break;
        }

        // touch has left screen - take note of this
      case MotionEvent.ACTION_POINTER_UP:
        {
          motorHandler.calcMotorSpeeds(x1, y1, x2, y2);
          break;
        }

      case MotionEvent.ACTION_MOVE:
        {
          x1 = (int) FloatMath.floor(event.getX(0));
          y1 = (int) FloatMath.floor(event.getY(0));
          if (event.getPointerCount() > 1) {
            x2 = (int) FloatMath.floor(event.getX(1));
            y2 = (int) FloatMath.floor(event.getY(1));
          }
          motorHandler.calcMotorSpeeds(x1, y1, x2, y2);
          break;
        }
    }
    return true;
  }
 private int getScrollRange() {
   return (int)
       Math.max(
           0,
           FloatMath.floor(mRefreshableView.getContentHeight() * mRefreshableView.getScale())
               - (getHeight() - getPaddingBottom() - getPaddingTop()));
 }
 @Override
 public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) {
   final int tilel = max(0, (int) FloatMath.floor((dst.left - INVALIDATE_PADDING) / mTileSize));
   final int tilet = max(0, (int) FloatMath.floor((dst.top - INVALIDATE_PADDING) / mTileSize));
   final int tiler =
       min(mTilesX - 1, (int) FloatMath.floor((dst.right + INVALIDATE_PADDING) / mTileSize));
   final int tileb =
       min(mTilesY - 1, (int) FloatMath.floor((dst.bottom + INVALIDATE_PADDING) / mTileSize));
   for (int tiley = tilet; tiley <= tileb; tiley++) {
     for (int tilex = tilel; tilex <= tiler; tilex++) {
       final Tile tile = mTiles[tiley * mTilesX + tilex];
       getDrawingCanvas(tile).drawBitmap(bitmap, src, dst, paint);
       tile.dirty = true;
     }
   }
 }
 @Override
 public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) {
   RectF dst = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
   matrix.mapRect(dst);
   final int tilel = max(0, (int) FloatMath.floor((dst.left - INVALIDATE_PADDING) / mTileSize));
   final int tilet = max(0, (int) FloatMath.floor((dst.top - INVALIDATE_PADDING) / mTileSize));
   final int tiler =
       min(mTilesX - 1, (int) FloatMath.floor((dst.right + INVALIDATE_PADDING) / mTileSize));
   final int tileb =
       min(mTilesY - 1, (int) FloatMath.floor((dst.bottom + INVALIDATE_PADDING) / mTileSize));
   for (int tiley = tilet; tiley <= tileb; tiley++) {
     for (int tilex = tilel; tilex <= tiler; tilex++) {
       final Tile tile = mTiles[tiley * mTilesX + tilex];
       getDrawingCanvas(tile).drawBitmap(bitmap, matrix, paint);
       tile.dirty = true;
     }
   }
 }
  protected Region getRegion(final PointF startPoint, final PointF endPoint) {
    final float width = getWidth();
    final float height = getHeight();
    final float xStep = width / GRID_X;
    final float yStep = height / GRID_Y;

    final float cellWidth = 100 / GRID_X;
    final float cellHeight = 100 / GRID_X;

    float left = MathUtils.fmin(startPoint.x, endPoint.x);
    float right = MathUtils.fmax(startPoint.x, endPoint.x);
    float top = MathUtils.fmin(startPoint.y, endPoint.y);
    float bottom = MathUtils.fmax(startPoint.y, endPoint.y);

    left = cellWidth * FloatMath.floor(left / xStep);
    right = cellWidth * FloatMath.floor(right / xStep) + cellWidth;
    top = cellHeight * FloatMath.floor(top / yStep);
    bottom = cellHeight * FloatMath.floor(bottom / yStep) + cellHeight;

    return new Region(MathUtils.rect(left, top, right, bottom));
  }
  private void invalidateAfterUpdate() {
    View view = mView.get();
    if (view == null) {
      return;
    }
    View parent = (View) view.getParent();
    if (parent == null) {
      return;
    }

    view.setAnimation(this);

    final RectF after = mAfter;
    computeRect(after, view);
    after.union(mBefore);

    parent.invalidate(
        (int) FloatMath.floor(after.left),
        (int) FloatMath.floor(after.top),
        (int) FloatMath.ceil(after.right),
        (int) FloatMath.ceil(after.bottom));
  }
  // ____________________________________________________________________________________
  public AmountSelector(Listener listener, Activity context, Tileset tileset, MenuItem item) {
    mItem = item;
    mListener = listener;
    mMax = item.getMaxCount();

    mRoot = Util.inflate(context, R.layout.amount_selector, R.id.dlg_frame);
    ImageView tileView = (ImageView) mRoot.findViewById(R.id.amount_tile);
    final SeekBar seek = ((SeekBar) mRoot.findViewById(R.id.amount_slider));
    if (item.getTile() != 0 && tileset.hasTiles()) {
      tileView.setVisibility(View.VISIBLE);
      tileView.setImageDrawable(new TileDrawable(tileset, item.getTile()));
    } else {
      tileView.setVisibility(View.GONE);
    }

    ((TextView) mRoot.findViewById(R.id.amount_title)).setText(" " + item.getName().toString());

    mAmountText = (TextView) mRoot.findViewById(R.id.amount);
    int pad = 9;
    while (pad <= mMax) pad = pad * 10 + 9;
    int w = (int) FloatMath.floor(mAmountText.getPaint().measureText(" " + Integer.toString(pad)));
    mAmountText.setWidth(w);

    seek.setOnSeekBarChangeListener(
        new OnSeekBarChangeListener() {
          public void onStopTrackingTouch(SeekBar seekBar) {}

          public void onStartTrackingTouch(SeekBar seekBar) {}

          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mAmountText.setText(Integer.toString(progress));
          }
        });
    seek.setMax(mMax);
    seek.setProgress(mMax);

    mRoot
        .findViewById(R.id.btn_inc)
        .setOnTouchListener(
            new OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                  mAmountTuner.start(v, seek, true);
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                  mAmountTuner.stop(v);
                }
                return true;
              }
            });

    mRoot
        .findViewById(R.id.btn_dec)
        .setOnTouchListener(
            new OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                  mAmountTuner.start(v, seek, false);
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                  mAmountTuner.stop(v);
                }
                return true;
              }
            });

    mRoot
        .findViewById(R.id.btn_0)
        .setOnClickListener(
            new OnClickListener() {
              public void onClick(View v) {
                if (mRoot != null) {
                  dismiss(seek.getProgress());
                }
              }
            });
    mRoot
        .findViewById(R.id.btn_1)
        .setOnClickListener(
            new OnClickListener() {
              public void onClick(View v) {
                dismiss(-1);
              }
            });

    seek.requestFocus();
    seek.requestFocusFromTouch();
  }
 @Override
 protected boolean isReadyForPullEnd() {
   float exactContentHeight =
       FloatMath.floor(mRefreshableView.getContentHeight() * mRefreshableView.getScale());
   return mRefreshableView.getScrollY() >= (exactContentHeight - mRefreshableView.getHeight());
 }
  @Override
  protected void drawContent(GL10 gl) {
    vecE.draw(gl);
    vecS.draw(gl);

    Vec3 vecSv = new Vec3(vecS.vec());

    float SS = vecSv.Norm();
    vecSv.normalize(); // とりあえず長さを1に。
    float vSt = vecSv.Theta() + (float) (Math.PI * 0.5);
    float vSp = vecSv.Phi();

    Vec3 vecS1 =
        new Vec3(
            FloatMath.sin(vSt) * FloatMath.cos(vSp),
            FloatMath.sin(vSt) * FloatMath.sin(vSp),
            FloatMath.cos(vSt));
    Vec3 vecS2 = vecS1.Cross(vecSv);

    vecS1.mul(SS); // 長さを100に。
    vecS2.mul(SS); // 長さを100に。

    float tt = t - FloatMath.floor(t);

    float vEx = vecE.vec().X() * tt;
    float vEy = vecE.vec().Y() * tt;
    float vEz = vecE.vec().Z() * tt;
    Vec3 vE = new Vec3(vEx, vEy, vEz);

    int i;
    for (i = 0; i < 200; i++) {
      s[i].setPos(vE);
      s[i].draw(gl);
    }

    vertices = new float[12];
    vertices[0] = 0f;
    vertices[1] = 0f;
    vertices[2] = 0f;
    vertices[3] = vecS1.X();
    vertices[4] = vecS1.Y();
    vertices[5] = vecS1.Z();
    vertices[6] = vecS2.X();
    vertices[7] = vecS2.Y();
    vertices[8] = vecS2.Z();
    vertices[9] = vecS1.X() + vecS2.X();
    vertices[10] = vecS1.Y() + vecS2.Y();
    vertices[11] = vecS1.Z() + vecS2.Z();
    ByteBuffer vbb3 = ByteBuffer.allocateDirect(vertices.length * 4);
    vbb3.order(ByteOrder.nativeOrder());
    vBuffer = vbb3.asFloatBuffer();
    vBuffer.put(vertices);
    vBuffer.position(0);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vBuffer);
    gl.glBlendFunc(GL10.GL_ALPHA_BITS, GL10.GL_ONE_MINUS_SRC_ALPHA);

    gl.glColor4f(1f, 1f, 1f, 0.8f);
    gl.glNormal3f(-vecSv.X(), -vecSv.Y(), -vecSv.Z());
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

    vertices2 = new float[12];
    vertices2[0] = vEx;
    vertices2[1] = vEy;
    vertices2[2] = vEz;
    vertices2[3] = vertices[3] + vEx;
    vertices2[4] = vertices[4] + vEy;
    vertices2[5] = vertices[5] + vEz;
    vertices2[6] = vertices[6] + vEx;
    vertices2[7] = vertices[7] + vEy;
    vertices2[8] = vertices[8] + vEz;
    vertices2[9] = vertices[9] + vEx;
    vertices2[10] = vertices[10] + vEy;
    vertices2[11] = vertices[11] + vEz;

    ByteBuffer vbb4 = ByteBuffer.allocateDirect(vertices2.length * 4);
    vbb4.order(ByteOrder.nativeOrder());
    vBuffer = vbb4.asFloatBuffer();
    vBuffer.put(vertices2);
    vBuffer.position(0);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vBuffer);
    gl.glBlendFunc(GL10.GL_ALPHA_BITS, GL10.GL_ONE_MINUS_SRC_ALPHA);

    gl.glColor4f(1f, 1f, 1f, 0.8f);
    gl.glNormal3f(vecSv.X(), vecSv.Y(), vecSv.Z());
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

    vertices3 = new float[12];
    vertices3[0] = vertices[0];
    vertices3[1] = vertices[1];
    vertices3[2] = vertices[2];
    vertices3[3] = vertices2[0];
    vertices3[4] = vertices2[1];
    vertices3[5] = vertices2[2];
    vertices3[6] = vertices[6];
    vertices3[7] = vertices[7];
    vertices3[8] = vertices[8];
    vertices3[9] = vertices2[6];
    vertices3[10] = vertices2[7];
    vertices3[11] = vertices2[8];

    ByteBuffer vbb5 = ByteBuffer.allocateDirect(vertices3.length * 4);
    vbb5.order(ByteOrder.nativeOrder());
    vBuffer = vbb5.asFloatBuffer();
    vBuffer.put(vertices3);
    vBuffer.position(0);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vBuffer);
    gl.glBlendFunc(GL10.GL_ALPHA_BITS, GL10.GL_ONE_MINUS_SRC_ALPHA);

    gl.glColor4f(1f, 0.9f, 0f, 0.4f);
    gl.glNormal3f(vecSv.X(), vecSv.Y(), vecSv.Z());
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

    vertices3[0] = vertices[0];
    vertices3[1] = vertices[1];
    vertices3[2] = vertices[2];
    vertices3[3] = vertices2[0];
    vertices3[4] = vertices2[1];
    vertices3[5] = vertices2[2];
    vertices3[6] = vertices[3];
    vertices3[7] = vertices[4];
    vertices3[8] = vertices[5];
    vertices3[9] = vertices2[3];
    vertices3[10] = vertices2[4];
    vertices3[11] = vertices2[5];

    ByteBuffer vbb6 = ByteBuffer.allocateDirect(vertices3.length * 4);
    vbb6.order(ByteOrder.nativeOrder());
    vBuffer = vbb6.asFloatBuffer();
    vBuffer.put(vertices3);
    vBuffer.position(0);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vBuffer);
    gl.glBlendFunc(GL10.GL_ALPHA_BITS, GL10.GL_ONE_MINUS_SRC_ALPHA);

    gl.glColor4f(0.9f, 1f, 0f, 0.4f);
    gl.glNormal3f(vecSv.X(), vecSv.Y(), vecSv.Z());
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

    vertices3[0] = vertices[9];
    vertices3[1] = vertices[10];
    vertices3[2] = vertices[11];
    vertices3[3] = vertices2[9];
    vertices3[4] = vertices2[10];
    vertices3[5] = vertices2[11];
    vertices3[6] = vertices[3];
    vertices3[7] = vertices[4];
    vertices3[8] = vertices[5];
    vertices3[9] = vertices2[3];
    vertices3[10] = vertices2[4];
    vertices3[11] = vertices2[5];

    ByteBuffer vbb7 = ByteBuffer.allocateDirect(vertices3.length * 4);
    vbb7.order(ByteOrder.nativeOrder());
    vBuffer = vbb7.asFloatBuffer();
    vBuffer.put(vertices3);
    vBuffer.position(0);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vBuffer);
    gl.glBlendFunc(GL10.GL_ALPHA_BITS, GL10.GL_ONE_MINUS_SRC_ALPHA);

    gl.glColor4f(1f, 1f, 0f, 0.4f);
    gl.glNormal3f(vecSv.X(), vecSv.Y(), vecSv.Z());
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

    vertices3[0] = vertices[9];
    vertices3[1] = vertices[10];
    vertices3[2] = vertices[11];
    vertices3[3] = vertices2[9];
    vertices3[4] = vertices2[10];
    vertices3[5] = vertices2[11];
    vertices3[6] = vertices[6];
    vertices3[7] = vertices[7];
    vertices3[8] = vertices[8];
    vertices3[9] = vertices2[6];
    vertices3[10] = vertices2[7];
    vertices3[11] = vertices2[8];

    ByteBuffer vbb8 = ByteBuffer.allocateDirect(vertices3.length * 4);
    vbb8.order(ByteOrder.nativeOrder());
    vBuffer = vbb8.asFloatBuffer();
    vBuffer.put(vertices3);
    vBuffer.position(0);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vBuffer);
    gl.glBlendFunc(GL10.GL_ALPHA_BITS, GL10.GL_ONE_MINUS_SRC_ALPHA);

    gl.glColor4f(0.9f, 0.9f, 0f, 0.4f);
    gl.glNormal3f(vecSv.X(), vecSv.Y(), vecSv.Z());
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
  }
Beispiel #12
0
 protected boolean qt() {
   float f =
       FloatMath.floor(((WebView) this.aAX).getContentHeight() * ((WebView) this.aAX).getScale());
   return ((WebView) this.aAX).getScrollY() >= f - ((WebView) this.aAX).getHeight();
 }
 @Override
 protected void updateTextBounds(final String pCharacterAsString) {
   this.mStrokePaint.getTextBounds(pCharacterAsString, 0, 1, this.mTextBounds);
   final int inset = -(int) FloatMath.floor(this.mStrokeWidth * 0.5f);
   this.mTextBounds.inset(inset, inset);
 }