Separate event handlers according to skin type.
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
public long initLayout() {
super.initLayout();
- // sdl uses this handle id.
- windowHandleId = getWindowHandleId();
-
- return windowHandleId;
+ /* sdl uses this handle ID */
+ return getWindowHandleId();
}
private long getWindowHandleId() {
protected void skinFinalize() {
pollThread.stopRequest();
+
+ super.skinFinalize();
}
public long initLayout() {
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
-import org.eclipse.swt.events.MouseTrackAdapter;
-import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.MouseWheelListener;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Canvas;
import org.tizen.emulator.skin.layout.PhoneShapeSkinComposer;
import org.tizen.emulator.skin.log.SkinLogger;
import org.tizen.emulator.skin.screenshot.ScreenShotDialog;
-import org.tizen.emulator.skin.util.SkinRegion;
import org.tizen.emulator.skin.util.SkinRotation;
import org.tizen.emulator.skin.util.SkinUtil;
import org.tizen.emulator.skin.util.SwtUtil;
protected Canvas lcdCanvas;
protected SkinInformation skinInfo;
protected ISkinComposer skinComposer;
- private Color hoverColor;
- private boolean isDefaultHoverColor;
protected EmulatorSkinState currentState;
- protected SkinRegion currentHoverRegion;
- protected SkinRegion currentPressedRegion;
- private int pressedMouseX;
- private int pressedMouseY;
- private boolean isMousePressed;
private boolean isDragStartedInLCD;
- private boolean isHoverState;
private boolean isShutdownRequested;
private boolean isAboutToReopen;
private boolean isOnTop;
private boolean isOnKbd;
- private SkinWindow controlPanel;
+ private SkinWindow controlPanel; //not used yet
protected ScreenShotDialog screenShotDialog;
private Menu contextMenu;
protected SocketCommunicator communicator;
- protected long windowHandleId;
private Listener shellCloseListener;
- private PaintListener shellPaintListener;
- private MouseTrackListener shellMouseTrackListener;
- private MouseMoveListener shellMouseMoveListener;
- private MouseListener shellMouseListener;
private MenuDetectListener shellMenuDetectListener;
//private DragDetectListener canvasDragDetectListener;
private FocusListener canvasFocusListener;
private LinkedList<KeyEventData> pressedKeyEventList;
- private int pressedHWKeyCode;
private EmulatorSkin reopenSkin;
protected EmulatorSkin(EmulatorConfig config, SkinInformation skinInfo, boolean isOnTop) {
this.config = config;
this.skinInfo = skinInfo;
- this.isDefaultHoverColor = true;
this.isOnTop = isOnTop;
this.pressedKeyEventList = new LinkedList<KeyEventData>();
- this.windowHandleId = 0;
- this.pressedHWKeyCode = 0;
-
int style = SWT.NO_TRIM;
if (skinInfo.isPhoneShape() == false) {
style = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.BORDER;
public long initLayout() {
imageRegistry = ImageRegistry.getInstance();
- if (skinInfo.isPhoneShape() == true) {
+ if (skinInfo.isPhoneShape() == true) { /* phone shape skin */
skinComposer = new PhoneShapeSkinComposer(config, shell,
- currentState, imageRegistry);
- } else {
+ currentState, imageRegistry, communicator);
+
+ ((PhoneShapeSkinComposer) skinComposer).addPhoneShapeListener(shell);
+ } else { /* general purpose skin */
skinComposer = new GeneralPurposeSkinComposer(config, shell,
currentState, imageRegistry, communicator);
}
+
lcdCanvas = skinComposer.compose();
- seteHoverColor();
+ /* load a hover color */
+ currentState.setHoverColor(loadHoverColor());
+ /* added event handlers */
addShellListener(shell);
addCanvasListener(shell, lcdCanvas);
+ /* attach a menu */
this.isOnKbd = false;
setMenu();
//
// }
- private void seteHoverColor() {
-
+ private Color loadHoverColor() {
ColorsType colors = config.getDbiContents().getColors();
- if ( null != colors ) {
+
+ if (null != colors) {
RgbType hoverRgb = colors.getHoverColor();
- if ( null != hoverRgb ) {
+ if (null != hoverRgb) {
Long r = hoverRgb.getR();
Long g = hoverRgb.getG();
Long b = hoverRgb.getB();
- if ( null != r && null != g && null != b ) {
- hoverColor = new Color( shell.getDisplay(), new RGB( r.intValue(), g.intValue(), b.intValue() ) );
- isDefaultHoverColor = false;
+ if (null != r && null != g && null != b) {
+ Color hoverColor = new Color(shell.getDisplay(),
+ new RGB(r.intValue(), g.intValue(), b.intValue()));
+ return hoverColor;
}
}
}
- if ( isDefaultHoverColor ) {
- hoverColor = shell.getDisplay().getSystemColor( SWT.COLOR_WHITE );
- }
-
+ /* white */
+ return (new Color(shell.getDisplay(), new RGB(255, 255, 255)));
}
public SkinReopenPolicy open() {
}
protected void skinFinalize() {
- //TODO:
+ skinComposer.composerFinalize();
}
- private void addShellListener( final Shell shell ) {
+ private void addShellListener(final Shell shell) {
shellCloseListener = new Listener() {
@Override
controlPanel = null;
}
- // save config only for emulator close
+ /* save config only for emulator close */
config.setSkinProperty(
SkinPropertiesConstants.WINDOW_X, shell.getLocation().x);
config.setSkinProperty(
currentState.getCurrentKeyPressedImage().dispose();
}
- if ( !isDefaultHoverColor ) {
- hoverColor.dispose();
+ if (currentState.getHoverColor() != null) {
+ currentState.getHoverColor().dispose();
}
skinFinalize();
shell.addListener( SWT.Close, shellCloseListener );
- 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);
- }
-
- }
- };
-
- if (skinInfo.isPhoneShape()) {
- shell.addPaintListener(shellPaintListener);
- }
-
- shellMouseTrackListener = new MouseTrackAdapter() {
- @Override
- public void mouseExit( MouseEvent e ) {
- // MouseMoveListener of shell does not receive event only with MouseMoveListener
- // in case that : hover hardkey -> mouse move into LCD area
- if ( isHoverState ) {
- if ( currentHoverRegion.width == 0 && currentHoverRegion.height == 0 ) {
- shell.redraw();
- } else {
- shell.redraw( currentHoverRegion.x, currentHoverRegion.y, currentHoverRegion.width + 1,
- currentHoverRegion.height + 1, false );
- }
- shell.setToolTipText(null);
-
- isHoverState = false;
- currentHoverRegion.width = currentHoverRegion.height = 0;
- }
- }
-
- };
-
- if (skinInfo.isPhoneShape()) {
- shell.addMouseTrackListener(shellMouseTrackListener);
- }
-
- shellMouseMoveListener = new MouseMoveListener() {
- @Override
- public void mouseMove( MouseEvent e ) {
- if ( EmulatorSkin.this.isMousePressed ) {
- if (0 == e.button) { /* left button */
-
- SkinRegion hardkeyRegion = SkinUtil.getHardKeyArea(e.x, e.y,
- currentState.getCurrentRotationId(), currentState.getCurrentScale());
-
- if ( null == hardkeyRegion ) {
- Point previouseLocation = shell.getLocation();
- int x = previouseLocation.x + ( e.x - EmulatorSkin.this.pressedMouseX );
- int y = previouseLocation.y + ( e.y - EmulatorSkin.this.pressedMouseY );
-
- shell.setLocation( x, y );
- }
-
- }
- } else {
- SkinRegion region = SkinUtil.getHardKeyArea(e.x, e.y,
- currentState.getCurrentRotationId(), currentState.getCurrentScale());
-
- if ( null == region ) {
- if ( isHoverState ) {
- if ( currentHoverRegion.width == 0 && currentHoverRegion.height == 0 ) {
- shell.redraw();
- } else {
- shell.redraw( currentHoverRegion.x, currentHoverRegion.y, currentHoverRegion.width + 1,
- currentHoverRegion.height + 1, false );
- }
- shell.setToolTipText(null);
-
- isHoverState = false;
- currentHoverRegion.width = currentHoverRegion.height = 0;
- }
- } else {
- if (isHoverState == false) {
- shell.setToolTipText(SkinUtil.getHardKeyToolTip(e.x, e.y,
- currentState.getCurrentRotationId(), currentState.getCurrentScale()));
- }
-
- isHoverState = true;
- currentHoverRegion = region;
-
- /* draw hover */
- shell.getDisplay().syncExec(new Runnable() {
- public void run() {
- if (currentHoverRegion.width != 0 && currentHoverRegion.height != 0) {
- GC gc = new GC(shell);
- if (gc != null) {
- gc.setLineWidth(1);
- gc.setForeground(hoverColor);
- gc.drawRectangle(currentHoverRegion.x, currentHoverRegion.y,
- currentHoverRegion.width, currentHoverRegion.height);
-
- gc.dispose();
- }
- }
- }
- });
- }
- }
-
- } //end of mouseMove
- };
-
- if (skinInfo.isPhoneShape()) {
- shell.addMouseMoveListener(shellMouseMoveListener);
- }
-
- shellMouseListener = new MouseListener() {
- @Override
- public void mouseUp( MouseEvent e ) {
- if (1 == e.button) { /* left button */
- logger.info( "mouseUp in Skin" );
- EmulatorSkin.this.pressedMouseX = 0;
- EmulatorSkin.this.pressedMouseY = 0;
- EmulatorSkin.this.isMousePressed = false;
-
- if (pressedHWKeyCode != 0) {
- /* send event */
- KeyEventData keyEventData = new KeyEventData(
- KeyEventType.RELEASED.value(), pressedHWKeyCode, 0, 0);
- communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
- pressedHWKeyCode = 0;
- }
-
- int keyCode = SkinUtil.getHardKeyCode(e.x, e.y,
- currentState.getCurrentRotationId(), currentState.getCurrentScale());
-
- if ( SkinUtil.UNKNOWN_KEYCODE != keyCode ) {
- /* null check : prevent from mouse up without a hover
- ex. doing always on top in hardkey area */
- if ( null != currentHoverRegion ) {
- if ( currentHoverRegion.width == 0 && currentHoverRegion.height == 0 ) {
- shell.redraw();
- } else {
- shell.redraw( currentHoverRegion.x, currentHoverRegion.y, currentHoverRegion.width + 1,
- currentHoverRegion.height + 1, false );
- }
- }
-
- SkinRegion region = SkinUtil.getHardKeyArea(e.x, e.y,
- currentState.getCurrentRotationId(), currentState.getCurrentScale());
- if (keyCode != 101) { // TODO: not necessary for home key
- SkinUtil.trimShell(shell, currentState.getCurrentImage(),
- region.x, region.y, region.width, region.height);
- }
- }
-
- }
- }
-
- @Override
- public void mouseDown( MouseEvent e ) {
- if (1 == e.button) { /* left button */
- logger.info( "mouseDown in Skin" );
- EmulatorSkin.this.pressedMouseX = e.x;
- EmulatorSkin.this.pressedMouseY = e.y;
- EmulatorSkin.this.isMousePressed = true;
-
- final int keyCode = SkinUtil.getHardKeyCode(e.x, e.y,
- currentState.getCurrentRotationId(), currentState.getCurrentScale());
-
- if (SkinUtil.UNKNOWN_KEYCODE != keyCode) {
- /* send event */
- KeyEventData keyEventData = new KeyEventData(
- KeyEventType.PRESSED.value(), keyCode, 0, 0);
- communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
- pressedHWKeyCode = keyCode;
-
- shell.setToolTipText(null);
-
- /* draw the button region as the cropped keyPressed image area */
- currentPressedRegion = SkinUtil.getHardKeyArea(e.x, e.y,
- currentState.getCurrentRotationId(), currentState.getCurrentScale());
-
- if (currentPressedRegion != null &&
- currentPressedRegion.width != 0 && currentPressedRegion.height != 0) {
- shell.getDisplay().syncExec(new Runnable() {
- public void run() {
- if (currentState.getCurrentKeyPressedImage() != null) {
- GC gc = new GC( shell );
- if (gc != null) {
-
- /* button */
- gc.drawImage(currentState.getCurrentKeyPressedImage(),
- currentPressedRegion.x + 1, currentPressedRegion.y + 1,
- currentPressedRegion.width - 1, currentPressedRegion.height - 1, //src
- currentPressedRegion.x + 1, currentPressedRegion.y + 1,
- currentPressedRegion.width - 1, currentPressedRegion.height - 1); //dst
-
- /* hover */
- if (currentHoverRegion.width != 0 && currentHoverRegion.height != 0) {
- gc.setLineWidth(1);
- gc.setForeground(hoverColor);
- gc.drawRectangle(currentHoverRegion.x, currentHoverRegion.y,
- currentHoverRegion.width, currentHoverRegion.height);
- }
-
- gc.dispose();
-
- if (keyCode != 101) { // TODO: not necessary for home key
- SkinUtil.trimShell(shell, currentState.getCurrentKeyPressedImage(),
- currentPressedRegion.x, currentPressedRegion.y,
- currentPressedRegion.width, currentPressedRegion.height);
- }
-
- currentPressedRegion = null;
- }
- }
- }
- });
- }
-
- }
- }
- }
-
- @Override
- public void mouseDoubleClick(MouseEvent e) {
- /* do nothing */
- }
- };
-
- if (skinInfo.isPhoneShape()) {
- shell.addMouseListener(shellMouseListener);
- }
-
shellMenuDetectListener = new MenuDetectListener() {
@Override
public void menuDetected(MenuDetectEvent e) {
Menu menu = EmulatorSkin.this.contextMenu;
- if (menu != null && EmulatorSkin.this.isMousePressed == false) {
+ if (menu != null) {
shell.setMenu(menu);
menu.setVisible(true);
e.doit = false;
}
private void removeShellListeners() {
-
- if ( null != shellCloseListener ) {
- shell.removeListener( SWT.Close, shellCloseListener );
- }
- if ( null != shellPaintListener ) {
- shell.removePaintListener( shellPaintListener );
- }
- if ( null != shellMouseTrackListener ) {
- shell.removeMouseTrackListener( shellMouseTrackListener );
- }
- if ( null != shellMouseMoveListener ) {
- shell.removeMouseMoveListener( shellMouseMoveListener );
- }
- if ( null != shellMouseListener ) {
- shell.removeMouseListener( shellMouseListener );
+ if (null != shellCloseListener) {
+ shell.removeListener(SWT.Close, shellCloseListener);
}
+ if (null != shellMenuDetectListener) {
+ shell.removeMenuDetectListener(shellMenuDetectListener);
+ }
}
private void addCanvasListener(final Shell shell, final Canvas canvas) {
package org.tizen.emulator.skin;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo;
+import org.tizen.emulator.skin.layout.HWKey;
public class EmulatorSkinState {
private Point currentResolution;
private Image currentImage;
private Image currentKeyPressedImage;
+ private Color hoverColor;
+
+ private HWKey currentPressedHWKey;
+ private HWKey currentHoveredHWKey;
public EmulatorSkinState() {
this.currentResolution = new Point(480, 800);
}
/* skin image */
- public Image getCurrentImage() {
+ public synchronized Image getCurrentImage() {
return currentImage;
}
- public void setCurrentImage(Image image) {
+ public synchronized void setCurrentImage(Image image) {
this.currentImage = image;
}
- public Image getCurrentKeyPressedImage() {
+ public synchronized Image getCurrentKeyPressedImage() {
return currentKeyPressedImage;
}
- public void setCurrentKeyPressedImag(Image keyPressedImage) {
+ public synchronized void setCurrentKeyPressedImag(Image keyPressedImage) {
this.currentKeyPressedImage = keyPressedImage;
}
+
+ /* color of hover */
+ public synchronized Color getHoverColor() {
+ return hoverColor;
+ }
+
+ public synchronized void setHoverColor(Color color) {
+ this.hoverColor = color;
+ }
+
+ /* pressed HW key */
+ public synchronized HWKey getCurrentPressedHWKey() {
+ return currentPressedHWKey;
+ }
+
+ public synchronized void setCurrentPressedHWKey(HWKey hwKey) {
+ this.currentPressedHWKey = hwKey;
+ }
+
+ /* hovered HW key */
+ public synchronized HWKey getCurrentHoveredHWKey() {
+ return currentHoveredHWKey;
+ }
+
+ public synchronized void setCurrentHoveredHWKey(HWKey hwKey) {
+ this.currentHoveredHWKey = hwKey;
+ }
}
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
-import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
}
private Display display;
- private int resolutionWidth;
- private int resolutionHeight;
private EmulatorUI dbiContents;
private Map<String, Image> skinImageMap;
return instance;
}
- public void initialize( EmulatorConfig config ) {
-
- if ( isInitialized ) {
+ public void initialize(EmulatorConfig config) {
+ if (isInitialized) {
return;
}
isInitialized = true;
this.display = Display.getDefault();
- int resolutionW = config.getArgInt(ArgsConstants.RESOLUTION_WIDTH);
- int resolutionH = config.getArgInt(ArgsConstants.RESOLUTION_HEIGHT);
this.argSkinPath = config.getArg(ArgsConstants.SKIN_PATH);
-
- this.resolutionWidth = resolutionW;
- this.resolutionHeight = resolutionH;
this.dbiContents = config.getDbiContents();
this.skinImageMap = new HashMap<String, Image>();
this.iconMap = new HashMap<String, Image>();
private SocketCommunicator communicator;
public GeneralPurposeSkinComposer(EmulatorConfig config, Shell shell,
- EmulatorSkinState currentState, ImageRegistry imageRegistry, SocketCommunicator communicator) {
+ EmulatorSkinState currentState, ImageRegistry imageRegistry,
+ SocketCommunicator communicator) {
this.config = config;
this.shell = shell;
this.currentState = currentState;
return lcdBounds;
}
+
+ @Override
+ public void composerFinalize() {
+ /* do nothing */
+ }
}
--- /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 org.tizen.emulator.skin.util.SkinRegion;
+import org.tizen.emulator.skin.util.SkinUtil;
+
+public class HWKey {
+ private int keyCode;
+ private SkinRegion region;
+ private String tooltip;
+
+ public HWKey() {
+ this.keyCode = SkinUtil.UNKNOWN_KEYCODE;
+ }
+
+ /* keycode */
+ public int getKeyCode() {
+ return keyCode;
+ }
+
+ public void setKeyCode(int keyCode) {
+ this.keyCode = keyCode;
+ }
+
+ /* region */
+ public SkinRegion getRegion() {
+ return region;
+ }
+
+ public void setRegion(SkinRegion region) {
+ this.region = region;
+ }
+
+ /* tooltip */
+ public String getTooltip() {
+ return tooltip;
+ }
+
+ public void setTooltip(String tooltip) {
+ this.tooltip = tooltip;
+ }
+}
public abstract Rectangle adjustLcdGeometry(
Canvas lcdCanvas, int resolutionW, int resolutionH,
int scale, short rotationId);
+
+ public abstract void composerFinalize();
}
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.MouseTrackAdapter;
+import org.eclipse.swt.events.MouseTrackListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.GC;
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;
import org.tizen.emulator.skin.EmulatorSkinState;
+import org.tizen.emulator.skin.comm.ICommunicator.KeyEventType;
+import org.tizen.emulator.skin.comm.ICommunicator.SendCommand;
+import org.tizen.emulator.skin.comm.sock.SocketCommunicator;
+import org.tizen.emulator.skin.comm.sock.data.KeyEventData;
import org.tizen.emulator.skin.config.EmulatorConfig;
import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
import org.tizen.emulator.skin.config.EmulatorConfig.SkinPropertiesConstants;
private Shell shell;
private Canvas lcdCanvas;
private EmulatorSkinState currentState;
-
private ImageRegistry imageRegistry;
+ private SocketCommunicator communicator;
+
+ private PaintListener shellPaintListener;
+ private MouseTrackListener shellMouseTrackListener;
+ private MouseMoveListener shellMouseMoveListener;
+ private MouseListener shellMouseListener;
+
+ private boolean isGrabbedShell;
+ private Point grabPosition;
public PhoneShapeSkinComposer(EmulatorConfig config, Shell shell,
- EmulatorSkinState currentState, ImageRegistry imageRegistry) {
+ EmulatorSkinState currentState, ImageRegistry imageRegistry,
+ SocketCommunicator communicator) {
this.config = config;
this.shell = shell;
this.currentState = currentState;
this.imageRegistry = imageRegistry;
+ this.communicator = communicator;
+ this.isGrabbedShell= false;
+ this.grabPosition = new Point(0, 0);
}
@Override
composeInternal(lcdCanvas, x, y, scale, rotationId);
logger.info("resolution : " + currentState.getCurrentResolution() +
", scale : " + scale);
-
+
return lcdCanvas;
}
arrangeSkin(scale, rotationId);
- if (/*skinInfo.isPhoneShape() &&*/ currentState.getCurrentImage() == null) {
+ if (currentState.getCurrentImage() == null) {
logger.severe("Failed to load initial skin image file. Kill this skin process.");
SkinUtil.openMessage(shell, null,
"Failed to load Skin image file.", SWT.ICON_ERROR, config);
return lcdBounds;
}
+
+ public void addPhoneShapeListener(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);
+
+ shellMouseTrackListener = new MouseTrackAdapter() {
+ @Override
+ public void mouseExit(MouseEvent e) {
+ /* shell does not receive event only with MouseMoveListener
+ * in case that : hover hardkey -> mouse move into LCD area */
+ HWKey hoveredHWKey = currentState.getCurrentHoveredHWKey();
+
+ if (hoveredHWKey != null) {
+ shell.redraw(hoveredHWKey.getRegion().x,
+ hoveredHWKey.getRegion().y,
+ hoveredHWKey.getRegion().width,
+ hoveredHWKey.getRegion().height, false);
+
+ currentState.setCurrentHoveredHWKey(null);
+ shell.setToolTipText(null);
+ }
+ }
+ };
+
+ shell.addMouseTrackListener(shellMouseTrackListener);
+
+ 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;
+ }
+
+ final HWKey hwKey = SkinUtil.getHWKey(e.x, e.y,
+ currentState.getCurrentRotationId(), currentState.getCurrentScale());
+ if (hwKey == null) {
+ /* remove hover */
+ HWKey hoveredHWKey = currentState.getCurrentHoveredHWKey();
+
+ if (hoveredHWKey != null) {
+ shell.redraw(hoveredHWKey.getRegion().x,
+ hoveredHWKey.getRegion().y,
+ hoveredHWKey.getRegion().width,
+ hoveredHWKey.getRegion().height, false);
+
+ currentState.setCurrentHoveredHWKey(null);
+ shell.setToolTipText(null);
+ }
+
+ return;
+ }
+
+ /* register a tooltip */
+ if (currentState.getCurrentHoveredHWKey() == null &&
+ hwKey.getTooltip().isEmpty() == false) {
+ shell.setToolTipText(hwKey.getTooltip());
+ }
+
+ /* draw hover */
+ shell.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ if (hwKey.getRegion().width != 0 && hwKey.getRegion().height != 0) {
+ GC gc = new GC(shell);
+ if (gc != null) {
+ gc.setLineWidth(1);
+ gc.setForeground(currentState.getHoverColor());
+ gc.drawRectangle(hwKey.getRegion().x, hwKey.getRegion().y,
+ hwKey.getRegion().width - 1, hwKey.getRegion().height - 1);
+
+ gc.dispose();
+
+ currentState.setCurrentHoveredHWKey(hwKey);
+ }
+ }
+ }
+ });
+
+ }
+ };
+
+ 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;
+
+ HWKey pressedHWKey = currentState.getCurrentPressedHWKey();
+ if (pressedHWKey == null) {
+ return;
+ }
+
+ if (pressedHWKey.getKeyCode() != SkinUtil.UNKNOWN_KEYCODE) {
+ /* send event */
+ KeyEventData keyEventData = new KeyEventData(
+ KeyEventType.RELEASED.value(), pressedHWKey.getKeyCode(), 0, 0);
+ communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
+
+ currentState.setCurrentPressedHWKey(null);
+
+ /* roll back a keyPressed image region */
+ shell.redraw(pressedHWKey.getRegion().x, pressedHWKey.getRegion().y,
+ pressedHWKey.getRegion().width, pressedHWKey.getRegion().height, false);
+
+ if (pressedHWKey.getKeyCode() != 101) { // TODO: not necessary for home key
+ SkinUtil.trimShell(shell, currentState.getCurrentImage(),
+ pressedHWKey.getRegion().x, pressedHWKey.getRegion().y,
+ pressedHWKey.getRegion().width, pressedHWKey.getRegion().height);
+ }
+ }
+ }
+ }
+
+ @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;
+
+ final HWKey hwKey = SkinUtil.getHWKey(e.x, e.y,
+ currentState.getCurrentRotationId(), currentState.getCurrentScale());
+ if (hwKey == null) {
+ return;
+ }
+
+ if (hwKey.getKeyCode() != SkinUtil.UNKNOWN_KEYCODE) {
+ /* send event */
+ KeyEventData keyEventData = new KeyEventData(
+ KeyEventType.PRESSED.value(), hwKey.getKeyCode(), 0, 0);
+ communicator.sendToQEMU(SendCommand.SEND_HARD_KEY_EVENT, keyEventData);
+
+ currentState.setCurrentPressedHWKey(hwKey);
+
+ shell.setToolTipText(null);
+
+ /* draw the HW key region as the cropped keyPressed image area */
+ if (hwKey.getRegion() != null &&
+ hwKey.getRegion().width != 0 && hwKey.getRegion().height != 0) {
+ shell.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ if (currentState.getCurrentKeyPressedImage() != null) {
+ GC gc = new GC(shell);
+ if (gc != null) {
+ gc.drawImage(currentState.getCurrentKeyPressedImage(),
+ hwKey.getRegion().x, hwKey.getRegion().y,
+ hwKey.getRegion().width, hwKey.getRegion().height, //src
+ hwKey.getRegion().x, hwKey.getRegion().y,
+ hwKey.getRegion().width, hwKey.getRegion().height); //dst
+
+ gc.dispose();
+
+ if (hwKey.getKeyCode() != 101) { // TODO: not necessary for home key
+ SkinUtil.trimShell(shell, currentState.getCurrentKeyPressedImage(),
+ hwKey.getRegion().x, hwKey.getRegion().y,
+ hwKey.getRegion().width, hwKey.getRegion().height);
+ }
+
+ }
+ }
+ } /* end of run */
+ });
+ }
+
+ }
+ }
+ }
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ /* do nothing */
+ }
+ };
+
+ shell.addMouseListener(shellMouseListener);
+ }
+
+ @Override
+ public void composerFinalize() {
+ if (null != shellPaintListener) {
+ shell.removePaintListener(shellPaintListener);
+ }
+
+ if (null != shellMouseTrackListener) {
+ shell.removeMouseTrackListener(shellMouseTrackListener);
+ }
+
+ if (null != shellMouseMoveListener) {
+ shell.removeMouseMoveListener(shellMouseMoveListener);
+ }
+
+ if (null != shellMouseListener) {
+ shell.removeMouseListener(shellMouseListener);
+ }
+ }
}
import org.eclipse.swt.widgets.ToolItem;
import org.tizen.emulator.skin.EmulatorSkin;
import org.tizen.emulator.skin.comm.ICommunicator.RotationInfo;
-import org.tizen.emulator.skin.comm.ICommunicator.SendCommand;
import org.tizen.emulator.skin.comm.sock.SocketCommunicator;
-import org.tizen.emulator.skin.comm.sock.SocketCommunicator.DataTranfer;
import org.tizen.emulator.skin.config.EmulatorConfig;
import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
import org.tizen.emulator.skin.exception.ScreenShotException;
import org.tizen.emulator.skin.dbi.RotationType;
import org.tizen.emulator.skin.image.ImageRegistry;
import org.tizen.emulator.skin.image.ImageRegistry.ImageType;
+import org.tizen.emulator.skin.layout.HWKey;
/**
return sdbPath;
}
- public static SkinRegion getHardKeyArea( int currentX, int currentY, short rotationId, int scale ) {
-
- float convertedScale = convertScale( scale );
-
- RotationType rotation = SkinRotation.getRotation( rotationId );
+ public static HWKey getHWKey(
+ int currentX, int currentY, short rotationId, int scale) {
+ float convertedScale = convertScale(scale);
+ RotationType rotation = SkinRotation.getRotation(rotationId);
List<KeyMapType> keyMapList = rotation.getKeyMapList().getKeyMap();
- for ( KeyMapType keyMap : keyMapList ) {
-
+ for (KeyMapType keyMap : keyMapList) {
RegionType region = keyMap.getRegion();
- int scaledX = (int) ( region.getLeft() * convertedScale );
- int scaledY = (int) ( region.getTop() * convertedScale );
- int scaledWidth = (int) ( region.getWidth() * convertedScale );
- int scaledHeight = (int) ( region.getHeight() * convertedScale );
-
- if ( isInGeometry( currentX, currentY, scaledX, scaledY, scaledWidth, scaledHeight ) ) {
- return new SkinRegion( scaledX, scaledY, scaledWidth, scaledHeight );
- }
-
- }
-
- return null;
-
- }
-
- public static int getHardKeyCode( int currentX, int currentY, short rotationId, int scale ) {
-
- float convertedScale = convertScale( scale );
-
- RotationType rotation = SkinRotation.getRotation( rotationId );
-
- List<KeyMapType> keyMapList = rotation.getKeyMapList().getKeyMap();
+ int scaledX = (int) (region.getLeft() * convertedScale);
+ int scaledY = (int) (region.getTop() * convertedScale);
+ int scaledWidth = (int) (region.getWidth() * convertedScale);
+ int scaledHeight = (int) (region.getHeight() * convertedScale);
- for ( KeyMapType keyMap : keyMapList ) {
- RegionType region = keyMap.getRegion();
-
- int scaledX = (int) ( region.getLeft() * convertedScale );
- int scaledY = (int) ( region.getTop() * convertedScale );
- int scaledWidth = (int) ( region.getWidth() * convertedScale );
- int scaledHeight = (int) ( region.getHeight() * convertedScale );
-
- if ( isInGeometry( currentX, currentY, scaledX, scaledY, scaledWidth, scaledHeight ) ) {
+ if (isInGeometry(currentX, currentY, scaledX, scaledY, scaledWidth, scaledHeight)) {
EventInfoType eventInfo = keyMap.getEventInfo();
- return eventInfo.getKeyCode();
- }
- }
- return UNKNOWN_KEYCODE;
+ HWKey hwKey = new HWKey();
+ hwKey.setKeyCode(eventInfo.getKeyCode());
+ hwKey.setRegion(new SkinRegion(scaledX, scaledY, scaledWidth, scaledHeight));
+ hwKey.setTooltip(keyMap.getTooltip());
- }
-
- //TODO: HardKey object
- public static String getHardKeyToolTip( int currentX, int currentY, short rotationId, int scale ) {
-
- float convertedScale = convertScale( scale );
-
- RotationType rotation = SkinRotation.getRotation( rotationId );
-
- List<KeyMapType> keyMapList = rotation.getKeyMapList().getKeyMap();
-
- for ( KeyMapType keyMap : keyMapList ) {
- RegionType region = keyMap.getRegion();
-
- int scaledX = (int) ( region.getLeft() * convertedScale );
- int scaledY = (int) ( region.getTop() * convertedScale );
- int scaledWidth = (int) ( region.getWidth() * convertedScale );
- int scaledHeight = (int) ( region.getHeight() * convertedScale );
-
- if ( isInGeometry( currentX, currentY, scaledX, scaledY, scaledWidth, scaledHeight ) ) {
- return keyMap.getTooltip();
+ return hwKey;
}
}
return null;
-
}
public static boolean isInGeometry( int currentX, int currentY, int targetX, int targetY, int targetWidth,