mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 04:53:25 +02:00
Android - Make joystick move up when showing the bottom bar
This commit is contained in:
parent
55d52f92df
commit
9acb83632c
8 changed files with 43 additions and 13 deletions
|
@ -43,12 +43,6 @@ Item {
|
||||||
HifiConstants { id: android }
|
HifiConstants { id: android }
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onEntered: {
|
|
||||||
Controller.setVPadEnabled(false);
|
|
||||||
}
|
|
||||||
onExited: {
|
|
||||||
Controller.setVPadEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
|
|
@ -94,6 +94,11 @@ void ControllerScriptingInterface::setVPadHidden(const bool hidden) {
|
||||||
virtualPadManager.hide(hidden);
|
virtualPadManager.hide(hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ControllerScriptingInterface::setVPadExtraBottomMargin(const int margin) {
|
||||||
|
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||||
|
virtualPadManager.setExtraBottomMargin(margin);
|
||||||
|
}
|
||||||
|
|
||||||
void ControllerScriptingInterface::emitKeyPressEvent(QKeyEvent* event) { emit keyPressEvent(KeyEvent(*event)); }
|
void ControllerScriptingInterface::emitKeyPressEvent(QKeyEvent* event) { emit keyPressEvent(KeyEvent(*event)); }
|
||||||
void ControllerScriptingInterface::emitKeyReleaseEvent(QKeyEvent* event) { emit keyReleaseEvent(KeyEvent(*event)); }
|
void ControllerScriptingInterface::emitKeyReleaseEvent(QKeyEvent* event) { emit keyReleaseEvent(KeyEvent(*event)); }
|
||||||
|
|
||||||
|
|
|
@ -65,8 +65,9 @@ public slots:
|
||||||
virtual glm::vec2 getViewportDimensions() const;
|
virtual glm::vec2 getViewportDimensions() const;
|
||||||
virtual QVariant getRecommendedHUDRect() const;
|
virtual QVariant getRecommendedHUDRect() const;
|
||||||
|
|
||||||
virtual void setVPadHidden(bool hidden); // Call it when a window should hide it
|
|
||||||
virtual void setVPadEnabled(bool enable);
|
virtual void setVPadEnabled(bool enable);
|
||||||
|
virtual void setVPadHidden(bool hidden); // Call it when a window should hide it
|
||||||
|
virtual void setVPadExtraBottomMargin(int margin);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void keyPressEvent(const KeyEvent& event);
|
void keyPressEvent(const KeyEvent& event);
|
||||||
|
|
|
@ -42,7 +42,6 @@ bool TouchscreenVirtualPadDevice::isSupported() const {
|
||||||
void TouchscreenVirtualPadDevice::init() {
|
void TouchscreenVirtualPadDevice::init() {
|
||||||
_fixedPosition = true; // This should be config
|
_fixedPosition = true; // This should be config
|
||||||
|
|
||||||
|
|
||||||
QScreen* eventScreen = qApp->primaryScreen();
|
QScreen* eventScreen = qApp->primaryScreen();
|
||||||
if (_screenDPI != eventScreen->physicalDotsPerInch()) {
|
if (_screenDPI != eventScreen->physicalDotsPerInch()) {
|
||||||
_screenWidthCenter = eventScreen->size().width() / 2;
|
_screenWidthCenter = eventScreen->size().width() / 2;
|
||||||
|
@ -51,18 +50,31 @@ void TouchscreenVirtualPadDevice::init() {
|
||||||
_screenDPI = eventScreen->physicalDotsPerInch();
|
_screenDPI = eventScreen->physicalDotsPerInch();
|
||||||
|
|
||||||
_fixedRadius = _screenDPI * 256 / 534;
|
_fixedRadius = _screenDPI * 256 / 534;
|
||||||
qreal margin = _screenDPI * 59 / 534; // 59px is for our 'base' of 534dpi (Pixel XL or Huawei Mate 9 Pro)
|
|
||||||
_fixedCenterPosition = glm::vec2( _fixedRadius + margin, eventScreen->size().height() - margin - _fixedRadius );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_fixedPosition) {
|
|
||||||
_firstTouchLeftPoint = _fixedCenterPosition;
|
|
||||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||||
|
setupFixedCenter(virtualPadManager, true);
|
||||||
|
|
||||||
|
if (_fixedPosition) {
|
||||||
virtualPadManager.getLeftVirtualPad()->setShown(virtualPadManager.isEnabled() && !virtualPadManager.isHidden()); // Show whenever it's enabled
|
virtualPadManager.getLeftVirtualPad()->setShown(virtualPadManager.isEnabled() && !virtualPadManager.isHidden()); // Show whenever it's enabled
|
||||||
virtualPadManager.getLeftVirtualPad()->setFirstTouch(_firstTouchLeftPoint);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TouchscreenVirtualPadDevice::setupFixedCenter(VirtualPad::Manager& virtualPadManager, bool force) {
|
||||||
|
if (!_fixedPosition) return;
|
||||||
|
|
||||||
|
//auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||||
|
if (_extraBottomMargin == virtualPadManager.extraBottomMargin() && !force) return; // Our only criteria to decide a center change is the bottom margin
|
||||||
|
|
||||||
|
_extraBottomMargin = virtualPadManager.extraBottomMargin();
|
||||||
|
qreal margin = _screenDPI * 59 / 534; // 59px is for our 'base' of 534dpi (Pixel XL or Huawei Mate 9 Pro)
|
||||||
|
QScreen* eventScreen = qApp->primaryScreen(); // do not call every time
|
||||||
|
_fixedCenterPosition = glm::vec2( _fixedRadius + margin, eventScreen->size().height() - margin - _fixedRadius - _extraBottomMargin);
|
||||||
|
|
||||||
|
_firstTouchLeftPoint = _fixedCenterPosition;
|
||||||
|
virtualPadManager.getLeftVirtualPad()->setFirstTouch(_firstTouchLeftPoint);
|
||||||
|
}
|
||||||
|
|
||||||
float clip(float n, float lower, float upper) {
|
float clip(float n, float lower, float upper) {
|
||||||
return std::max(lower, std::min(n, upper));
|
return std::max(lower, std::min(n, upper));
|
||||||
}
|
}
|
||||||
|
@ -74,6 +86,8 @@ void TouchscreenVirtualPadDevice::pluginUpdate(float deltaTime, const controller
|
||||||
});
|
});
|
||||||
|
|
||||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||||
|
setupFixedCenter(virtualPadManager);
|
||||||
|
|
||||||
if (_validTouchLeft) {
|
if (_validTouchLeft) {
|
||||||
float leftDistanceScaleX, leftDistanceScaleY;
|
float leftDistanceScaleX, leftDistanceScaleY;
|
||||||
leftDistanceScaleX = (_currentTouchLeftPoint.x - _firstTouchLeftPoint.x) / _screenDPIScale.x;
|
leftDistanceScaleX = (_currentTouchLeftPoint.x - _firstTouchLeftPoint.x) / _screenDPIScale.x;
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <controllers/InputDevice.h>
|
#include <controllers/InputDevice.h>
|
||||||
#include "InputPlugin.h"
|
#include "InputPlugin.h"
|
||||||
#include <QtGui/qtouchdevice.h>
|
#include <QtGui/qtouchdevice.h>
|
||||||
|
#include "VirtualPadManager.h"
|
||||||
|
|
||||||
class QTouchEvent;
|
class QTouchEvent;
|
||||||
class QGestureEvent;
|
class QGestureEvent;
|
||||||
|
@ -78,6 +79,7 @@ protected:
|
||||||
bool _fixedPosition;
|
bool _fixedPosition;
|
||||||
glm::vec2 _fixedCenterPosition;
|
glm::vec2 _fixedCenterPosition;
|
||||||
qreal _fixedRadius;
|
qreal _fixedRadius;
|
||||||
|
int _extraBottomMargin {0};
|
||||||
|
|
||||||
void touchLeftBegin(glm::vec2 touchPoint);
|
void touchLeftBegin(glm::vec2 touchPoint);
|
||||||
void touchLeftUpdate(glm::vec2 touchPoint);
|
void touchLeftUpdate(glm::vec2 touchPoint);
|
||||||
|
@ -86,6 +88,7 @@ protected:
|
||||||
void touchRightBegin(glm::vec2 touchPoint);
|
void touchRightBegin(glm::vec2 touchPoint);
|
||||||
void touchRightUpdate(glm::vec2 touchPoint);
|
void touchRightUpdate(glm::vec2 touchPoint);
|
||||||
void touchRightEnd();
|
void touchRightEnd();
|
||||||
|
void setupFixedCenter(VirtualPad::Manager& virtualPadManager, bool force = false);
|
||||||
// just for debug
|
// just for debug
|
||||||
private:
|
private:
|
||||||
void debugPoints(const QTouchEvent* event, QString who);
|
void debugPoints(const QTouchEvent* event, QString who);
|
||||||
|
|
|
@ -59,6 +59,14 @@ namespace VirtualPad {
|
||||||
return _hidden;
|
return _hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Manager::extraBottomMargin() {
|
||||||
|
return _extraBottomMargin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Manager::setExtraBottomMargin(int margin) {
|
||||||
|
_extraBottomMargin = margin;
|
||||||
|
}
|
||||||
|
|
||||||
Instance* Manager::getLeftVirtualPad() {
|
Instance* Manager::getLeftVirtualPad() {
|
||||||
return &_leftVPadInstance;
|
return &_leftVPadInstance;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,10 +42,13 @@ namespace VirtualPad {
|
||||||
void enable(bool enable);
|
void enable(bool enable);
|
||||||
bool isHidden();
|
bool isHidden();
|
||||||
void hide(bool hide);
|
void hide(bool hide);
|
||||||
|
int extraBottomMargin();
|
||||||
|
void setExtraBottomMargin(int margin);
|
||||||
private:
|
private:
|
||||||
Instance _leftVPadInstance;
|
Instance _leftVPadInstance;
|
||||||
bool _enabled;
|
bool _enabled;
|
||||||
bool _hidden;
|
bool _hidden;
|
||||||
|
int _extraBottomMargin {0};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -196,6 +196,7 @@ function lowerBottomBar() {
|
||||||
if (bottomHudOptionsBar) {
|
if (bottomHudOptionsBar) {
|
||||||
bottomHudOptionsBar.show();
|
bottomHudOptionsBar.show();
|
||||||
}
|
}
|
||||||
|
Controller.setVPadExtraBottomMargin(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function raiseBottomBar() {
|
function raiseBottomBar() {
|
||||||
|
@ -206,6 +207,7 @@ function raiseBottomBar() {
|
||||||
if (bottomHudOptionsBar) {
|
if (bottomHudOptionsBar) {
|
||||||
bottomHudOptionsBar.hide();
|
bottomHudOptionsBar.hide();
|
||||||
}
|
}
|
||||||
|
Controller.setVPadExtraBottomMargin(255); // Height in bottombar.qml
|
||||||
print('[bottombar.js] raiseBottomBar end');
|
print('[bottombar.js] raiseBottomBar end');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue