import java.util.ArrayList;
import java.util.logging.Logger;
-import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
public class EmulatorFingers {
private static final int MAX_FINGER_CNT = 10;
private static final int FINGER_POINT_SIZE = 32;
+ private static final int FINGER_POINT_ALPHA = 0x7E;
private static final int RED_MASK = 0x0000FF00;
private static final int GREEN_MASK = 0x00FF0000;
private int grabFingerID = 0;
private ArrayList<FingerPoint> FingerPointList;
- protected FingerPoint fingerSlot;
protected int fingerPointSize;
protected int fingerPointSizeHalf;
- private Color fingerPointColor;
- private Color fingerPointOutlineColor;
- protected Image fingerSlotimage;
- protected ImageData imageData;
+ protected Image fingerPointImage;
protected SocketCommunicator communicator;
private EmulatorSkinState currentState;
}
public FingerPoint getFingerPointSearch(int x, int y) {
- int i;
FingerPoint fingerPoint = null;
- int fingerRegion = (this.fingerPointSize) + 2;
+ int fingerRegion = fingerPointSize + 2;
//logger.info("x: "+x+ "y: "+ y + " fingerRegion: " + fingerRegion);
- for (i = this.fingerCnt - 1; i >= 0; i--) {
+ for (int i = fingerCnt - 1; i >= 0; i--) {
fingerPoint = getFingerPointFromSlot(i);
if (fingerPoint != null) {
return null;
}
- public void initMultiTouchState(int maximum) {
+ private void initMultiTouchState(int maximum) {
multiTouchEnable = 0;
int fingerCntMax = maximum;
setMaxTouchPoint(fingerCntMax);
logger.info("maxTouchPoint : " + getMaxTouchPoint());
- this.fingerCnt = 0;
-
- if (this.fingerSlot != null) {
- this.fingerSlot = null;
- }
+ fingerCnt = 0;
FingerPointList = new ArrayList<FingerPoint>();
for (int i = 0; i <= getMaxTouchPoint(); i++) {
}
this.fingerPointSize = FINGER_POINT_SIZE;
- this.fingerPointSizeHalf = this.fingerPointSize / 2;
+ this.fingerPointSizeHalf = fingerPointSize / 2;
- this.fingerPointOutlineColor = new Color(Display.getCurrent(), 0xDD, 0xDD, 0xDD);
- this.fingerPointColor = new Color(Display.getCurrent(), 0x0F, 0x0F, 0x0F);
+ Color pointOutlineColor = new Color(Display.getCurrent(), 0xDD, 0xDD, 0xDD);
+ Color pointColor = new Color(Display.getCurrent(), 0x0F, 0x0F, 0x0F);
PaletteData palette = new PaletteData(RED_MASK, GREEN_MASK, BLUE_MASK);
- this.imageData = new ImageData(
+ ImageData imageData = new ImageData(
fingerPointSize + 4, fingerPointSize + 4, COLOR_DEPTH, palette);
- this.imageData.transparentPixel = 0;
- this.fingerSlotimage = new Image(Display.getCurrent(), imageData);
+ imageData.transparentPixel = 0;
+ this.fingerPointImage = new Image(Display.getCurrent(), imageData);
- GC gc = new GC(this.fingerSlotimage);
+ /* draw point image */
+ GC gc = new GC(fingerPointImage);
- gc.setBackground(this.fingerPointColor);
- gc.fillOval(2, 2, this.fingerPointSize, this.fingerPointSize);
-
- gc.setForeground(this.fingerPointOutlineColor);
- gc.drawOval(0, 0, this.fingerPointSize + 2, this.fingerPointSize + 2);
+ gc.setBackground(pointColor);
+ gc.fillOval(2, 2, fingerPointSize, fingerPointSize);
+ gc.setForeground(pointOutlineColor);
+ gc.drawOval(0, 0, fingerPointSize + 2, fingerPointSize + 2);
gc.dispose();
+ pointOutlineColor.dispose();
+ pointColor.dispose();
}
- public void setMultiTouchEnable(int multiTouchEnable) {
- this.multiTouchEnable = multiTouchEnable;
+ public void setMultiTouchEnable(int value) {
+ multiTouchEnable = value;
}
public int getMultiTouchEnable() {
- return this.multiTouchEnable;
+ return multiTouchEnable;
}
protected int addFingerPoint(int originX, int originY, int x, int y) {
- if (this.fingerCnt == getMaxTouchPoint()) {
- logger.info("support multi-touch up to "
+ if (fingerCnt == getMaxTouchPoint()) {
+ logger.warning("support multi-touch up to "
+ getMaxTouchPoint() + " fingers");
return -1;
}
- this.fingerCnt += 1;
- FingerPointList.get(fingerCnt - 1).id = this.fingerCnt;
+ fingerCnt += 1;
+
+ FingerPointList.get(fingerCnt - 1).id = 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;
+ logger.info(fingerCnt + " finger touching");
+
+ return fingerCnt;
}
- protected void drawImage(PaintEvent e, int currentAngle) {
- //by mq
- 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);
+ protected void drawFingerPoints(GC gc) {
+ int alpha = gc.getAlpha();
+ gc.setAlpha(FINGER_POINT_ALPHA);
+
+ FingerPoint fingerSlot = null;
+ for (int i = 0; i < fingerCnt; i++) {
+ fingerSlot = getFingerPointFromSlot(i);
+
+ if (fingerSlot != null) {
+ gc.drawImage(fingerPointImage,
+ fingerSlot.originX - fingerPointSizeHalf - 2,
+ fingerSlot.originY - fingerPointSizeHalf - 2);
+ }
}
+
+ gc.setAlpha(alpha);
}
public void maruFingerProcessing1(
int touchType, int originX, int originY, int x, int y) {
FingerPoint finger = null;
- MouseEventData mouseEventData;
+ MouseEventData mouseEventData = null;
if (touchType == MouseEventType.PRESS.value() ||
touchType == MouseEventType.DRAG.value()) { /* pressed */
public void maruFingerProcessing2(
int touchType, int originX, int originY, int x, int y) {
FingerPoint finger = null;
- MouseEventData mouseEventData;
+ MouseEventData mouseEventData = null;
if (touchType == MouseEventType.PRESS.value() ||
touchType == MouseEventType.DRAG.value()) { /* pressed */
}
}
- private Boolean CalculateOriginCoordinates(
- int ScaledLcdWitdh, int ScaledLcdHeight,
+ private Boolean calculateOriginCoordinates(
+ int scaledDisplayWitdh, int scaledDisplayHeight,
double scaleFactor, int rotationType, FingerPoint finger) {
-
- int pointX, pointY, rotatedPointX, rotatedPointY, flag;
- flag = 0;
+ int pointX = 0, pointY = 0;
+ int rotatedPointX = 0, rotatedPointY = 0;
+ int flag = 0;
/* logger.info("ScaledLcdWitdh:" + ScaledLcdWitdh +
" ScaledLcdHeight:" + ScaledLcdHeight +
if (rotationType == RotationInfo.LANDSCAPE.id()) {
rotatedPointX = pointY;
- rotatedPointY = ScaledLcdWitdh - pointX;
+ rotatedPointY = scaledDisplayWitdh - pointX;
} else if (rotationType == RotationInfo.REVERSE_PORTRAIT.id()) {
- rotatedPointX = ScaledLcdWitdh - pointX;
- rotatedPointY = ScaledLcdHeight - pointY;
+ rotatedPointX = scaledDisplayWitdh - pointX;
+ rotatedPointY = scaledDisplayHeight - pointY;
} else if (rotationType == RotationInfo.REVERSE_LANDSCAPE.id()) {
- rotatedPointX = ScaledLcdHeight - pointY;
+ rotatedPointX = scaledDisplayHeight - pointY;
rotatedPointY = pointX;
} else {
/* PORTRAIT: do nothing */
}
public int rearrangeFingerPoints(
- int lcdWidth, int lcdHeight, double scaleFactor, int rotationType) {
- int i = 0;
- int count = 0;
- FingerPoint finger = null;
-
- if (this.multiTouchEnable == 0) {
+ int displayWidth, int displayHeight, double scaleFactor, int rotationType) {
+ if (multiTouchEnable == 0) {
return 0;
}
+ int count = 0;
+ FingerPoint finger = null;
+
scaleFactor = scaleFactor / 100;
- lcdWidth *= scaleFactor;
- lcdHeight *= scaleFactor;
+ displayWidth *= scaleFactor;
+ displayHeight *= scaleFactor;
- for (i = 0; i < this.fingerCnt; i++) {
+ for (int i = 0; i < fingerCnt; i++) {
finger = getFingerPointFromSlot(i);
if (finger != null && finger.id != 0) {
- if (CalculateOriginCoordinates(
- lcdWidth, lcdHeight, scaleFactor, rotationType, finger) == true) {
+ if (calculateOriginCoordinates(
+ displayWidth, displayHeight, scaleFactor, rotationType, finger) == true) {
count++;
}
}
}
if (count != 0) {
- this.grabFingerID = 0;
+ grabFingerID = 0;
}
return count;
int i = 0;
FingerPoint finger = null;
- for (i = 0; i < this.fingerCnt; i++) {
+ logger.info("clear multi-touch slot");
+
+ for (i = 0; i < 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) {
+ if (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, false);
- }
+ 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, false);
+ }
- finger.id = 0;
- finger.originX = finger.originY = finger.x = finger.y = -1;
+ finger.id = 0;
+ finger.originX = finger.originY = finger.x = finger.y = -1;
+ }
}
- this.grabFingerID = 0;
- this.fingerCnt = 0;
- logger.info("clear multi touch");
+ grabFingerID = 0;
+ fingerCnt = 0;
}
- public void cleanup_multiTouchState() {
- this.multiTouchEnable = 0;
+ public void cleanupMultiTouchState() {
+ multiTouchEnable = 0;
clearFingerSlot();
- fingerSlotimage.dispose();
+
+ fingerPointImage.dispose();
}
public int getMaxTouchPoint() {
- if (this.maxTouchPoint <= 0) {
+ if (maxTouchPoint <= 0) {
setMaxTouchPoint(1);
}
- return this.maxTouchPoint;
+ return maxTouchPoint;
}
public void setMaxTouchPoint(int cnt) {
cnt = 1;
}
- this.maxTouchPoint = cnt;
+ maxTouchPoint = cnt;
}
}