Loading tools/layoutlib/bridge/src/android/graphics/GradientShader.java +50 −42 Original line number Diff line number Diff line Loading @@ -120,6 +120,7 @@ public abstract class GradientShader extends Shader { */ protected int getGradientColor(float pos) { if (pos < 0.f) { if (mTileMode != null) { switch (mTileMode) { case CLAMP: pos = 0.f; Loading @@ -143,7 +144,11 @@ public abstract class GradientShader extends Shader { } break; } } else { pos = 0.0f; } } else if (pos > 1f) { if (mTileMode != null) { switch (mTileMode) { case CLAMP: pos = 1.f; Loading @@ -165,6 +170,9 @@ public abstract class GradientShader extends Shader { } break; } } else { pos = 1.0f; } } int index = (int)((pos * GRADIENT_SIZE) + .5); Loading tools/layoutlib/bridge/src/android/graphics/SweepGradient.java +86 −14 Original line number Diff line number Diff line Loading @@ -16,9 +16,9 @@ package android.graphics; import java.awt.Paint; public class SweepGradient extends GradientShader { public class SweepGradient extends Shader { private SweepGradientPaint mPaint; /** * A subclass of Shader that draws a sweep gradient around a center point. Loading @@ -36,15 +36,9 @@ public class SweepGradient extends Shader { */ public SweepGradient(float cx, float cy, int colors[], float positions[]) { if (colors.length < 2) { throw new IllegalArgumentException("needs >= 2 number of colors"); } if (positions != null && colors.length != positions.length) { throw new IllegalArgumentException( "color and position arrays must be of equal length"); } super(colors, positions); // FIXME Implement shader mPaint = new SweepGradientPaint(cx, cy, mColors, mPositions); } /** Loading @@ -56,13 +50,91 @@ public class SweepGradient extends Shader { * @param color1 The color to use at the end of the sweep */ public SweepGradient(float cx, float cy, int color0, int color1) { // FIXME Implement shader this(cx, cy, new int[] { color0, color1}, null /*positions*/); } @Override Paint getJavaPaint() { // TODO Auto-generated method stub return null; java.awt.Paint getJavaPaint() { return mPaint; } private static class SweepGradientPaint extends GradientPaint { private final float mCx; private final float mCy; public SweepGradientPaint(float cx, float cy, int[] colors, float[] positions) { super(colors, positions, null /*tileMode*/); mCx = cx; mCy = cy; } public java.awt.PaintContext createContext( java.awt.image.ColorModel colorModel, java.awt.Rectangle deviceBounds, java.awt.geom.Rectangle2D userBounds, java.awt.geom.AffineTransform xform, java.awt.RenderingHints hints) { precomputeGradientColors(); return new SweepGradientPaintContext(colorModel); } private class SweepGradientPaintContext implements java.awt.PaintContext { private final java.awt.image.ColorModel mColorModel; public SweepGradientPaintContext(java.awt.image.ColorModel colorModel) { mColorModel = colorModel; } public void dispose() { } public java.awt.image.ColorModel getColorModel() { return mColorModel; } public java.awt.image.Raster getRaster(int x, int y, int w, int h) { java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(w, h, java.awt.image.BufferedImage.TYPE_INT_ARGB); int[] data = new int[w*h]; // compute angle from each point to the center, and figure out the distance from // it. int index = 0; for (int iy = 0 ; iy < h ; iy++) { for (int ix = 0 ; ix < w ; ix++) { float dx = x + ix - mCx; float dy = y + iy - mCy; float angle; if (dx == 0) { angle = (float) (dy < 0 ? 3 * Math.PI / 2 : Math.PI / 2); } else if (dy == 0) { angle = (float) (dx < 0 ? Math.PI : 0); } else { angle = (float) Math.atan(dy / dx); if (dx > 0) { if (dy < 0) { angle += Math.PI * 2; } } else { angle += Math.PI; } } // convert to 0-1. value and get color data[index++] = getGradientColor((float) (angle / (2 * Math.PI))); } } image.setRGB(0 /*startX*/, 0 /*startY*/, w, h, data, 0 /*offset*/, w /*scansize*/); return image.getRaster(); } } } } tools/layoutlib/bridge/src/android/graphics/RadialGradient.java +4 −4 File changed.Contains only whitespace changes. Show changes Loading
tools/layoutlib/bridge/src/android/graphics/GradientShader.java +50 −42 Original line number Diff line number Diff line Loading @@ -120,6 +120,7 @@ public abstract class GradientShader extends Shader { */ protected int getGradientColor(float pos) { if (pos < 0.f) { if (mTileMode != null) { switch (mTileMode) { case CLAMP: pos = 0.f; Loading @@ -143,7 +144,11 @@ public abstract class GradientShader extends Shader { } break; } } else { pos = 0.0f; } } else if (pos > 1f) { if (mTileMode != null) { switch (mTileMode) { case CLAMP: pos = 1.f; Loading @@ -165,6 +170,9 @@ public abstract class GradientShader extends Shader { } break; } } else { pos = 1.0f; } } int index = (int)((pos * GRADIENT_SIZE) + .5); Loading
tools/layoutlib/bridge/src/android/graphics/SweepGradient.java +86 −14 Original line number Diff line number Diff line Loading @@ -16,9 +16,9 @@ package android.graphics; import java.awt.Paint; public class SweepGradient extends GradientShader { public class SweepGradient extends Shader { private SweepGradientPaint mPaint; /** * A subclass of Shader that draws a sweep gradient around a center point. Loading @@ -36,15 +36,9 @@ public class SweepGradient extends Shader { */ public SweepGradient(float cx, float cy, int colors[], float positions[]) { if (colors.length < 2) { throw new IllegalArgumentException("needs >= 2 number of colors"); } if (positions != null && colors.length != positions.length) { throw new IllegalArgumentException( "color and position arrays must be of equal length"); } super(colors, positions); // FIXME Implement shader mPaint = new SweepGradientPaint(cx, cy, mColors, mPositions); } /** Loading @@ -56,13 +50,91 @@ public class SweepGradient extends Shader { * @param color1 The color to use at the end of the sweep */ public SweepGradient(float cx, float cy, int color0, int color1) { // FIXME Implement shader this(cx, cy, new int[] { color0, color1}, null /*positions*/); } @Override Paint getJavaPaint() { // TODO Auto-generated method stub return null; java.awt.Paint getJavaPaint() { return mPaint; } private static class SweepGradientPaint extends GradientPaint { private final float mCx; private final float mCy; public SweepGradientPaint(float cx, float cy, int[] colors, float[] positions) { super(colors, positions, null /*tileMode*/); mCx = cx; mCy = cy; } public java.awt.PaintContext createContext( java.awt.image.ColorModel colorModel, java.awt.Rectangle deviceBounds, java.awt.geom.Rectangle2D userBounds, java.awt.geom.AffineTransform xform, java.awt.RenderingHints hints) { precomputeGradientColors(); return new SweepGradientPaintContext(colorModel); } private class SweepGradientPaintContext implements java.awt.PaintContext { private final java.awt.image.ColorModel mColorModel; public SweepGradientPaintContext(java.awt.image.ColorModel colorModel) { mColorModel = colorModel; } public void dispose() { } public java.awt.image.ColorModel getColorModel() { return mColorModel; } public java.awt.image.Raster getRaster(int x, int y, int w, int h) { java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(w, h, java.awt.image.BufferedImage.TYPE_INT_ARGB); int[] data = new int[w*h]; // compute angle from each point to the center, and figure out the distance from // it. int index = 0; for (int iy = 0 ; iy < h ; iy++) { for (int ix = 0 ; ix < w ; ix++) { float dx = x + ix - mCx; float dy = y + iy - mCy; float angle; if (dx == 0) { angle = (float) (dy < 0 ? 3 * Math.PI / 2 : Math.PI / 2); } else if (dy == 0) { angle = (float) (dx < 0 ? Math.PI : 0); } else { angle = (float) Math.atan(dy / dx); if (dx > 0) { if (dy < 0) { angle += Math.PI * 2; } } else { angle += Math.PI; } } // convert to 0-1. value and get color data[index++] = getGradientColor((float) (angle / (2 * Math.PI))); } } image.setRGB(0 /*startX*/, 0 /*startY*/, w, h, data, 0 /*offset*/, w /*scansize*/); return image.getRaster(); } } } }
tools/layoutlib/bridge/src/android/graphics/RadialGradient.java +4 −4 File changed.Contains only whitespace changes. Show changes