use mouse events for offscreenui because touch events aren't working with the eventFilter, cleanup

This commit is contained in:
SamGondelman 2017-11-13 16:45:00 -08:00
parent 60db24f2d3
commit 210fd209f5
7 changed files with 42 additions and 27 deletions

View file

@ -105,7 +105,12 @@ unsigned int PickScriptingInterface::createStylusPick(const QVariant& properties
filter = PickFilter(propMap["filter"].toUInt());
}
return DependencyManager::get<PickManager>()->addPick(PickQuery::Stylus, std::make_shared<StylusPick>(filter, side, enabled));
float maxDistance = 0.0f;
if (propMap["maxDistance"].isValid()) {
maxDistance = propMap["maxDistance"].toFloat();
}
return DependencyManager::get<PickManager>()->addPick(PickQuery::Stylus, std::make_shared<StylusPick>(side, filter, maxDistance, enabled));
}
void PickScriptingInterface::enablePick(unsigned int uid) {

View file

@ -31,11 +31,11 @@ public:
Q_INVOKABLE QVariantMap getPrevPickResult(unsigned int uid) const;
Q_INVOKABLE void setPrecisionPicking(unsigned int uid, bool precisionPicking) const { DependencyManager::get<PointerManager>()->setPrecisionPicking(uid, precisionPicking); }
Q_INVOKABLE void setLaserLength(unsigned int uid, float laserLength) const { DependencyManager::get<PointerManager>()->setLength(uid, laserLength); }
Q_INVOKABLE void setLength(unsigned int uid, float length) const { DependencyManager::get<PointerManager>()->setLength(uid, length); }
Q_INVOKABLE void setIgnoreItems(unsigned int uid, const QScriptValue& ignoreEntities) const;
Q_INVOKABLE void setIncludeItems(unsigned int uid, const QScriptValue& includeEntities) const;
Q_INVOKABLE void setLockEndUUID(unsigned int uid, const QUuid& objectID, bool isOverlay) const { DependencyManager::get<PointerManager>()->setLockEndUUID(uid, objectID, isOverlay); }
Q_INVOKABLE void setLockEndUUID(unsigned int uid, const QUuid& objectID, bool isOverlay, const glm::mat4& offsetMat = glm::mat4()) const { DependencyManager::get<PointerManager>()->setLockEndUUID(uid, objectID, isOverlay, offsetMat); }
Q_INVOKABLE bool isLeftHand(unsigned int uid) { return DependencyManager::get<PointerManager>()->isLeftHand(uid); }
Q_INVOKABLE bool isRightHand(unsigned int uid) { return DependencyManager::get<PointerManager>()->isRightHand(uid); }

View file

@ -60,8 +60,7 @@ glm::vec3 RayPick::intersectRayWithXYPlane(const glm::vec3& origin, const glm::v
glm::vec3 RayPick::intersectRayWithOverlayXYPlane(const QUuid& overlayID, const glm::vec3& origin, const glm::vec3& direction) {
glm::vec3 position = vec3FromVariant(qApp->getOverlays().getProperty(overlayID, "position").value);
glm::quat rotation = quatFromVariant(qApp->getOverlays().getProperty(overlayID, "rotation").value);
const glm::vec3 DEFAULT_REGISTRATION_POINT = glm::vec3(0.5f);
return intersectRayWithXYPlane(origin, direction, position, rotation, DEFAULT_REGISTRATION_POINT);
return intersectRayWithXYPlane(origin, direction, position, rotation, ENTITY_ITEM_DEFAULT_REGISTRATION_POINT);
}
glm::vec3 RayPick::intersectRayWithEntityXYPlane(const QUuid& entityID, const glm::vec3& origin, const glm::vec3& direction) {
@ -98,8 +97,7 @@ glm::vec2 RayPick::projectOntoOverlayXYPlane(const QUuid& overlayID, const glm::
dimensions = glm::vec3(vec2FromVariant(qApp->getOverlays().getProperty(overlayID, "dimensions").value), 0.01);
}
const glm::vec3 DEFAULT_REGISTRATION_POINT = glm::vec3(0.5f);
return projectOntoXYPlane(worldPos, position, rotation, dimensions, DEFAULT_REGISTRATION_POINT, unNormalized);
return projectOntoXYPlane(worldPos, position, rotation, dimensions, ENTITY_ITEM_DEFAULT_REGISTRATION_POINT, unNormalized);
}
glm::vec2 RayPick::projectOntoEntityXYPlane(const QUuid& entityID, const glm::vec3& worldPos, bool unNormalized) {

View file

@ -26,7 +26,7 @@ using namespace bilateral;
static Setting::Handle<double> USE_FINGER_AS_STYLUS("preferAvatarFingerOverStylus", false);
static const float WEB_STYLUS_LENGTH = 0.2f;
static const float WEB_TOUCH_Y_OFFSET = 0.105f; // how far forward (or back with a negative number) to slide stylus in hand
static const glm::vec3 TIP_OFFSET{ 0.0f, WEB_STYLUS_LENGTH - WEB_TOUCH_Y_OFFSET, 0.0f };
static const glm::vec3 TIP_OFFSET = glm::vec3(0.0f, WEB_STYLUS_LENGTH - WEB_TOUCH_Y_OFFSET, 0.0f);
struct SideData {
QString avatarJoint;
@ -65,8 +65,8 @@ bool StylusPickResult::checkOrFilterAgainstMaxDistance(float maxDistance) {
return distance < maxDistance;
}
StylusPick::StylusPick(const PickFilter& filter, Side side, bool enabled) :
Pick(filter, 0.0f, enabled),
StylusPick::StylusPick(Side side, const PickFilter& filter, float maxDistance, bool enabled) :
Pick(filter, maxDistance, enabled),
_side(side)
{
}
@ -150,7 +150,6 @@ PickResultPointer StylusPick::getEntityIntersection(const StylusTip& pick) {
}
auto entity = qApp->getEntities()->getTree()->findEntityByEntityItemID(target);
// Don't interact with non-3D or invalid overlays
if (!entity) {
continue;
}

View file

@ -58,7 +58,7 @@ public:
class StylusPick : public Pick<StylusTip> {
using Side = bilateral::Side;
public:
StylusPick(const PickFilter& filter, Side side, bool enabled);
StylusPick(Side side, const PickFilter& filter, float maxDistance, bool enabled);
StylusTip getMathematicalPick() const override;
PickResultPointer getDefaultResult(const QVariantMap& pickVariant) const override;
@ -67,12 +67,11 @@ public:
PickResultPointer getAvatarIntersection(const StylusTip& pick) override;
PickResultPointer getHUDIntersection(const StylusTip& pick) override;
bool isLeftHand() const override { return _side == Side::Left; }
bool isRightHand() const override { return _side == Side::Right; }
private:
const Side _side;
};
#endif // hifi_StylusPick_h
#endif // hifi_StylusPick_h

View file

@ -1109,16 +1109,19 @@ bool OffscreenUi::eventFilter(QObject* originalDestination, QEvent* event) {
case QEvent::MouseMove: {
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
QPointF transformedPos = mapToVirtualScreen(mouseEvent->localPos());
PointerEvent pointerEvent(choosePointerEventType(mouseEvent->type()), PointerManager::MOUSE_POINTER_ID, glm::vec2(transformedPos.x(), transformedPos.y()),
PointerEvent::Button(mouseEvent->button()), mouseEvent->buttons(), mouseEvent->modifiers());
result = OffscreenQmlSurface::handlePointerEvent(pointerEvent, _touchDevice);
// FIXME: touch events are always being accepted. Use mouse events on the OffScreenUi for now, and investigate properly switching to touch events
// (using handlePointerEvent) later
QMouseEvent mappedEvent(mouseEvent->type(), transformedPos, mouseEvent->screenPos(), mouseEvent->button(), mouseEvent->buttons(), mouseEvent->modifiers());
mappedEvent.ignore();
if (QCoreApplication::sendEvent(getWindow(), &mappedEvent)) {
return mappedEvent.isAccepted();
}
break;
}
default:
break;
}
// Check if this is a key press/release event that might need special attention
auto type = event->type();
if (type != QEvent::KeyPress && type != QEvent::KeyRelease) {

View file

@ -1031,6 +1031,7 @@ bool OffscreenQmlSurface::handlePointerEvent(const PointerEvent& event, class QT
touchEvent.setTarget(_rootItem);
touchEvent.setTouchPoints(touchPoints);
touchEvent.setTouchPointStates(touchPointStates);
touchEvent.ignore();
}
// Send mouse events to the surface so that HTML dialog elements work with mouse press and hover.
@ -1046,29 +1047,39 @@ bool OffscreenQmlSurface::handlePointerEvent(const PointerEvent& event, class QT
buttons |= Qt::LeftButton;
}
bool eventsAccepted = false;
bool eventSent = false;
bool eventsAccepted = true;
if (event.getType() == PointerEvent::Move) {
QMouseEvent mouseEvent(QEvent::MouseMove, windowPoint, windowPoint, windowPoint, button, buttons, event.getKeyboardModifiers());
// TODO - this line necessary for the QML Tooltop to work (which is not currently being used), but it causes interface to crash on launch on a fresh install
// need to investigate into why this crash is happening.
//_qmlContext->setContextProperty("lastMousePosition", windowPoint);
QCoreApplication::sendEvent(_quickWindow, &mouseEvent);
eventsAccepted &= mouseEvent.isAccepted();
mouseEvent.ignore();
if (QCoreApplication::sendEvent(_quickWindow, &mouseEvent)) {
eventSent = true;
eventsAccepted &= mouseEvent.isAccepted();
}
}
if (touchType == QEvent::TouchBegin) {
_touchBeginAccepted = QCoreApplication::sendEvent(_quickWindow, &touchEvent);
if (_touchBeginAccepted) {
eventSent = true;
eventsAccepted &= touchEvent.isAccepted();
}
} else if (_touchBeginAccepted) {
QCoreApplication::sendEvent(_quickWindow, &touchEvent);
if (QCoreApplication::sendEvent(_quickWindow, &touchEvent)) {
eventSent = true;
eventsAccepted &= touchEvent.isAccepted();
}
}
eventsAccepted &= touchEvent.isAccepted();
if (removeTouchPoint) {
_activeTouchPoints.erase(event.getID());
}
return eventsAccepted;
return eventSent && eventsAccepted;
}
void OffscreenQmlSurface::pause() {