diff options
author | Tor Norbye <tnorbye@google.com> | 2010-11-09 12:38:50 -0800 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2010-11-09 12:38:50 -0800 |
commit | 6b32cd049db314cdda25b18113e1a3a359cc7c11 (patch) | |
tree | f2c2fbb7ee43e4c3aa7ead55ac88cc7be729e5f8 | |
parent | 0b51399d2ae99b94608c6cbb3533a3101142c24c (diff) | |
parent | 93b86c1f3185c8df21e2a45a31e4cd9ce567cef0 (diff) | |
download | sdk-6b32cd049db314cdda25b18113e1a3a359cc7c11.zip sdk-6b32cd049db314cdda25b18113e1a3a359cc7c11.tar.gz sdk-6b32cd049db314cdda25b18113e1a3a359cc7c11.tar.bz2 |
Merge "Fix icon painting transparency for the palette"
3 files changed, 60 insertions, 24 deletions
diff --git a/eclipse/dictionary.txt b/eclipse/dictionary.txt index a010809..9e0bc97 100644 --- a/eclipse/dictionary.txt +++ b/eclipse/dictionary.txt @@ -5,6 +5,7 @@ aidl alt android antialias +antialiased apache api apk @@ -95,6 +96,7 @@ registry reparse reparses residual +scrollable scrollbar scrollbars sdk @@ -105,6 +107,7 @@ standalone stateless stderr stdout +subclassing supertype syncs themed @@ -120,6 +123,7 @@ uri url validator verbosity +vs webtools workflow xml diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/IconFactory.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/IconFactory.java index c57734b..a899bba 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/IconFactory.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/IconFactory.java @@ -22,12 +22,14 @@ import com.android.sdklib.SdkConstants; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; import java.util.HashMap; @@ -47,22 +49,22 @@ public class IconFactory { public static final int SHAPE_CIRCLE = 'C'; public static final int SHAPE_RECT = 'R'; public static final int SHAPE_DEFAULT = SHAPE_CIRCLE; - + private static IconFactory sInstance; private HashMap<String, Image> mIconMap = new HashMap<String, Image>(); private HashMap<String, ImageDescriptor> mImageDescMap = new HashMap<String, ImageDescriptor>(); - + private IconFactory() { } - + public static synchronized IconFactory getInstance() { if (sInstance == null) { sInstance = new IconFactory(); } return sInstance; } - + public void Dispose() { // Dispose icons for (Image icon : mIconMap.values()) { @@ -78,7 +80,7 @@ public class IconFactory { * Returns an Image for a given icon name. * <p/> * Callers should not dispose it. - * + * * @param osName The leaf name, without the extension, of an existing icon in the * editor's "icons" directory. If it doesn't exists, a default icon will be * generated automatically based on the name. @@ -91,7 +93,7 @@ public class IconFactory { * Returns an Image for a given icon name. * <p/> * Callers should not dispose it. - * + * * @param osName The leaf name, without the extension, of an existing icon in the * editor's "icons" directory. If it doesn't exists, a default icon will be * generated automatically based on the name. @@ -119,7 +121,7 @@ public class IconFactory { * Returns an ImageDescriptor for a given icon name. * <p/> * Callers should not dispose it. - * + * * @param osName The leaf name, without the extension, of an existing icon in the * editor's "icons" directory. If it doesn't exists, a default icon will be * generated automatically based on the name. @@ -127,12 +129,12 @@ public class IconFactory { public ImageDescriptor getImageDescriptor(String osName) { return getImageDescriptor(osName, COLOR_DEFAULT, SHAPE_DEFAULT); } - + /** * Returns an ImageDescriptor for a given icon name. * <p/> * Callers should not dispose it. - * + * * @param osName The leaf name, without the extension, of an existing icon in the * editor's "icons" directory. If it doesn't exists, a default icon will be * generated automatically based on the name. @@ -152,7 +154,7 @@ public class IconFactory { if (id == null) { id = new LetterImageDescriptor(osName.charAt(0), color, shape); } - + // Note that we store null references in the icon map, to avoid looking them // up every time. If it didn't exist once, it will not exist later. mImageDescMap.put(key, id); @@ -171,40 +173,54 @@ public class IconFactory { private final int mShape; public LetterImageDescriptor(char letter, int color, int shape) { - mLetter = letter; + mLetter = Character.toUpperCase(letter); mColor = color; mShape = shape; } - + @Override public ImageData getImageData() { - + final int SX = 15; final int SY = 15; final int RX = 4; final int RY = 4; - + Display display = Display.getCurrent(); if (display == null) { return null; } Image image = new Image(display, SX, SY); - - image.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); - + GC gc = new GC(image); gc.setAdvanced(true); gc.setAntialias(SWT.ON); gc.setTextAntialias(SWT.ON); + // image.setBackground() does not appear to have any affect; we must explicitly + // paint into the image the background color we want masked out later. + // HOWEVER, alpha transparency does not work; we only get to mark a single color + // as transparent. You might think we could pick a system color (to avoid having + // to allocate and dispose the color), or a wildly unique color (to make sure we + // don't accidentally pick up any extra pixels in the image as transparent), but + // this has the very unfortunate side effect of making neighbor pixels in the + // antialiased rendering of the circle pick up shades of that alternate color, + // which looks bad. Therefore we pick a color which is similar to one of our + // existing colors but hopefully different from most pixels. A visual check + // confirms that this seems to work pretty well: + RGB backgroundRgb = new RGB(254, 254, 254); + Color backgroundColor = new Color(display, backgroundRgb); + gc.setBackground(backgroundColor); + gc.fillRectangle(0, 0, SX, SY); + gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); if (mShape == SHAPE_CIRCLE) { gc.fillOval(0, 0, SX - 1, SY - 1); } else if (mShape == SHAPE_RECT) { gc.fillRoundRectangle(0, 0, SX - 1, SY - 1, RX, RY); } - + gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK)); gc.setLineWidth(1); if (mShape == SHAPE_CIRCLE) { @@ -234,9 +250,17 @@ public class IconFactory { if (SdkConstants.CURRENT_PLATFORM == SdkConstants.PLATFORM_WINDOWS) { ofx = +1; ofy = -1; + } else if (SdkConstants.CURRENT_PLATFORM == SdkConstants.PLATFORM_DARWIN) { + // Tweak pixel positioning of some letters that don't look good on the Mac + if (mLetter != 'T' && mLetter != 'V') { + ofy = -1; + } + if (mLetter == 'I') { + ofx = -2; + } } - - String s = Character.toString(mLetter).toUpperCase(); + + String s = Character.toString(mLetter); Point p = gc.textExtent(s); int tx = (SX + ofx - p.x) / 2; int ty = (SY + ofy - p.y) / 2; @@ -244,12 +268,20 @@ public class IconFactory { font.dispose(); gc.dispose(); - + ImageData data = image.getImageData(); image.dispose(); + backgroundColor.dispose(); + + // Set transparent pixel in the palette such that on paint (over palette, + // which has a background of SWT.COLOR_WIDGET_BACKGROUND, and over the tree + // which has a white background) we will substitute the background in for + // the backgroundPixel. + int backgroundPixel = data.palette.getPixel(backgroundRgb); + data.transparentPixel = backgroundPixel; + return data; } - } - + } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteComposite.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteComposite.java index 4d62502..71b1605 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteComposite.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteComposite.java @@ -159,7 +159,7 @@ public class PaletteComposite extends Composite { // ----- private methods ---- - /** Returns true if scroolbar changed. */ + /** Returns true if scrollbar changed. */ private boolean recomputeScrollbar() { if (mVBar != null && mRoot != null) { |