ui: fixed the button corners transparent
authorminkee.lee <minkee.lee@samsung.com>
Fri, 21 Aug 2015 08:34:11 +0000 (17:34 +0900)
committerminkee.lee <minkee.lee@samsung.com>
Fri, 21 Aug 2015 08:34:11 +0000 (17:34 +0900)
- Now, the corners outside the rounded button is transparent.

Change-id: I6ee95d4c090b14917063e7e50e66cc3c667cbf38
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
src/org/tizen/emulator/manager/renewal/resources/ColorResources.java
src/org/tizen/emulator/manager/renewal/resources/PatchImageResources.java
src/org/tizen/emulator/manager/ui/renewal/widgets/ButtonResourceInfo.java
src/org/tizen/emulator/manager/ui/renewal/widgets/GrayButton.java
src/org/tizen/emulator/manager/ui/renewal/widgets/ImageButton.java
src/org/tizen/emulator/manager/ui/renewal/widgets/NinePatchButton.java
src/org/tizen/emulator/manager/ui/renewal/widgets/NinePatchResourceInfo.java

index 4ce44c2..4d5efbe 100644 (file)
@@ -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;
 
index 75f9f20..a2454bd 100644 (file)
 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;
        }
 
 }
index 646dd17..23f1283 100644 (file)
@@ -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));
 
        }
 
index 9c19094..0d6e1ae 100644 (file)
@@ -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,
index cec7560..bf88131 100644 (file)
@@ -87,7 +87,7 @@ public class ImageButton extends Canvas {
                fonts = new ArrayList<Font>();
 
                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);
index 11031b9..417671e 100644 (file)
@@ -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;
index b0a1b4b..f3d6b23 100644 (file)
@@ -41,6 +41,10 @@ public class NinePatchResourceInfo {
        private final Map<String, ImageResources> map = new HashMap<String, ImageResources> ();
        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;
+       }
 }