mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-08 07:22:25 +02:00
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:
commit
41dfdf4d82
8 changed files with 58 additions and 5 deletions
|
@ -298,6 +298,23 @@ FocusScope {
|
|||
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) {
|
||||
pinned = newPinned
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ Item {
|
|||
readonly property int frameMarginRight: frame.decoration ? frame.decoration.frameMarginRight : 0
|
||||
readonly property int frameMarginTop: frame.decoration ? frame.decoration.frameMarginTop : 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
|
||||
// beyond the window via negative margin sizes
|
||||
|
@ -73,7 +74,7 @@ Item {
|
|||
Rectangle {
|
||||
id: sizeOutline
|
||||
x: -frameMarginLeft
|
||||
y: -frameMarginTop
|
||||
y: -frameMarginTop - offsetCorrection
|
||||
width: window ? window.width + frameMarginLeft + frameMarginRight + 2 : 0
|
||||
height: window ? window.height + frameMarginTop + frameMarginBottom + 2 : 0
|
||||
color: hifi.colors.baseGrayHighlight15
|
||||
|
|
|
@ -171,6 +171,11 @@ void WindowScriptingInterface::setPreviousBrowseAssetLocation(const QString& loc
|
|||
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
|
||||
/// might be in same thread as a script that sets the reticle to invisible
|
||||
void WindowScriptingInterface::ensureReticleVisible() const {
|
||||
|
|
|
@ -72,6 +72,7 @@ public slots:
|
|||
void shareSnapshot(const QString& path, const QUrl& href = QUrl(""));
|
||||
bool isPhysicsEnabled();
|
||||
bool setDisplayTexture(const QString& name);
|
||||
bool isPointOnDesktopWindow(QVariant point);
|
||||
|
||||
int openMessageBox(QString title, QString text, int buttons, int defaultButton);
|
||||
void updateMessageBox(int id, QString title, QString text, int buttons, int defaultButton);
|
||||
|
|
|
@ -136,6 +136,14 @@ void OffscreenUi::toggle(const QUrl& url, const QString& name, std::function<voi
|
|||
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) {
|
||||
QQuickItem* item = getRootItem()->findChild<QQuickItem*>(name);
|
||||
if (item) {
|
||||
|
|
|
@ -78,6 +78,7 @@ public:
|
|||
bool eventFilter(QObject* originalDestination, QEvent* event) override;
|
||||
void addMenuInitializer(std::function<void(VrMenu*)> f);
|
||||
QObject* getFlags();
|
||||
Q_INVOKABLE bool isPointOnDesktopWindow(QVariant point);
|
||||
QQuickItem* getDesktop();
|
||||
QQuickItem* getToolWindow();
|
||||
QObject* getRootMenu();
|
||||
|
|
|
@ -108,13 +108,17 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
"userData"
|
||||
];
|
||||
|
||||
|
||||
var MARGIN = 25;
|
||||
function FarActionGrabEntity(hand) {
|
||||
this.hand = hand;
|
||||
this.grabbedThingID = null;
|
||||
this.actionID = null; // action this script created...
|
||||
this.entityWithContextOverlay = false;
|
||||
this.contextOverlayTimer = false;
|
||||
this.reticleMinX = MARGIN;
|
||||
this.reticleMaxX;
|
||||
this.reticleMinY = MARGIN;
|
||||
this.reticleMaxY;
|
||||
|
||||
var ACTION_TTL = 15; // seconds
|
||||
|
||||
|
@ -344,12 +348,28 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
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) {
|
||||
var intersection = controllerData.rayPicks[this.hand];
|
||||
var entityProperty = Entities.getEntityProperties(intersection.objectID);
|
||||
var entityType = entityProperty.type;
|
||||
var hudRayPick = controllerData.hudRayPicks[this.hand];
|
||||
var point2d = this.calculateNewReticlePosition(hudRayPick.intersection);
|
||||
if ((intersection.type === RayPick.INTERSECTED_ENTITY && entityType === "Web") ||
|
||||
intersection.type === RayPick.INTERSECTED_OVERLAY) {
|
||||
intersection.type === RayPick.INTERSECTED_OVERLAY || Window.isPointOnDesktopWindow(point2d)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -178,11 +178,11 @@
|
|||
}
|
||||
var hudRayPick = controllerData.hudRayPicks[this.hand];
|
||||
var point2d = this.calculateNewReticlePosition(hudRayPick.intersection);
|
||||
this.setReticlePosition(point2d);
|
||||
if (!Reticle.isPointingAtSystemOverlay(point2d)) {
|
||||
if (!Window.isPointOnDesktopWindow(point2d) && !controllerData.triggerClicks[this.hand]) {
|
||||
this.exitModule();
|
||||
return false;
|
||||
}
|
||||
this.setReticlePosition(point2d);
|
||||
Reticle.visible = false;
|
||||
this.movedAway = false;
|
||||
this.triggerClicked = controllerData.triggerClicks[this.hand];
|
||||
|
|
Loading…
Reference in a new issue