Merge pull request #11509 from druiz17/fix-hud-module

Hud module. check if laser is pointing at UI element without moving the reticle first
This commit is contained in:
Seth Alves 2017-10-03 09:44:45 -07:00 committed by GitHub
commit 41dfdf4d82
8 changed files with 58 additions and 5 deletions

View file

@ -298,6 +298,23 @@ FocusScope {
pinned = !pinned pinned = !pinned
} }
function isPointOnWindow(point) {
for (var i = 0; i < desktop.visibleChildren.length; i++) {
var child = desktop.visibleChildren[i];
if (child.visible) {
if (child.hasOwnProperty("modality")) {
var mappedPoint = child.mapFromGlobal(point.x, point.y);
var outLine = child.frame.children[2];
var framePoint = outLine.mapFromGlobal(point.x, point.y);
if (child.contains(mappedPoint) || outLine.contains(framePoint)) {
return true;
}
}
}
}
return false;
}
function setPinned(newPinned) { function setPinned(newPinned) {
pinned = newPinned pinned = newPinned
} }

View file

@ -26,6 +26,7 @@ Item {
readonly property int frameMarginRight: frame.decoration ? frame.decoration.frameMarginRight : 0 readonly property int frameMarginRight: frame.decoration ? frame.decoration.frameMarginRight : 0
readonly property int frameMarginTop: frame.decoration ? frame.decoration.frameMarginTop : 0 readonly property int frameMarginTop: frame.decoration ? frame.decoration.frameMarginTop : 0
readonly property int frameMarginBottom: frame.decoration ? frame.decoration.frameMarginBottom : 0 readonly property int frameMarginBottom: frame.decoration ? frame.decoration.frameMarginBottom : 0
readonly property int offsetCorrection: 20
// Frames always fill their parents, but their decorations may extend // Frames always fill their parents, but their decorations may extend
// beyond the window via negative margin sizes // beyond the window via negative margin sizes
@ -73,7 +74,7 @@ Item {
Rectangle { Rectangle {
id: sizeOutline id: sizeOutline
x: -frameMarginLeft x: -frameMarginLeft
y: -frameMarginTop y: -frameMarginTop - offsetCorrection
width: window ? window.width + frameMarginLeft + frameMarginRight + 2 : 0 width: window ? window.width + frameMarginLeft + frameMarginRight + 2 : 0
height: window ? window.height + frameMarginTop + frameMarginBottom + 2 : 0 height: window ? window.height + frameMarginTop + frameMarginBottom + 2 : 0
color: hifi.colors.baseGrayHighlight15 color: hifi.colors.baseGrayHighlight15

View file

@ -171,6 +171,11 @@ void WindowScriptingInterface::setPreviousBrowseAssetLocation(const QString& loc
Setting::Handle<QVariant>(LAST_BROWSE_ASSETS_LOCATION_SETTING).set(location); Setting::Handle<QVariant>(LAST_BROWSE_ASSETS_LOCATION_SETTING).set(location);
} }
bool WindowScriptingInterface::isPointOnDesktopWindow(QVariant point) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
return offscreenUi->isPointOnDesktopWindow(point);
}
/// Makes sure that the reticle is visible, use this in blocking forms that require a reticle and /// Makes sure that the reticle is visible, use this in blocking forms that require a reticle and
/// might be in same thread as a script that sets the reticle to invisible /// might be in same thread as a script that sets the reticle to invisible
void WindowScriptingInterface::ensureReticleVisible() const { void WindowScriptingInterface::ensureReticleVisible() const {

View file

@ -72,6 +72,7 @@ public slots:
void shareSnapshot(const QString& path, const QUrl& href = QUrl("")); void shareSnapshot(const QString& path, const QUrl& href = QUrl(""));
bool isPhysicsEnabled(); bool isPhysicsEnabled();
bool setDisplayTexture(const QString& name); bool setDisplayTexture(const QString& name);
bool isPointOnDesktopWindow(QVariant point);
int openMessageBox(QString title, QString text, int buttons, int defaultButton); int openMessageBox(QString title, QString text, int buttons, int defaultButton);
void updateMessageBox(int id, QString title, QString text, int buttons, int defaultButton); void updateMessageBox(int id, QString title, QString text, int buttons, int defaultButton);

View file

@ -136,6 +136,14 @@ void OffscreenUi::toggle(const QUrl& url, const QString& name, std::function<voi
shownProperty.write(!shownProperty.read().toBool()); shownProperty.write(!shownProperty.read().toBool());
} }
bool OffscreenUi::isPointOnDesktopWindow(QVariant point) {
QVariant result;
BLOCKING_INVOKE_METHOD(_desktop, "isPointOnWindow",
Q_RETURN_ARG(QVariant, result),
Q_ARG(QVariant, point));
return result.toBool();
}
void OffscreenUi::hide(const QString& name) { void OffscreenUi::hide(const QString& name) {
QQuickItem* item = getRootItem()->findChild<QQuickItem*>(name); QQuickItem* item = getRootItem()->findChild<QQuickItem*>(name);
if (item) { if (item) {

View file

@ -78,6 +78,7 @@ public:
bool eventFilter(QObject* originalDestination, QEvent* event) override; bool eventFilter(QObject* originalDestination, QEvent* event) override;
void addMenuInitializer(std::function<void(VrMenu*)> f); void addMenuInitializer(std::function<void(VrMenu*)> f);
QObject* getFlags(); QObject* getFlags();
Q_INVOKABLE bool isPointOnDesktopWindow(QVariant point);
QQuickItem* getDesktop(); QQuickItem* getDesktop();
QQuickItem* getToolWindow(); QQuickItem* getToolWindow();
QObject* getRootMenu(); QObject* getRootMenu();

View file

@ -108,13 +108,17 @@ Script.include("/~/system/libraries/controllers.js");
"userData" "userData"
]; ];
var MARGIN = 25;
function FarActionGrabEntity(hand) { function FarActionGrabEntity(hand) {
this.hand = hand; this.hand = hand;
this.grabbedThingID = null; this.grabbedThingID = null;
this.actionID = null; // action this script created... this.actionID = null; // action this script created...
this.entityWithContextOverlay = false; this.entityWithContextOverlay = false;
this.contextOverlayTimer = false; this.contextOverlayTimer = false;
this.reticleMinX = MARGIN;
this.reticleMaxX;
this.reticleMinY = MARGIN;
this.reticleMaxY;
var ACTION_TTL = 15; // seconds var ACTION_TTL = 15; // seconds
@ -344,12 +348,28 @@ Script.include("/~/system/libraries/controllers.js");
this.grabbedThingID = null; this.grabbedThingID = null;
}; };
this.updateRecommendedArea = function() {
var dims = Controller.getViewportDimensions();
this.reticleMaxX = dims.x - MARGIN;
this.reticleMaxY = dims.y - MARGIN;
};
this.calculateNewReticlePosition = function(intersection) {
this.updateRecommendedArea();
var point2d = HMD.overlayFromWorldPoint(intersection);
point2d.x = Math.max(this.reticleMinX, Math.min(point2d.x, this.reticleMaxX));
point2d.y = Math.max(this.reticleMinY, Math.min(point2d.y, this.reticleMaxY));
return point2d;
};
this.notPointingAtEntity = function(controllerData) { this.notPointingAtEntity = function(controllerData) {
var intersection = controllerData.rayPicks[this.hand]; var intersection = controllerData.rayPicks[this.hand];
var entityProperty = Entities.getEntityProperties(intersection.objectID); var entityProperty = Entities.getEntityProperties(intersection.objectID);
var entityType = entityProperty.type; var entityType = entityProperty.type;
var hudRayPick = controllerData.hudRayPicks[this.hand];
var point2d = this.calculateNewReticlePosition(hudRayPick.intersection);
if ((intersection.type === RayPick.INTERSECTED_ENTITY && entityType === "Web") || if ((intersection.type === RayPick.INTERSECTED_ENTITY && entityType === "Web") ||
intersection.type === RayPick.INTERSECTED_OVERLAY) { intersection.type === RayPick.INTERSECTED_OVERLAY || Window.isPointOnDesktopWindow(point2d)) {
return true; return true;
} }
return false; return false;

View file

@ -178,11 +178,11 @@
} }
var hudRayPick = controllerData.hudRayPicks[this.hand]; var hudRayPick = controllerData.hudRayPicks[this.hand];
var point2d = this.calculateNewReticlePosition(hudRayPick.intersection); var point2d = this.calculateNewReticlePosition(hudRayPick.intersection);
this.setReticlePosition(point2d); if (!Window.isPointOnDesktopWindow(point2d) && !controllerData.triggerClicks[this.hand]) {
if (!Reticle.isPointingAtSystemOverlay(point2d)) {
this.exitModule(); this.exitModule();
return false; return false;
} }
this.setReticlePosition(point2d);
Reticle.visible = false; Reticle.visible = false;
this.movedAway = false; this.movedAway = false;
this.triggerClicked = controllerData.triggerClicks[this.hand]; this.triggerClicked = controllerData.triggerClicks[this.hand];