mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-01 05:18:38 +00:00
feat: small eye
This commit is contained in:
parent
2664cecad9
commit
d4475fd4ac
6 changed files with 96 additions and 19 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QCursor>
|
#include <QCursor>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "inputconvertgame.h"
|
#include "inputconvertgame.h"
|
||||||
|
|
||||||
|
@ -76,6 +77,27 @@ void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize &frameSize, c
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// small eyes
|
||||||
|
if (from->key() == m_keyMap.getMouseMoveMap().data.mouseMove.smallEyes.key) {
|
||||||
|
m_ctrlMouseMove.smallEyes = (QEvent::KeyPress == from->type());
|
||||||
|
|
||||||
|
if (QEvent::KeyPress == from->type()) {
|
||||||
|
m_processMouseMove = false;
|
||||||
|
int delay = 30;
|
||||||
|
QTimer::singleShot(delay, this, [this]() { mouseMoveStopTouch(); });
|
||||||
|
QTimer::singleShot(delay * 2, this, [this]() {
|
||||||
|
mouseMoveStartTouch(nullptr);
|
||||||
|
m_processMouseMove = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
stopMouseMoveTimer();
|
||||||
|
} else {
|
||||||
|
mouseMoveStopTouch();
|
||||||
|
mouseMoveStartTouch(nullptr);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (node.type) {
|
switch (node.type) {
|
||||||
// 处理方向盘
|
// 处理方向盘
|
||||||
case KeyMap::KMT_STEER_WHEEL:
|
case KeyMap::KMT_STEER_WHEEL:
|
||||||
|
@ -304,7 +326,6 @@ bool InputConvertGame::processMouseClick(const QMouseEvent *from)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "mouse event " << from->type();
|
|
||||||
if (QEvent::MouseButtonPress == from->type() || QEvent::MouseButtonDblClick == from->type()) {
|
if (QEvent::MouseButtonPress == from->type() || QEvent::MouseButtonDblClick == from->type()) {
|
||||||
int id = attachTouchID(from->button());
|
int id = attachTouchID(from->button());
|
||||||
sendTouchDownEvent(id, node.data.click.keyNode.pos);
|
sendTouchDownEvent(id, node.data.click.keyNode.pos);
|
||||||
|
@ -330,7 +351,7 @@ bool InputConvertGame::processMouseMove(const QMouseEvent *from)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_ctrlMouseMove.lastPos.isNull()) {
|
if (!m_ctrlMouseMove.lastPos.isNull() && m_processMouseMove) {
|
||||||
QPointF distance = from->localPos() - m_ctrlMouseMove.lastPos;
|
QPointF distance = from->localPos() - m_ctrlMouseMove.lastPos;
|
||||||
distance /= m_keyMap.getMouseMoveMap().data.mouseMove.speedRatio;
|
distance /= m_keyMap.getMouseMoveMap().data.mouseMove.speedRatio;
|
||||||
|
|
||||||
|
@ -340,10 +361,20 @@ bool InputConvertGame::processMouseMove(const QMouseEvent *from)
|
||||||
m_ctrlMouseMove.lastConverPos.setX(m_ctrlMouseMove.lastConverPos.x() + distance.x() / m_showSize.width());
|
m_ctrlMouseMove.lastConverPos.setX(m_ctrlMouseMove.lastConverPos.x() + distance.x() / m_showSize.width());
|
||||||
m_ctrlMouseMove.lastConverPos.setY(m_ctrlMouseMove.lastConverPos.y() + distance.y() / m_showSize.height());
|
m_ctrlMouseMove.lastConverPos.setY(m_ctrlMouseMove.lastConverPos.y() + distance.y() / m_showSize.height());
|
||||||
|
|
||||||
if (m_ctrlMouseMove.lastConverPos.x() < 0.1 || m_ctrlMouseMove.lastConverPos.x() > 0.8 || m_ctrlMouseMove.lastConverPos.y() < 0.1
|
if (m_ctrlMouseMove.lastConverPos.x() < 0.1 || m_ctrlMouseMove.lastConverPos.x() > 0.98 || m_ctrlMouseMove.lastConverPos.y() < 0.1
|
||||||
|| m_ctrlMouseMove.lastConverPos.y() > 0.8) {
|
|| m_ctrlMouseMove.lastConverPos.y() > 0.98) {
|
||||||
mouseMoveStopTouch();
|
if (m_ctrlMouseMove.smallEyes) {
|
||||||
mouseMoveStartTouch(from);
|
m_processMouseMove = false;
|
||||||
|
int delay = 30;
|
||||||
|
QTimer::singleShot(delay, this, [this]() { mouseMoveStopTouch(); });
|
||||||
|
QTimer::singleShot(delay * 2, this, [this]() {
|
||||||
|
mouseMoveStartTouch(nullptr);
|
||||||
|
m_processMouseMove = true;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
mouseMoveStopTouch();
|
||||||
|
mouseMoveStartTouch(from);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendTouchMoveEvent(getTouchID(Qt::ExtraButton24), m_ctrlMouseMove.lastConverPos);
|
sendTouchMoveEvent(getTouchID(Qt::ExtraButton24), m_ctrlMouseMove.lastConverPos);
|
||||||
|
@ -390,7 +421,8 @@ void InputConvertGame::mouseMoveStartTouch(const QMouseEvent *from)
|
||||||
{
|
{
|
||||||
Q_UNUSED(from)
|
Q_UNUSED(from)
|
||||||
if (!m_ctrlMouseMove.touching) {
|
if (!m_ctrlMouseMove.touching) {
|
||||||
QPointF mouseMoveStartPos = m_keyMap.getMouseMoveMap().data.mouseMove.startPos;
|
QPointF mouseMoveStartPos
|
||||||
|
= m_ctrlMouseMove.smallEyes ? m_keyMap.getMouseMoveMap().data.mouseMove.smallEyes.pos : m_keyMap.getMouseMoveMap().data.mouseMove.startPos;
|
||||||
int id = attachTouchID(Qt::ExtraButton24);
|
int id = attachTouchID(Qt::ExtraButton24);
|
||||||
sendTouchDownEvent(id, mouseMoveStartPos);
|
sendTouchDownEvent(id, mouseMoveStartPos);
|
||||||
m_ctrlMouseMove.lastConverPos = mouseMoveStartPos;
|
m_ctrlMouseMove.lastConverPos = mouseMoveStartPos;
|
||||||
|
|
|
@ -66,6 +66,8 @@ private:
|
||||||
int m_multiTouchID[MULTI_TOUCH_MAX_NUM] = { 0 };
|
int m_multiTouchID[MULTI_TOUCH_MAX_NUM] = { 0 };
|
||||||
KeyMap m_keyMap;
|
KeyMap m_keyMap;
|
||||||
|
|
||||||
|
bool m_processMouseMove = true;
|
||||||
|
|
||||||
// steer wheel
|
// steer wheel
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -86,6 +88,7 @@ private:
|
||||||
QPointF lastPos = { 0.0, 0.0 };
|
QPointF lastPos = { 0.0, 0.0 };
|
||||||
bool touching = false;
|
bool touching = false;
|
||||||
int timer = 0;
|
int timer = 0;
|
||||||
|
bool smallEyes = false;
|
||||||
} m_ctrlMouseMove;
|
} m_ctrlMouseMove;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,39 @@ void KeyMap::loadKeyMap(const QString &json)
|
||||||
if (checkItemDouble(startPos, "y")) {
|
if (checkItemDouble(startPos, "y")) {
|
||||||
keyMapNode.data.mouseMove.startPos.setY(getItemDouble(startPos, "y"));
|
keyMapNode.data.mouseMove.startPos.setY(getItemDouble(startPos, "y"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// small eyes
|
||||||
|
if (checkItemObject(mouseMoveMap, "smallEyes")) {
|
||||||
|
QJsonObject smallEyes = mouseMoveMap.value("smallEyes").toObject();
|
||||||
|
if (!smallEyes.contains("type") || !smallEyes.value("type").isString()) {
|
||||||
|
errorString = QString("json error: smallEyes no find node type");
|
||||||
|
goto parseError;
|
||||||
|
}
|
||||||
|
|
||||||
|
// type just support KMT_CLICK
|
||||||
|
KeyMap::KeyMapType type = getItemKeyMapType(smallEyes, "type");
|
||||||
|
if (KeyMap::KMT_CLICK != type) {
|
||||||
|
errorString = QString("json error: smallEyes just support KMT_CLICK");
|
||||||
|
goto parseError;
|
||||||
|
}
|
||||||
|
|
||||||
|
// safe check
|
||||||
|
if (!checkForClick(smallEyes)) {
|
||||||
|
errorString = QString("json error: smallEyes node format error");
|
||||||
|
goto parseError;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPair<ActionType, int> key = getItemKey(smallEyes, "key");
|
||||||
|
if (key.first == AT_INVALID) {
|
||||||
|
errorString = QString("json error: keyMapNodes node invalid key: %1").arg(smallEyes.value("key").toString());
|
||||||
|
goto parseError;
|
||||||
|
}
|
||||||
|
|
||||||
|
keyMapNode.data.mouseMove.smallEyes.type = key.first;
|
||||||
|
keyMapNode.data.mouseMove.smallEyes.key = key.second;
|
||||||
|
keyMapNode.data.mouseMove.smallEyes.pos = getItemPos(smallEyes, "pos");
|
||||||
|
}
|
||||||
|
|
||||||
m_idxMouseMove = m_keyMapNodes.size();
|
m_idxMouseMove = m_keyMapNodes.size();
|
||||||
m_keyMapNodes.push_back(keyMapNode);
|
m_keyMapNodes.push_back(keyMapNode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ public:
|
||||||
{
|
{
|
||||||
QPointF startPos = { 0.0, 0.0 };
|
QPointF startPos = { 0.0, 0.0 };
|
||||||
int speedRatio = 1;
|
int speedRatio = 1;
|
||||||
|
KeyNode smallEyes;
|
||||||
} mouseMove;
|
} mouseMove;
|
||||||
DATA() {}
|
DATA() {}
|
||||||
~DATA() {}
|
~DATA() {}
|
||||||
|
|
|
@ -454,7 +454,7 @@ void VideoForm::onSwitchFullScreen()
|
||||||
|
|
||||||
void VideoForm::updateFPS(quint32 fps)
|
void VideoForm::updateFPS(quint32 fps)
|
||||||
{
|
{
|
||||||
qDebug() << "FPS:" << fps;
|
//qDebug() << "FPS:" << fps;
|
||||||
if (!m_fpsLabel) {
|
if (!m_fpsLabel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -556,6 +556,14 @@ void VideoForm::mouseDoubleClickEvent(QMouseEvent *event)
|
||||||
if (event->button() == Qt::RightButton && m_device) {
|
if (event->button() == Qt::RightButton && m_device) {
|
||||||
emit m_device->postBackOrScreenOn();
|
emit m_device->postBackOrScreenOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_videoWidget->geometry().contains(event->pos())) {
|
||||||
|
if (!m_device) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint()));
|
||||||
|
emit m_device->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoForm::wheelEvent(QWheelEvent *event)
|
void VideoForm::wheelEvent(QWheelEvent *event)
|
||||||
|
|
|
@ -5,7 +5,17 @@
|
||||||
"x": 0.57,
|
"x": 0.57,
|
||||||
"y": 0.26
|
"y": 0.26
|
||||||
},
|
},
|
||||||
"speedRatio": 8
|
"smallEyes": {
|
||||||
|
"comment": "小眼睛",
|
||||||
|
"type": "KMT_CLICK",
|
||||||
|
"key": "Key_Alt",
|
||||||
|
"pos": {
|
||||||
|
"x": 0.8,
|
||||||
|
"y": 0.31
|
||||||
|
},
|
||||||
|
"switchMap": false
|
||||||
|
},
|
||||||
|
"speedRatio": 10
|
||||||
},
|
},
|
||||||
"keyMapNodes": [
|
"keyMapNodes": [
|
||||||
{
|
{
|
||||||
|
@ -102,16 +112,6 @@
|
||||||
},
|
},
|
||||||
"switchMap": false
|
"switchMap": false
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"comment": "小眼睛",
|
|
||||||
"type": "KMT_CLICK",
|
|
||||||
"key": "Key_Alt",
|
|
||||||
"pos": {
|
|
||||||
"x": 0.8,
|
|
||||||
"y": 0.31
|
|
||||||
},
|
|
||||||
"switchMap": false
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"comment": "捡东西1",
|
"comment": "捡东西1",
|
||||||
"type": "KMT_CLICK",
|
"type": "KMT_CLICK",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue