Receive deltas instead of abs positions from phone

This commit is contained in:
Albert Vaca Cintora 2019-07-21 12:26:33 +02:00
parent 0d13da9786
commit 9a4bb293a7
2 changed files with 14 additions and 5 deletions

View file

@ -29,6 +29,7 @@
#include <QQuickView> #include <QQuickView>
#include <QQmlError> #include <QQmlError>
#include <QQuickItem> #include <QQuickItem>
#include <QtGlobal>
#include <core/device.h> #include <core/device.h>
#include <core/daemon.h> #include <core/daemon.h>
@ -79,19 +80,26 @@ bool PresenterPlugin::receivePacket(const NetworkPacket& np)
if (!m_view) { if (!m_view) {
m_view = new PresenterView; m_view = new PresenterView;
m_xPos = 0.5f;
m_yPos = 0.5f;
m_view->showFullScreen(); m_view->showFullScreen();
connect(this, &QObject::destroyed, m_view, &QObject::deleteLater); connect(this, &QObject::destroyed, m_view, &QObject::deleteLater);
connect(m_timer, &QTimer::timeout, m_view, &QObject::deleteLater); connect(m_timer, &QTimer::timeout, m_view, &QObject::deleteLater);
} }
auto screenSize = m_view->screen()->size(); QSize screenSize = m_view->screen()->size();
auto ratio = screenSize.width()/screenSize.height(); float ratio = float(screenSize.width())/screenSize.height();
m_xPos += np.get<float>(QStringLiteral("dx"));
m_yPos += np.get<float>(QStringLiteral("dy")) * ratio;
m_xPos = qBound(0.f, m_xPos, 1.f);
m_yPos = qBound(0.f, m_yPos, 1.f);
m_timer->start(); m_timer->start();
auto object = m_view->rootObject(); QQuickItem* object = m_view->rootObject();
object->setProperty("xPos", np.get<qreal>(QStringLiteral("px"))/2 + 0.5); object->setProperty("xPos", m_xPos);
object->setProperty("yPos", np.get<qreal>(QStringLiteral("py"))/2 + 0.5); object->setProperty("yPos", m_yPos);
return true; return true;
} }

View file

@ -47,6 +47,7 @@ public:
private: private:
QPointer<PresenterView> m_view; QPointer<PresenterView> m_view;
QTimer* m_timer; QTimer* m_timer;
float m_xPos, m_yPos;
}; };
#endif #endif