From c0850ee5d1d624565859cc7cd0b91e0dd910478b Mon Sep 17 00:00:00 2001 From: "giwoong.kim" Date: Thu, 29 Nov 2012 21:59:48 +0900 Subject: [PATCH] skin: trim a nine-patch skin trim a nine-patch image in general skin Signed-off-by: GiWoong Kim --- .../skin/layout/GeneralPurposeSkinComposer.java | 27 +++++++++++++++++++++- .../tizen/emulator/skin/layout/SkinPatches.java | 13 ++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java index cce4980..23a6d78 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/GeneralPurposeSkinComposer.java @@ -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 diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/SkinPatches.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/SkinPatches.java index 8a9608a..9916e2a 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/SkinPatches.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/SkinPatches.java @@ -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); -- 2.7.4