Bug fix for click events received by entity scripts

PointerEvent.isLeftButton should be true even on left button release events.
in a previous PR this behavior was changed. isLeftButton was used as a flag indicating the button state, which would be false on left button release events.
Because we have scripts that rely on the old behavior, I've changed it back to the original and introduced isPrimaryHeld properties instead.
This commit is contained in:
Anthony J. Thibault 2016-08-29 16:21:39 -07:00
parent 3890197efe
commit e34aecde49
2 changed files with 30 additions and 28 deletions

View file

@ -81,28 +81,43 @@ QScriptValue PointerEvent::toScriptValue(QScriptEngine* engine, const PointerEve
direction.setProperty("z", event._direction.z); direction.setProperty("z", event._direction.z);
obj.setProperty("pos3D", direction); obj.setProperty("pos3D", direction);
bool isPrimaryButton = false;
bool isSecondaryButton = false;
bool isTertiaryButton = false;
switch (event._button) { switch (event._button) {
case NoButtons: case NoButtons:
obj.setProperty("button", "None"); obj.setProperty("button", "None");
break; break;
case PrimaryButton: case PrimaryButton:
obj.setProperty("button", "Primary"); obj.setProperty("button", "Primary");
isPrimaryButton = true;
break; break;
case SecondaryButton: case SecondaryButton:
obj.setProperty("button", "Secondary"); obj.setProperty("button", "Secondary");
isSecondaryButton = true;
break; break;
case TertiaryButton: case TertiaryButton:
obj.setProperty("button", "Tertiary"); obj.setProperty("button", "Tertiary");
isTertiaryButton = true;
break; break;
} }
obj.setProperty("isLeftButton", areFlagsSet(event._buttons, PrimaryButton)); if (isPrimaryButton) {
obj.setProperty("isRightButton", areFlagsSet(event._buttons, SecondaryButton)); obj.setProperty("isPrimaryButton", isPrimaryButton);
obj.setProperty("isMiddleButton", areFlagsSet(event._buttons, TertiaryButton)); obj.setProperty("isLeftButton", isPrimaryButton);
}
if (isSecondaryButton) {
obj.setProperty("isSecondaryButton", isSecondaryButton);
obj.setProperty("isRightButton", isSecondaryButton);
}
if (isTertiaryButton) {
obj.setProperty("isTertiaryButton", isTertiaryButton);
obj.setProperty("isMiddleButton", isTertiaryButton);
}
obj.setProperty("isPrimaryButton", areFlagsSet(event._buttons, PrimaryButton)); obj.setProperty("isPrimaryHeld", areFlagsSet(event._buttons, PrimaryButton));
obj.setProperty("isSecondaryButton", areFlagsSet(event._buttons, SecondaryButton)); obj.setProperty("isSecondaryHeld", areFlagsSet(event._buttons, SecondaryButton));
obj.setProperty("isTertiaryButton", areFlagsSet(event._buttons, TertiaryButton)); obj.setProperty("isTertiaryHeld", areFlagsSet(event._buttons, TertiaryButton));
return obj; return obj;
} }
@ -146,9 +161,9 @@ void PointerEvent::fromScriptValue(const QScriptValue& object, PointerEvent& eve
event._button = NoButtons; event._button = NoButtons;
} }
bool primary = object.property("isPrimary").toBool() || object.property("isLeftButton").toBool(); bool primary = object.property("isPrimaryHeld").toBool();
bool secondary = object.property("isSecondary").toBool() || object.property("isRightButton").toBool(); bool secondary = object.property("isSecondaryHeld").toBool();
bool tertiary = object.property("isTertiary").toBool() || object.property("isMiddleButton").toBool(); bool tertiary = object.property("isTertiaryHeld").toBool();
event._buttons = 0; event._buttons = 0;
if (primary) { if (primary) {
event._buttons |= PrimaryButton; event._buttons |= PrimaryButton;

View file

@ -1426,10 +1426,7 @@ function MyController(hand) {
pos3D: rayPickInfo.intersection, pos3D: rayPickInfo.intersection,
normal: rayPickInfo.normal, normal: rayPickInfo.normal,
direction: rayPickInfo.searchRay.direction, direction: rayPickInfo.searchRay.direction,
button: "None", button: "None"
isPrimaryButton: false,
isSecondaryButton: false,
isTertiaryButton: false
}; };
this.hoverEntity = entity; this.hoverEntity = entity;
@ -1449,10 +1446,7 @@ function MyController(hand) {
pos3D: rayPickInfo.intersection, pos3D: rayPickInfo.intersection,
normal: rayPickInfo.normal, normal: rayPickInfo.normal,
direction: rayPickInfo.searchRay.direction, direction: rayPickInfo.searchRay.direction,
button: "None", button: "None"
isPrimaryButton: false,
isSecondaryButton: false,
isTertiaryButton: false
}; };
Entities.sendMouseMoveOnEntity(entity, pointerEvent); Entities.sendMouseMoveOnEntity(entity, pointerEvent);
@ -2124,9 +2118,7 @@ function MyController(hand) {
normal: intersectInfo.normal, normal: intersectInfo.normal,
direction: intersectInfo.searchRay.direction, direction: intersectInfo.searchRay.direction,
button: "Primary", button: "Primary",
isPrimaryButton: true, isPrimaryHeld: true
isSecondaryButton: false,
isTertiaryButton: false
}; };
Entities.sendMousePressOnEntity(this.grabbedEntity, pointerEvent); Entities.sendMousePressOnEntity(this.grabbedEntity, pointerEvent);
@ -2152,15 +2144,12 @@ function MyController(hand) {
pos3D: intersectInfo.point, pos3D: intersectInfo.point,
normal: intersectInfo.normal, normal: intersectInfo.normal,
direction: intersectInfo.searchRay.direction, direction: intersectInfo.searchRay.direction,
button: "Primary", button: "Primary"
isPrimaryButton: false,
isSecondaryButton: false,
isTertiaryButton: false
}; };
} else { } else {
pointerEvent = this.touchingEnterPointerEvent; pointerEvent = this.touchingEnterPointerEvent;
pointerEvent.button = "Primary"; pointerEvent.button = "Primary";
pointerEvent.isPrimaryButton = false; pointerEvent.isPrimaryHeld = false;
} }
Entities.sendMouseReleaseOnEntity(this.grabbedEntity, pointerEvent); Entities.sendMouseReleaseOnEntity(this.grabbedEntity, pointerEvent);
@ -2197,9 +2186,7 @@ function MyController(hand) {
normal: intersectInfo.normal, normal: intersectInfo.normal,
direction: intersectInfo.searchRay.direction, direction: intersectInfo.searchRay.direction,
button: "NoButtons", button: "NoButtons",
isPrimaryButton: true, isPrimaryHeld: true
isSecondaryButton: false,
isTertiaryButton: false
}; };
var POINTER_PRESS_TO_MOVE_DELAY = 0.15; // seconds var POINTER_PRESS_TO_MOVE_DELAY = 0.15; // seconds