From: minkee.lee Date: Fri, 21 Aug 2015 08:34:11 +0000 (+0900) Subject: ui: fixed the button corners transparent X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8588ce29e8584ab2cb9e91d056b7514bf85ce946;p=sdk%2Femulator%2Femulator-manager.git ui: fixed the button corners transparent - Now, the corners outside the rounded button is transparent. Change-id: I6ee95d4c090b14917063e7e50e66cc3c667cbf38 Signed-off-by: minkee.lee --- diff --git a/src/org/tizen/emulator/manager/renewal/resources/ColorResources.java b/src/org/tizen/emulator/manager/renewal/resources/ColorResources.java index 4ce44c2..4d5efbe 100644 --- a/src/org/tizen/emulator/manager/renewal/resources/ColorResources.java +++ b/src/org/tizen/emulator/manager/renewal/resources/ColorResources.java @@ -34,14 +34,15 @@ import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; public enum ColorResources { + WHITE(255, 255, 255), + BLACK(0, 0, 0), + // nine patch button GRAY_BTN_NORMAL(149, 159, 164), GRAY_BTN_HOVER(149, 159, 164), GRAY_BTN_PUSH(100, 110, 144), GRAY_BTN_DISABLE(208, 208, 208), - GRAY_BTN_FONT(255, 255, 255), - MESSAGE_BOX_TITLE_BG(111, 125, 149), MESSAGE_BOX_TITLE_FONT(255, 255, 255), MESSAGE_BOX_CONTENTS_BG(255, 255, 255), @@ -50,6 +51,9 @@ public enum ColorResources { MESSAGE_BOX_BUTTON_BG(149, 159, 165), MESSAGE_BOX_BUTTON_FONT(255, 255, 255); + public static ColorResources GRAY_BTN_FONT = WHITE; + + Color color; int r,g,b; diff --git a/src/org/tizen/emulator/manager/renewal/resources/PatchImageResources.java b/src/org/tizen/emulator/manager/renewal/resources/PatchImageResources.java index 75f9f20..a2454bd 100644 --- a/src/org/tizen/emulator/manager/renewal/resources/PatchImageResources.java +++ b/src/org/tizen/emulator/manager/renewal/resources/PatchImageResources.java @@ -31,14 +31,16 @@ package org.tizen.emulator.manager.renewal.resources; import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.widgets.Display; import org.tizen.emulator.manager.ui.renewal.widgets.NinePatchResourceInfo; public class PatchImageResources { - public static Image getButtonImage(int width, int height, NinePatchResourceInfo ninePatchImagesInfo) { + public static Image getNinePatchButtonImage(int width, int height, NinePatchResourceInfo ninePatchImagesInfo) { Image lt = ninePatchImagesInfo.getLeftTopImage().getImage(); Image t = ninePatchImagesInfo.getTopImage().getImage(); Image rt = ninePatchImagesInfo.getRightTopImage().getImage(); @@ -52,6 +54,13 @@ public class PatchImageResources { GC gc = new GC(image); gc.setInterpolation(SWT.NONE); + + // First, fill background to make corner transparent. + Color transparentColor = ninePatchImagesInfo.getTransparentColor().getColor(); + gc.setBackground(transparentColor); + gc.fillRectangle(0, 0, width, height); + + // draw background gc.setBackground(ninePatchImagesInfo.getBackground().getColor()); gc.fillRectangle(l.getImageData().width, t.getImageData().height, width - l.getImageData().width - r.getImageData().width, @@ -87,7 +96,17 @@ public class PatchImageResources { b.getImageData().height); gc.drawImage(rb, width - rb.getImageData().width, height - rb.getImageData().height); gc.dispose(); - return image; + + // Make corner transparent + ImageData data = image.getImageData(); + int cornerPixel = data.palette.getPixel(transparentColor.getRGB()); + data.transparentPixel = cornerPixel; + Image cornerTransparentedImage = new Image(Display.getCurrent(), data); + + // dispose original image + image.dispose(); + + return cornerTransparentedImage; } } diff --git a/src/org/tizen/emulator/manager/ui/renewal/widgets/ButtonResourceInfo.java b/src/org/tizen/emulator/manager/ui/renewal/widgets/ButtonResourceInfo.java index 646dd17..23f1283 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/widgets/ButtonResourceInfo.java +++ b/src/org/tizen/emulator/manager/ui/renewal/widgets/ButtonResourceInfo.java @@ -43,44 +43,45 @@ public class ButtonResourceInfo { private final WSTATE disableState = WSTATE.DISABLE_ON; - public void setNormalImage(ColorResources background, + public void setNormalImage(ColorResources background, ColorResources transparentColor, ImageResources lt, ImageResources t, ImageResources rt, ImageResources r, ImageResources rb, ImageResources b, ImageResources lb, ImageResources l) { - setImages(WSTATE.NORMAL, background, lt, t, rt, r, rb, b, lb, l); + setImages(WSTATE.NORMAL, background, transparentColor, lt, t, rt, r, rb, b, lb, l); } - public void setHoverImage(ColorResources background, + public void setHoverImage(ColorResources background, ColorResources transparentColor, ImageResources lt, ImageResources t, ImageResources rt, ImageResources r, ImageResources rb, ImageResources b, ImageResources lb, ImageResources l) { - setImages(WSTATE.HOVER, background, lt, t, rt, r, rb, b, lb, l); + setImages(WSTATE.HOVER, background, transparentColor, lt, t, rt, r, rb, b, lb, l); } - public void setPushImage(ColorResources background, + public void setPushImage(ColorResources background, ColorResources transparentColor, ImageResources lt, ImageResources t, ImageResources rt, ImageResources r, ImageResources rb, ImageResources b, ImageResources lb, ImageResources l) { - setImages(WSTATE.PUSH, background, lt, t, rt, r, rb, b, lb, l); + setImages(WSTATE.PUSH, background, transparentColor, lt, t, rt, r, rb, b, lb, l); } - public void setDisableImage(ColorResources background, + public void setDisableImage(ColorResources background, ColorResources transparentColor, ImageResources lt, ImageResources t, ImageResources rt, ImageResources r, ImageResources rb, ImageResources b, ImageResources lb, ImageResources l) { - setImages(disableState, background, lt, t, rt, r, rb, b, lb, l); + setImages(disableState, background, transparentColor, lt, t, rt, r, rb, b, lb, l); } - private void setImages(WSTATE wState, ColorResources background, + private void setImages(WSTATE wState, ColorResources background, ColorResources transparentColor, ImageResources lt, ImageResources t, ImageResources rt, ImageResources r, ImageResources rb, ImageResources b, ImageResources lb, ImageResources l) { - map.put(wState, new NinePatchResourceInfo(background, lt, t, rt, r, rb, b, lb, l)); + map.put(wState, new NinePatchResourceInfo(background, transparentColor, + lt, t, rt, r, rb, b, lb, l)); } diff --git a/src/org/tizen/emulator/manager/ui/renewal/widgets/GrayButton.java b/src/org/tizen/emulator/manager/ui/renewal/widgets/GrayButton.java index 9c19094..0d6e1ae 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/widgets/GrayButton.java +++ b/src/org/tizen/emulator/manager/ui/renewal/widgets/GrayButton.java @@ -55,6 +55,7 @@ public class GrayButton extends NinePatchButton { private static void initButtonResourceInfo() { buttonResourceInfo = new ButtonResourceInfo(); buttonResourceInfo.setNormalImage(ColorResources.GRAY_BTN_NORMAL, + ColorResources.BLACK, ImageResources.GRAY_BTN_NORMAL_LT, ImageResources.GRAY_BTN_NORMAL_T, ImageResources.GRAY_BTN_NORMAL_RT, @@ -65,6 +66,7 @@ public class GrayButton extends NinePatchButton { ImageResources.GRAY_BTN_NORMAL_L); buttonResourceInfo.setHoverImage(ColorResources.GRAY_BTN_HOVER, + ColorResources.BLACK, ImageResources.GRAY_BTN_HOVER_LT, ImageResources.GRAY_BTN_HOVER_T, ImageResources.GRAY_BTN_HOVER_RT, @@ -75,6 +77,7 @@ public class GrayButton extends NinePatchButton { ImageResources.GRAY_BTN_HOVER_L); buttonResourceInfo.setPushImage(ColorResources.GRAY_BTN_PUSH, + ColorResources.BLACK, ImageResources.GRAY_BTN_PUSH_LT, ImageResources.GRAY_BTN_PUSH_T, ImageResources.GRAY_BTN_PUSH_RT, @@ -85,6 +88,7 @@ public class GrayButton extends NinePatchButton { ImageResources.GRAY_BTN_PUSH_L); buttonResourceInfo.setDisableImage(ColorResources.GRAY_BTN_DISABLE, + ColorResources.BLACK, ImageResources.GRAY_BTN_DISABLE_LT, ImageResources.GRAY_BTN_DISABLE_T, ImageResources.GRAY_BTN_DISABLE_RT, diff --git a/src/org/tizen/emulator/manager/ui/renewal/widgets/ImageButton.java b/src/org/tizen/emulator/manager/ui/renewal/widgets/ImageButton.java index cec7560..bf88131 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/widgets/ImageButton.java +++ b/src/org/tizen/emulator/manager/ui/renewal/widgets/ImageButton.java @@ -87,7 +87,7 @@ public class ImageButton extends Canvas { fonts = new ArrayList(); for (WSTATE s : WSTATE.values()) { - colors.add(s.getId(), ColorResources.GRAY_BTN_NORMAL.getColor()); + colors.add(s.getId(), null); fontColors.add(s.getId(), ColorResources.GRAY_BTN_FONT.getColor()); fonts.add(s.getId(), FontResources.BUTTON_FONT.getFont()); images.add(s.getId(), null); diff --git a/src/org/tizen/emulator/manager/ui/renewal/widgets/NinePatchButton.java b/src/org/tizen/emulator/manager/ui/renewal/widgets/NinePatchButton.java index 11031b9..417671e 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/widgets/NinePatchButton.java +++ b/src/org/tizen/emulator/manager/ui/renewal/widgets/NinePatchButton.java @@ -70,28 +70,28 @@ public abstract class NinePatchButton extends ImageButton { switch(state) { case HOVER: if (hoverImage == null) { - hoverImage = PatchImageResources.getButtonImage(width, height, + hoverImage = PatchImageResources.getNinePatchButtonImage(width, height, getButtonResourceInfo().getHoverImages()); } image = hoverImage; break; case PUSH: if (pushImage == null) { - pushImage = PatchImageResources.getButtonImage(width, height, + pushImage = PatchImageResources.getNinePatchButtonImage(width, height, getButtonResourceInfo().getPushImages()); } image = pushImage; break; case DISABLE_ON: if (disableImage == null) { - disableImage = PatchImageResources.getButtonImage(width, height, + disableImage = PatchImageResources.getNinePatchButtonImage(width, height, getButtonResourceInfo().getDisableImages()); } image = disableImage; break; default: if (nomalImage == null) { - nomalImage = PatchImageResources.getButtonImage(width, height, + nomalImage = PatchImageResources.getNinePatchButtonImage(width, height, getButtonResourceInfo().getNormalImages()); } image = nomalImage; diff --git a/src/org/tizen/emulator/manager/ui/renewal/widgets/NinePatchResourceInfo.java b/src/org/tizen/emulator/manager/ui/renewal/widgets/NinePatchResourceInfo.java index b0a1b4b..f3d6b23 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/widgets/NinePatchResourceInfo.java +++ b/src/org/tizen/emulator/manager/ui/renewal/widgets/NinePatchResourceInfo.java @@ -41,6 +41,10 @@ public class NinePatchResourceInfo { private final Map map = new HashMap (); private final ColorResources background; + // This is used to make the corners of button transparent. + // This color should be set as which is not included in button image. + private final ColorResources transparentColor; + static final String LT = "lt"; static final String T = "t"; static final String RT = "rt"; @@ -50,12 +54,13 @@ public class NinePatchResourceInfo { static final String LB = "lb"; static final String L = "l"; - NinePatchResourceInfo(ColorResources background, + NinePatchResourceInfo(ColorResources background, ColorResources transparentColor, ImageResources lt, ImageResources t, ImageResources rt, ImageResources r, ImageResources rb, ImageResources b, ImageResources lb, ImageResources l) { this.background = background; + this.transparentColor = transparentColor; map.put(LT, lt); map.put(T, t); map.put(RT, rt); @@ -101,4 +106,8 @@ public class NinePatchResourceInfo { public ColorResources getBackground() { return background; } + + public ColorResources getTransparentColor() { + return transparentColor; + } }