diff options
author | nicolasroard <nicolasroard@google.com> | 2012-10-17 17:46:47 -0700 |
---|---|---|
committer | nicolasroard <nicolasroard@google.com> | 2012-10-18 17:05:58 -0700 |
commit | e1fb53368803126d6f128b16799f1875705d3562 (patch) | |
tree | 7861b0783d5fab7a4b46d7c05196eacbdf716391 /src/com/android/gallery3d/filtershow/ui/ImageCurves.java | |
parent | 10ed0fbdb5619d0972aa3cc6fd8c05201a992e39 (diff) | |
download | android_packages_apps_Snap-e1fb53368803126d6f128b16799f1875705d3562.tar.gz android_packages_apps_Snap-e1fb53368803126d6f128b16799f1875705d3562.tar.bz2 android_packages_apps_Snap-e1fb53368803126d6f128b16799f1875705d3562.zip |
Fix undo/redo/back button behaviour with effects and enable history
bug:7332980
bug:7357734
bug:7325872
Change-Id: Ie952a410c218c91ac927095ddcf542209fe7b90c
Diffstat (limited to 'src/com/android/gallery3d/filtershow/ui/ImageCurves.java')
-rw-r--r-- | src/com/android/gallery3d/filtershow/ui/ImageCurves.java | 91 |
1 files changed, 27 insertions, 64 deletions
diff --git a/src/com/android/gallery3d/filtershow/ui/ImageCurves.java b/src/com/android/gallery3d/filtershow/ui/ImageCurves.java index a8445b830..84edf234a 100644 --- a/src/com/android/gallery3d/filtershow/ui/ImageCurves.java +++ b/src/com/android/gallery3d/filtershow/ui/ImageCurves.java @@ -21,7 +21,6 @@ public class ImageCurves extends ImageSlave { private static final String LOGTAG = "ImageCurves"; Paint gPaint = new Paint(); - Spline[] mSplines = new Spline[4]; Path gPathSpline = new Path(); private int mCurrentCurveIndex = 0; @@ -54,23 +53,16 @@ public class ImageCurves extends ImageSlave { return false; } - public void reloadCurve() { + private ImageFilterCurves curves() { if (getMaster() != null) { String filterName = getFilterName(); - ImageFilterCurves filter = (ImageFilterCurves) getImagePreset() - .getFilter(filterName); - if (filter == null) { - resetCurve(); - return; - } - for (int i = 0; i < 4; i++) { - Spline spline = filter.getSpline(i); - if (spline != null) { - mSplines[i] = new Spline(spline); - } - } - applyNewCurve(); + return (ImageFilterCurves) getImagePreset().getFilter(filterName); } + return null; + } + + private Spline getSpline(int index) { + return curves().getSpline(index); } @Override @@ -82,16 +74,9 @@ public class ImageCurves extends ImageSlave { } public void resetCurve() { - Spline spline = new Spline(); - - spline.addPoint(0.0f, 1.0f); - spline.addPoint(1.0f, 0.0f); - - for (int i = 0; i < 4; i++) { - mSplines[i] = new Spline(spline); - } - if (getMaster() != null) { - applyNewCurve(); + if (getMaster() != null && curves() != null) { + curves().reset(); + updateCachedImage(); } } @@ -118,7 +103,7 @@ public class ImageCurves extends ImageSlave { // We only display the other channels curves when showing the RGB curve if (mCurrentCurveIndex == Spline.RGB) { for (int i = 0; i < 4; i++) { - Spline spline = mSplines[i]; + Spline spline = getSpline(i); if (i != mCurrentCurveIndex && !spline.isOriginal()) { // And we only display a curve if it has more than two // points @@ -127,7 +112,7 @@ public class ImageCurves extends ImageSlave { } } // ...but we always display the current curve. - mSplines[mCurrentCurveIndex] + getSpline(mCurrentCurveIndex) .draw(canvas, Spline.colorForCurve(mCurrentCurveIndex), getWidth(), getHeight(), true); drawToast(canvas); @@ -136,12 +121,13 @@ public class ImageCurves extends ImageSlave { private int pickControlPoint(float x, float y) { int pick = 0; - float px = mSplines[mCurrentCurveIndex].getPoint(0).x; - float py = mSplines[mCurrentCurveIndex].getPoint(0).y; + Spline spline = getSpline(mCurrentCurveIndex); + float px = spline.getPoint(0).x; + float py = spline.getPoint(0).y; double delta = Math.sqrt((px - x) * (px - x) + (py - y) * (py - y)); - for (int i = 1; i < mSplines[mCurrentCurveIndex].getNbPoints(); i++) { - px = mSplines[mCurrentCurveIndex].getPoint(i).x; - py = mSplines[mCurrentCurveIndex].getPoint(i).y; + for (int i = 1; i < spline.getNbPoints(); i++) { + px = spline.getPoint(i).x; + py = spline.getPoint(i).y; double currentDelta = Math.sqrt((px - x) * (px - x) + (py - y) * (py - y)); if (currentDelta < delta) { @@ -151,7 +137,7 @@ public class ImageCurves extends ImageSlave { } if (!mDidAddPoint && (delta * getWidth() > 100) - && (mSplines[mCurrentCurveIndex].getNbPoints() < 10)) { + && (spline.getNbPoints() < 10)) { return -1; } @@ -176,15 +162,8 @@ public class ImageCurves extends ImageSlave { posY = (posY - margin) / (getHeight() - 2 * margin); if (e.getActionMasked() == MotionEvent.ACTION_UP) { - applyNewCurve(); mCurrentControlPoint = null; - String name = "Curves"; - ImagePreset copy = new ImagePreset(getImagePreset(), name); - - copy.setIsFx(false); - mImageLoader.getHistory().insert(copy, 0); - - invalidate(); + updateCachedImage(); mDidAddPoint = false; if (mDidDelete) { mDidDelete = false; @@ -196,48 +175,32 @@ public class ImageCurves extends ImageSlave { return true; } + Spline spline = getSpline(mCurrentCurveIndex); int pick = pickControlPoint(posX, posY); if (mCurrentControlPoint == null) { if (pick == -1) { mCurrentControlPoint = new ControlPoint(posX, posY); - mSplines[mCurrentCurveIndex].addPoint(mCurrentControlPoint); + spline.addPoint(mCurrentControlPoint); mDidAddPoint = true; } else { - mCurrentControlPoint = mSplines[mCurrentCurveIndex].getPoint(pick); + mCurrentControlPoint = spline.getPoint(pick); } } - if (mSplines[mCurrentCurveIndex].isPointContained(posX, pick)) { + if (spline.isPointContained(posX, pick)) { mCurrentControlPoint.x = posX; mCurrentControlPoint.y = posY; } else if (pick != -1) { - mSplines[mCurrentCurveIndex].deletePoint(pick); + spline.deletePoint(pick); mDidDelete = true; } - applyNewCurve(); - invalidate(); + updateCachedImage(); return true; } - public synchronized void applyNewCurve() { + public synchronized void updateCachedImage() { // update image if (getImagePreset() != null) { - String filterName = getFilterName(); - ImageFilterCurves filter = (ImageFilterCurves) getImagePreset() - .getFilter(filterName); - if (filter == null) { - filter = new ImageFilterCurves(); - filter.setName(filterName); - ImagePreset copy = new ImagePreset(getImagePreset()); - copy.add(filter); - setImagePreset(copy, false); - } - - if (filter != null) { - for (int i = 0; i < 4; i++) { - filter.setSpline(new Spline(mSplines[i]), i); - } - } mImageLoader.resetImageForPreset(getImagePreset(), this); invalidate(); } |