Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cesine committed Oct 23, 2011
2 parents 339d9e0 + 64c0b0c commit 1d606aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/fi/harism/curl/CurlMesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ public synchronized void draw(GL10 gl) {
if (DRAW_TEXTURE && mBitmap != null) {
gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[0]);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, mBitmap, 0);
mBitmap.recycle();
mBitmap = null;
}

Expand Down Expand Up @@ -698,12 +699,21 @@ public synchronized void setBitmap(Bitmap bitmap) {
// be power of two.
int newW = getNextHighestPO2(w);
int newH = getNextHighestPO2(h);
//Recycle the previous bitmap if it still exists.
if(mBitmap != null){
mBitmap.recycle();
mBitmap = null;
}
// TODO: Is there another way to create a bigger Bitmap and copy
// original Bitmap to it more efficiently? Immutable bitmap anyone?
mBitmap = Bitmap.createBitmap(newW, newH, bitmap.getConfig());
Canvas c = new Canvas(mBitmap);
c.drawBitmap(bitmap, 0, 0, null);


//Recycle the now unused bitmap
bitmap.recycle();
bitmap = null;

// Calculate final texture coordinates.
float texX = (float) w / newW;
float texY = (float) h / newH;
Expand Down
15 changes: 9 additions & 6 deletions src/fi/harism/curl/CurlView.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public boolean onTouch(View view, MotionEvent me) {
if (mEnableTouchPressure) {
mPointerPos.mPressure = me.getPressure();
} else {
mPointerPos.mPressure = 0f;
mPointerPos.mPressure = 0.8f;
}

switch (me.getAction()) {
Expand Down Expand Up @@ -719,16 +719,19 @@ private void updateCurlPos(PointerPosition pointerPos) {
// Actual curl position calculation.
if (dist >= curlLen) {
double translate = (dist - curlLen) / 2;
mCurlPos.x -= mCurlDir.x * translate / dist;
if(mViewMode == SHOW_TWO_PAGES){
mCurlPos.x -= mCurlDir.x * translate / dist;
}else{
float pageLeftX = mRenderer.getPageRect(CurlRenderer.PAGE_RIGHT).left;
radius = Math.max(Math.min(mCurlPos.x - pageLeftX, radius), 0f);
}
mCurlPos.y -= mCurlDir.y * translate / dist;
} else {
double angle = Math.PI * Math.sqrt(dist / curlLen);
double translate = radius * Math.sin(angle);
mCurlPos.x += mCurlDir.x * translate / dist;
mCurlPos.y += mCurlDir.y * translate / dist;
}

setCurlPos(mCurlPos, mCurlDir, radius);
}
// Otherwise we'll let curl follow pointer position.
else if (mCurlState == CURL_LEFT) {
Expand All @@ -741,9 +744,9 @@ else if (mCurlState == CURL_LEFT) {
mCurlPos.x -= Math.min(pageRightX - mCurlPos.x, radius);
mCurlDir.x = mCurlPos.x + mDragStartPos.x;
mCurlDir.y = mCurlPos.y - mDragStartPos.y;

setCurlPos(mCurlPos, mCurlDir, radius);
}

setCurlPos(mCurlPos, mCurlDir, radius);
}

/**
Expand Down

0 comments on commit 1d606aa

Please sign in to comment.