aboutsummaryrefslogtreecommitdiffstats
path: root/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java
diff options
context:
space:
mode:
Diffstat (limited to 'assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java')
-rw-r--r--assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java100
1 files changed, 48 insertions, 52 deletions
diff --git a/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java b/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java
index 07b7a6b..8fdbddf 100644
--- a/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java
+++ b/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java
@@ -16,7 +16,9 @@
package com.android.assetstudiolib;
-import com.android.resources.Density;
+import com.android.assetstudiolib.Util.Effect;
+import com.android.assetstudiolib.Util.FillEffect;
+import com.android.assetstudiolib.Util.ShadowEffect;
import java.awt.Color;
import java.awt.GradientPaint;
@@ -28,65 +30,59 @@ import java.awt.image.BufferedImage;
* A {@link GraphicGenerator} that generates Android "menu" icons.
*/
public class MenuIconGenerator extends GraphicGenerator {
- private static final Rectangle BASE_IMAGE_RECT = new Rectangle(0, 0, 48, 48);
- private static final Rectangle BASE_TARGET_RECT = new Rectangle(8, 8, 32, 32);
-
- private Options mOptions;
-
- public MenuIconGenerator(GraphicGeneratorContext context, Options options) {
- mOptions = options;
+ /** Creates a menu icon generator */
+ public MenuIconGenerator() {
}
- public BufferedImage generate() {
- final float scaleFactor = GraphicGenerator.getScaleFactor(mOptions.density);
- Rectangle imageRect = Util.scaleRectangle(BASE_IMAGE_RECT, scaleFactor);
- Rectangle targetRect = Util.scaleRectangle(BASE_TARGET_RECT, scaleFactor);
+ @Override
+ public BufferedImage generate(GraphicGeneratorContext context, Options options) {
+ Rectangle imageSizeHdpi = new Rectangle(0, 0, 72, 72);
+ Rectangle targetRectHdpi = new Rectangle(12, 12, 48, 48);
+ float scaleFactor = GraphicGenerator.getHdpiScaleFactor(options.density);
+ Rectangle imageRect = Util.scaleRectangle(imageSizeHdpi, scaleFactor);
+ Rectangle targetRect = Util.scaleRectangle(targetRectHdpi, scaleFactor);
BufferedImage outImage = Util.newArgbBufferedImage(imageRect.width, imageRect.height);
Graphics2D g = (Graphics2D) outImage.getGraphics();
- {
- BufferedImage tempImage = Util.newArgbBufferedImage(
- imageRect.width, imageRect.height);
- Graphics2D g2 = (Graphics2D) tempImage.getGraphics();
- Util.drawCenterInside(g2, mOptions.sourceImage, targetRect);
+ BufferedImage tempImage = Util.newArgbBufferedImage(
+ imageRect.width, imageRect.height);
+ Graphics2D g2 = (Graphics2D) tempImage.getGraphics();
+ Util.drawCenterInside(g2, options.sourceImage, targetRect);
- Util.drawEffects(g, tempImage, 0, 0, new Util.Effect[]{
- new Util.FillEffect(
- new GradientPaint(
- 0, 0,
- new Color(0xa3a3a3),
- 0, imageRect.height,
- new Color(0x787878))),
- new Util.ShadowEffect(
- 0,
- 3 * scaleFactor,
- 3 * scaleFactor,
- Color.black,
- 0.2,
- true),
- new Util.ShadowEffect(
- 0,
- 1,
- 0,
- Color.black,
- 0.35,
- true),
- new Util.ShadowEffect(
- 0,
- -1,
- 0,
- Color.white,
- 0.35,
- true),
- });
- }
+ Util.drawEffects(g, tempImage, 0, 0, new Effect[] {
+ new FillEffect(
+ new GradientPaint(
+ 0, 0,
+ new Color(0xa3a3a3),
+ 0, imageRect.height,
+ new Color(0x787878))),
+ new ShadowEffect(
+ 0,
+ 3 * scaleFactor,
+ 3 * scaleFactor,
+ Color.BLACK,
+ 0.2,
+ true),
+ new ShadowEffect(
+ 0,
+ 1,
+ 0,
+ Color.BLACK,
+ 0.35,
+ true),
+ new ShadowEffect(
+ 0,
+ -1,
+ 0,
+ Color.WHITE,
+ 0.35,
+ true),
+ });
- return outImage;
- }
+ g.dispose();
+ g2.dispose();
- public static class Options {
- public BufferedImage sourceImage;
- public Density density = Density.XHIGH;
+ return outImage;
}
}