mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-02 05:48:38 +00:00
鼠标移动优化
This commit is contained in:
parent
70ebf39a2b
commit
3709804fa2
2 changed files with 19 additions and 14 deletions
|
@ -317,7 +317,7 @@ bool InputConvertGame::processMouseMove(const QMouseEvent *from)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mouseMoveStartTouch();
|
mouseMoveStartTouch(from);
|
||||||
startMouseMoveTimer();
|
startMouseMoveTimer();
|
||||||
|
|
||||||
// move
|
// move
|
||||||
|
@ -327,23 +327,25 @@ bool InputConvertGame::processMouseMove(const QMouseEvent *from)
|
||||||
pos.setX(pos.x() / m_showSize.width());
|
pos.setX(pos.x() / m_showSize.width());
|
||||||
pos.setY(pos.y() / m_showSize.height());
|
pos.setY(pos.y() / m_showSize.height());
|
||||||
sendTouchMoveEvent(getTouchID(Qt::ExtraButton24), pos);
|
sendTouchMoveEvent(getTouchID(Qt::ExtraButton24), pos);
|
||||||
|
m_mouseMoveLastPos = pos;
|
||||||
if (pos.x() < 0.1 || pos.x() > 0.9 || pos.y() < 0.1 || pos.y() > 0.9) {
|
if (pos.x() < 0.1 || pos.x() > 0.9 || pos.y() < 0.1 || pos.y() > 0.9) {
|
||||||
mouseMoveStopTouch();
|
mouseMoveStopTouch();
|
||||||
|
mouseMoveStartTouch(from);
|
||||||
QPoint localPos = QPoint(m_showSize.width()*m_mouseMoveStartPos.x(), m_showSize.height()*m_mouseMoveStartPos.y());
|
|
||||||
QPoint posOffset = from->localPos().toPoint() - localPos;
|
|
||||||
QPoint globalPos = from->globalPos();
|
|
||||||
|
|
||||||
globalPos += posOffset;
|
|
||||||
QCursor::setPos(globalPos);
|
|
||||||
|
|
||||||
mouseMoveStartTouch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputConvertGame::moveCursorToStart(const QMouseEvent *from)
|
||||||
|
{
|
||||||
|
QPoint localPos = QPoint(m_showSize.width()*m_mouseMoveStartPos.x(), m_showSize.height()*m_mouseMoveStartPos.y());
|
||||||
|
QPoint posOffset = from->localPos().toPoint() - localPos;
|
||||||
|
QPoint globalPos = from->globalPos();
|
||||||
|
|
||||||
|
globalPos -= posOffset;
|
||||||
|
QCursor::setPos(globalPos);
|
||||||
|
}
|
||||||
|
|
||||||
void InputConvertGame::startMouseMoveTimer()
|
void InputConvertGame::startMouseMoveTimer()
|
||||||
{
|
{
|
||||||
stopMouseMoveTimer();
|
stopMouseMoveTimer();
|
||||||
|
@ -358,9 +360,10 @@ void InputConvertGame::stopMouseMoveTimer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputConvertGame::mouseMoveStartTouch()
|
void InputConvertGame::mouseMoveStartTouch(const QMouseEvent* from)
|
||||||
{
|
{
|
||||||
if (!m_mouseMovePress) {
|
if (!m_mouseMovePress) {
|
||||||
|
moveCursorToStart(from);
|
||||||
int id = attachTouchID(Qt::ExtraButton24);
|
int id = attachTouchID(Qt::ExtraButton24);
|
||||||
sendTouchDownEvent(id, m_mouseMoveStartPos);
|
sendTouchDownEvent(id, m_mouseMoveStartPos);
|
||||||
m_mouseMovePress = true;
|
m_mouseMovePress = true;
|
||||||
|
@ -370,7 +373,7 @@ void InputConvertGame::mouseMoveStartTouch()
|
||||||
void InputConvertGame::mouseMoveStopTouch()
|
void InputConvertGame::mouseMoveStopTouch()
|
||||||
{
|
{
|
||||||
if (m_mouseMovePress) {
|
if (m_mouseMovePress) {
|
||||||
sendTouchUpEvent(getTouchID(Qt::ExtraButton24), m_mouseMoveStartPos);
|
sendTouchUpEvent(getTouchID(Qt::ExtraButton24), m_mouseMoveLastPos);
|
||||||
detachTouchID(Qt::ExtraButton24);
|
detachTouchID(Qt::ExtraButton24);
|
||||||
m_mouseMovePress = false;
|
m_mouseMovePress = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,9 +41,10 @@ protected:
|
||||||
// mouse
|
// mouse
|
||||||
bool processMouseClick(const QMouseEvent* from);
|
bool processMouseClick(const QMouseEvent* from);
|
||||||
bool processMouseMove(const QMouseEvent* from);
|
bool processMouseMove(const QMouseEvent* from);
|
||||||
|
void moveCursorToStart(const QMouseEvent* from);
|
||||||
void startMouseMoveTimer();
|
void startMouseMoveTimer();
|
||||||
void stopMouseMoveTimer();
|
void stopMouseMoveTimer();
|
||||||
void mouseMoveStartTouch();
|
void mouseMoveStartTouch(const QMouseEvent* from);
|
||||||
void mouseMoveStopTouch();
|
void mouseMoveStopTouch();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -73,6 +74,7 @@ private:
|
||||||
|
|
||||||
// mouse move
|
// mouse move
|
||||||
QPointF m_mouseMoveStartPos = {0.57f, 0.26f};
|
QPointF m_mouseMoveStartPos = {0.57f, 0.26f};
|
||||||
|
QPointF m_mouseMoveLastPos;
|
||||||
bool m_mouseMovePress = false;
|
bool m_mouseMovePress = false;
|
||||||
int m_mouseMoveTimer = 0;
|
int m_mouseMoveTimer = 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue