skin: trim a nine-patch skin
authorgiwoong.kim <giwoong.kim@samsung.com>
Thu, 29 Nov 2012 12:59:48 +0000 (21:59 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Thu, 29 Nov 2012 12:59:48 +0000 (21:59 +0900)
trim a nine-patch image in general skin

Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java
tizen/src/skin/client/src/org/tizen/emulator/skin/layout/SkinPatches.java

index cce4980..23a6d78 100644 (file)
@@ -40,6 +40,7 @@ import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.graphics.ImageData;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.graphics.Region;
 import org.eclipse.swt.widgets.Canvas;
 import org.eclipse.swt.widgets.Shell;
 import org.tizen.emulator.skin.EmulatorSkinState;
@@ -174,7 +175,7 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
                }
 
                /* custom window shape */
-               SkinUtil.trimShell(shell, currentState.getCurrentImage());
+               trimPatchedShell(shell, currentState.getCurrentImage());
 
                /* set window size */
                if (currentState.getCurrentImage() != null) {
@@ -211,6 +212,30 @@ public class GeneralPurposeSkinComposer implements ISkinComposer {
                return lcdBounds;
        }
 
+       public static void trimPatchedShell(Shell shell, Image image) {
+               if (null == image) {
+                       return;
+               }
+               ImageData imageData = image.getImageData();
+
+               int width = imageData.width;
+               int height = imageData.height;
+
+               Region region = new Region();
+               region.add(new Rectangle(0, 0, width, height));
+
+               for (int i = 0; i < width; i++) {
+                       for (int j = 0; j < height; j++) {
+                               int colorPixel = imageData.getPixel(i, j);
+                               if (colorPixel == 0xFF00FF /* magenta */) {
+                                       region.subtract(i, j, 1, 1);
+                               }
+                       }
+               }
+
+               shell.setRegion(region);
+       }
+
        public void addGeneralPurposeListener(final Shell shell) {
                shellPaintListener = new PaintListener() {
                        @Override
index 8a9608a..9916e2a 100644 (file)
@@ -30,6 +30,7 @@ package org.tizen.emulator.skin.layout;
 
 import java.util.logging.Logger;
 
+import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.GC;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Display;
@@ -89,12 +90,16 @@ public class SkinPatches {
        }
 
        public Image getPatchedImage(int centerPatchWidth, int centerPatchHeight) {
+               int patchedImageWidth = (patchWidth * 2) + centerPatchWidth;
+               int patchedImageHeight = (patchHeight * 2) + centerPatchHeight;
+
                Image patchedImage = new Image(display,
-                               (patchWidth * 2) + centerPatchWidth,
-                               (patchHeight * 2) + centerPatchHeight);
+                               patchedImageWidth, patchedImageHeight);
 
-               // TODO: transparency
+               // TODO: copy alphaData
                GC gc = new GC(patchedImage);
+               gc.setBackground(display.getSystemColor(SWT.COLOR_MAGENTA));
+               gc.fillRectangle(0, 0, patchedImageWidth, patchedImageHeight);
 
                /* top side */
                gc.drawImage(imageLT, 0, 0);
@@ -105,6 +110,8 @@ public class SkinPatches {
                /* middle side */
                gc.drawImage(imageL, 0, 0, imageL.getImageData().width, imageL.getImageData().height,
                                0, patchHeight, patchWidth, centerPatchHeight);
+               gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
+               gc.fillRectangle(patchWidth, patchHeight, centerPatchWidth, centerPatchHeight); /* center */
                gc.drawImage(imageR, 0, 0, imageR.getImageData().width, imageR.getImageData().height,
                                patchWidth + centerPatchWidth, patchHeight, patchWidth, centerPatchHeight);