OSDN Git Service

fixes the draw and clean up the UI
authorJohn Hoford <hoford@google.com>
Tue, 12 Feb 2013 04:55:45 +0000 (20:55 -0800)
committerJohn Hoford <hoford@google.com>
Tue, 12 Feb 2013 04:57:18 +0000 (20:57 -0800)
Change-Id: Ia52dfc3ec407c307612dcfc91fb61a1fb89e32ec

res/drawable-nodpi/brush1.png [deleted file]
res/drawable-nodpi/brush_marker.png [new file with mode: 0644]
res/drawable-nodpi/brush_spatter.png [moved from res/drawable-nodpi/brush2.png with 100% similarity]
res/menu/filtershow_menu_draw.xml
res/values/filtershow_strings.xml
src/com/android/gallery3d/filtershow/editors/EditorDraw.java
src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java
src/com/android/gallery3d/filtershow/imageshow/ImageDraw.java

diff --git a/res/drawable-nodpi/brush1.png b/res/drawable-nodpi/brush1.png
deleted file mode 100644 (file)
index 6030f25..0000000
Binary files a/res/drawable-nodpi/brush1.png and /dev/null differ
diff --git a/res/drawable-nodpi/brush_marker.png b/res/drawable-nodpi/brush_marker.png
new file mode 100644 (file)
index 0000000..24eb747
Binary files /dev/null and b/res/drawable-nodpi/brush_marker.png differ
index be6dc70..9455f70 100644 (file)
             android:id="@+id/draw_menu_style_line"
             android:title="@string/draw_style_line" />
          <item
-            android:id="@+id/draw_menu_style_brush"
-            android:title="@string/draw_style_brush" />
+            android:id="@+id/draw_menu_style_brush_marker"
+            android:title="@string/draw_style_brush_marker"/>
+         <item
+            android:id="@+id/draw_menu_style_brush_spatter"
+            android:title="@string/draw_style_brush_spatter"/>
          <item
             android:id="@+id/draw_menu_size"
             android:title="@string/draw_size" />
index 92cc06a..cf6e80d 100644 (file)
     <string name="draw_color">Color</string>
     <!--  Label for the line style of drawing in [CHAR LIMIT=14] -->
     <string name="draw_style_line">Lines</string>
-    <!--  Label for the brush style of drawing in [CHAR LIMIT=14] -->
-    <string name="draw_style_brush">Brush</string>
+    <!--  Label for the Marker brush style of drawing in [CHAR LIMIT=14] -->
+    <string name="draw_style_brush_spatter">Marker</string>
+    <!--  Label for the Spatter brush style of drawing in [CHAR LIMIT=14] -->
+    <string name="draw_style_brush_marker">Spatter</string>
 
     <!--  Label for the select the color [CHAR LIMIT=30] -->
     <string name="color_pick_select">Choose custom color</string>
index ff40185..128af8e 100644 (file)
@@ -111,11 +111,12 @@ public class EditorDraw extends Editor {
                     showColorGrid(item);
                 } else if (item.getItemId() == R.id.draw_menu_size) {
                     showSizeDialog(item);
-                } else if (item.getItemId() == R.id.draw_menu_style_brush) {
+                } else if (item.getItemId() == R.id.draw_menu_style_brush_marker) {
                     ImageDraw idraw = (ImageDraw) mImageShow;
-                    idraw.setStyle((byte) (idraw.getStyle() + 1));
-                    item.setIcon(idraw.getIcon(mContext));
-                    popupMenu.show();
+                    idraw.setStyle(ImageFilterDraw.BRUSH_STYLE_MARKER);
+                } else if (item.getItemId() == R.id.draw_menu_style_brush_spatter) {
+                    ImageDraw idraw = (ImageDraw) mImageShow;
+                    idraw.setStyle(ImageFilterDraw.BRUSH_STYLE_SPATTER);
                 } else if (item.getItemId() == R.id.draw_menu_style_line) {
                     ImageDraw idraw = (ImageDraw) mImageShow;
                     idraw.setStyle(ImageFilterDraw.SIMPLE_STYLE);
index ed02c1d..d2b5507 100644 (file)
@@ -16,7 +16,6 @@
 
 package com.android.gallery3d.filtershow.filters;
 
-import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.Canvas;
@@ -28,10 +27,9 @@ import android.graphics.Path;
 import android.graphics.PathMeasure;
 import android.graphics.PorterDuff;
 import android.graphics.PorterDuffColorFilter;
+import android.util.Log;
 
 import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.FilterShowActivity;
-import com.android.gallery3d.filtershow.editors.EditorDraw;
 import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation.StrokeData;
 import com.android.gallery3d.filtershow.imageshow.MasterImage;
 
@@ -40,7 +38,8 @@ import java.util.Vector;
 public class ImageFilterDraw extends ImageFilter {
     private static final String LOGTAG = "ImageFilterDraw";
     public final static byte SIMPLE_STYLE = 0;
-    public final static byte BRUSH_STYLE = 1;
+    public final static byte BRUSH_STYLE_SPATTER = 1;
+    public final static byte BRUSH_STYLE_MARKER = 2;
     public final static int NUMBER_OF_STYLES = 3;
     Bitmap mOverlayBitmap; // this accelerates interaction
     int mCachedStrokes = -1;
@@ -53,7 +52,10 @@ public class ImageFilterDraw extends ImageFilter {
     }
 
     DrawStyle[] mDrawingsTypes = new DrawStyle[] {
-            new SimpleDraw(), new Brush(R.drawable.brush1), new Brush(R.drawable.brush2) };
+            new SimpleDraw(),
+            new Brush(R.drawable.brush_marker),
+            new Brush(R.drawable.brush_spatter)
+    };
     {
         for (int i = 0; i < mDrawingsTypes.length; i++) {
             mDrawingsTypes[i].setType((byte) i);
@@ -109,7 +111,7 @@ public class ImageFilterDraw extends ImageFilter {
             paint.setColor(sd.mColor);
             paint.setStrokeWidth(toScrMatrix.mapRadius(sd.mRadius));
 
-            // don this way because of a bug in path.transform(matrix)
+            // done this way because of a bug in path.transform(matrix)
             Path mCacheTransPath = new Path();
             mCacheTransPath.addPath(sd.mPath, toScrMatrix);
 
@@ -118,7 +120,7 @@ public class ImageFilterDraw extends ImageFilter {
     }
 
     class Brush implements DrawStyle {
-        int mBrushID = R.drawable.brush2;
+        int mBrushID;
         Bitmap mBrush;
         byte mType;
 
@@ -138,23 +140,32 @@ public class ImageFilterDraw extends ImageFilter {
         @Override
         public void paint(FilterDrawRepresentation.StrokeData sd, Canvas canvas, Matrix toScrMatrix,
                 boolean highQuality) {
-            if (sd == null) {
-                return;
-            }
-
             if (sd == null || sd.mPath == null) {
                 return;
             }
             Paint paint = new Paint();
             paint.setStyle(Style.STROKE);
-
-            float scale = toScrMatrix.mapRadius(1);
+            paint.setAntiAlias(true);
             Path mCacheTransPath = new Path();
             mCacheTransPath.addPath(sd.mPath, toScrMatrix);
-            draw(canvas, paint, sd.mColor, toScrMatrix.mapRadius(sd.mRadius),
+            draw(canvas, paint, sd.mColor, toScrMatrix.mapRadius(sd.mRadius) * 2,
                     mCacheTransPath);
         }
 
+        public Bitmap createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)
+        {
+            Matrix m = new Matrix();
+            m.setScale(dstWidth / (float) src.getWidth(), dstHeight / (float) src.getHeight());
+            Bitmap result = Bitmap.createBitmap(dstWidth, dstHeight, src.getConfig());
+            Canvas canvas = new Canvas(result);
+
+            Paint paint = new Paint();
+            paint.setFilterBitmap(filter);
+            canvas.drawBitmap(src, m, paint);
+
+            return result;
+
+        }
         void draw(Canvas canvas, Paint paint, int color, float size, Path path) {
             PathMeasure mPathMeasure = new PathMeasure();
             float[] mPosition = new float[2];
@@ -164,11 +175,15 @@ public class ImageFilterDraw extends ImageFilter {
 
             paint.setAntiAlias(true);
             paint.setColor(color);
+
             paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
-            Bitmap brush = Bitmap.createScaledBitmap(getBrush(), (int) size, (int) size, true);
+            Bitmap brush;
+            // done this way because of a bug in
+            // Bitmap.createScaledBitmap(getBrush(),(int) size,(int) size,true);
+            brush = createScaledBitmap(getBrush(), (int) size, (int) size, true);
             float len = mPathMeasure.getLength();
             float s2 = size / 2;
-            float step = s2 / 6;
+            float step = s2 / 8;
             for (float i = 0; i < len; i += step) {
                 mPathMeasure.getPosTan(i, mPosition, mTan);
                 //                canvas.drawCircle(pos[0], pos[1], size, paint);
@@ -196,7 +211,7 @@ public class ImageFilterDraw extends ImageFilter {
         paint.setColor(Color.RED);
         paint.setStrokeWidth(40);
 
-        if (mParameters.getDrawing().isEmpty()) {
+        if (mParameters.getDrawing().isEmpty() && mParameters.getCurrentDrawing() == null) {
             return;
         }
         if (highQuality) {
@@ -252,9 +267,9 @@ public class ImageFilterDraw extends ImageFilter {
 
         Matrix m = new Matrix();
         m.setScale(scaleFactor, scaleFactor);
-
         drawData(new Canvas(bitmap), m, highQuality);
 
+
         return bitmap;
     }
 
index 65ccf1f..2dc0221 100644 (file)
@@ -5,8 +5,11 @@ import android.content.Context;
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Matrix;
+import android.graphics.Rect;
+import android.graphics.RectF;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
+import android.util.Log;
 import android.view.MotionEvent;
 
 import com.android.gallery3d.filtershow.editors.EditorDraw;