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

Commit

Permalink
Support for dragging outside the widget bounds (#2745)
Browse files Browse the repository at this point in the history
* Support for scrolling outside the widget bounds

* Resize fix
  • Loading branch information
keianhzo authored Apr 9, 2020
1 parent e6e9999 commit ce6de42
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 29 deletions.
60 changes: 38 additions & 22 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,26 +391,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 @@ -432,11 +453,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 @@ -468,7 +484,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

0 comments on commit ce6de42

Please sign in to comment.