feat: ready for key map script

This commit is contained in:
rankun 2019-08-21 13:17:42 +08:00
parent bbb758e684
commit 7887f38d57
4 changed files with 96 additions and 0 deletions

View file

@ -10,3 +10,8 @@ SOURCES += \
$$PWD/inputconvertnormal.cpp \
$$PWD/controlmsg.cpp
include ($$PWD/keymap/keymap.pri)
INCLUDEPATH += \
$$PWD/keymap

View file

@ -0,0 +1,39 @@
#include "keymap.h"
KeyMap::KeyMap()
{
}
void KeyMap::loadKeyMapNode()
{
KeyMapNode node;
node.type = KMT_CLICK;
node.click.keyNode.key = Qt::Key_J;
node.click.keyNode.pos = QPointF(0.5f, 0.5f);
node.click.quitMap = false;
m_keyMapNodes.push_back(node);
}
KeyMap::KeyMapNode KeyMap::getKeyMapNode(int key)
{
KeyMapNode retNode;
bool find = false;
for (auto& node : m_keyMapNodes) {
switch (node.type) {
case KMT_CLICK:
if (node.click.keyNode.key == key) {
retNode = node;
find = true;
}
break;
}
if (find) {
break;
}
}
return retNode;
}

View file

@ -0,0 +1,47 @@
#ifndef KEYMAP_H
#define KEYMAP_H
#include <QPointF>
#include <QVector>
class KeyMap
{
public:
enum KeyMapType {
KMT_INVALID = -1,
KMT_CLICK = 0,
KMT_CLICK_TWICE,
};
struct KeyNode {
int key = Qt::Key_unknown;
QPointF pos = QPointF(0, 0);
};
struct KeyMapNode {
KeyMapType type = KMT_INVALID;
union {
struct {
KeyNode keyNode;
bool quitMap = false;
} click;
struct {
KeyNode keyNode;
bool quitMap = false;
} clickTwice;
};
KeyMapNode() {}
~KeyMapNode() {}
};
KeyMap();
void loadKeyMapNode();
KeyMap::KeyMapNode getKeyMapNode(int key);
private:
QVector<KeyMapNode> m_keyMapNodes;
};
#endif // KEYMAP_H

View file

@ -0,0 +1,5 @@
HEADERS += \
$$PWD/keymap.h
SOURCES += \
$$PWD/keymap.cpp