From: giwoong.kim Date: Tue, 13 Nov 2012 07:22:50 +0000 (+0900) Subject: skin: separate a event handlers X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~1358^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=73eba1bab83be55c4699e73eba931fc67009c0c1;p=sdk%2Femulator%2Fqemu.git skin: separate a event handlers Separate event handlers according to skin type. Signed-off-by: GiWoong Kim --- diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSdlSkin.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSdlSkin.java index cae80926ab..d93e78ae3c 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSdlSkin.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSdlSkin.java @@ -56,10 +56,8 @@ public class EmulatorSdlSkin extends EmulatorSkin { public long initLayout() { super.initLayout(); - // sdl uses this handle id. - windowHandleId = getWindowHandleId(); - - return windowHandleId; + /* sdl uses this handle ID */ + return getWindowHandleId(); } private long getWindowHandleId() { diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java index 676da2afdb..8a0ce6dcb7 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java @@ -139,6 +139,8 @@ public class EmulatorShmSkin extends EmulatorSkin { protected void skinFinalize() { pollThread.stopRequest(); + + super.skinFinalize(); } public long initLayout() { diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java index 05c7fa30f0..f34fffd184 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java @@ -53,15 +53,10 @@ import org.eclipse.swt.events.MenuDetectListener; 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; @@ -98,7 +93,6 @@ import org.tizen.emulator.skin.layout.ISkinComposer; 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; @@ -142,35 +136,22 @@ public class EmulatorSkin { 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; @@ -182,7 +163,6 @@ public class EmulatorSkin { private FocusListener canvasFocusListener; private LinkedList pressedKeyEventList; - private int pressedHWKeyCode; private EmulatorSkin reopenSkin; @@ -194,13 +174,9 @@ public class EmulatorSkin { protected EmulatorSkin(EmulatorConfig config, SkinInformation skinInfo, boolean isOnTop) { this.config = config; this.skinInfo = skinInfo; - this.isDefaultHoverColor = true; this.isOnTop = isOnTop; this.pressedKeyEventList = new LinkedList(); - this.windowHandleId = 0; - this.pressedHWKeyCode = 0; - int style = SWT.NO_TRIM; if (skinInfo.isPhoneShape() == false) { style = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.BORDER; @@ -217,20 +193,26 @@ public class EmulatorSkin { 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(); @@ -279,26 +261,25 @@ public class EmulatorSkin { // // } - 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() { @@ -334,10 +315,10 @@ public class EmulatorSkin { } protected void skinFinalize() { - //TODO: + skinComposer.composerFinalize(); } - private void addShellListener( final Shell shell ) { + private void addShellListener(final Shell shell) { shellCloseListener = new Listener() { @Override @@ -367,7 +348,7 @@ public class EmulatorSkin { controlPanel = null; } - // save config only for emulator close + /* save config only for emulator close */ config.setSkinProperty( SkinPropertiesConstants.WINDOW_X, shell.getLocation().x); config.setSkinProperty( @@ -388,8 +369,8 @@ public class EmulatorSkin { currentState.getCurrentKeyPressedImage().dispose(); } - if ( !isDefaultHoverColor ) { - hoverColor.dispose(); + if (currentState.getHoverColor() != null) { + currentState.getHoverColor().dispose(); } skinFinalize(); @@ -409,242 +390,12 @@ public class EmulatorSkin { 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; @@ -658,23 +409,13 @@ public class EmulatorSkin { } 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) { diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinState.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinState.java index 846050097a..247a36efb3 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinState.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinState.java @@ -28,9 +28,11 @@ 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; @@ -40,6 +42,10 @@ public class EmulatorSkinState { private Image currentImage; private Image currentKeyPressedImage; + private Color hoverColor; + + private HWKey currentPressedHWKey; + private HWKey currentHoveredHWKey; public EmulatorSkinState() { this.currentResolution = new Point(480, 800); @@ -108,19 +114,46 @@ public class EmulatorSkinState { } /* 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; + } } diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/RamdumpDialog.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/RamdumpDialog.java index 90a5aecf44..faba7e2a21 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/RamdumpDialog.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/RamdumpDialog.java @@ -6,7 +6,6 @@ import java.util.logging.Logger; 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; diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java index c90a041e51..1d60b5f122 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/image/ImageRegistry.java @@ -105,8 +105,6 @@ public class ImageRegistry { } private Display display; - private int resolutionWidth; - private int resolutionHeight; private EmulatorUI dbiContents; private Map skinImageMap; @@ -127,21 +125,15 @@ public class ImageRegistry { 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(); this.iconMap = new HashMap(); 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 e136643e5f..daa8024be5 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 @@ -75,7 +75,8 @@ public class GeneralPurposeSkinComposer implements ISkinComposer { 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; @@ -228,4 +229,9 @@ public class GeneralPurposeSkinComposer implements ISkinComposer { return lcdBounds; } + + @Override + public void composerFinalize() { + /* do nothing */ + } } diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/HWKey.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/HWKey.java new file mode 100644 index 0000000000..32b18c08e2 --- /dev/null +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/HWKey.java @@ -0,0 +1,69 @@ +/** + * + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * GiWoong Kim + * YeongKyoon Lee + * + * 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; + } +} diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ISkinComposer.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ISkinComposer.java index 5862ee70d9..402a3238bf 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ISkinComposer.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/ISkinComposer.java @@ -42,4 +42,6 @@ public interface ISkinComposer { public abstract Rectangle adjustLcdGeometry( Canvas lcdCanvas, int resolutionW, int resolutionH, int scale, short rotationId); + + public abstract void composerFinalize(); } diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/PhoneShapeSkinComposer.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/PhoneShapeSkinComposer.java index 980cf48977..e6250f3ddb 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/PhoneShapeSkinComposer.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/layout/PhoneShapeSkinComposer.java @@ -31,12 +31,25 @@ package org.tizen.emulator.skin.layout; 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; @@ -59,15 +72,27 @@ public class PhoneShapeSkinComposer implements ISkinComposer { 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 @@ -93,7 +118,7 @@ public class PhoneShapeSkinComposer implements ISkinComposer { composeInternal(lcdCanvas, x, y, scale, rotationId); logger.info("resolution : " + currentState.getCurrentResolution() + ", scale : " + scale); - + return lcdCanvas; } @@ -117,7 +142,7 @@ public class PhoneShapeSkinComposer implements ISkinComposer { 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); @@ -216,4 +241,223 @@ public class PhoneShapeSkinComposer implements ISkinComposer { 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); + } + } } diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ScreenShotDialog.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ScreenShotDialog.java index de7f50afee..7cf1ffd201 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ScreenShotDialog.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ScreenShotDialog.java @@ -67,9 +67,7 @@ import org.eclipse.swt.widgets.ToolBar; 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; diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/util/SkinUtil.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/util/SkinUtil.java index 75f83032df..76df3fb77b 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/util/SkinUtil.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/util/SkinUtil.java @@ -49,6 +49,7 @@ import org.tizen.emulator.skin.dbi.RegionType; 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; /** @@ -106,83 +107,34 @@ public class SkinUtil { 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 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 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 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,