From b6d6e9db55fcf2c718d99e9ec14bbaffd1332e26 Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Tue, 23 Jun 2020 23:14:45 +0200 Subject: [PATCH] Add layer priority sorting. Make pointer not affect widget sorting. (#3533) --- .../vrbrowser/ui/widgets/KeyboardWidget.java | 1 + .../vrbrowser/ui/widgets/WidgetPlacement.java | 2 ++ app/src/main/cpp/BrowserWorld.cpp | 13 ++++++++++--- app/src/main/cpp/WidgetPlacement.cpp | 1 + app/src/main/cpp/WidgetPlacement.h | 1 + 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java index 49d1d6a05..a002ef65a 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java @@ -391,6 +391,7 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { aPlacement.worldWidth = WidgetPlacement.floatDimension(context, R.dimen.keyboard_world_width); aPlacement.visible = false; aPlacement.cylinder = true; + aPlacement.layerPriority = 1; } @Override diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WidgetPlacement.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WidgetPlacement.java index ecd6773d8..ec92f8a9b 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WidgetPlacement.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WidgetPlacement.java @@ -54,6 +54,7 @@ public WidgetPlacement(Context aContext) { public boolean showPointer = true; public boolean composited = false; public boolean layer = true; + public int layerPriority = 0; // Used for depth sorting public boolean proxifyLayer = false; public float textureScale = 0.7f; // Widget will be curved if enabled. @@ -99,6 +100,7 @@ public void copyFrom(WidgetPlacement w) { this.showPointer = w.showPointer; this.composited = w.composited; this.layer = w.layer; + this.layerPriority = w.layerPriority; this.proxifyLayer = w.proxifyLayer; this.textureScale = w.textureScale; this.cylinder = w.cylinder; diff --git a/app/src/main/cpp/BrowserWorld.cpp b/app/src/main/cpp/BrowserWorld.cpp index 988bd149f..613b9af1e 100644 --- a/app/src/main/cpp/BrowserWorld.cpp +++ b/app/src/main/cpp/BrowserWorld.cpp @@ -686,13 +686,18 @@ BrowserWorld::State::SortWidgets() { } } if (!target) { + bool isPointer = false; for (Controller& controller: controllers->GetControllers()) { if (controller.pointer && controller.pointer->GetRoot() == node) { - target = controller.pointer->GetHitWidget().get(); - zDelta = 0.02f; + isPointer = true; break; } } + if (isPointer) { + // Always render the pointer on top + depthSorting.emplace(node.get(), std::make_pair(target, 0.0f)); + continue; + } } if (!target && widgetResizer && widgetResizer->GetRoot() == node) { @@ -717,12 +722,14 @@ BrowserWorld::State::SortWidgets() { Widget* wa = da->second.first; Widget* wb = db->second.first; - // Parenting sort + // Parenting or layer priority sort if (wa && wb && wa->IsVisible() && wb->IsVisible()) { if (IsParent(*wa, *wb)) { return true; } else if (IsParent(*wb, *wa)) { return false; + } else if (wa->GetPlacement()->layerPriority != wb->GetPlacement()->layerPriority) { + return wa->GetPlacement()->layerPriority > wb->GetPlacement()->layerPriority; } } diff --git a/app/src/main/cpp/WidgetPlacement.cpp b/app/src/main/cpp/WidgetPlacement.cpp index 5432c9c8d..1d996f93b 100644 --- a/app/src/main/cpp/WidgetPlacement.cpp +++ b/app/src/main/cpp/WidgetPlacement.cpp @@ -66,6 +66,7 @@ WidgetPlacement::FromJava(JNIEnv* aEnv, jobject& aObject) { GET_BOOLEAN_FIELD(showPointer); GET_BOOLEAN_FIELD(composited); GET_BOOLEAN_FIELD(layer); + GET_INT_FIELD(layerPriority); GET_BOOLEAN_FIELD(proxifyLayer); GET_FLOAT_FIELD(textureScale, "textureScale"); GET_BOOLEAN_FIELD(cylinder); diff --git a/app/src/main/cpp/WidgetPlacement.h b/app/src/main/cpp/WidgetPlacement.h index 39116bbd8..d16b1d16b 100644 --- a/app/src/main/cpp/WidgetPlacement.h +++ b/app/src/main/cpp/WidgetPlacement.h @@ -38,6 +38,7 @@ struct WidgetPlacement { bool showPointer; bool composited; bool layer; + int32_t layerPriority; bool proxifyLayer; float textureScale; bool cylinder;