8211 Add very short haptic feedback when highlighting letters on keyboard

This commit is contained in:
beholder 2017-10-26 20:42:08 +03:00
parent 61a2d80117
commit 5969e0b118
3 changed files with 29 additions and 0 deletions

View file

@ -55,8 +55,21 @@ Item {
mouse.accepted = true;
}
property var _HAPTIC_STRENGTH: 0.1;
property var _HAPTIC_DURATION: 3.0;
property var leftHand: 0;
property var rightHand: 1;
onEntered: {
keyItem.state = "mouseOver";
var globalPosition = keyItem.mapToGlobal(mouseArea1.mouseX, mouseArea1.mouseY);
var deviceId = Web3DOverlay.deviceIdByTouchPoint(globalPosition.x, globalPosition.y);
var hand = deviceId - 1;
if(hand == leftHand || hand == rightHand) {
Controller.triggerHapticPulse(_HAPTIC_STRENGTH, _HAPTIC_DURATION, hand);
}
}
onExited: {

View file

@ -244,6 +244,8 @@ void Web3DOverlay::setupQmlSurface() {
_webSurface->getSurfaceContext()->setContextProperty("SoundCache", DependencyManager::get<SoundCache>().data());
_webSurface->getSurfaceContext()->setContextProperty("MenuInterface", MenuScriptingInterface::getInstance());
_webSurface->getSurfaceContext()->setContextProperty("Settings", SettingsScriptingInterface::getInstance());
_webSurface->getSurfaceContext()->setContextProperty("Controller", DependencyManager::get<controller::ScriptingInterface>().data());
_webSurface->getSurfaceContext()->setContextProperty("Web3DOverlay", this);
_webSurface->getSurfaceContext()->setContextProperty("pathToFonts", "../../");
@ -272,6 +274,18 @@ void Web3DOverlay::onResizeWebSurface() {
_webSurface->resize(QSize(_resolution.x, _resolution.y));
}
Q_INVOKABLE int Web3DOverlay::deviceIdByTouchPoint(qreal x, qreal y)
{
auto mapped = _webSurface->getRootItem()->mapFromGlobal(QPoint(x, y));
for (auto pair : _activeTouchPoints) {
if (mapped.x() == (int) pair.second.pos().x() && mapped.y() == (int) pair.second.pos().y())
return pair.first;
}
return -1;
}
void Web3DOverlay::render(RenderArgs* args) {
if (!_visible || !getParentVisible()) {
return;

View file

@ -66,6 +66,8 @@ public:
void destroyWebSurface();
void onResizeWebSurface();
Q_INVOKABLE int deviceIdByTouchPoint(qreal x, qreal y);
public slots:
void emitScriptEvent(const QVariant& scriptMessage);