Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Support for dragging outside the widget bounds #2745

Merged
merged 2 commits into from
Apr 9, 2020
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
60 changes: 38 additions & 22 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,26 +392,47 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
vrb::Vector hitPoint;
vrb::Vector hitNormal;

for (const WidgetPtr& widget: widgets) {
if (resizingWidget && resizingWidget->IsResizingActive() && resizingWidget != widget) {
// Don't interact with other widgets when resizing gesture is active.
continue;
}
if (movingWidget && movingWidget->GetWidget() != widget) {
// Don't interact with other widgets when moving gesture is active.
continue;
}
const bool pressed = controller.buttonState & ControllerDelegate::BUTTON_TRIGGER ||
controller.buttonState & ControllerDelegate::BUTTON_TOUCHPAD;
const bool wasPressed = controller.lastButtonState & ControllerDelegate::BUTTON_TRIGGER ||
controller.lastButtonState & ControllerDelegate::BUTTON_TOUCHPAD;

bool isResizing = resizingWidget && resizingWidget->IsResizingActive();
bool isDragging = pressed && wasPressed && controller.widget && !isResizing;
if (isDragging) {
WidgetPtr widget = GetWidget(controller.widget);
vrb::Vector result;
vrb::Vector normal;
float distance = 0.0f;
bool isInWidget = false;
const bool clamp = !widget->IsResizing() && !movingWidget;
if (widget->TestControllerIntersection(start, direction, result, normal, clamp, isInWidget, distance)) {
if (isInWidget && (distance < hitDistance)) {
hitWidget = widget;
hitDistance = distance;
hitPoint = result;
hitNormal = normal;
if (widget->TestControllerIntersection(start, direction, result, normal, false, isInWidget, distance)) {
hitWidget = widget;
hitPoint = result;
hitNormal = normal;
}

} else {
for (const WidgetPtr& widget: widgets) {
if (isResizing && resizingWidget != widget) {
// Don't interact with other widgets when resizing gesture is active.
continue;
}
if (movingWidget && movingWidget->GetWidget() != widget) {
// Don't interact with other widgets when moving gesture is active.
continue;
}
vrb::Vector result;
vrb::Vector normal;
float distance = 0.0f;
bool isInWidget = false;
const bool clamp = !widget->IsResizing() && !movingWidget;
if (widget->TestControllerIntersection(start, direction, result, normal, clamp, isInWidget, distance)) {
if (isInWidget && (distance < hitDistance)) {
hitWidget = widget;
hitDistance = distance;
hitPoint = result;
hitNormal = normal;
}
}
}
}
Expand All @@ -433,11 +454,6 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
}
}

const bool pressed = controller.buttonState & ControllerDelegate::BUTTON_TRIGGER ||
controller.buttonState & ControllerDelegate::BUTTON_TOUCHPAD;
const bool wasPressed = controller.lastButtonState & ControllerDelegate::BUTTON_TRIGGER ||
controller.lastButtonState & ControllerDelegate::BUTTON_TOUCHPAD;

if (movingWidget && movingWidget->IsMoving(controller.index)) {
if (!pressed && wasPressed) {
movingWidget->EndMoving();
Expand Down Expand Up @@ -469,7 +485,7 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
}
} else if (hitWidget) {
float theX = 0.0f, theY = 0.0f;
hitWidget->ConvertToWidgetCoordinates(hitPoint, theX, theY);
hitWidget->ConvertToWidgetCoordinates(hitPoint, theX, theY, !isDragging);
const uint32_t handle = hitWidget->GetHandle();
if (!pressed && wasPressed) {
controller.inDeadZone = true;
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/cpp/Cylinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@ Cylinder::ConvertToQuadCoordinates(const vrb::Vector& point, float& aX, float& a
if (ratioX < 0.0f) {
ratioX = 0.0f;
}

aX = ratioX * m.textureWidth;
aY = ratioY * m.textureHeight;
}

aX = ratioX * m.textureWidth;
aY = ratioY * m.textureHeight;
}

void
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/cpp/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,12 @@ Widget::TestControllerIntersection(const vrb::Vector& aStartPoint, const vrb::Ve
}

void
Widget::ConvertToWidgetCoordinates(const vrb::Vector& point, float& aX, float& aY) const {
Widget::ConvertToWidgetCoordinates(const vrb::Vector& point, float& aX, float& aY, bool aClamp) const {
bool clamp = !m.resizing;
if (m.quad) {
m.quad->ConvertToQuadCoordinates(point, aX, aY, clamp);
m.quad->ConvertToQuadCoordinates(point, aX, aY, clamp && aClamp);
} else {
m.cylinder->ConvertToQuadCoordinates(point, aX, aY, clamp);
m.cylinder->ConvertToQuadCoordinates(point, aX, aY, clamp && aClamp);
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Widget {
void GetWorldSize(float& aWidth, float& aHeight) const;
bool TestControllerIntersection(const vrb::Vector& aStartPoint, const vrb::Vector& aDirection, vrb::Vector& aResult, vrb::Vector& aNormal,
const bool aClamp, bool& aIsInWidget, float& aDistance) const;
void ConvertToWidgetCoordinates(const vrb::Vector& aPoint, float& aX, float& aY) const;
void ConvertToWidgetCoordinates(const vrb::Vector& aPoint, float& aX, float& aY, bool aClamp = true) const;
vrb::Vector ConvertToWorldCoordinates(const vrb::Vector& aLocalPoint) const;
vrb::Vector ConvertToWorldCoordinates(const float aWidgetX, const float aWidgetY) const;
const vrb::Matrix GetTransform() const;
Expand Down