mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 09:08:47 +02:00
Android - Make Joystick appear always when possible (not in radar mode and when not hidden by some windows)
This commit is contained in:
parent
428f4b7b9d
commit
55d52f92df
10 changed files with 55 additions and 15 deletions
|
@ -40,12 +40,6 @@ Item {
|
||||||
var keys = Object.keys(properties).forEach(function (key) {
|
var keys = Object.keys(properties).forEach(function (key) {
|
||||||
button[key] = properties[key];
|
button[key] = properties[key];
|
||||||
});
|
});
|
||||||
button.entered.connect(function() {
|
|
||||||
Controller.setVPadEnabled(false);
|
|
||||||
});
|
|
||||||
button.exited.connect(function() {
|
|
||||||
Controller.setVPadEnabled(true);
|
|
||||||
});
|
|
||||||
return button;
|
return button;
|
||||||
} else if( component.status == Component.Error) {
|
} else if( component.status == Component.Error) {
|
||||||
console.log("Load button errors " + component.errorString());
|
console.log("Load button errors " + component.errorString());
|
||||||
|
|
|
@ -89,6 +89,11 @@ void ControllerScriptingInterface::setVPadEnabled(const bool enable) {
|
||||||
virtualPadManager.enable(enable);
|
virtualPadManager.enable(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ControllerScriptingInterface::setVPadHidden(const bool hidden) {
|
||||||
|
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||||
|
virtualPadManager.hide(hidden);
|
||||||
|
}
|
||||||
|
|
||||||
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,6 +65,7 @@ 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);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -96,7 +96,7 @@ bool Basic2DWindowOpenGLDisplayPlugin::internalActivate() {
|
||||||
|
|
||||||
void Basic2DWindowOpenGLDisplayPlugin::compositeExtra() {
|
void Basic2DWindowOpenGLDisplayPlugin::compositeExtra() {
|
||||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||||
if(virtualPadManager.getLeftVirtualPad()->isBeingTouched()) {
|
if(virtualPadManager.getLeftVirtualPad()->isShown()) {
|
||||||
// render stick base
|
// render stick base
|
||||||
auto stickBaseTransform = DependencyManager::get<CompositorHelper>()->getPoint2DTransform(virtualPadManager.getLeftVirtualPad()->getFirstTouch(),
|
auto stickBaseTransform = DependencyManager::get<CompositorHelper>()->getPoint2DTransform(virtualPadManager.getLeftVirtualPad()->getFirstTouch(),
|
||||||
_virtualPadPixelSize, _virtualPadPixelSize);
|
_virtualPadPixelSize, _virtualPadPixelSize);
|
||||||
|
|
|
@ -39,19 +39,28 @@ bool TouchscreenVirtualPadDevice::isSupported() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::initFromEvent(const QTouchEvent* event) {
|
void TouchscreenVirtualPadDevice::init() {
|
||||||
QScreen* eventScreen = event->window()->screen();
|
_fixedPosition = true; // This should be config
|
||||||
|
|
||||||
|
|
||||||
|
QScreen* eventScreen = qApp->primaryScreen();
|
||||||
if (_screenDPI != eventScreen->physicalDotsPerInch()) {
|
if (_screenDPI != eventScreen->physicalDotsPerInch()) {
|
||||||
_screenWidthCenter = eventScreen->size().width() / 2;
|
_screenWidthCenter = eventScreen->size().width() / 2;
|
||||||
_screenDPIScale.x = (float)eventScreen->physicalDotsPerInchX();
|
_screenDPIScale.x = (float)eventScreen->physicalDotsPerInchX();
|
||||||
_screenDPIScale.y = (float)eventScreen->physicalDotsPerInchY();
|
_screenDPIScale.y = (float)eventScreen->physicalDotsPerInchY();
|
||||||
_screenDPI = eventScreen->physicalDotsPerInch();
|
_screenDPI = eventScreen->physicalDotsPerInch();
|
||||||
|
|
||||||
_fixedPosition = true; // This should be config
|
|
||||||
_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)
|
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 );
|
_fixedCenterPosition = glm::vec2( _fixedRadius + margin, eventScreen->size().height() - margin - _fixedRadius );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float clip(float n, float lower, float upper) {
|
float clip(float n, float lower, float upper) {
|
||||||
|
@ -82,14 +91,21 @@ void TouchscreenVirtualPadDevice::pluginUpdate(float deltaTime, const controller
|
||||||
|
|
||||||
/* Shared variables for stick rendering (clipped to the stick radius)*/
|
/* Shared variables for stick rendering (clipped to the stick radius)*/
|
||||||
// Prevent this for being done when not in first person view
|
// Prevent this for being done when not in first person view
|
||||||
virtualPadManager.getLeftVirtualPad()->setBeingTouched(true);
|
|
||||||
virtualPadManager.getLeftVirtualPad()->setFirstTouch(_firstTouchLeftPoint);
|
virtualPadManager.getLeftVirtualPad()->setFirstTouch(_firstTouchLeftPoint);
|
||||||
virtualPadManager.getLeftVirtualPad()->setCurrentTouch(
|
virtualPadManager.getLeftVirtualPad()->setCurrentTouch(
|
||||||
glm::vec2(clip(_currentTouchLeftPoint.x, -STICK_RADIUS_INCHES * _screenDPIScale.x + _firstTouchLeftPoint.x, STICK_RADIUS_INCHES * _screenDPIScale.x + _firstTouchLeftPoint.x),
|
glm::vec2(clip(_currentTouchLeftPoint.x, -STICK_RADIUS_INCHES * _screenDPIScale.x + _firstTouchLeftPoint.x, STICK_RADIUS_INCHES * _screenDPIScale.x + _firstTouchLeftPoint.x),
|
||||||
clip(_currentTouchLeftPoint.y, -STICK_RADIUS_INCHES * _screenDPIScale.y + _firstTouchLeftPoint.y, STICK_RADIUS_INCHES * _screenDPIScale.y + _firstTouchLeftPoint.y))
|
clip(_currentTouchLeftPoint.y, -STICK_RADIUS_INCHES * _screenDPIScale.y + _firstTouchLeftPoint.y, STICK_RADIUS_INCHES * _screenDPIScale.y + _firstTouchLeftPoint.y))
|
||||||
);
|
);
|
||||||
|
virtualPadManager.getLeftVirtualPad()->setBeingTouched(true);
|
||||||
|
virtualPadManager.getLeftVirtualPad()->setShown(true); // If touched, show in any mode (fixed joystick position or non-fixed)
|
||||||
} else {
|
} else {
|
||||||
virtualPadManager.getLeftVirtualPad()->setBeingTouched(false);
|
virtualPadManager.getLeftVirtualPad()->setBeingTouched(false);
|
||||||
|
if (_fixedPosition) {
|
||||||
|
virtualPadManager.getLeftVirtualPad()->setCurrentTouch(_fixedCenterPosition); // reset to the center
|
||||||
|
virtualPadManager.getLeftVirtualPad()->setShown(virtualPadManager.isEnabled() && !virtualPadManager.isHidden()); // Show whenever it's enabled
|
||||||
|
} else {
|
||||||
|
virtualPadManager.getLeftVirtualPad()->setShown(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_validTouchRight) {
|
if (_validTouchRight) {
|
||||||
|
@ -149,12 +165,13 @@ void TouchscreenVirtualPadDevice::touchBeginEvent(const QTouchEvent* event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
KeyboardMouseDevice::enableTouch(false);
|
KeyboardMouseDevice::enableTouch(false);
|
||||||
initFromEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) {
|
void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) {
|
||||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||||
if (!virtualPadManager.isEnabled()) {
|
if (!virtualPadManager.isEnabled()) {
|
||||||
|
touchLeftEnd();
|
||||||
|
touchRightEnd();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// touch end here is a big reset -> resets both pads
|
// touch end here is a big reset -> resets both pads
|
||||||
|
|
|
@ -26,6 +26,7 @@ Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Plugin functions
|
// Plugin functions
|
||||||
|
virtual void init() override;
|
||||||
virtual bool isSupported() const override;
|
virtual bool isSupported() const override;
|
||||||
virtual const QString getName() const override { return NAME; }
|
virtual const QString getName() const override { return NAME; }
|
||||||
|
|
||||||
|
@ -88,7 +89,6 @@ protected:
|
||||||
// just for debug
|
// just for debug
|
||||||
private:
|
private:
|
||||||
void debugPoints(const QTouchEvent* event, QString who);
|
void debugPoints(const QTouchEvent* event, QString who);
|
||||||
void initFromEvent(const QTouchEvent* event);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -51,8 +51,24 @@ namespace VirtualPad {
|
||||||
return _enabled;
|
return _enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Manager::hide(bool hidden) {
|
||||||
|
_hidden = hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Manager::isHidden() {
|
||||||
|
return _hidden;
|
||||||
|
}
|
||||||
|
|
||||||
Instance* Manager::getLeftVirtualPad() {
|
Instance* Manager::getLeftVirtualPad() {
|
||||||
return &_leftVPadInstance;
|
return &_leftVPadInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Instance::isShown() {
|
||||||
|
return _shown;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Instance::setShown(bool show) {
|
||||||
|
_shown = show;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,13 @@ namespace VirtualPad {
|
||||||
virtual glm::vec2 getFirstTouch();
|
virtual glm::vec2 getFirstTouch();
|
||||||
virtual void setCurrentTouch(glm::vec2 point);
|
virtual void setCurrentTouch(glm::vec2 point);
|
||||||
virtual glm::vec2 getCurrentTouch();
|
virtual glm::vec2 getCurrentTouch();
|
||||||
|
virtual bool isShown();
|
||||||
|
virtual void setShown(bool show);
|
||||||
private:
|
private:
|
||||||
bool _isBeingTouched;
|
bool _isBeingTouched;
|
||||||
glm::vec2 _firstTouch;
|
glm::vec2 _firstTouch;
|
||||||
glm::vec2 _currentTouch;
|
glm::vec2 _currentTouch;
|
||||||
|
bool _shown;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Manager : public QObject, public Dependency {
|
class Manager : public QObject, public Dependency {
|
||||||
|
@ -37,9 +40,12 @@ namespace VirtualPad {
|
||||||
Instance* getLeftVirtualPad();
|
Instance* getLeftVirtualPad();
|
||||||
bool isEnabled();
|
bool isEnabled();
|
||||||
void enable(bool enable);
|
void enable(bool enable);
|
||||||
|
bool isHidden();
|
||||||
|
void hide(bool hide);
|
||||||
private:
|
private:
|
||||||
Instance _leftVPadInstance;
|
Instance _leftVPadInstance;
|
||||||
bool _enabled;
|
bool _enabled;
|
||||||
|
bool _hidden;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
show: function() {
|
show: function() {
|
||||||
Controller.setVPadEnabled(false);
|
Controller.setVPadHidden(true);
|
||||||
if (window) {
|
if (window) {
|
||||||
window.fromQml.connect(fromQml);
|
window.fromQml.connect(fromQml);
|
||||||
window.setVisible(true);
|
window.setVisible(true);
|
||||||
|
@ -60,7 +60,7 @@ module.exports = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
hide: function() {
|
hide: function() {
|
||||||
Controller.setVPadEnabled(true);
|
Controller.setVPadHidden(false);
|
||||||
if (window) {
|
if (window) {
|
||||||
window.fromQml.disconnect(fromQml);
|
window.fromQml.disconnect(fromQml);
|
||||||
window.setVisible(false);
|
window.setVisible(false);
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
Controller.setVPadEnabled(true);
|
Controller.setVPadEnabled(true);
|
||||||
|
Controller.setVPadHidden(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
Loading…
Reference in a new issue