Android - Make joystick move up when showing the bottom bar

This commit is contained in:
Cristian Luis Duarte 2018-02-28 18:52:13 -03:00
parent 55d52f92df
commit 9acb83632c
8 changed files with 43 additions and 13 deletions

View file

@ -43,12 +43,6 @@ Item {
HifiConstants { id: android }
MouseArea {
anchors.fill: parent
onEntered: {
Controller.setVPadEnabled(false);
}
onExited: {
Controller.setVPadEnabled(true);
}
}
Rectangle {

View file

@ -94,6 +94,11 @@ void ControllerScriptingInterface::setVPadHidden(const bool 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::emitKeyReleaseEvent(QKeyEvent* event) { emit keyReleaseEvent(KeyEvent(*event)); }

View file

@ -65,8 +65,9 @@ public slots:
virtual glm::vec2 getViewportDimensions() 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 setVPadHidden(bool hidden); // Call it when a window should hide it
virtual void setVPadExtraBottomMargin(int margin);
signals:
void keyPressEvent(const KeyEvent& event);

View file

@ -42,7 +42,6 @@ bool TouchscreenVirtualPadDevice::isSupported() const {
void TouchscreenVirtualPadDevice::init() {
_fixedPosition = true; // This should be config
QScreen* eventScreen = qApp->primaryScreen();
if (_screenDPI != eventScreen->physicalDotsPerInch()) {
_screenWidthCenter = eventScreen->size().width() / 2;
@ -51,18 +50,31 @@ void TouchscreenVirtualPadDevice::init() {
_screenDPI = eventScreen->physicalDotsPerInch();
_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 );
}
auto& virtualPadManager = VirtualPad::Manager::instance();
setupFixedCenter(virtualPadManager, true);
if (_fixedPosition) {
_firstTouchLeftPoint = _fixedCenterPosition;
auto& virtualPadManager = VirtualPad::Manager::instance();
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) {
return std::max(lower, std::min(n, upper));
}
@ -74,6 +86,8 @@ void TouchscreenVirtualPadDevice::pluginUpdate(float deltaTime, const controller
});
auto& virtualPadManager = VirtualPad::Manager::instance();
setupFixedCenter(virtualPadManager);
if (_validTouchLeft) {
float leftDistanceScaleX, leftDistanceScaleY;
leftDistanceScaleX = (_currentTouchLeftPoint.x - _firstTouchLeftPoint.x) / _screenDPIScale.x;

View file

@ -15,6 +15,7 @@
#include <controllers/InputDevice.h>
#include "InputPlugin.h"
#include <QtGui/qtouchdevice.h>
#include "VirtualPadManager.h"
class QTouchEvent;
class QGestureEvent;
@ -78,6 +79,7 @@ protected:
bool _fixedPosition;
glm::vec2 _fixedCenterPosition;
qreal _fixedRadius;
int _extraBottomMargin {0};
void touchLeftBegin(glm::vec2 touchPoint);
void touchLeftUpdate(glm::vec2 touchPoint);
@ -86,6 +88,7 @@ protected:
void touchRightBegin(glm::vec2 touchPoint);
void touchRightUpdate(glm::vec2 touchPoint);
void touchRightEnd();
void setupFixedCenter(VirtualPad::Manager& virtualPadManager, bool force = false);
// just for debug
private:
void debugPoints(const QTouchEvent* event, QString who);

View file

@ -59,6 +59,14 @@ namespace VirtualPad {
return _hidden;
}
int Manager::extraBottomMargin() {
return _extraBottomMargin;
}
void Manager::setExtraBottomMargin(int margin) {
_extraBottomMargin = margin;
}
Instance* Manager::getLeftVirtualPad() {
return &_leftVPadInstance;
}

View file

@ -42,10 +42,13 @@ namespace VirtualPad {
void enable(bool enable);
bool isHidden();
void hide(bool hide);
int extraBottomMargin();
void setExtraBottomMargin(int margin);
private:
Instance _leftVPadInstance;
bool _enabled;
bool _hidden;
int _extraBottomMargin {0};
};
}

View file

@ -196,6 +196,7 @@ function lowerBottomBar() {
if (bottomHudOptionsBar) {
bottomHudOptionsBar.show();
}
Controller.setVPadExtraBottomMargin(0);
}
function raiseBottomBar() {
@ -206,6 +207,7 @@ function raiseBottomBar() {
if (bottomHudOptionsBar) {
bottomHudOptionsBar.hide();
}
Controller.setVPadExtraBottomMargin(255); // Height in bottombar.qml
print('[bottombar.js] raiseBottomBar end');
}