mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-17 22:08:27 +02:00
Merge pull request #12686 from gcalero/android_ui_not_move_camera
Android - Prevent Camera movement with UI (especially Windows and Radar mode)
This commit is contained in:
commit
d2a74e5713
8 changed files with 37 additions and 89 deletions
|
@ -67,6 +67,10 @@ Item {
|
|||
fill: parent
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
}
|
||||
|
||||
QmlHifi.WindowHeader {
|
||||
id: header
|
||||
iconSource: "../../../icons/goto-i.svg"
|
||||
|
|
|
@ -58,6 +58,10 @@ Item {
|
|||
width: parent ? parent.width : 0
|
||||
height: parent ? parent.height : 0
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
}
|
||||
|
||||
gradient: Gradient {
|
||||
GradientStop { position: 0.0; color: android.color.gradientTop }
|
||||
GradientStop { position: 1.0; color: android.color.gradientBottom }
|
||||
|
|
|
@ -118,7 +118,7 @@ Item {
|
|||
tabletRoot.playButtonClickSound();
|
||||
}*/
|
||||
}
|
||||
onEntered: {
|
||||
onPressed: {
|
||||
button.isEntered = true;
|
||||
button.entered();
|
||||
if (button.isActive) {
|
||||
|
@ -127,7 +127,7 @@ Item {
|
|||
button.state = "hover state";
|
||||
}
|
||||
}
|
||||
onExited: {
|
||||
onReleased: {
|
||||
button.isEntered = false;
|
||||
button.exited()
|
||||
if (button.isActive) {
|
||||
|
|
|
@ -166,18 +166,30 @@ bool OffscreenSurface::eventFilter(QObject* originalDestination, QEvent* event)
|
|||
case QEvent::TouchUpdate:
|
||||
case QEvent::TouchEnd: {
|
||||
QTouchEvent *originalEvent = static_cast<QTouchEvent *>(event);
|
||||
QTouchEvent fakeEvent(*originalEvent);
|
||||
auto newTouchPoints = fakeEvent.touchPoints();
|
||||
for (size_t i = 0; i < newTouchPoints.size(); ++i) {
|
||||
const auto &originalPoint = originalEvent->touchPoints()[i];
|
||||
auto &newPoint = newTouchPoints[i];
|
||||
newPoint.setPos(originalPoint.pos());
|
||||
QEvent::Type fakeMouseEventType = QEvent::None;
|
||||
Qt::MouseButton fakeMouseButton = Qt::LeftButton;
|
||||
Qt::MouseButtons fakeMouseButtons = Qt::NoButton;
|
||||
switch (event->type()) {
|
||||
case QEvent::TouchBegin:
|
||||
fakeMouseEventType = QEvent::MouseButtonPress;
|
||||
fakeMouseButtons = Qt::LeftButton;
|
||||
break;
|
||||
case QEvent::TouchUpdate:
|
||||
fakeMouseEventType = QEvent::MouseMove;
|
||||
fakeMouseButtons = Qt::LeftButton;
|
||||
break;
|
||||
case QEvent::TouchEnd:
|
||||
fakeMouseEventType = QEvent::MouseButtonRelease;
|
||||
fakeMouseButtons = Qt::NoButton;
|
||||
break;
|
||||
}
|
||||
fakeEvent.setTouchPoints(newTouchPoints);
|
||||
if (QCoreApplication::sendEvent(_sharedObject->getWindow(), &fakeEvent)) {
|
||||
qInfo() << __FUNCTION__ << "sent fake touch event:" << fakeEvent.type()
|
||||
<< "_quickWindow handled it... accepted:" << fakeEvent.isAccepted();
|
||||
return false; //event->isAccepted();
|
||||
// Same case as OffscreenUi.cpp::eventFilter: touch events are always being accepted so we now use mouse events and consider one touch, touchPoints()[0].
|
||||
QMouseEvent fakeMouseEvent(fakeMouseEventType, originalEvent->touchPoints()[0].pos(), fakeMouseButton, fakeMouseButtons, Qt::NoModifier);
|
||||
fakeMouseEvent.ignore();
|
||||
if (QCoreApplication::sendEvent(_sharedObject->getWindow(), &fakeMouseEvent)) {
|
||||
/*qInfo() << __FUNCTION__ << "sent fake touch event:" << fakeMouseEvent.type()
|
||||
<< "_quickWindow handled it... accepted:" << fakeMouseEvent.isAccepted();*/
|
||||
return fakeMouseEvent.isAccepted();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@ function onMuteClicked() {
|
|||
printd("On Mute Clicked");
|
||||
//Menu.setIsOptionChecked("Mute Microphone", !Menu.isOptionChecked("Mute Microphone"));
|
||||
Audio.muted = !Audio.muted;
|
||||
onMuteToggled();
|
||||
}
|
||||
|
||||
function onMuteToggled() {
|
||||
|
|
|
@ -35,6 +35,7 @@ function fromQml(message) { // messages are {method, params}, like json-rpc. See
|
|||
break;
|
||||
case 'hide':
|
||||
Controller.setVPadHidden(false);
|
||||
module.exports.hide();
|
||||
module.exports.onHidden();
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -33,7 +33,6 @@ function init() {
|
|||
radar.setUniqueColor(uniqueColor);
|
||||
radar.init();
|
||||
setupModesBar();
|
||||
radar.isTouchValid = isRadarModeValidTouch;
|
||||
}
|
||||
|
||||
function shutdown() {
|
||||
|
@ -183,34 +182,6 @@ function onButtonClicked(clickedButton, whatToDo, hideAllAfter) {
|
|||
}
|
||||
}
|
||||
|
||||
function isRadarModeValidTouch(coords) {
|
||||
var qmlFragments = [modesbar.qmlFragment];
|
||||
var windows = [];
|
||||
for (var i=0; i < qmlFragments.length; i++) {
|
||||
var aQmlFrag = qmlFragments[i];
|
||||
if (aQmlFrag != null && aQmlFrag.isVisible() &&
|
||||
coords.x >= aQmlFrag.position.x * 3 && coords.x <= aQmlFrag.position.x * 3 + aQmlFrag.size.x * 3 &&
|
||||
coords.y >= aQmlFrag.position.y * 3 && coords.y <= aQmlFrag.position.y * 3 + aQmlFrag.size.y * 3
|
||||
) {
|
||||
printd("godViewModeTouchValid- false because of qmlFragments!? idx " + i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i=0; i < windows.length; i++) {
|
||||
var aWin = windows[i];
|
||||
if (aWin != null && aWin.position() != null &&
|
||||
coords.x >= aWin.position().x * 3 && coords.x <= aWin.position().x * 3 + aWin.width() * 3 &&
|
||||
coords.y >= aWin.position().y * 3 && coords.y <= aWin.position().y * 3 + aWin.height() * 3
|
||||
) {
|
||||
printd("godViewModeTouchValid- false because of windows!?");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
printd("godViewModeTouchValid- true by default ");
|
||||
return true;
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(function () {
|
||||
shutdown();
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
var radarModeInterface = {};
|
||||
|
||||
var logEnabled = true;
|
||||
var logEnabled = false;
|
||||
function printd(str) {
|
||||
if (logEnabled) {
|
||||
print("[radar.js] " + str);
|
||||
|
@ -118,19 +118,10 @@ function actionOnObjectFromEvent(event) {
|
|||
}
|
||||
|
||||
function mousePress(event) {
|
||||
if (!isTouchValid(coords)) {
|
||||
currentTouchIsValid = false;
|
||||
return;
|
||||
} else {
|
||||
currentTouchIsValid = true;
|
||||
}
|
||||
mousePressOrTouchEnd(event);
|
||||
}
|
||||
|
||||
function mousePressOrTouchEnd(event) {
|
||||
if (!currentTouchIsValid) {
|
||||
return;
|
||||
}
|
||||
if (radar) {
|
||||
if (actionOnObjectFromEvent(event)) {
|
||||
return;
|
||||
|
@ -155,9 +146,6 @@ function fakeDoubleTap(event) {
|
|||
teleporter.dragTeleportRelease(event);
|
||||
}
|
||||
|
||||
var currentTouchIsValid = false; // Currently used to know if touch hasn't
|
||||
// started on a UI overlay
|
||||
|
||||
var DOUBLE_TAP_TIME = 300;
|
||||
var fakeDoubleTapStart = Date.now();
|
||||
var touchEndCount = 0;
|
||||
|
@ -238,12 +226,6 @@ function touchEnd(event) {
|
|||
return;
|
||||
}
|
||||
|
||||
// if touch is invalid, cancel
|
||||
if (!currentTouchIsValid) {
|
||||
printd("touchEnd fail because !currentTouchIsValid");
|
||||
return;
|
||||
}
|
||||
|
||||
if (analyzeDoubleTap(event))
|
||||
return; // double tap detected, finish
|
||||
|
||||
|
@ -345,20 +327,6 @@ function computePointAtPlaneY(x, y, py) {
|
|||
p2.z, py);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
function isTouchValid(coords) {
|
||||
// TODO: Extend to the detection of touches on new menu bars
|
||||
var radarModeTouchValid = radarModeInterface.isTouchValid(coords);
|
||||
|
||||
// getItemAtPoint does not exist anymore, look for another way to know if we
|
||||
// are touching buttons
|
||||
// is it still needed?
|
||||
return /* !tablet.getItemAtPoint(coords) && */radarModeTouchValid;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
******************************************************************************/
|
||||
|
@ -373,16 +341,8 @@ function touchBegin(event) {
|
|||
x : event.x,
|
||||
y : event.y
|
||||
};
|
||||
if (!isTouchValid(coords)) {
|
||||
printd("analyze touch - RADAR_TOUCH - INVALID");
|
||||
currentTouchIsValid = false;
|
||||
touchStartingCoordinates = null;
|
||||
} else {
|
||||
printd("analyze touch - RADAR_TOUCH - ok");
|
||||
currentTouchIsValid = true;
|
||||
touchStartingCoordinates = coords;
|
||||
touchBeginTime = Date.now();
|
||||
}
|
||||
touchStartingCoordinates = coords;
|
||||
touchBeginTime = Date.now();
|
||||
}
|
||||
|
||||
var startedDraggingCamera = false; // first time
|
||||
|
@ -848,9 +808,6 @@ function oneFingerTouchUpdate(event) {
|
|||
}
|
||||
|
||||
function touchUpdate(event) {
|
||||
if (!currentTouchIsValid) {
|
||||
return; // avoid moving and zooming when tap is over UI entities
|
||||
}
|
||||
if (event.isPinching || event.isPinchOpening) {
|
||||
pinchUpdate(event);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue