Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,14 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.width = WidgetPlacement.dpDimension(context, R.dimen.tray_width);
aPlacement.height = WidgetPlacement.dpDimension(context, R.dimen.tray_height);
aPlacement.worldWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.tray_world_width);
aPlacement.translationY = WidgetPlacement.unitFromMeters(context, R.dimen.tray_world_y);
aPlacement.translationZ = WidgetPlacement.unitFromMeters(context, R.dimen.tray_world_z);
aPlacement.translationY = WidgetPlacement.unitFromMeters(context, R.dimen.tray_world_y) -
WidgetPlacement.unitFromMeters(context, R.dimen.window_world_y);
aPlacement.translationZ = WidgetPlacement.unitFromMeters(context, R.dimen.tray_world_z) -
WidgetPlacement.unitFromMeters(context, R.dimen.window_world_z);
aPlacement.anchorX = 0.5f;
aPlacement.anchorY = 0.5f;
aPlacement.parentAnchorX = 0.5f;
aPlacement.parentAnchorY = 0.5f;
aPlacement.parentAnchorY = 0.0f;
aPlacement.rotationAxisX = 1.0f;
aPlacement.rotation = (float)Math.toRadians(-45);
aPlacement.opaque = false;
Expand Down Expand Up @@ -267,6 +269,8 @@ public void detachFromWindow() {
if (mAttachedWindow != null) {
mAttachedWindow.removeBookmarksListener(this);
}
mWidgetPlacement.parentHandle = -1;

}

@Override
Expand All @@ -277,6 +281,7 @@ public void attachToWindow(@NonNull WindowWidget aWindow) {
detachFromWindow();

mAttachedWindow = aWindow;
mWidgetPlacement.parentHandle = aWindow.getHandle();
mAttachedWindow.addBookmarksListener(this);

mSessionStack = aWindow.getSessionStack();
Expand Down Expand Up @@ -328,6 +333,9 @@ private void toggleSettingsDialog() {
mSettingsDialogHandle = widget.getHandle();
}

if (mAttachedWindow != null) {
widget.getPlacement().parentHandle = mAttachedWindow.getHandle();
}
if (widget.isVisible()) {
widget.hide(REMOVE_WIDGET);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,13 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.width = WidgetPlacement.dpDimension(getContext(), R.dimen.settings_width);
aPlacement.height = WidgetPlacement.dpDimension(getContext(), R.dimen.settings_height);
aPlacement.parentAnchorX = 0.5f;
aPlacement.parentAnchorY = 0.5f;
aPlacement.parentAnchorY = 0.0f;
aPlacement.anchorX = 0.5f;
aPlacement.anchorY = 0.5f;
aPlacement.translationY = WidgetPlacement.unitFromMeters(getContext(), R.dimen.settings_world_y);
aPlacement.translationZ = WidgetPlacement.unitFromMeters(getContext(), R.dimen.settings_world_z);
aPlacement.translationY = WidgetPlacement.unitFromMeters(getContext(), R.dimen.settings_world_y) -
WidgetPlacement.unitFromMeters(getContext(), R.dimen.window_world_y);
aPlacement.translationZ = WidgetPlacement.unitFromMeters(getContext(), R.dimen.settings_world_z) -
WidgetPlacement.unitFromMeters(getContext(), R.dimen.window_world_z);
}

private void onSettingsPrivacyClick() {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,10 @@ BrowserWorld::LayoutWidget(int32_t aHandle) {
translation = transform.GetTranslation();
}
widget->SetTransform(parent ? parent->GetTransform().PostMultiply(transform) : transform);

if (!widget->GetCylinder()) {
widget->LayoutQuadWithCylinderParent(parent && parent->GetCylinder() ? parent->GetCylinder() : nullptr);
}
}

void
Expand Down
18 changes: 15 additions & 3 deletions app/src/main/cpp/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,16 @@ struct Widget::State {
// Translate the z of the cylinder to make the back of the curved surface the z position anchor point.
vrb::Matrix translation = vrb::Matrix::Translation(vrb::Vector(0.0f, 0.0f, radius * scale));
cylinder->SetTransform(translation.PostMultiply(scaleMatrix));
AdjustCylinderRotation(radius * scale);
}

void AdjustCylinderRotation(const float radius) {
const float x = transform->GetTransform().GetTranslation().x();
if (x != 0.0f && placement->cylinderMapRadius > 0) {
// Automatically adjust correct yaw angle & position for the cylinders not centered on the X axis
const float r = radius * scale;
const float perimeter = 2.0f * r * (float)M_PI;
const float perimeter = 2.0f * radius * (float)M_PI;
float angle = 0.5f * (float)M_PI - x / perimeter * 2.0f * (float)M_PI;
float delta = placement->cylinderMapRadius - radius * scale;
float delta = placement->cylinderMapRadius - radius;
vrb::Matrix transform = vrb::Matrix::Rotation(vrb::Vector(-cosf(angle), 0.0f, sinf(angle)));
transform.PreMultiplyInPlace(vrb::Matrix::Translation(vrb::Vector(0.0f, 0.0f, -delta)));
transform.PostMultiplyInPlace(vrb::Matrix::Translation(vrb::Vector(-x, 0.0f, delta)));
Expand Down Expand Up @@ -591,6 +594,15 @@ Widget::SetProxifyLayer(const bool aValue) {
m.layerProxy->ToggleAll(true);
}

Widget::LayoutQuadWithCylinderParent(const CylinderPtr& aCylinder) {
if (aCylinder) {
const float radius = aCylinder->GetTransformNode()->GetTransform().GetScale().x();
m.AdjustCylinderRotation(radius);
} else {
m.transformContainer->SetTransform(vrb::Matrix::Identity());
}
}

Widget::Widget(State& aState, vrb::RenderContextPtr& aContext) : m(aState) {
m.context = aContext;
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Widget {
float GetCylinderDensity() const;
void SetBorderColor(const vrb::Color& aColor);
void SetProxifyLayer(const bool aValue);
void LayoutQuadWithCylinderParent(const CylinderPtr& aCylinder);
protected:
struct State;
Widget(State& aState, vrb::RenderContextPtr& aContext);
Expand Down