feat: optimize process steer wheel

This commit is contained in:
rankun 2020-01-30 19:40:46 +08:00
parent b4b7b0dc25
commit 1b87d3b58b
2 changed files with 31 additions and 27 deletions

View file

@ -119,7 +119,6 @@ void InputConvertGame::loadKeyMap(const QString &json)
m_ctrlMouseMove.startPosPixel = calcFrameAbsolutePos(m_ctrlMouseMove.startPosRel);
}
if(m_keyMap.isValidSteerWheelMap()){
m_ctrlSteerWheel.valid = true;
m_ctrlMouseMove.touching = false;
}
}
@ -231,37 +230,42 @@ void InputConvertGame::processSteerWheel(const KeyMap::KeyMapNode &node, const Q
} else { // left
m_ctrlSteerWheel.pressedLeft = flag;
}
// calc offset and pressed number
QPointF offset(0.0, 0.0);
int nPressed = 0;
int pressedNum = 0;
if (m_ctrlSteerWheel.pressedUp) {
++nPressed;
++pressedNum;
offset.ry() -= node.data.steerWheel.up.extendOffset;
}
if (m_ctrlSteerWheel.pressedRight) {
++nPressed;
++pressedNum;
offset.rx() += node.data.steerWheel.right.extendOffset;
}
if (m_ctrlSteerWheel.pressedDown) {
++nPressed;
++pressedNum;
offset.ry() += node.data.steerWheel.down.extendOffset;
}
if (m_ctrlSteerWheel.pressedLeft) {
++nPressed;
++pressedNum;
offset.rx() -= node.data.steerWheel.left.extendOffset;
}
// action
//qDebug()<<nPressed<<"-"<<char(from->key())<<"-"<<from->type()<<"-"<<offset;
if(nPressed == 0){ // release all
if(pressedNum == 0){
// touch up release all
int id = getTouchID(m_ctrlSteerWheel.touchKey);
sendTouchUpEvent(id, node.data.steerWheel.centerPos + m_ctrlSteerWheel.lastOffset);
detachTouchID(m_ctrlSteerWheel.touchKey);
} else {
int id;
if(nPressed == 1 && flag){ // first press
// first press, get key and touch down
if (pressedNum == 1 && flag) {
m_ctrlSteerWheel.touchKey = from->key();
id = attachTouchID(m_ctrlSteerWheel.touchKey);
sendTouchDownEvent(id, node.data.steerWheel.centerPos);
} else {
// jsut get touch id and move
id = getTouchID(m_ctrlSteerWheel.touchKey);
}
sendTouchMoveEvent(id, node.data.steerWheel.centerPos + offset);

View file

@ -68,13 +68,13 @@ private:
// steer wheel
struct {
bool valid = false;
bool touching = false;
int touchKey = Qt::Key_unknown; // the first key pressed
int nKeyPressed = 0;
bool pressedUp = false, pressedDown = false;
bool pressedLeft = false, pressedRight = false;
QPointF centerPos;
// the first key pressed
int touchKey = Qt::Key_unknown;
bool pressedUp = false;
bool pressedDown = false;
bool pressedLeft = false;
bool pressedRight = false;
// for last up
QPointF lastOffset;
} m_ctrlSteerWheel;