X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tizen%2Fsrc%2Fskin%2Fclient%2Fsrc%2Forg%2Ftizen%2Femulator%2Fskin%2FEmulatorFingers.java;h=ccc6c90837656b668b701778447c9fa4be192ea7;hb=b0e96416c6dfd795f017359ed39adb23f76e8929;hp=b7ebb4106caa73fe1671e30bcdf11bf7fd99fc32;hpb=689bc01f3155484257c9f3be4681a146adebbab8;p=sdk%2Femulator%2Fqemu.git diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java index b7ebb41..ccc6c90 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java @@ -53,7 +53,10 @@ public class EmulatorFingers { private static final int GREEN_MASK = 0x00FF0000; private static final int BLUE_MASK = 0xFF000000; private static final int COLOR_DEPTH = 32; - private Logger logger = SkinLogger.getSkinLogger( EmulatorFingers.class ).getLogger(); + + private Logger logger = + SkinLogger.getSkinLogger(EmulatorFingers.class).getLogger(); + private int multiTouchEnable; private int maxTouchPoint; protected int fingerCnt; @@ -69,18 +72,18 @@ public class EmulatorFingers { protected SocketCommunicator communicator; protected EmulatorSkin emulatorSkin; ArrayList FingerPointList; - + EmulatorSkinState currentState; - + EmulatorFingers(EmulatorSkinState currentState) { this.currentState = currentState; initMultiTouchState(); } - - protected void setCommunicator(SocketCommunicator communicator) { + + protected void setCommunicator(SocketCommunicator communicator) { this.communicator = communicator; } - + //private fingerPointSurface; protected class FingerPoint { int id; @@ -88,14 +91,14 @@ public class EmulatorFingers { int originY; int x; int y; - + FingerPoint(int originX, int originY, int x, int y) { this.originX = originX; this.originY = -originY; this.x = x; this.y = y; } - + FingerPoint(int id, int originX, int originY, int x, int y) { this.id = id; this.originX = originX; @@ -104,24 +107,26 @@ public class EmulatorFingers { this.y = y; } } - + public FingerPoint getFingerPointFromSlot(int index) { - if(index < 0 || index > this.fingerCntMax) { + if (index < 0 || index > this.fingerCntMax) { return null; } + return FingerPointList.get(index); } - + public FingerPoint getFingerPointSearch(int x, int y) { int i; FingerPoint fingerPoint = null; - int fingerRegion = (this.fingerPointSize ) + 2; + int fingerRegion = (this.fingerPointSize) + 2; //logger.info("x: "+x+ "y: "+ y + " fingerRegion: " + fingerRegion); - for(i = this.fingerCnt -1; i >= 0; i--) { + + for (i = this.fingerCnt - 1; i >= 0; i--) { fingerPoint = getFingerPointFromSlot(i); - - if(fingerPoint != null) { - if(x >= (fingerPoint.x - fingerRegion) && + + if (fingerPoint != null) { + if (x >= (fingerPoint.x - fingerRegion) && x < (fingerPoint.x + fingerRegion) && y >= (fingerPoint.y - fingerRegion) && y < (fingerPoint.y + fingerRegion)) { @@ -130,372 +135,408 @@ public class EmulatorFingers { } } } + return null; } - + protected void setEmulatorSkin(EmulatorSkin emulatorSkin) { this.emulatorSkin = emulatorSkin; } - + public void initMultiTouchState() { this.multiTouchEnable = 0; this.fingerCntMax = this.currentState.getMaxTouchPoint(); - if(this.fingerCntMax > MAX_FINGER_CNT) { + + if (this.fingerCntMax > MAX_FINGER_CNT) { this.fingerCntMax = MAX_FINGER_CNT; setMaxTouchPoint(this.fingerCntMax); } + logger.info("maxTouchPoint="+ this.fingerCntMax); this.fingerCnt = 0; - + if (this.fingerSlot != null) { this.fingerSlot = null; } - + FingerPointList = new ArrayList(); int i; - for(i = 0; i <= fingerCntMax; i++) { + for (i = 0; i <= fingerCntMax; i++) { FingerPointList.add(new FingerPoint(-1, -1, -1, -1)); } this.fingerPointSize = 32; - this.fingerPointSizeHalf = this.fingerPointSize / 2 ; - + this.fingerPointSizeHalf = this.fingerPointSize / 2; + this.fingerPointOutlineColor = new Color(Display.getCurrent(), 0xDD, 0xDD, 0xDD); this.fingerPointColor = new Color(Display.getCurrent(), 0x0F, 0x0F, 0x0F); PaletteData palette = new PaletteData(RED_MASK, GREEN_MASK, BLUE_MASK); - - this.imageData = new ImageData(fingerPointSize + 4, fingerPointSize + 4, COLOR_DEPTH, palette); + + this.imageData = new ImageData( + fingerPointSize + 4, fingerPointSize + 4, COLOR_DEPTH, palette); this.imageData.transparentPixel = 0; this.fingerSlotimage = new Image(Display.getCurrent(), imageData); GC gc = new GC(this.fingerSlotimage); - + gc.setForeground(this.fingerPointOutlineColor); - gc.drawOval(0, 0, this.fingerPointSize+2 , this.fingerPointSize+2); - + gc.drawOval(0, 0, this.fingerPointSize + 2, this.fingerPointSize + 2); + gc.setBackground(this.fingerPointColor); - gc.fillOval(2, 2 , this.fingerPointSize, this.fingerPointSize); - + gc.fillOval(2, 2, this.fingerPointSize, this.fingerPointSize); + gc.dispose(); } - + public void setMultiTouchEnable(int multiTouchEnable) { this.multiTouchEnable = multiTouchEnable; } - + public int getMultiTouchEnable() { return this.multiTouchEnable; } - + protected int addFingerPoint(int originX, int originY, int x, int y) { if (this.fingerCnt == this.fingerCntMax) { - logger.info("support multi-touch up to " + this.fingerCntMax +" fingers"); + logger.info("support multi-touch up to " + + this.fingerCntMax + " fingers"); return -1; } this.fingerCnt += 1; - + FingerPointList.get(fingerCnt -1).id = this.fingerCnt; FingerPointList.get(fingerCnt -1).originX = originX; FingerPointList.get(fingerCnt -1).originY = originY; FingerPointList.get(fingerCnt -1).x = x; FingerPointList.get(fingerCnt -1).y = y; logger.info(this.fingerCnt + " finger touching"); - + return this.fingerCnt; - } - + protected void drawImage(PaintEvent e, int currentAngle) { //by mq - for(int i=0; i < this.fingerCnt; i++) { + for (int i = 0; i < this.fingerCnt; i++) { this.fingerSlot = this.getFingerPointFromSlot(i); e.gc.setAlpha(0x7E); // logger.info("OriginX: "+ this.fingerSlot.originX + ",OriginY: " + (this.fingerSlot.originY)); // logger.info("x: "+ this.fingerSlot.x + ",y: " + (this.fingerSlot.y)); - + e.gc.drawImage(this.fingerSlotimage, this.fingerSlot.originX - fingerPointSizeHalf - 2, this.fingerSlot.originY - fingerPointSizeHalf - 2); e.gc.setAlpha(0xFF); } } - - public void maruFingerProcessing1(int touchType, int originX, int originY, int x, int y) { + + public void maruFingerProcessing1( + int touchType, int originX, int originY, int x, int y) { FingerPoint finger = null; MouseEventData mouseEventData; - if (touchType == MouseEventType.PRESS.value() || touchType == MouseEventType.DRAG.value()) { /* pressed */ - if (grabFingerID > 0) { - finger = getFingerPointFromSlot(grabFingerID - 1); - if (finger != null) { - finger.originX = originX; - finger.originY = originY; - finger.x = x; - finger.y = y; - if (finger.id != 0) { - logger.info(String.format("id %d finger multi-touch dragging = (%d, %d)", this.grabFingerID, x, y)); - mouseEventData = new MouseEventData( + + if (touchType == MouseEventType.PRESS.value() || + touchType == MouseEventType.DRAG.value()) { /* pressed */ + if (grabFingerID > 0) { + finger = getFingerPointFromSlot(grabFingerID - 1); + if (finger != null) { + finger.originX = originX; + finger.originY = originY; + finger.x = x; + finger.y = y; + + if (finger.id != 0) { + logger.info(String.format( + "id %d finger multi-touch dragging = (%d, %d)", + this.grabFingerID, x, y)); + + mouseEventData = new MouseEventData( MouseButtonType.LEFT.value(), MouseEventType.PRESS.value(), - originX, originY, x, y, grabFingerID -1); - communicator.sendToQEMU( SendCommand.SEND_MOUSE_EVENT, mouseEventData ); - } - } - return; - } - - if(this.fingerCnt == 0) { - //first finger touch input - if(addFingerPoint(originX, originY, x, y) == -1) { - return; - } - + originX, originY, x, y, grabFingerID - 1); + communicator.sendToQEMU(SendCommand.SEND_MOUSE_EVENT, mouseEventData); + } + } + + return; + } + + if (this.fingerCnt == 0) + { /* first finger touch input */ + if (addFingerPoint(originX, originY, x, y) == -1) { + return; + } + mouseEventData = new MouseEventData( MouseButtonType.LEFT.value(), MouseEventType.PRESS.value(), originX, originY, x, y, 0); - communicator.sendToQEMU( SendCommand.SEND_MOUSE_EVENT, mouseEventData ); - } - //check the position of previous touch event - else if ((finger = getFingerPointSearch(x, y)) != null) { - //finger point is selected - this.grabFingerID = finger.id; - logger.info(String.format("id %d finger is grabbed\n", this.grabFingerID)); - } - //Let's assume that this event is last finger touch input - else if (this.fingerCnt == this.fingerCntMax) { - finger = getFingerPointFromSlot(this.fingerCntMax -1); - if(finger != null) { + communicator.sendToQEMU(SendCommand.SEND_MOUSE_EVENT, mouseEventData); + } + else if ((finger = getFingerPointSearch(x, y)) != null) + { /* check the position of previous touch event */ + /* finger point is selected */ + this.grabFingerID = finger.id; + logger.info(String.format("id %d finger is grabbed\n", this.grabFingerID)); + } + else if (this.fingerCnt == this.fingerCntMax) + { /* Let's assume that this event is last finger touch input */ + finger = getFingerPointFromSlot(this.fingerCntMax - 1); + if (finger != null) { mouseEventData = new MouseEventData( MouseButtonType.LEFT.value(), MouseEventType.RELEASE.value(), - originX, originY, finger.x, finger.y, this.fingerCntMax -1); - communicator.sendToQEMU( SendCommand.SEND_MOUSE_EVENT, mouseEventData ); - + originX, originY, finger.x, finger.y, this.fingerCntMax - 1); + communicator.sendToQEMU(SendCommand.SEND_MOUSE_EVENT, mouseEventData); + finger.originX = originX; finger.originY = originY; finger.x = x; finger.y = y; - if(finger.id != 0) { + + if (finger.id != 0) { mouseEventData = new MouseEventData( MouseButtonType.LEFT.value(), MouseEventType.PRESS.value(), - originX, originY, x, y, this.fingerCntMax -1); - communicator.sendToQEMU( SendCommand.SEND_MOUSE_EVENT, mouseEventData ); - + originX, originY, x, y, this.fingerCntMax - 1); + communicator.sendToQEMU(SendCommand.SEND_MOUSE_EVENT, mouseEventData); } - } - } - else { //one more finger - addFingerPoint(originX, originY, x, y); - mouseEventData = new MouseEventData( + } + } + else + { /* one more finger */ + addFingerPoint(originX, originY, x, y); + mouseEventData = new MouseEventData( MouseButtonType.LEFT.value(), MouseEventType.PRESS.value(), - originX, originY, x, y, this.fingerCnt -1); - communicator.sendToQEMU( SendCommand.SEND_MOUSE_EVENT, mouseEventData ); - - } - } - else if (touchType == MouseEventType.RELEASE.value()) { /* released */ + originX, originY, x, y, this.fingerCnt - 1); + communicator.sendToQEMU(SendCommand.SEND_MOUSE_EVENT, mouseEventData); + } + } else if (touchType == MouseEventType.RELEASE.value()) { /* released */ logger.info("mouse up for multi touch"); this.grabFingerID = 0; } - } - - public void maruFingerProcessing2(int touchType, int originX, int originY, int x, int y) { + + public void maruFingerProcessing2( + int touchType, int originX, int originY, int x, int y) { FingerPoint finger = null; MouseEventData mouseEventData; - if (touchType == MouseEventType.PRESS.value() || touchType == MouseEventType.DRAG.value()) { /* pressed */ - if(this.grabFingerID > 0) { + + if (touchType == MouseEventType.PRESS.value() || + touchType == MouseEventType.DRAG.value()) { /* pressed */ + if (this.grabFingerID > 0) { finger = getFingerPointFromSlot(grabFingerID - 1); - if(finger != null) { + if (finger != null) { int originDistanceX = originX - finger.originX; int originDistanceY = originY - finger.originY; int distanceX = x - finger.x; int distanceY = y - finger.y; - + int currrntScreenW = currentState.getCurrentResolutionWidth(); int currrntScreenH = currentState.getCurrentResolutionHeight(); int tempFingerX, tempFingerY; - + int i; /* bounds checking */ - for(i = 0; i < this.fingerCnt; i++) { - finger = getFingerPointFromSlot(i); - if (finger != null) { - tempFingerX = finger.x + distanceX; - tempFingerY = finger.y + distanceY; - if (tempFingerX > currrntScreenW || tempFingerX < 0 - || tempFingerY > currrntScreenH || tempFingerY < 0) { - logger.info(String.format("id %d finger is out of bounds (%d, %d)\n", i + 1, tempFingerX, tempFingerY)); - return; - } - } - } - - for(i = 0; i < this.fingerCnt; i++) { - finger = getFingerPointFromSlot(i); - - if (finger != null) { - finger.originX += originDistanceX; - finger.originY += originDistanceY; - finger.x += distanceX; - finger.y += distanceY; - if (finger.id != 0) { - mouseEventData = new MouseEventData( - MouseButtonType.LEFT.value(), MouseEventType.PRESS.value(), - originX, originY, finger.x, finger.y, i); - communicator.sendToQEMU( SendCommand.SEND_MOUSE_EVENT, mouseEventData ); - //logger.info(String.format("id %d finger multi-touch dragging = (%d, %d)", i + 1, finger.x, finger.y)); - } - try { + for (i = 0; i < this.fingerCnt; i++) { + finger = getFingerPointFromSlot(i); + if (finger != null) { + tempFingerX = finger.x + distanceX; + tempFingerY = finger.y + distanceY; + + if (tempFingerX > currrntScreenW || tempFingerX < 0 || + tempFingerY > currrntScreenH || tempFingerY < 0) { + logger.info(String.format( + "id %d finger is out of bounds (%d, %d)\n", + i + 1, tempFingerX, tempFingerY)); + return; + } + } + } + + for (i = 0; i < this.fingerCnt; i++) { + finger = getFingerPointFromSlot(i); + if (finger != null) { + finger.originX += originDistanceX; + finger.originY += originDistanceY; + finger.x += distanceX; + finger.y += distanceY; + + if (finger.id != 0) { + mouseEventData = new MouseEventData( + MouseButtonType.LEFT.value(), MouseEventType.PRESS.value(), + originX, originY, finger.x, finger.y, i); + communicator.sendToQEMU(SendCommand.SEND_MOUSE_EVENT, mouseEventData); + + /* logger.info(String.format( + "id %d finger multi-touch dragging = (%d, %d)", + i + 1, finger.x, finger.y));*/ + } + + try { Thread.sleep(2); } catch (InterruptedException e) { e.printStackTrace(); - } - } - } - } - return; - } - + } + } + } + + return; + } + if (this.fingerCnt == 0) - { //first finger touch input + { /* first finger touch input */ if (this.addFingerPoint(originX, originY, x, y) == -1) { - return; - } + return; + } + mouseEventData = new MouseEventData( MouseButtonType.LEFT.value(), MouseEventType.PRESS.value(), originX, originY, x, y, 0); - communicator.sendToQEMU( SendCommand.SEND_MOUSE_EVENT, mouseEventData ); - } - else if((finger = this.getFingerPointSearch(x, y)) != null) //check the position of previous touch event - { - //finger point is selected - this.grabFingerID = finger.id; + communicator.sendToQEMU(SendCommand.SEND_MOUSE_EVENT, mouseEventData); + } + else if ((finger = this.getFingerPointSearch(x, y)) != null) + { /* check the position of previous touch event */ + /* finger point is selected */ + this.grabFingerID = finger.id; logger.info(String.format("id %d finger is grabbed\n", this.grabFingerID)); - - } - else if(this.fingerCnt == this.fingerCntMax) //Let's assume that this event is last finger touch input - { - //do nothing - } - else //one more finger - { - addFingerPoint(originX, originY, x, y); - mouseEventData = new MouseEventData( + } + else if (this.fingerCnt == this.fingerCntMax) + { /* Let's assume that this event is last finger touch input */ + /* do nothing */ + } + else /* one more finger */ + { + addFingerPoint(originX, originY, x, y); + mouseEventData = new MouseEventData( MouseButtonType.LEFT.value(), MouseEventType.PRESS.value(), - originX, originY, x, y, this.fingerCnt -1); - communicator.sendToQEMU( SendCommand.SEND_MOUSE_EVENT, mouseEventData ); - } - }else if (touchType == MouseEventType.RELEASE.value()) { /* released */ + originX, originY, x, y, this.fingerCnt - 1); + communicator.sendToQEMU(SendCommand.SEND_MOUSE_EVENT, mouseEventData); + } + } else if (touchType == MouseEventType.RELEASE.value()) { /* released */ logger.info("mouse up for multi touch"); this.grabFingerID = 0; - } - + } } - - private Boolean CalculateOriginCoordinates(int ScaledLcdWitdh, int ScaledLcdHeight, double scaleFactor, int rotationType, FingerPoint finger) { - + + private Boolean CalculateOriginCoordinates( + int ScaledLcdWitdh, int ScaledLcdHeight, + double scaleFactor, int rotationType, FingerPoint finger) { + int pointX, pointY, rotatedPointX, rotatedPointY, flag; - flag = 0; -// logger.info("ScaledLcdWitdh:"+ScaledLcdWitdh+" ScaledLcdHeight:"+ScaledLcdHeight+ " scaleFactor:"+ scaleFactor+" rotationType:"+rotationType); - rotatedPointX = pointX = (int)(finger.x * scaleFactor); - rotatedPointY = pointY = (int)(finger.y * scaleFactor); -// logger.info("rotatedPointX:"+rotatedPointX+" rotatedPointY:"+rotatedPointY); - if (rotationType == RotationInfo.LANDSCAPE.id()) { - rotatedPointX = pointY; - rotatedPointY = ScaledLcdWitdh - pointX; - } else if (rotationType == RotationInfo.REVERSE_PORTRAIT.id()) { - rotatedPointX = ScaledLcdWitdh - pointX; - rotatedPointY = ScaledLcdHeight - pointY; - } else if (rotationType == RotationInfo.REVERSE_LANDSCAPE.id()) { - rotatedPointX = ScaledLcdHeight - pointY; - rotatedPointY = pointX; - } else { - //PORTRAIT: do nothing - } - - - if (finger.originX != rotatedPointX) { - logger.info("finger.originX: " +finger.originX); - finger.originX = rotatedPointX; - flag = 1; - } - if (finger.originY != rotatedPointY) { - logger.info("finger.originY: " +finger.originY); - finger.originY = rotatedPointY; - flag = 1; - } - - if (flag != 0) { - return true; - } - - return false; + flag = 0; + + /* logger.info("ScaledLcdWitdh:" + ScaledLcdWitdh + + " ScaledLcdHeight:" + ScaledLcdHeight + + " scaleFactor:" + scaleFactor + " rotationType:" + rotationType); */ + + rotatedPointX = pointX = (int)(finger.x * scaleFactor); + rotatedPointY = pointY = (int)(finger.y * scaleFactor); + + /* logger.info("rotatedPointX:" + rotatedPointX + + " rotatedPointY:" + rotatedPointY); */ + + if (rotationType == RotationInfo.LANDSCAPE.id()) { + rotatedPointX = pointY; + rotatedPointY = ScaledLcdWitdh - pointX; + } else if (rotationType == RotationInfo.REVERSE_PORTRAIT.id()) { + rotatedPointX = ScaledLcdWitdh - pointX; + rotatedPointY = ScaledLcdHeight - pointY; + } else if (rotationType == RotationInfo.REVERSE_LANDSCAPE.id()) { + rotatedPointX = ScaledLcdHeight - pointY; + rotatedPointY = pointX; + } else { + /* PORTRAIT: do nothing */ + } + + if (finger.originX != rotatedPointX) { + logger.info("finger.originX: " +finger.originX); + finger.originX = rotatedPointX; + flag = 1; + } + if (finger.originY != rotatedPointY) { + logger.info("finger.originY: " +finger.originY); + finger.originY = rotatedPointY; + flag = 1; + } + + if (flag != 0) { + return true; + } + + return false; } - - public int rearrangeFingerPoints(int lcdWidth, int lcdHeight, double scaleFactor, int rotationType) { - int i = 0; - int count = 0; - FingerPoint finger = null; - - if (this.multiTouchEnable == 0) { - return 0; - } - scaleFactor = scaleFactor/100; - lcdWidth *= scaleFactor; - lcdHeight *= scaleFactor; - - for (i = 0; i < this.fingerCnt; i++) { - finger = getFingerPointFromSlot(i); - if (finger != null && finger.id != 0) { - if (CalculateOriginCoordinates(lcdWidth, lcdHeight, - scaleFactor, rotationType, finger) == true) { - count++; - } - } - } - - if (count != 0) { - this.grabFingerID = 0; - } - - return count; + + public int rearrangeFingerPoints( + int lcdWidth, int lcdHeight, double scaleFactor, int rotationType) { + int i = 0; + int count = 0; + FingerPoint finger = null; + + if (this.multiTouchEnable == 0) { + return 0; + } + + scaleFactor = scaleFactor / 100; + lcdWidth *= scaleFactor; + lcdHeight *= scaleFactor; + + for (i = 0; i < this.fingerCnt; i++) { + finger = getFingerPointFromSlot(i); + if (finger != null && finger.id != 0) { + if (CalculateOriginCoordinates( + lcdWidth, lcdHeight, scaleFactor, rotationType, finger) == true) { + count++; + } + } + } + + if (count != 0) { + this.grabFingerID = 0; + } + + return count; } - + public void clearFingerSlot() { int i = 0; FingerPoint finger = null; - for(i = 0; i < this.fingerCnt; i++) { + + for (i = 0; i < this.fingerCnt; i++) { finger = getFingerPointFromSlot(i); - if(finger != null && finger.id != 0) { - logger.info(String.format("clear %d, %d, %d", finger.x, finger.y, finger.id -1)); + if (finger != null && finger.id != 0) { + logger.info(String.format( + "clear %d, %d, %d", finger.x, finger.y, finger.id - 1)); + MouseEventData mouseEventData = new MouseEventData( MouseButtonType.LEFT.value(), MouseEventType.RELEASE.value(), - 0, 0, finger.x, finger.y, finger.id -1); - communicator.sendToQEMU( SendCommand.SEND_MOUSE_EVENT, mouseEventData ); + 0, 0, finger.x, finger.y, finger.id - 1); + communicator.sendToQEMU(SendCommand.SEND_MOUSE_EVENT, mouseEventData); } + finger.id = 0; finger.originX = finger.originY = finger.x = finger.y = -1; } + this.grabFingerID = 0; this.fingerCnt = 0; logger.info("clear multi touch"); } - + public void cleanup_multiTouchState() { this.multiTouchEnable = 0; clearFingerSlot(); fingerSlotimage.dispose(); } - + public int getMaxTouchPoint() { - if(this.maxTouchPoint <= 0 ) { + if (this.maxTouchPoint <= 0) { setMaxTouchPoint(1); } + return this.maxTouchPoint; } - + public void setMaxTouchPoint(int cnt) { - if(cnt <=0) { - cnt =1; + if (cnt <=0) { + cnt = 1; } + this.maxTouchPoint = cnt; } }