From cc7be02e68137ab21843531d600a53ae7d33d29a Mon Sep 17 00:00:00 2001 From: Christian Graffe Date: Mon, 30 Apr 2012 17:54:41 -0430 Subject: [PATCH] Added 2 pages landscape support --- README.md | 2 + project.properties | 2 +- src/fi/harism/curl/CurlActivity.java | 5 +- src/fi/harism/curl/CurlMesh.java | 138 +++++++++++- src/fi/harism/curl/CurlView.java | 326 ++++++++++++++++++++------- 5 files changed, 381 insertions(+), 92 deletions(-) diff --git a/README.md b/README.md index fa491a0..027470c 100644 --- a/README.md +++ b/README.md @@ -121,3 +121,5 @@ Not to forget many of the true real-time rendering heros. One day We're about to * Rgba&Tbc - Elevated [http://www.youtube.com/watch?v=_YWMGuh15nE] * Andromeda&Orb - Stargazer [http://www.youtube.com/watch?v=5u1cqYLNbJI] * Cncd&Flt - Numb Res [http://www.youtube.com/watch?v=LTOC_ajkRkU] + +// cags12 Edit: Added 2 pages landscape support - [http://www.youtube.com/watch?v=iwu7P5PCpsw] diff --git a/project.properties b/project.properties index ea89160..f049142 100644 --- a/project.properties +++ b/project.properties @@ -8,4 +8,4 @@ # project structure. # Project target. -target=android-8 +target=android-10 diff --git a/src/fi/harism/curl/CurlActivity.java b/src/fi/harism/curl/CurlActivity.java index 8795d09..001cc90 100644 --- a/src/fi/harism/curl/CurlActivity.java +++ b/src/fi/harism/curl/CurlActivity.java @@ -50,7 +50,10 @@ public void onCreate(Bundle savedInstanceState) { // This is something somewhat experimental. Before uncommenting next // line, please see method comments in CurlView. - // mCurlView.setEnableTouchPressure(true); + mCurlView.setEnableTouchPressure(true); + + // CAGS: This is to allow 2 pages landscape mode, set to false for legacy mode + mCurlView.set2PagesLandscape(true); } @Override diff --git a/src/fi/harism/curl/CurlMesh.java b/src/fi/harism/curl/CurlMesh.java index 06a8550..8ef6fbc 100644 --- a/src/fi/harism/curl/CurlMesh.java +++ b/src/fi/harism/curl/CurlMesh.java @@ -24,6 +24,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; +import android.graphics.Matrix; import android.graphics.PointF; import android.graphics.RectF; import android.opengl.GLUtils; @@ -57,10 +58,17 @@ public class CurlMesh { private static final float[] SHADOW_OUTER_COLOR = { 0f, 0f, 0f, .0f }; // Alpha values for front and back facing texture. - private static final double BACKFACE_ALPHA = .2f; + // CAGS: Modified to avoid transparency in landscape + private static double BACKFACE_ALPHA = 1f; + //private static final double BACKFACE_ALPHA = .2f; private static final double FRONTFACE_ALPHA = 1f; // Boolean for 'flipping' texture sideways. private boolean mFlipTexture = false; + + // CAGS: Method to change Alpha value landscape/portraid + public static void setALPHA (double value){ + BACKFACE_ALPHA = value; + } // For testing purposes. private int mCurlPositionLinesCount; @@ -90,6 +98,12 @@ public class CurlMesh { private int[] mTextureIds; private Bitmap mBitmap; private RectF mTextureRect = new RectF(); + + // CAGS : Added some new needed variables + private Bitmap mBitmapB; + private int mWidthAux; + private boolean mNewTex = false; + //public boolean mSwapSheet = false; // Let's avoid using 'new' as much as possible. Meaning we introduce arrays // once here and reuse them on runtime. Doesn't really have very much effect @@ -531,8 +545,8 @@ public synchronized void draw(GL10 gl) { // First allocate texture if there is not one yet. if (DRAW_TEXTURE && mTextureIds == null) { // Generate texture. - mTextureIds = new int[1]; - gl.glGenTextures(1, mTextureIds, 0); + mTextureIds = new int[2]; + gl.glGenTextures(2, mTextureIds, 0); // Set texture attributes. gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[0]); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, @@ -543,18 +557,45 @@ public synchronized void draw(GL10 gl) { GL10.GL_CLAMP_TO_EDGE); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); + //CAGS: Back Texture + gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[1]); + gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, + GL10.GL_LINEAR); + gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, + GL10.GL_LINEAR); + gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, + GL10.GL_CLAMP_TO_EDGE); + gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, + GL10.GL_CLAMP_TO_EDGE); } // If mBitmap != null we have a new texture. - if (DRAW_TEXTURE && mBitmap != null) { + if (DRAW_TEXTURE && mNewTex) { gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[0]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, mBitmap, 0); - mBitmap = null; - } + //mBitmap.recycle(); + //mBitmap = null; + gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[1]); + GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, mBitmapB, 0); + //mBitmapB.recycle(); + //mBitmapB = null; + mNewTex = false; + } if (DRAW_TEXTURE) { gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[0]); } - + + /* CAGS: Invert the textures if mSwapSheet == true -> Not acomplished due + * to not figured out where to put again swapSheet = false and avoid a bad behaivor + * of the curled page + if (DRAW_TEXTURE) { + if (!mSwapSheet){ + gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[0]); + }else{ + gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[1]); + } + }*/ + // Some 'global' settings. gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); @@ -597,6 +638,20 @@ public synchronized void draw(GL10 gl) { gl.glDisable(GL10.GL_TEXTURE_2D); gl.glDisable(GL10.GL_BLEND); } + if (DRAW_TEXTURE) { + gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[1]); + } + /* CAGS: Invert the textures if mSwapSheet == true -> Not acomplished due + * to not figured out where to put again swapSheet = false and avoid a bad behaivor + * of the curled page + if (!mSwapSheet){ + gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[1]); + }else{ + gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[0]); + //mSwapSheet=false; + } + }*/ + int backStartIdx = Math.max(0, mVerticesCountFront - 2); int backCount = mVerticesCountFront + mVerticesCountBack - backStartIdx; // Draw blank / 'white' back facing vertices. @@ -688,7 +743,7 @@ public synchronized void resetTexture() { /** * Sets new texture for this mesh. */ - public synchronized void setBitmap(Bitmap bitmap) { + public synchronized void setBitmap(Bitmap bitmap, Bitmap bitmapB) { if (DRAW_TEXTURE) { // Bitmap original size. int w = bitmap.getWidth(); @@ -698,12 +753,53 @@ 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; + } + + if(mBitmapB != null){ + mBitmapB.recycle(); + mBitmapB = 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; + + if (bitmapB != null){ + // Bitmap original size. + int w2 = bitmapB.getWidth(); + int h2 = bitmapB.getHeight(); + // Bitmap size expanded to next power of two. This is done due to + // the requirement on many devices, texture width and height should + // be power of two. + int newW2 = getNextHighestPO2(w2); + int newH2 = getNextHighestPO2(h2); + // TODO: Is there another way to create a bigger Bitmap and copy + // original Bitmap to it more efficiently? Immutable bitmap anyone? + mBitmapB= Bitmap.createBitmap(newW2, newH2, bitmapB.getConfig()); + Canvas c2 = new Canvas(mBitmapB); + //CAGS: Flip Back facing Bitmap + Matrix flipHorizontalMatrix = new Matrix(); + flipHorizontalMatrix.setScale(-1,1); + flipHorizontalMatrix.postTranslate(w2,0); + c2.drawBitmap(bitmapB, flipHorizontalMatrix, null); + //Recycle the now unused bitmap + bitmapB.recycle(); + bitmapB = null; + + } else { + mBitmapB = mBitmap; + } + //CAGS: Store w2 for later flip + mWidthAux = w; + mNewTex = true; // Calculate final texture coordinates. float texX = (float) w / newW; float texY = (float) h / newH; @@ -715,6 +811,30 @@ public synchronized void setBitmap(Bitmap bitmap) { } } } + + /** + * Swap Front and Back Sheets/Textures. + */ + /*CAGS: This method depends on keeping the mBitmaps objects, I supose + it consume more memory due to keep those bitmaps in memory.*/ + // TODO: Optimize the swap of textures without keeping the mBitmaps + // in memory, see draw() method for a reference on how I was trying to do it + public void swapSheet (){ + Bitmap aux; + aux = mBitmap; + mBitmap= Bitmap.createBitmap(mBitmapB); + Canvas c = new Canvas(mBitmap); + //Flip Matrix + Matrix flipHorizontalMatrix = new Matrix(); + flipHorizontalMatrix.setScale(-1,1); + flipHorizontalMatrix.postTranslate(mWidthAux,0); + c.drawBitmap(mBitmap, flipHorizontalMatrix, null); + + mBitmapB= Bitmap.createBitmap(aux); + Canvas c2 = new Canvas(mBitmapB); + c2.drawBitmap(mBitmapB, flipHorizontalMatrix, null); + mNewTex = true; + } /** * If true, flips texture sideways. diff --git a/src/fi/harism/curl/CurlView.java b/src/fi/harism/curl/CurlView.java index 7a2ea45..4f79d5f 100644 --- a/src/fi/harism/curl/CurlView.java +++ b/src/fi/harism/curl/CurlView.java @@ -42,6 +42,8 @@ public class CurlView extends GLSurfaceView implements View.OnTouchListener, private boolean mRenderLeftPage = true; private boolean mAllowLastPageCurl = true; + // Allow 2 pages landscape mode + private boolean mAllow2PagesLandscape = false; // Page meshes. Left and right meshes are 'static' while curl is used to // show page flipping. @@ -137,15 +139,34 @@ public void onDrawFrame() { mPageCurl = curl; mPageRight = right; // If we were curling left page update current index. - if (mCurlState == CURL_LEFT) { - mCurrentIndex--; + if (mViewMode == SHOW_ONE_PAGE || !mAllow2PagesLandscape) { + if (mCurlState == CURL_LEFT) { + mCurrentIndex--; + } + } else { + if (mCurlState == CURL_LEFT) { + mCurrentIndex=mCurrentIndex-2; + mPageRight.swapSheet(); + /*CAGS: Alternate method to swap sheets but inefficient in time at running, + * needs to load 4 images in every curl instead 2 + * Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, mCurrentIndex);//CAGS + Bitmap bitmap2 = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, mCurrentIndex+1);//CAGS + mPageRight.setBitmap(bitmap,bitmap2); + */ + } } } else if (mAnimationTargetEvent == SET_CURL_TO_LEFT) { // Switch curled page to left. CurlMesh left = mPageCurl; CurlMesh curl = mPageLeft; left.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT)); - left.setFlipTexture(true); + if (mViewMode == SHOW_ONE_PAGE || !mAllow2PagesLandscape) { + left.setFlipTexture(true); + }else{ + left.setFlipTexture(false); + } left.reset(); mRenderer.removeCurlMesh(curl); if (!mRenderLeftPage) { @@ -154,8 +175,24 @@ public void onDrawFrame() { mPageCurl = curl; mPageLeft = left; // If we were curling right page update current index. - if (mCurlState == CURL_RIGHT) { - mCurrentIndex++; + if (mViewMode == SHOW_ONE_PAGE || !mAllow2PagesLandscape) { + if (mCurlState == CURL_RIGHT) { + mCurrentIndex++; + } + } else { + // If we were curling right page update current index. + if (mCurlState == CURL_RIGHT) { + mCurrentIndex=mCurrentIndex+2; + mPageLeft.swapSheet(); + /*CAGS: Alternate method to swap sheets but inefficient in time at running, + * needs to load 4 images in every curl instead 2 + * Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, mCurrentIndex+1);//CAGS + Bitmap bitmap2 = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, mCurrentIndex);//CAGS + mPageLeft.setBitmap(bitmap,bitmap2); + */ + } } } mCurlState = CURL_NONE; @@ -217,7 +254,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()) { @@ -417,14 +454,27 @@ public void setViewMode(int viewMode) { switch (viewMode) { case SHOW_ONE_PAGE: mViewMode = viewMode; + CurlMesh.setALPHA(.2f); + mPageLeft.setFlipTexture(true); mRenderer.setViewMode(CurlRenderer.SHOW_ONE_PAGE); break; case SHOW_TWO_PAGES: mViewMode = viewMode; + if (mAllow2PagesLandscape){ + CurlMesh.setALPHA(1f); + mPageLeft.setFlipTexture(false); + } mRenderer.setViewMode(CurlRenderer.SHOW_TWO_PAGES); break; } } + + /** + * If set to true, 2 pages landscape mode is enabled + */ + public void set2PagesLandscape(boolean Allow2PagesLandscape) { + mAllow2PagesLandscape = Allow2PagesLandscape; + } /** * Initialize method. @@ -510,7 +560,8 @@ private void setCurlPos(PointF curlPos, PointF curlDir, double radius) { } /** - * Switches meshes and loads new bitmaps if available. + * Switches meshes and loads new bitmaps if available. Updated + * to support 2 pages in landscape */ private void startCurl(int page) { switch (page) { @@ -528,28 +579,53 @@ private void startCurl(int page) { CurlMesh curl = mPageRight; mPageRight = mPageCurl; mPageCurl = curl; - + + if (mViewMode == SHOW_ONE_PAGE || !mAllow2PagesLandscape) { // If there is something to show on left page, simply add it to // renderer. - if (mCurrentIndex > 0) { - mPageLeft - .setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT)); - mPageLeft.reset(); - if (mRenderLeftPage) { - mRenderer.addCurlMesh(mPageLeft); + if (mCurrentIndex > 0) { + mPageLeft.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT)); + mPageLeft.reset(); + if (mRenderLeftPage) { + mRenderer.addCurlMesh(mPageLeft); + } + } + // If there is new/next available, set it to right page. + if (mCurrentIndex < mBitmapProvider.getBitmapCount() - 1) { + Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, mCurrentIndex + 1); + mPageRight.setBitmap(bitmap,null); + mPageRight.setRect(mRenderer + .getPageRect(CurlRenderer.PAGE_RIGHT)); + mPageRight.setFlipTexture(false); + mPageRight.reset(); + mRenderer.addCurlMesh(mPageRight); + } + } else { + if (mCurrentIndex > 0) { + mPageLeft + .setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT)); + mPageLeft.reset(); + if (mRenderLeftPage) { + mRenderer.addCurlMesh(mPageLeft); + } + } + if (mCurrentIndex < mBitmapProvider.getBitmapCount() - 2) { + Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, mCurrentIndex + 2); + Bitmap bitmap2; + if (mCurrentIndex < mBitmapProvider.getBitmapCount() - 3) { + bitmap2 = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, mCurrentIndex + 3); + }else{ + bitmap2 = bitmap; + } + mPageRight.setBitmap(bitmap,bitmap2); + mPageRight.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_RIGHT)); + mPageRight.setFlipTexture(false); + mPageRight.reset(); + mRenderer.addCurlMesh(mPageRight); } - } - - // If there is new/next available, set it to right page. - if (mCurrentIndex < mBitmapProvider.getBitmapCount() - 1) { - Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, - mPageBitmapHeight, mCurrentIndex + 1); - mPageRight.setBitmap(bitmap); - mPageRight.setRect(mRenderer - .getPageRect(CurlRenderer.PAGE_RIGHT)); - mPageRight.setFlipTexture(false); - mPageRight.reset(); - mRenderer.addCurlMesh(mPageRight); } // Add curled page to renderer. @@ -576,17 +652,34 @@ private void startCurl(int page) { mPageLeft = mPageCurl; mPageCurl = curl; + if (mViewMode == SHOW_ONE_PAGE || !mAllow2PagesLandscape) { // If there is new/previous bitmap available load it to left page. - if (mCurrentIndex > 1) { - Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, - mPageBitmapHeight, mCurrentIndex - 2); - mPageLeft.setBitmap(bitmap); - mPageLeft - .setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT)); - mPageLeft.setFlipTexture(true); - mPageLeft.reset(); - if (mRenderLeftPage) { - mRenderer.addCurlMesh(mPageLeft); + if (mCurrentIndex > 1) { + Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, mCurrentIndex - 2); + mPageLeft.setBitmap(bitmap,null); + mPageLeft + .setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT)); + mPageLeft.setFlipTexture(true); + mPageLeft.reset(); + if (mRenderLeftPage) { + mRenderer.addCurlMesh(mPageLeft); + } + } + } else { + if (mCurrentIndex > 2) { + Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, mCurrentIndex - 3); + Bitmap bitmap2 = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, mCurrentIndex-4); + mPageLeft.setBitmap(bitmap,bitmap2); + mPageLeft + .setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT)); + mPageLeft.setFlipTexture(false); + mPageLeft.reset(); + if (mRenderLeftPage) { + mRenderer.addCurlMesh(mPageLeft); + } } } @@ -606,7 +699,12 @@ private void startCurl(int page) { } else { mPageCurl .setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT)); - mPageCurl.setFlipTexture(true); + if (mAllow2PagesLandscape){ + mPageCurl.setFlipTexture(false); + } else { + mPageCurl.setFlipTexture(true); + } + } mPageCurl.reset(); mRenderer.addCurlMesh(mPageCurl); @@ -632,49 +730,112 @@ private void updateBitmaps() { mRenderer.removeCurlMesh(mPageRight); mRenderer.removeCurlMesh(mPageCurl); - int leftIdx = mCurrentIndex - 1; - int rightIdx = mCurrentIndex; - int curlIdx = -1; - if (mCurlState == CURL_LEFT) { - curlIdx = leftIdx; - leftIdx--; - } else if (mCurlState == CURL_RIGHT) { - curlIdx = rightIdx; - rightIdx++; - } + if (mViewMode == SHOW_ONE_PAGE || !mAllow2PagesLandscape) { + int leftIdx = mCurrentIndex - 1; + int rightIdx = mCurrentIndex; + int curlIdx = -1; + if (mCurlState == CURL_LEFT) { + curlIdx = leftIdx; + leftIdx--; + } else if (mCurlState == CURL_RIGHT) { + curlIdx = rightIdx; + rightIdx++; + } - if (rightIdx >= 0 && rightIdx < mBitmapProvider.getBitmapCount()) { - Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, - mPageBitmapHeight, rightIdx); - mPageRight.setBitmap(bitmap); - mPageRight.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_RIGHT)); - mPageRight.reset(); - mRenderer.addCurlMesh(mPageRight); - } - if (leftIdx >= 0 && leftIdx < mBitmapProvider.getBitmapCount()) { - Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, - mPageBitmapHeight, leftIdx); - mPageLeft.setBitmap(bitmap); - mPageLeft.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT)); - mPageLeft.reset(); - if (mRenderLeftPage) { - mRenderer.addCurlMesh(mPageLeft); + if (rightIdx >= 0 && rightIdx < mBitmapProvider.getBitmapCount()) { + Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, rightIdx); + mPageRight.setBitmap(bitmap,null); + mPageRight.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_RIGHT)); + mPageRight.reset(); + mRenderer.addCurlMesh(mPageRight); } - } - if (curlIdx >= 0 && curlIdx < mBitmapProvider.getBitmapCount()) { - Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, - mPageBitmapHeight, curlIdx); - mPageCurl.setBitmap(bitmap); - if (mCurlState == CURL_RIGHT - || (mCurlState == CURL_LEFT && mViewMode == SHOW_TWO_PAGES)) { - mPageCurl.setRect(mRenderer - .getPageRect(CurlRenderer.PAGE_RIGHT)); + if (leftIdx >= 0 && leftIdx < mBitmapProvider.getBitmapCount()) { + Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, leftIdx); + mPageLeft.setBitmap(bitmap,null); + mPageLeft.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT)); + mPageLeft.reset(); + if (mRenderLeftPage) { + mRenderer.addCurlMesh(mPageLeft); + } + } + if (curlIdx >= 0 && curlIdx < mBitmapProvider.getBitmapCount()) { + Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, curlIdx); + mPageCurl.setBitmap(bitmap,null); + if (mCurlState == CURL_RIGHT + || (mCurlState == CURL_LEFT && mViewMode == SHOW_TWO_PAGES)) { + mPageCurl.setRect(mRenderer + .getPageRect(CurlRenderer.PAGE_RIGHT)); + } else { + mPageCurl + .setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT)); + } + mPageCurl.reset(); + mRenderer.addCurlMesh(mPageCurl); + } + } else { + int leftIdx; + int rightIdx; + int curlIdx = -1; + if (mCurrentIndex % 2 == 0){ + leftIdx = mCurrentIndex - 1; + rightIdx = mCurrentIndex; } else { - mPageCurl - .setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT)); + leftIdx = mCurrentIndex; + rightIdx = mCurrentIndex +1; + mCurrentIndex = rightIdx; + } + if (mCurlState == CURL_LEFT) { + curlIdx = leftIdx; + leftIdx--; + } else if (mCurlState == CURL_RIGHT) { + curlIdx = rightIdx; + rightIdx++; + } + + + if (rightIdx >= 0 && rightIdx < mBitmapProvider.getBitmapCount()-1) { + Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, rightIdx); + Bitmap bitmap2 = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, rightIdx+1); + mPageRight.setBitmap(bitmap,bitmap2); + + mPageRight.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_RIGHT)); + mPageRight.reset(); + mRenderer.addCurlMesh(mPageRight); + } + if (leftIdx >= 0 && leftIdx < mBitmapProvider.getBitmapCount()) { + Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, leftIdx); + Bitmap bitmap2 = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, leftIdx-1); + mPageLeft.setBitmap(bitmap,bitmap2); + mPageLeft.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT)); + mPageLeft.reset(); + if (mRenderLeftPage) { + mRenderer.addCurlMesh(mPageLeft); + } + } + if (curlIdx >= 0 && curlIdx < mBitmapProvider.getBitmapCount()-1) { + Bitmap bitmap = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, curlIdx); + Bitmap bitmap2 = mBitmapProvider.getBitmap(mPageBitmapWidth, + mPageBitmapHeight, curlIdx+1); + mPageCurl.setBitmap(bitmap,bitmap2); + if (mCurlState == CURL_RIGHT + || (mCurlState == CURL_LEFT && mViewMode == SHOW_TWO_PAGES)) { + mPageCurl.setRect(mRenderer + .getPageRect(CurlRenderer.PAGE_RIGHT)); + } else { + mPageCurl + .setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT)); + } + mPageCurl.reset(); + mRenderer.addCurlMesh(mPageCurl); } - mPageCurl.reset(); - mRenderer.addCurlMesh(mPageCurl); } } @@ -721,7 +882,12 @@ 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); @@ -729,8 +895,6 @@ private void updateCurlPos(PointerPosition pointerPos) { 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) { @@ -743,9 +907,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); } /**