#include <QDebug>
#include "multitouchtracker.h"
+#include "displaybase.h"
extern "C" {
void virtio_touchscreen_event(int x, int y, int z, int buttons_state);
this->guestPos = guestPos;
}
-MultiTouchTracker::MultiTouchTracker(int maxTouchPoint)
+MultiTouchTracker::MultiTouchTracker(
+ TouchScreenHelper* parent, int maxTouchPoint)
{
+ this->parent = parent;
this->maxTouchPoint = maxTouchPoint;
this->pointRadius = 16; // TODO:
this->grabTouchPoint = NULL;
/* parallel moving mode */
void MultiTouchTracker::touchProcessingPara(QPoint hostPos, QPoint guestPos)
{
- //TODO:
+ TouchPoint *point = NULL;
+ const int touchCnt = touchPointList.count();
+
+ if (grabTouchPoint != NULL) {
+ const int hostPosDiffX = hostPos.x() - grabTouchPoint->getHostPos().x();
+ const int hostPosDiffY = hostPos.y() - grabTouchPoint->getHostPos().y();
+
+ /* bounds checking */
+ // TODO:
+
+ /* move whole touch points */
+ for (int i = 0; i < touchPointList.count(); i++) {
+ point = touchPointList.at(i);
+ if (point != NULL) {
+ QPoint hostMovedPos(
+ point->getHostPos().x() + hostPosDiffX,
+ point->getHostPos().y() + hostPosDiffY);
+ QPoint guestMovedPos =
+ ((DisplayBase *)parent->getParent())->getGuestPos(hostMovedPos);
+ point->updatePos(hostMovedPos, guestMovedPos);
+
+ virtio_touchscreen_event(
+ point->getGuestPos().x(), point->getGuestPos().y(),
+ point->getID() - 1, 1);
+ }
+ }
+
+ return;
+ }
+
+ if (touchCnt == 0) { /* first touch input */
+ qDebug("mt para mode processing");
+
+ if (addTouchPoint(hostPos, guestPos) == -1) {
+ return;
+ }
+
+ virtio_touchscreen_event(guestPos.x(), guestPos.y(), 0, 1);
+ } else if ((point = searchTouchPoint(hostPos)) != NULL) { /* grab a touch */
+ qDebug() << "ID" << point->getID() << "point is taken";
+ grabTouchPoint = point;
+ } else if (touchCnt == getMaxTouchPoint()) { /* last touch */
+ /* do nothing */
+ return;
+ } else { /* additional touch */
+ if (addTouchPoint(hostPos, guestPos) == -1) {
+ return;
+ }
+
+ point = touchPointList.last();
+ virtio_touchscreen_event(guestPos.x(), guestPos.y(),
+ point->getID() - 1, 1);
+ }
}
/* symmetrical moving mode */
void MultiTouchTracker::touchProcessingSymm(QPoint hostPos, QPoint guestPos)
{
- //TODO:
+ TouchPoint *point = NULL;
+ const int touchCnt = touchPointList.count();
+
+ if (grabTouchPoint != NULL) {
+ const int hostPosDiffX = hostPos.x() - grabTouchPoint->getHostPos().x();
+ const int hostPosDiffY = hostPos.y() - grabTouchPoint->getHostPos().y();
+
+ /* move selected point */
+ grabTouchPoint->updatePos(hostPos, guestPos);
+ virtio_touchscreen_event(guestPos.x(), guestPos.y(),
+ grabTouchPoint->getID() - 1, 1);
+
+ /* bounds checking */
+ // TODO:
+
+ /* move other points */
+ for (int i = 0; i < touchPointList.count(); i++) {
+ point = touchPointList.at(i);
+ if (point != NULL && point != grabTouchPoint) {
+ QPoint hostMovedPos(
+ point->getHostPos().x() - hostPosDiffX,
+ point->getHostPos().y() - hostPosDiffY);
+ QPoint guestMovedPos =
+ ((DisplayBase *)parent->getParent())->getGuestPos(hostMovedPos);
+ point->updatePos(hostMovedPos, guestMovedPos);
+
+ virtio_touchscreen_event(
+ point->getGuestPos().x(), point->getGuestPos().y(),
+ point->getID() - 1, 1);
+ }
+ }
+
+ return;
+ }
+
+ if (touchCnt == 0) { /* first touch input */
+ qDebug("mt symm mode processing");
+
+ if (addTouchPoint(hostPos, guestPos) == -1) {
+ return;
+ }
+
+ virtio_touchscreen_event(guestPos.x(), guestPos.y(), 0, 1);
+ } else if ((point = searchTouchPoint(hostPos)) != NULL) { /* grab a touch */
+ qDebug() << "ID" << point->getID() << "point is taken";
+ grabTouchPoint = point;
+ } else if (touchCnt >= 2) { /* last touch */
+ /* supports up to 2 touch points */
+ point = touchPointList.last();
+ if (point != NULL) {
+ /* re-input */
+ qDebug() << "ID" << point->getID() << "point re-touching";
+
+ virtio_touchscreen_event(
+ point->getGuestPos().x(), point->getGuestPos().y(),
+ point->getID() - 1, 0);
+
+ point->updatePos(hostPos, guestPos);
+ virtio_touchscreen_event(
+ point->getGuestPos().x(), point->getGuestPos().y(),
+ point->getID() - 1, 1);
+ }
+ } else { /* additional touch */
+ if (addTouchPoint(hostPos, guestPos) == -1) {
+ return;
+ }
+
+ point = touchPointList.last();
+ virtio_touchscreen_event(guestPos.x(), guestPos.y(),
+ point->getID() - 1, 1);
+ }
}
void MultiTouchTracker::touchReleasing()