mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Merge pull request #12519 from gcalero/android_experimental_joystick_fixed
Android - Make the virtual pad (joystick) position fixed. Change assets.
This commit is contained in:
commit
3f762c7900
18 changed files with 229 additions and 61 deletions
Binary file not shown.
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2 KiB After Width: | Height: | Size: 12 KiB |
|
@ -43,12 +43,6 @@ Item {
|
|||
HifiConstants { id: android }
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onEntered: {
|
||||
Controller.setVPadEnabled(false);
|
||||
}
|
||||
onExited: {
|
||||
Controller.setVPadEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
|
|
|
@ -40,12 +40,6 @@ Item {
|
|||
var keys = Object.keys(properties).forEach(function (key) {
|
||||
button[key] = properties[key];
|
||||
});
|
||||
button.entered.connect(function() {
|
||||
Controller.setVPadEnabled(false);
|
||||
});
|
||||
button.exited.connect(function() {
|
||||
Controller.setVPadEnabled(true);
|
||||
});
|
||||
return button;
|
||||
} else if( component.status == Component.Error) {
|
||||
console.log("Load button errors " + component.errorString());
|
||||
|
|
|
@ -89,6 +89,16 @@ void ControllerScriptingInterface::setVPadEnabled(const bool enable) {
|
|||
virtualPadManager.enable(enable);
|
||||
}
|
||||
|
||||
void ControllerScriptingInterface::setVPadHidden(const bool hidden) {
|
||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||
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)); }
|
||||
|
||||
|
|
|
@ -66,6 +66,8 @@ public slots:
|
|||
virtual QVariant getRecommendedHUDRect() const;
|
||||
|
||||
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);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <mutex>
|
||||
|
||||
#include <QScreen>
|
||||
#include <QtGui/QWindow>
|
||||
#include <QtGui/QGuiApplication>
|
||||
#include <QtWidgets/QAction>
|
||||
|
@ -26,10 +27,14 @@ void Basic2DWindowOpenGLDisplayPlugin::customizeContext() {
|
|||
#if defined(Q_OS_ANDROID)
|
||||
auto iconPath = PathUtils::resourcesPath() + "images/analog_stick.png";
|
||||
auto image = QImage(iconPath);
|
||||
qreal dpi = getFullscreenTarget()->physicalDotsPerInch();
|
||||
_virtualPadPixelSize = dpi * 512 / 534; // 534 dpi for Pixel XL and Mate 9 Pro
|
||||
|
||||
if (image.format() != QImage::Format_ARGB32) {
|
||||
image = image.convertToFormat(QImage::Format_ARGB32);
|
||||
}
|
||||
if ((image.width() > 0) && (image.height() > 0)) {
|
||||
image = image.scaled(_virtualPadPixelSize, _virtualPadPixelSize, Qt::KeepAspectRatio);
|
||||
|
||||
_virtualPadStickTexture = gpu::Texture::createStrict(
|
||||
gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA),
|
||||
|
@ -50,6 +55,8 @@ void Basic2DWindowOpenGLDisplayPlugin::customizeContext() {
|
|||
image = image.convertToFormat(QImage::Format_ARGB32);
|
||||
}
|
||||
if ((image.width() > 0) && (image.height() > 0)) {
|
||||
image = image.scaled(_virtualPadPixelSize, _virtualPadPixelSize, Qt::KeepAspectRatio);
|
||||
|
||||
_virtualPadStickBaseTexture = gpu::Texture::createStrict(
|
||||
gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA),
|
||||
image.width(), image.height(),
|
||||
|
@ -90,9 +97,10 @@ bool Basic2DWindowOpenGLDisplayPlugin::internalActivate() {
|
|||
void Basic2DWindowOpenGLDisplayPlugin::compositeExtra() {
|
||||
#if defined(Q_OS_ANDROID)
|
||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||
if(virtualPadManager.getLeftVirtualPad()->isBeingTouched()) {
|
||||
if(virtualPadManager.getLeftVirtualPad()->isShown()) {
|
||||
// render stick base
|
||||
auto stickBaseTransform = DependencyManager::get<CompositorHelper>()->getPoint2DTransform(virtualPadManager.getLeftVirtualPad()->getFirstTouch());
|
||||
auto stickBaseTransform = DependencyManager::get<CompositorHelper>()->getPoint2DTransform(virtualPadManager.getLeftVirtualPad()->getFirstTouch(),
|
||||
_virtualPadPixelSize, _virtualPadPixelSize);
|
||||
render([&](gpu::Batch& batch) {
|
||||
batch.enableStereo(false);
|
||||
batch.setProjectionTransform(mat4());
|
||||
|
@ -104,7 +112,8 @@ void Basic2DWindowOpenGLDisplayPlugin::compositeExtra() {
|
|||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
});
|
||||
// render stick head
|
||||
auto stickTransform = DependencyManager::get<CompositorHelper>()->getPoint2DTransform(virtualPadManager.getLeftVirtualPad()->getCurrentTouch());
|
||||
auto stickTransform = DependencyManager::get<CompositorHelper>()->getPoint2DTransform(virtualPadManager.getLeftVirtualPad()->getCurrentTouch(),
|
||||
_virtualPadPixelSize, _virtualPadPixelSize);
|
||||
render([&](gpu::Batch& batch) {
|
||||
batch.enableStereo(false);
|
||||
batch.setProjectionTransform(mat4());
|
||||
|
|
|
@ -45,5 +45,6 @@ private:
|
|||
#if defined(Q_OS_ANDROID)
|
||||
gpu::TexturePointer _virtualPadStickTexture;
|
||||
gpu::TexturePointer _virtualPadStickBaseTexture;
|
||||
qreal _virtualPadPixelSize;
|
||||
#endif
|
||||
};
|
||||
|
|
|
@ -458,9 +458,8 @@ glm::mat4 CompositorHelper::getReticleTransform(const glm::mat4& eyePose, const
|
|||
return result;
|
||||
}
|
||||
|
||||
glm::mat4 CompositorHelper::getPoint2DTransform(const glm::vec2& point) const {
|
||||
glm::mat4 CompositorHelper::getPoint2DTransform(const glm::vec2& point, float sizeX, float sizeY) const {
|
||||
glm::mat4 result;
|
||||
static const float PIXEL_SIZE = 512.0f;
|
||||
const auto canvasSize = vec2(toGlm(_renderingWidget->size()));;
|
||||
QPoint qPoint(point.x,point.y);
|
||||
vec2 position = toGlm(_renderingWidget->mapFromGlobal(qPoint));
|
||||
|
@ -469,7 +468,7 @@ glm::mat4 CompositorHelper::getPoint2DTransform(const glm::vec2& point) const {
|
|||
position -= 1.0;
|
||||
position.y *= -1.0f;
|
||||
|
||||
vec2 size = PIXEL_SIZE / canvasSize;
|
||||
vec2 size = vec2(sizeX / canvasSize.x, sizeY / canvasSize.y);
|
||||
result = glm::scale(glm::translate(glm::mat4(), vec3(position, 0.0f)), vec3(size, 1.0f));
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ public:
|
|||
glm::vec2 getReticleMaximumPosition() const;
|
||||
|
||||
glm::mat4 getReticleTransform(const glm::mat4& eyePose = glm::mat4(), const glm::vec3& headPosition = glm::vec3()) const;
|
||||
glm::mat4 getPoint2DTransform(const glm::vec2& point = glm::vec2()) const;
|
||||
glm::mat4 getPoint2DTransform(const glm::vec2& point = glm::vec2(), float sizeX = 512.0f, float sizeY = 512.0f) const;
|
||||
|
||||
ReticleInterface* getReticleInterface() { return _reticleInterface; }
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include <NumericalConstants.h>
|
||||
#include "VirtualPadManager.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
const char* TouchscreenVirtualPadDevice::NAME = "TouchscreenVirtualPad";
|
||||
|
||||
bool TouchscreenVirtualPadDevice::isSupported() const {
|
||||
|
@ -37,10 +39,121 @@ bool TouchscreenVirtualPadDevice::isSupported() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
void TouchscreenVirtualPadDevice::init() {
|
||||
_fixedPosition = true; // This should be config
|
||||
|
||||
QScreen* eventScreen = qApp->primaryScreen();
|
||||
if (_screenDPIProvided != eventScreen->physicalDotsPerInch()) {
|
||||
_screenWidthCenter = eventScreen->size().width() / 2;
|
||||
_screenDPIScale.x = (float)eventScreen->physicalDotsPerInchX();
|
||||
_screenDPIScale.y = (float)eventScreen->physicalDotsPerInchY();
|
||||
_screenDPIProvided = eventScreen->physicalDotsPerInch();
|
||||
_screenDPI = eventScreen->physicalDotsPerInch();
|
||||
|
||||
_fixedRadius = _screenDPI * 256 / 534;
|
||||
_fixedRadiusForCalc = _fixedRadius - _screenDPI * 105 / 534; // 105 is the radius of the stick circle
|
||||
}
|
||||
|
||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||
setupFixedCenter(virtualPadManager, true);
|
||||
|
||||
if (_fixedPosition) {
|
||||
virtualPadManager.getLeftVirtualPad()->setShown(virtualPadManager.isEnabled() && !virtualPadManager.isHidden()); // Show whenever it's enabled
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
float 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));
|
||||
}
|
||||
|
||||
glm::vec2 TouchscreenVirtualPadDevice::clippedPointInCircle(float radius, glm::vec2 origin, glm::vec2 touchPoint) {
|
||||
float deltaX = touchPoint.x-origin.x;
|
||||
float deltaY = touchPoint.y-origin.y;
|
||||
|
||||
float distance = sqrt(pow(deltaX,2)+pow(deltaY,2));
|
||||
|
||||
// First case, inside the boundaires, just use the distance
|
||||
if (distance <= radius) {
|
||||
return touchPoint;
|
||||
}
|
||||
|
||||
// Second case, purely vertical (avoid division by zero)
|
||||
if (deltaX == 0.0f) {
|
||||
return vec2(touchPoint.x, clip(touchPoint.y, origin.y-radius, origin.y+radius) );
|
||||
}
|
||||
|
||||
// Third case, calculate point in circumference
|
||||
// line formula
|
||||
float m = deltaY/deltaX;
|
||||
float b = touchPoint.y - m * touchPoint.x;
|
||||
|
||||
// quadtratic coefs of circumference and line intersection
|
||||
float qa = pow(m,2)+1;
|
||||
float qb = 2 * ( m * b - origin.x - origin.y * m );
|
||||
float qc = powf(origin.x, 2) - powf(radius,2) + b * b - 2 * b * origin.y + powf(origin.y, 2);
|
||||
|
||||
float discr = qb * qb - 4 * qa * qc;
|
||||
float discrSign = deltaX>0?1.0:-1.0;
|
||||
|
||||
float finalX = (- qb + discrSign * sqrtf(discr)) / (2 * qa);
|
||||
float finalY = m * finalX + b;
|
||||
|
||||
return vec2(finalX, finalY);
|
||||
}
|
||||
|
||||
void TouchscreenVirtualPadDevice::processInputUseCircleMethod(VirtualPad::Manager& virtualPadManager) {
|
||||
vec2 clippedPoint = clippedPointInCircle(_fixedRadiusForCalc, _firstTouchLeftPoint, _currentTouchLeftPoint);
|
||||
|
||||
_inputDevice->_axisStateMap[controller::LX] = (clippedPoint.x - _firstTouchLeftPoint.x) / _fixedRadiusForCalc;
|
||||
_inputDevice->_axisStateMap[controller::LY] = (clippedPoint.y - _firstTouchLeftPoint.y) / _fixedRadiusForCalc;
|
||||
|
||||
virtualPadManager.getLeftVirtualPad()->setFirstTouch(_firstTouchLeftPoint);
|
||||
virtualPadManager.getLeftVirtualPad()->setCurrentTouch(clippedPoint);
|
||||
virtualPadManager.getLeftVirtualPad()->setBeingTouched(true);
|
||||
virtualPadManager.getLeftVirtualPad()->setShown(true); // If touched, show in any mode (fixed joystick position or non-fixed)
|
||||
}
|
||||
|
||||
void TouchscreenVirtualPadDevice::processInputUseSquareMethod(VirtualPad::Manager& virtualPadManager) {
|
||||
float leftDistanceScaleX, leftDistanceScaleY;
|
||||
leftDistanceScaleX = (_currentTouchLeftPoint.x - _firstTouchLeftPoint.x) / _screenDPIScale.x;
|
||||
leftDistanceScaleY = (_currentTouchLeftPoint.y - _firstTouchLeftPoint.y) / _screenDPIScale.y;
|
||||
|
||||
leftDistanceScaleX = clip(leftDistanceScaleX, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES);
|
||||
leftDistanceScaleY = clip(leftDistanceScaleY, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES);
|
||||
|
||||
// NOW BETWEEN -1 1
|
||||
leftDistanceScaleX /= STICK_RADIUS_INCHES;
|
||||
leftDistanceScaleY /= STICK_RADIUS_INCHES;
|
||||
|
||||
_inputDevice->_axisStateMap[controller::LX] = leftDistanceScaleX;
|
||||
_inputDevice->_axisStateMap[controller::LY] = leftDistanceScaleY;
|
||||
|
||||
/* Shared variables for stick rendering (clipped to the stick radius)*/
|
||||
// Prevent this for being done when not in first person view
|
||||
virtualPadManager.getLeftVirtualPad()->setFirstTouch(_firstTouchLeftPoint);
|
||||
virtualPadManager.getLeftVirtualPad()->setCurrentTouch(
|
||||
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))
|
||||
);
|
||||
virtualPadManager.getLeftVirtualPad()->setBeingTouched(true);
|
||||
virtualPadManager.getLeftVirtualPad()->setShown(true); // If touched, show in any mode (fixed joystick position or non-fixed)
|
||||
}
|
||||
|
||||
void TouchscreenVirtualPadDevice::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
|
||||
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
||||
userInputMapper->withLock([&, this]() {
|
||||
|
@ -48,31 +161,18 @@ 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;
|
||||
leftDistanceScaleY = (_currentTouchLeftPoint.y - _firstTouchLeftPoint.y) / _screenDPIScale.y;
|
||||
|
||||
leftDistanceScaleX = clip(leftDistanceScaleX, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES);
|
||||
leftDistanceScaleY = clip(leftDistanceScaleY, -STICK_RADIUS_INCHES, STICK_RADIUS_INCHES);
|
||||
|
||||
// NOW BETWEEN -1 1
|
||||
leftDistanceScaleX /= STICK_RADIUS_INCHES;
|
||||
leftDistanceScaleY /= STICK_RADIUS_INCHES;
|
||||
|
||||
_inputDevice->_axisStateMap[controller::LX] = leftDistanceScaleX;
|
||||
_inputDevice->_axisStateMap[controller::LY] = leftDistanceScaleY;
|
||||
|
||||
/* Shared variables for stick rendering (clipped to the stick radius)*/
|
||||
// Prevent this for being done when not in first person view
|
||||
virtualPadManager.getLeftVirtualPad()->setBeingTouched(true);
|
||||
virtualPadManager.getLeftVirtualPad()->setFirstTouch(_firstTouchLeftPoint);
|
||||
virtualPadManager.getLeftVirtualPad()->setCurrentTouch(
|
||||
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))
|
||||
);
|
||||
processInputUseCircleMethod(virtualPadManager);
|
||||
} else {
|
||||
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) {
|
||||
|
@ -132,18 +232,13 @@ void TouchscreenVirtualPadDevice::touchBeginEvent(const QTouchEvent* event) {
|
|||
return;
|
||||
}
|
||||
KeyboardMouseDevice::enableTouch(false);
|
||||
QScreen* eventScreen = event->window()->screen();
|
||||
_screenWidthCenter = eventScreen->size().width() / 2;
|
||||
if (_screenDPI != eventScreen->physicalDotsPerInch()) {
|
||||
_screenDPIScale.x = (float)eventScreen->physicalDotsPerInchX();
|
||||
_screenDPIScale.y = (float)eventScreen->physicalDotsPerInchY();
|
||||
_screenDPI = eventScreen->physicalDotsPerInch();
|
||||
}
|
||||
}
|
||||
|
||||
void TouchscreenVirtualPadDevice::touchEndEvent(const QTouchEvent* event) {
|
||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||
if (!virtualPadManager.isEnabled()) {
|
||||
touchLeftEnd();
|
||||
touchRightEnd();
|
||||
return;
|
||||
}
|
||||
// touch end here is a big reset -> resets both pads
|
||||
|
@ -169,14 +264,13 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) {
|
|||
bool rightTouchFound = false;
|
||||
for (int i = 0; i < _touchPointCount; ++i) {
|
||||
glm::vec2 thisPoint(tPoints[i].pos().x(), tPoints[i].pos().y());
|
||||
if (thisPoint.x < _screenWidthCenter) {
|
||||
if (_validTouchLeft) {
|
||||
leftTouchFound = true;
|
||||
touchLeftUpdate(thisPoint);
|
||||
} else if (touchLeftBeginPointIsValid(thisPoint)) {
|
||||
if (!leftTouchFound) {
|
||||
leftTouchFound = true;
|
||||
if (!_validTouchLeft) {
|
||||
touchLeftBegin(thisPoint);
|
||||
} else {
|
||||
touchLeftUpdate(thisPoint);
|
||||
}
|
||||
touchLeftBegin(thisPoint);
|
||||
}
|
||||
} else {
|
||||
if (!rightTouchFound) {
|
||||
|
@ -197,10 +291,24 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) {
|
|||
}
|
||||
}
|
||||
|
||||
bool TouchscreenVirtualPadDevice::touchLeftBeginPointIsValid(glm::vec2 touchPoint) {
|
||||
if (_fixedPosition) {
|
||||
// inside circle
|
||||
return pow(touchPoint.x - _fixedCenterPosition.x,2.0) + pow(touchPoint.y - _fixedCenterPosition.y, 2.0) < pow(_fixedRadius, 2.0);
|
||||
} else {
|
||||
// left side
|
||||
return touchPoint.x < _screenWidthCenter;
|
||||
}
|
||||
}
|
||||
|
||||
void TouchscreenVirtualPadDevice::touchLeftBegin(glm::vec2 touchPoint) {
|
||||
auto& virtualPadManager = VirtualPad::Manager::instance();
|
||||
if (virtualPadManager.isEnabled()) {
|
||||
_firstTouchLeftPoint = touchPoint;
|
||||
if (_fixedPosition) {
|
||||
_firstTouchLeftPoint = _fixedCenterPosition;
|
||||
} else {
|
||||
_firstTouchLeftPoint = touchPoint;
|
||||
}
|
||||
_validTouchLeft = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <controllers/InputDevice.h>
|
||||
#include "InputPlugin.h"
|
||||
#include <QtGui/qtouchdevice.h>
|
||||
#include "VirtualPadManager.h"
|
||||
|
||||
class QTouchEvent;
|
||||
class QGestureEvent;
|
||||
|
@ -26,6 +27,7 @@ Q_OBJECT
|
|||
public:
|
||||
|
||||
// Plugin functions
|
||||
virtual void init() override;
|
||||
virtual bool isSupported() const override;
|
||||
virtual const QString getName() const override { return NAME; }
|
||||
|
||||
|
@ -60,9 +62,10 @@ public:
|
|||
const std::shared_ptr<InputDevice>& getInputDevice() const { return _inputDevice; }
|
||||
|
||||
protected:
|
||||
qreal _lastPinchScale;
|
||||
qreal _pinchScale;
|
||||
qreal _screenDPI;
|
||||
float _lastPinchScale;
|
||||
float _pinchScale;
|
||||
float _screenDPI;
|
||||
qreal _screenDPIProvided;
|
||||
glm::vec2 _screenDPIScale;
|
||||
bool _validTouchLeft;
|
||||
glm::vec2 _firstTouchLeftPoint;
|
||||
|
@ -74,12 +77,24 @@ protected:
|
|||
int _screenWidthCenter;
|
||||
std::shared_ptr<InputDevice> _inputDevice { std::make_shared<InputDevice>() };
|
||||
|
||||
bool _fixedPosition;
|
||||
glm::vec2 _fixedCenterPosition;
|
||||
float _fixedRadius;
|
||||
float _fixedRadiusForCalc;
|
||||
int _extraBottomMargin {0};
|
||||
|
||||
void touchLeftBegin(glm::vec2 touchPoint);
|
||||
void touchLeftUpdate(glm::vec2 touchPoint);
|
||||
void touchLeftEnd();
|
||||
bool touchLeftBeginPointIsValid(glm::vec2 touchPoint);
|
||||
void touchRightBegin(glm::vec2 touchPoint);
|
||||
void touchRightUpdate(glm::vec2 touchPoint);
|
||||
void touchRightEnd();
|
||||
void setupFixedCenter(VirtualPad::Manager& virtualPadManager, bool force = false);
|
||||
|
||||
void processInputUseCircleMethod(VirtualPad::Manager& virtualPadManager);
|
||||
void processInputUseSquareMethod(VirtualPad::Manager& virtualPadManager);
|
||||
glm::vec2 clippedPointInCircle(float radius, glm::vec2 origin, glm::vec2 touchPoint);
|
||||
// just for debug
|
||||
private:
|
||||
void debugPoints(const QTouchEvent* event, QString who);
|
||||
|
|
|
@ -100,7 +100,7 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend
|
|||
// Lighting Buffer ready for tone mapping
|
||||
// Forward rendering on GLES doesn't support tonemapping to and from the same FBO, so we specify
|
||||
// the output FBO as null, which causes the tonemapping to target the blit framebuffer
|
||||
const auto toneMappingInputs = ToneMappingDeferred::Inputs(framebuffer, nullptr).asVarying();
|
||||
const auto toneMappingInputs = ToneMappingDeferred::Inputs(framebuffer, static_cast<gpu::FramebufferPointer>(nullptr) ).asVarying();
|
||||
task.addJob<ToneMappingDeferred>("ToneMapping", toneMappingInputs);
|
||||
|
||||
// Layered Overlays
|
||||
|
|
|
@ -51,8 +51,32 @@ namespace VirtualPad {
|
|||
return _enabled;
|
||||
}
|
||||
|
||||
void Manager::hide(bool hidden) {
|
||||
_hidden = hidden;
|
||||
}
|
||||
|
||||
bool Manager::isHidden() {
|
||||
return _hidden;
|
||||
}
|
||||
|
||||
int Manager::extraBottomMargin() {
|
||||
return _extraBottomMargin;
|
||||
}
|
||||
|
||||
void Manager::setExtraBottomMargin(int margin) {
|
||||
_extraBottomMargin = margin;
|
||||
}
|
||||
|
||||
Instance* Manager::getLeftVirtualPad() {
|
||||
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 void setCurrentTouch(glm::vec2 point);
|
||||
virtual glm::vec2 getCurrentTouch();
|
||||
virtual bool isShown();
|
||||
virtual void setShown(bool show);
|
||||
private:
|
||||
bool _isBeingTouched;
|
||||
glm::vec2 _firstTouch;
|
||||
glm::vec2 _currentTouch;
|
||||
bool _shown;
|
||||
};
|
||||
|
||||
class Manager : public QObject, public Dependency {
|
||||
|
@ -37,9 +40,15 @@ namespace VirtualPad {
|
|||
Instance* getLeftVirtualPad();
|
||||
bool isEnabled();
|
||||
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};
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -198,6 +198,7 @@ function lowerBottomBar() {
|
|||
if (bottomHudOptionsBar) {
|
||||
bottomHudOptionsBar.show();
|
||||
}
|
||||
Controller.setVPadExtraBottomMargin(0);
|
||||
}
|
||||
|
||||
function raiseBottomBar() {
|
||||
|
@ -208,6 +209,7 @@ function raiseBottomBar() {
|
|||
if (bottomHudOptionsBar) {
|
||||
bottomHudOptionsBar.hide();
|
||||
}
|
||||
Controller.setVPadExtraBottomMargin(255); // Height in bottombar.qml
|
||||
print('[bottombar.js] raiseBottomBar end');
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ module.exports = {
|
|||
});
|
||||
},
|
||||
show: function() {
|
||||
Controller.setVPadEnabled(false);
|
||||
Controller.setVPadHidden(true);
|
||||
if (window) {
|
||||
window.fromQml.connect(fromQml);
|
||||
window.setVisible(true);
|
||||
|
@ -60,7 +60,7 @@ module.exports = {
|
|||
}
|
||||
},
|
||||
hide: function() {
|
||||
Controller.setVPadEnabled(true);
|
||||
Controller.setVPadHidden(false);
|
||||
if (window) {
|
||||
window.fromQml.disconnect(fromQml);
|
||||
window.setVisible(false);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
function init() {
|
||||
Controller.setVPadEnabled(true);
|
||||
Controller.setVPadHidden(false);
|
||||
}
|
||||
|
||||
init();
|
||||
|
|
Loading…
Reference in a new issue