1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 10:19:33 +02:00

better rendering for curl animation

This commit is contained in:
Nikolay Pultsin 2011-04-01 00:11:56 +01:00
parent 4b4a99986d
commit f26c851c5b
7 changed files with 67 additions and 49 deletions

View file

@ -1,10 +1,10 @@
===== 1.0 (Mar ??, 2011) =====
* Differnt (and configurable) actions for short and long Back button press (original code by Steffen Siebert)
* Different (and configurable) actions for short and long Back button press (original code by Steffen Siebert)
* SlovoEd dictionaries support has been fixed
* Czech translation has been updated (by Marek Pavelka)
* No OutOfMemoryErrors in image loading
* Float series index parsing has been fixed
* Separate color for visited hyperlinks (original code by Steffen Siebert)
* Different colors for visited and non-visited hyperlinks (original code by Steffen Siebert)
* Removed menubar.xml: menu list is moved into the code
* Proguard obfuscation has been added; package size decreased

View file

@ -21,6 +21,8 @@ package org.geometerplus.zlibrary.ui.android.view;
import android.graphics.*;
import org.geometerplus.zlibrary.core.view.ZLView;
abstract class AnimationProvider {
protected final Paint myPaint;
protected int myStartX;
@ -29,6 +31,9 @@ abstract class AnimationProvider {
protected int myEndY;
protected boolean myHorizontal;
protected int myWidth;
protected int myHeight;
protected AnimationProvider(Paint paint) {
myPaint = paint;
}
@ -37,13 +42,17 @@ abstract class AnimationProvider {
return myHorizontal ? myEndX - myStartX : myEndY - myStartY;
}
void setup(int startX, int startY, int endX, int endY, boolean horizontal) {
void setup(int startX, int startY, int endX, int endY, boolean horizontal, int width, int height) {
myStartX = startX;
myStartY = startY;
myEndX = endX;
myEndY = endY;
myHorizontal = horizontal;
myWidth = width;
myHeight = height;
}
abstract void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap);
abstract ZLView.PageIndex getPageToScrollTo();
}

View file

@ -21,6 +21,8 @@ package org.geometerplus.zlibrary.ui.android.view;
import android.graphics.*;
import org.geometerplus.zlibrary.core.view.ZLView;
class CurlAnimationProvider extends AnimationProvider {
private final Paint myEdgePaint = new Paint();
@ -32,27 +34,24 @@ class CurlAnimationProvider extends AnimationProvider {
public void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
canvas.drawBitmap(bgBitmap, 0, 0, myPaint);
final int w = fgBitmap.getWidth();
final int h = fgBitmap.getHeight();
final int cornerX = myStartX > w / 2 ? w : 0;
final int cornerY = myStartY > h / 2 ? h : 0;
final int oppositeX = Math.abs(w - cornerX);
final int oppositeY = Math.abs(h - cornerY);
final int cornerX = myStartX > myWidth / 2 ? myWidth : 0;
final int cornerY = myStartY > myHeight / 2 ? myHeight : 0;
final int oppositeX = Math.abs(myWidth - cornerX);
final int oppositeY = Math.abs(myHeight - cornerY);
final int x, y;
if (myHorizontal) {
x = Math.max(1, Math.min(w - 1, myEndX));
x = Math.max(1, Math.min(myWidth - 1, myEndX));
if (cornerY == 0) {
y = Math.max(1, Math.min(h / 2, myEndY));
y = Math.max(1, Math.min(myHeight / 2, myEndY));
} else {
y = Math.max(h / 2, Math.min(h - 1, myEndY));
y = Math.max(myHeight / 2, Math.min(myHeight - 1, myEndY));
}
} else {
y = Math.max(1, Math.min(h - 1, myEndY));
y = Math.max(1, Math.min(myHeight - 1, myEndY));
if (cornerX == 0) {
x = Math.max(1, Math.min(w / 2, myEndX));
x = Math.max(1, Math.min(myWidth / 2, myEndX));
} else {
x = Math.max(w / 2, Math.min(w - 1, myEndX));
x = Math.max(myWidth / 2, Math.min(myWidth - 1, myEndX));
}
}
final int dX = Math.abs(x - cornerX);
@ -87,4 +86,10 @@ class CurlAnimationProvider extends AnimationProvider {
path.lineTo(cornerX, y1);
canvas.drawPath(path, myEdgePaint);
}
ZLView.PageIndex getPageToScrollTo() {
return myHorizontal
? (myStartX < myWidth / 2 ? ZLView.PageIndex.previous : ZLView.PageIndex.next)
: (myStartY < myHeight / 2 ? ZLView.PageIndex.previous : ZLView.PageIndex.next);
}
}

View file

@ -28,26 +28,24 @@ class ShiftAnimationProvider extends SimpleAnimationProvider {
@Override
public void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
final int w = fgBitmap.getWidth();
final int h = fgBitmap.getHeight();
myPaint.setColor(Color.rgb(127, 127, 127));
if (myHorizontal) {
final int dX = myEndX - myStartX;
canvas.drawBitmap(bgBitmap, dX > 0 ? dX - w : dX + w, 0, myPaint);
canvas.drawBitmap(bgBitmap, dX > 0 ? dX - myWidth : dX + myWidth, 0, myPaint);
canvas.drawBitmap(fgBitmap, dX, 0, myPaint);
if (dX > 0 && dX < w) {
canvas.drawLine(dX, 0, dX, h + 1, myPaint);
} else if (dX < 0 && dX > -w) {
canvas.drawLine(dX + w, 0, dX + w, h + 1, myPaint);
if (dX > 0 && dX < myWidth) {
canvas.drawLine(dX, 0, dX, myHeight + 1, myPaint);
} else if (dX < 0 && dX > -myWidth) {
canvas.drawLine(dX + myWidth, 0, dX + myWidth, myHeight + 1, myPaint);
}
} else {
final int dY = myEndY - myStartY;
canvas.drawBitmap(bgBitmap, 0, dY > 0 ? dY - h : dY + h, myPaint);
canvas.drawBitmap(bgBitmap, 0, dY > 0 ? dY - myHeight : dY + myHeight, myPaint);
canvas.drawBitmap(fgBitmap, 0, dY, myPaint);
if (dY > 0 && dY < h) {
canvas.drawLine(0, dY, w + 1, dY, myPaint);
} else if (dY < 0 && dY > -h) {
canvas.drawLine(0, dY + h, w + 1, dY + h, myPaint);
if (dY > 0 && dY < myHeight) {
canvas.drawLine(0, dY, myWidth + 1, dY, myPaint);
} else if (dY < 0 && dY > -myHeight) {
canvas.drawLine(0, dY + myHeight, myWidth + 1, dY + myHeight, myPaint);
}
}
}

View file

@ -21,8 +21,16 @@ package org.geometerplus.zlibrary.ui.android.view;
import android.graphics.Paint;
import org.geometerplus.zlibrary.core.view.ZLView;
abstract class SimpleAnimationProvider extends AnimationProvider {
SimpleAnimationProvider(Paint paint) {
super(paint);
}
ZLView.PageIndex getPageToScrollTo() {
return myHorizontal
? (myStartX < myEndX ? ZLView.PageIndex.previous : ZLView.PageIndex.next)
: (myStartY < myEndY ? ZLView.PageIndex.previous : ZLView.PageIndex.next);
}
}

View file

@ -29,24 +29,22 @@ class SlideAnimationProvider extends SimpleAnimationProvider {
@Override
public void draw(Canvas canvas, Bitmap bgBitmap, Bitmap fgBitmap) {
canvas.drawBitmap(bgBitmap, 0, 0, myPaint);
final int w = fgBitmap.getWidth();
final int h = fgBitmap.getHeight();
myPaint.setColor(Color.rgb(127, 127, 127));
if (myHorizontal) {
final int dX = myEndX - myStartX;
canvas.drawBitmap(fgBitmap, dX, 0, myPaint);
if (dX > 0 && dX < w) {
canvas.drawLine(dX, 0, dX, h + 1, myPaint);
} else if (dX < 0 && dX > -w) {
canvas.drawLine(dX + w, 0, dX + w, h + 1, myPaint);
if (dX > 0 && dX < myWidth) {
canvas.drawLine(dX, 0, dX, myHeight + 1, myPaint);
} else if (dX < 0 && dX > -myWidth) {
canvas.drawLine(dX + myWidth, 0, dX + myWidth, myHeight + 1, myPaint);
}
} else {
final int dY = myEndY - myStartY;
canvas.drawBitmap(fgBitmap, 0, dY, myPaint);
if (dY > 0 && dY < h) {
canvas.drawLine(0, dY, w + 1, dY, myPaint);
} else if (dY < 0 && dY > -h) {
canvas.drawLine(0, dY + h, w + 1, dY + h, myPaint);
if (dY > 0 && dY < myHeight) {
canvas.drawLine(0, dY, myWidth + 1, dY, myPaint);
} else if (dY < 0 && dY > -myHeight) {
canvas.drawLine(0, dY + myHeight, myWidth + 1, dY + myHeight, myPaint);
}
}
}

View file

@ -207,7 +207,8 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
getAnimationProvider().setup(
myStartX, myStartY,
myEndX, myEndY,
myScrollHorizontally
myScrollHorizontally,
getWidth(), getMainAreaHeight()
);
getAnimationProvider().draw(
canvas,
@ -230,25 +231,24 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
}
public void scrollManually(int startX, int startY, int endX, int endY, boolean horizontally) {
myScrollingState = ScrollingState.ManualScrolling;
myScrollHorizontally = horizontally;
final int shift = horizontally ? endX - startX : endY - startY;
if (myMainBitmap == null) {
return;
}
if ((shift > 0 && getAnimationProvider().getScrollingShift() <= 0) ||
(shift < 0 && getAnimationProvider().getScrollingShift() >= 0)) {
mySecondaryBitmapIsUpToDate = false;
}
myScrollingState = ScrollingState.ManualScrolling;
myScrollHorizontally = horizontally;
myStartX = startX;
myStartY = startY;
myEndX = endX;
myEndY = endY;
setPageToScrollTo(shift < 0 ? ZLView.PageIndex.next : ZLView.PageIndex.previous);
getAnimationProvider().setup(
startX, startY,
endX, endY,
horizontally,
getHeight(), getMainAreaHeight()
);
setPageToScrollTo(getAnimationProvider().getPageToScrollTo());
drawOnBitmap(mySecondaryBitmap);
postInvalidate();
}