this.pressedKeyEventList = new LinkedList<KeyEventData>();
int style = SWT.NO_TRIM | SWT.DOUBLE_BUFFERED;
- if (skinInfo.isPhoneShape() == false) {
- style = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.BORDER;
- }
+// if (skinInfo.isPhoneShape() == false) {
+// style = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.BORDER;
+// }
this.shell = new Shell(Display.getDefault(), style);
this.currentState = state;
} else { /* general purpose skin */
skinComposer = new GeneralPurposeSkinComposer(config, shell,
currentState, imageRegistry, communicator);
+
+ ((GeneralPurposeSkinComposer) skinComposer).addGeneralPurposeListener(shell);
}
lcdCanvas = skinComposer.compose();
}
- public ImageData getSkinImageData( Short id, ImageType imageType ) {
+ public ImageData getSkinImageData(Short id, ImageType imageType) {
- Image image = skinImageMap.get( makeKey( id, imageType ) );
-
- if ( null != image ) {
+ Image image = skinImageMap.get(makeKey(id, imageType));
+ if (null != image) {
return image.getImageData();
-
} else {
-
RotationsType rotations = dbiContents.getRotations();
- if ( null == rotations ) {
- logger.severe( "Fail to loading rotations element from dbi." );
+ if (null == rotations) {
+ logger.severe("Fail to loading rotations element from dbi.");
return null;
}
String skinPath = getSkinPath(argSkinPath);
logger.info("get image data of skin from " + skinPath);
- RotationType targetRotation = SkinRotation.getRotation( id );
-
+ RotationType targetRotation = SkinRotation.getRotation(id);
List<RotationType> rotationList = rotations.getRotation();
- for ( RotationType rotation : rotationList ) {
-
+ for (RotationType rotation : rotationList) {
ImageListType imageList = rotation.getImageList();
+ if (imageList == null) {
+ continue;
+ }
+
String mainImage = imageList.getMainImage();
String keyPressedImage = imageList.getKeyPressedImage();
- if ( targetRotation.getName().value().equals( rotation.getName().value() ) ) {
-
- String mainKey = makeKey( id, ImageType.IMG_TYPE_MAIN );
- skinImageMap.put( mainKey, new Image( display, skinPath + File.separator + mainImage ) );
+ if (targetRotation.getName().value().equals(rotation.getName().value())) {
+ String mainKey = makeKey(id, ImageType.IMG_TYPE_MAIN);
+ skinImageMap.put(mainKey,
+ new Image(display, skinPath + File.separator + mainImage));
- String pressedKey = makeKey( id, ImageType.IMG_TYPE_PRESSED );
- skinImageMap.put( pressedKey, new Image( display, skinPath + File.separator + keyPressedImage ) );
+ String pressedKey = makeKey(id, ImageType.IMG_TYPE_PRESSED);
+ skinImageMap.put(pressedKey,
+ new Image(display, skinPath + File.separator + keyPressedImage));
break;
-
}
-
}
- Image registeredImage = skinImageMap.get( makeKey( id, imageType ) );
+ Image registeredImage = skinImageMap.get(makeKey(id, imageType));
- if ( null != registeredImage ) {
+ if (null != registeredImage) {
return registeredImage.getImageData();
} else {
return null;
import java.util.logging.Logger;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.MouseMoveListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+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.widgets.Canvas;
import org.eclipse.swt.widgets.Shell;
private EmulatorSkinState currentState;
private ImageRegistry imageRegistry;
+ private SkinPatches frame;
private SocketCommunicator communicator;
+ private PaintListener shellPaintListener;
+ private MouseMoveListener shellMouseMoveListener;
+ private MouseListener shellMouseListener;
+
+ private boolean isGrabbedShell;
+ private Point grabPosition;
+
public GeneralPurposeSkinComposer(EmulatorConfig config, Shell shell,
EmulatorSkinState currentState, ImageRegistry imageRegistry,
SocketCommunicator communicator) {
this.shell = shell;
this.currentState = currentState;
this.imageRegistry = imageRegistry;
- this.communicator = communicator;
+ this.communicator = communicator; //TODO: delete
+ this.isGrabbedShell= false;
+ this.grabPosition = new Point(0, 0);
+
+ this.frame = new SkinPatches("images/emul-window/");
}
@Override
lcdCanvas.setBounds(lcdBounds);
+ /* arrange the skin image */
+ Image tempImage = null;
+
+ if (currentState.getCurrentImage() != null) {
+ tempImage = currentState.getCurrentImage();
+ }
+
+ currentState.setCurrentImage(
+ frame.getPatchedImage(lcdBounds.width, lcdBounds.height));
+
+ if (tempImage != null) {
+ tempImage.dispose();
+ }
+
+ /* custom window shape */
+ SkinUtil.trimShell(shell, currentState.getCurrentImage());
+
+ /* set window size */
+ if (currentState.getCurrentImage() != null) {
+ ImageData imageData = currentState.getCurrentImage().getImageData();
+ shell.setMinimumSize(imageData.width, imageData.height);
+ shell.setSize(imageData.width, imageData.height);
+ }
+
shell.pack();
shell.redraw();
}
public Rectangle adjustLcdGeometry(
Canvas lcdCanvas, int resolutionW, int resolutionH,
int scale, short rotationId) {
- Rectangle lcdBounds = new Rectangle(0, 0, 0, 0);
+
+ Rectangle lcdBounds = new Rectangle(
+ frame.getPatchWidth(), frame.getPatchHeight(), 0, 0);
float convertedScale = SkinUtil.convertScale(scale);
RotationInfo rotation = RotationInfo.getValue(rotationId);
return lcdBounds;
}
+ public void addGeneralPurposeListener(final Shell shell) {
+ shellPaintListener = new PaintListener() {
+ @Override
+ public void paintControl(final PaintEvent e) {
+ /* general shell does not support native transparency,
+ * so draw image with GC. */
+ if (currentState.getCurrentImage() != null) {
+ e.gc.drawImage(currentState.getCurrentImage(), 0, 0);
+ }
+
+ }
+ };
+
+ shell.addPaintListener(shellPaintListener);
+
+ shellMouseMoveListener = new MouseMoveListener() {
+ @Override
+ public void mouseMove(MouseEvent e) {
+ if (isGrabbedShell == true && e.button == 0/* left button */ &&
+ currentState.getCurrentPressedHWKey() == null) {
+ /* move a window */
+ Point previousLocation = shell.getLocation();
+ int x = previousLocation.x + (e.x - grabPosition.x);
+ int y = previousLocation.y + (e.y - grabPosition.y);
+
+ shell.setLocation(x, y);
+ return;
+ }
+ }
+ };
+
+ shell.addMouseMoveListener(shellMouseMoveListener);
+
+ shellMouseListener = new MouseListener() {
+ @Override
+ public void mouseUp(MouseEvent e) {
+ if (e.button == 1) { /* left button */
+ logger.info("mouseUp in Skin");
+
+ isGrabbedShell = false;
+ grabPosition.x = grabPosition.y = 0;
+ }
+ }
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ if (1 == e.button) { /* left button */
+ logger.info("mouseDown in Skin");
+
+ isGrabbedShell = true;
+ grabPosition.x = e.x;
+ grabPosition.y = e.y;
+ }
+ }
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ /* do nothing */
+ }
+ };
+
+ shell.addMouseListener(shellMouseListener);
+ }
+
// private void createHWKeyRegion() {
// if (compositeBase != null) {
// compositeBase.dispose();
@Override
public void composerFinalize() {
- /* do nothing */
+ if (null != shellPaintListener) {
+ shell.removePaintListener(shellPaintListener);
+ }
+
+ if (null != shellMouseMoveListener) {
+ shell.removeMouseMoveListener(shellMouseMoveListener);
+ }
+
+ if (null != shellMouseListener) {
+ shell.removeMouseListener(shellMouseListener);
+ }
+
+ frame.freePatches();
}
}
--- /dev/null
+/**
+ *
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.skin.layout;
+
+import java.util.logging.Logger;
+
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.tizen.emulator.skin.log.SkinLogger;
+
+public class SkinPatches {
+ private Logger logger =
+ SkinLogger.getSkinLogger(SkinPatches.class).getLogger();
+
+ private String pathImage;
+ private int patchWidth;
+ private int patchHeight;
+
+ /* nine patches */
+ private Image imageLT; /* left-top */
+ private Image imageCT; /* center-top */
+ private Image imageRT; /* right-top */
+
+ private Image imageLC;
+ private Image imageRC;
+
+ private Image imageLB; /* left-bottom */
+ private Image imageCB;
+ private Image imageRB;
+
+ // TODO: configurable
+ private static final String filenameLT = "LT.png";
+ private static final String filenameCT = "CT.png";
+ private static final String filenameRT = "RT.png";
+
+ private static final String filenameLC = "LC.png";
+ private static final String filenameRC = "RC.png";
+
+ private static final String filenameLB = "LB.png";
+ private static final String filenameCB = "CB.png";
+ private static final String filenameRB = "RB.png";
+
+ public SkinPatches(String path) {
+ this.pathImage = path;
+
+ loadPatches(pathImage);
+
+ // TODO:
+ this.patchWidth = imageLT.getImageData().width;
+ this.patchHeight = imageLT.getImageData().height;
+ logger.info("patch size : " + patchWidth + "x" + patchHeight);
+ }
+
+ public int getPatchWidth() {
+ return patchWidth;
+ }
+
+ public int getPatchHeight() {
+ return patchHeight;
+ }
+
+ public Image getPatchedImage(int resolutionWidth, int resolutionHeight) {
+ Image patchedImage = new Image(Display.getCurrent(),
+ (patchWidth * 2) + resolutionWidth,
+ (patchHeight * 2) + resolutionHeight);
+
+ GC gc = new GC(patchedImage);
+
+ /* top side */
+ gc.drawImage(imageLT, 0, 0);
+ gc.drawImage(imageCT, 0, 0, 1, patchHeight,
+ patchWidth, 0, resolutionWidth, patchHeight);
+ gc.drawImage(imageRT, patchWidth + resolutionWidth, 0);
+
+ /* middle side */
+ gc.drawImage(imageLC, 0, 0, patchWidth, 1,
+ 0, patchHeight, patchWidth, resolutionHeight);
+ gc.drawImage(imageRC, 0, 0, patchWidth, 1,
+ patchWidth + resolutionWidth, patchHeight, patchWidth, resolutionHeight);
+
+ /* bottom side */
+ gc.drawImage(imageLB, 0, patchHeight + resolutionHeight);
+ gc.drawImage(imageCB, 0, 0, 1, patchHeight,
+ patchWidth, patchHeight + resolutionHeight, resolutionWidth, patchHeight);
+ gc.drawImage(imageRB, patchWidth + resolutionWidth, patchHeight + resolutionHeight);
+
+ gc.dispose();
+
+ return patchedImage;
+ }
+
+ private void loadPatches(String path) {
+ ClassLoader loader = this.getClass().getClassLoader();
+
+ imageLT = new Image(Display.getCurrent(),
+ loader.getResourceAsStream(path + filenameLT));
+ logger.info("left-top image is loaded from " + path + filenameLT);
+ imageCT = new Image(Display.getCurrent(),
+ loader.getResourceAsStream(path + filenameCT));
+ imageRT = new Image(Display.getCurrent(),
+ loader.getResourceAsStream(path + filenameRT));
+
+ imageLC = new Image(Display.getCurrent(),
+ loader.getResourceAsStream(path + filenameLC));
+ imageRC = new Image(Display.getCurrent(),
+ loader.getResourceAsStream(path + filenameRC));
+
+ imageLB = new Image(Display.getCurrent(),
+ loader.getResourceAsStream(path + filenameLB));
+ imageCB = new Image(Display.getCurrent(),
+ loader.getResourceAsStream(path + filenameCB));
+ imageRB = new Image(Display.getCurrent(),
+ loader.getResourceAsStream(path + filenameRB));
+ }
+
+ public void freePatches() {
+ imageLT.dispose();
+ imageCT.dispose();
+ imageRT.dispose();
+
+ imageLC.dispose();
+ imageRC.dispose();
+
+ imageLB.dispose();
+ imageCB.dispose();
+ imageRB.dispose();
+ }
+}