Merge pull request #9328 from hyperlogic/tablet-ui

Allow Hifi.SoundEffect to be used in all qml
This commit is contained in:
Seth Alves 2017-01-06 15:21:08 -08:00 committed by GitHub
commit ad6175857d
6 changed files with 16 additions and 32 deletions

View file

@ -20,7 +20,7 @@ Item {
} }
function playButtonClickSound() { function playButtonClickSound() {
buttonClickSound.play(); buttonClickSound.play(globalPosition);
} }
Loader { Loader {

View file

@ -107,15 +107,10 @@ Web3DOverlay::~Web3DOverlay() {
} }
void Web3DOverlay::update(float deltatime) { void Web3DOverlay::update(float deltatime) {
// FIXME: applyTransformTo causes tablet overlay to detach from tablet entity. if (_webSurface) {
// Perhaps rather than deleting the following code it should be run only if isFacingAvatar() is true? // update globalPosition
/* _webSurface->getRootContext()->setContextProperty("globalPosition", vec3toVariant(getPosition()));
if (usecTimestampNow() > _transformExpiry) {
Transform transform = getTransform();
applyTransformTo(transform);
setTransform(transform);
} }
*/
} }
void Web3DOverlay::loadSourceURL() { void Web3DOverlay::loadSourceURL() {
@ -141,6 +136,7 @@ void Web3DOverlay::loadSourceURL() {
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem(), _webSurface.data()); tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem(), _webSurface.data());
} }
} }
_webSurface->getRootContext()->setContextProperty("globalPosition", vec3toVariant(getPosition()));
} }
void Web3DOverlay::render(RenderArgs* args) { void Web3DOverlay::render(RenderArgs* args) {

View file

@ -271,6 +271,7 @@ void RenderableWebEntityItem::loadSourceURL() {
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem(), _webSurface.data()); tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem(), _webSurface.data());
} }
} }
_webSurface->getRootContext()->setContextProperty("globalPosition", vec3toVariant(getPosition()));
} }
@ -403,6 +404,12 @@ void RenderableWebEntityItem::destroyWebSurface() {
} }
void RenderableWebEntityItem::update(const quint64& now) { void RenderableWebEntityItem::update(const quint64& now) {
if (_webSurface) {
// update globalPosition
_webSurface->getRootContext()->setContextProperty("globalPosition", vec3toVariant(getPosition()));
}
auto interval = now - _lastRenderTime; auto interval = now - _lastRenderTime;
if (interval > MAX_NO_RENDER_INTERVAL) { if (interval > MAX_NO_RENDER_INTERVAL) {
destroyWebSurface(); destroyWebSurface();

View file

@ -12,6 +12,7 @@
#include <AudioInjector.h> #include <AudioInjector.h>
#include <PathUtils.h> #include <PathUtils.h>
#include <RegisteredMetaTypes.h>
#include "ScriptEngineLogging.h" #include "ScriptEngineLogging.h"
TabletScriptingInterface::TabletScriptingInterface() { TabletScriptingInterface::TabletScriptingInterface() {
@ -165,10 +166,6 @@ void TabletProxy::updateAudioBar(const double micLevel) {
} }
} }
void TabletProxy::updateTabletPosition(glm::vec3 tabletPosition) {
_position.set(tabletPosition);
}
void TabletProxy::emitScriptEvent(QVariant msg) { void TabletProxy::emitScriptEvent(QVariant msg) {
if (_qmlOffscreenSurface) { if (_qmlOffscreenSurface) {
QMetaObject::invokeMethod(_qmlOffscreenSurface, "emitScriptEvent", Qt::AutoConnection, Q_ARG(QVariant, msg)); QMetaObject::invokeMethod(_qmlOffscreenSurface, "emitScriptEvent", Qt::AutoConnection, Q_ARG(QVariant, msg));
@ -269,13 +266,13 @@ void SoundEffect::setSource(QUrl url) {
_sound = DependencyManager::get<SoundCache>()->getSound(_url); _sound = DependencyManager::get<SoundCache>()->getSound(_url);
} }
void SoundEffect::play() { void SoundEffect::play(QVariant position) {
auto tsi = DependencyManager::get<TabletScriptingInterface>(); auto tsi = DependencyManager::get<TabletScriptingInterface>();
if (tsi) { if (tsi) {
TabletProxy* tablet = qobject_cast<TabletProxy*>(tsi->getTablet("com.highfidelity.interface.tablet.system")); TabletProxy* tablet = qobject_cast<TabletProxy*>(tsi->getTablet("com.highfidelity.interface.tablet.system"));
if (tablet) { if (tablet) {
AudioInjectorOptions options; AudioInjectorOptions options;
options.position = tablet->getPosition(); options.position = vec3FromVariant(position);
options.localOnly = true; options.localOnly = true;
if (_injector) { if (_injector) {
_injector->setOptions(options); _injector->setOptions(options);

View file

@ -24,7 +24,6 @@
#include <DependencyManager.h> #include <DependencyManager.h>
#include <SoundCache.h> #include <SoundCache.h>
#include <ThreadSafeValueCache.h>
class TabletProxy; class TabletProxy;
class TabletButtonProxy; class TabletButtonProxy;
@ -101,17 +100,6 @@ public:
*/ */
Q_INVOKABLE void updateAudioBar(const double micLevel); Q_INVOKABLE void updateAudioBar(const double micLevel);
/**jsdoc
* Updates the tablet's position in world space. This is necessary for the tablet
* to emit audio with the correct spatialization.
* @function TabletProxy#updateTabletPosition
* @param position {vec3} tablet position in world space.
*/
Q_INVOKABLE void updateTabletPosition(glm::vec3 tabletPosition);
glm::vec3 getPosition() const { return _position.get(); }
QString getName() const { return _name; } QString getName() const { return _name; }
/**jsdoc /**jsdoc
@ -141,7 +129,6 @@ protected:
std::vector<QSharedPointer<TabletButtonProxy>> _tabletButtonProxies; std::vector<QSharedPointer<TabletButtonProxy>> _tabletButtonProxies;
QQuickItem* _qmlTabletRoot { nullptr }; QQuickItem* _qmlTabletRoot { nullptr };
QObject* _qmlOffscreenSurface { nullptr }; QObject* _qmlOffscreenSurface { nullptr };
ThreadSafeValueCache<glm::vec3> _position;
}; };
/**jsdoc /**jsdoc
@ -202,7 +189,7 @@ public:
QUrl getSource() const; QUrl getSource() const;
void setSource(QUrl url); void setSource(QUrl url);
Q_INVOKABLE void play(); Q_INVOKABLE void play(QVariant position);
protected: protected:
QUrl _url; QUrl _url;
SharedSoundPointer _sound; SharedSoundPointer _sound;

View file

@ -50,9 +50,6 @@
var currentMicLevel = getMicLevel(); var currentMicLevel = getMicLevel();
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
tablet.updateAudioBar(currentMicLevel); tablet.updateAudioBar(currentMicLevel);
if (UIWebTablet) {
tablet.updateTabletPosition(UIWebTablet.getPosition());
}
} }
if (HMD.showTablet && !tabletShown) { if (HMD.showTablet && !tabletShown) {