mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
Merge pull request #15562 from jherico/bugz-133
BUGZ-133: Expose additional functionality to QML/Scripts
This commit is contained in:
commit
6b3707873b
8 changed files with 160 additions and 55 deletions
|
@ -192,7 +192,7 @@
|
|||
#include "scripting/WalletScriptingInterface.h"
|
||||
#include "scripting/TTSScriptingInterface.h"
|
||||
#include "scripting/KeyboardScriptingInterface.h"
|
||||
#include "scripting/RefreshRateScriptingInterface.h"
|
||||
#include "scripting/PerformanceScriptingInterface.h"
|
||||
|
||||
|
||||
|
||||
|
@ -3274,7 +3274,7 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) {
|
|||
|
||||
surfaceContext->setContextProperty("Controller", DependencyManager::get<controller::ScriptingInterface>().data());
|
||||
surfaceContext->setContextProperty("Entities", DependencyManager::get<EntityScriptingInterface>().data());
|
||||
surfaceContext->setContextProperty("RefreshRate", new RefreshRateScriptingInterface());
|
||||
surfaceContext->setContextProperty("Performance", new PerformanceScriptingInterface());
|
||||
_fileDownload = new FileScriptingInterface(engine);
|
||||
surfaceContext->setContextProperty("File", _fileDownload);
|
||||
connect(_fileDownload, &FileScriptingInterface::unzipResult, this, &Application::handleUnzip);
|
||||
|
@ -3424,7 +3424,7 @@ void Application::setupQmlSurface(QQmlContext* surfaceContext, bool setAdditiona
|
|||
|
||||
surfaceContext->setContextProperty("Settings", SettingsScriptingInterface::getInstance());
|
||||
surfaceContext->setContextProperty("MenuInterface", MenuScriptingInterface::getInstance());
|
||||
surfaceContext->setContextProperty("RefreshRate", new RefreshRateScriptingInterface());
|
||||
surfaceContext->setContextProperty("Performance", new PerformanceScriptingInterface());
|
||||
|
||||
surfaceContext->setContextProperty("Account", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED
|
||||
surfaceContext->setContextProperty("GlobalServices", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED
|
||||
|
@ -7392,7 +7392,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe
|
|||
scriptEngine->registerGlobalObject("LODManager", DependencyManager::get<LODManager>().data());
|
||||
|
||||
scriptEngine->registerGlobalObject("Keyboard", DependencyManager::get<KeyboardScriptingInterface>().data());
|
||||
scriptEngine->registerGlobalObject("RefreshRate", new RefreshRateScriptingInterface);
|
||||
scriptEngine->registerGlobalObject("Performance", new PerformanceScriptingInterface());
|
||||
|
||||
scriptEngine->registerGlobalObject("Paths", DependencyManager::get<PathUtils>().data());
|
||||
|
||||
|
|
|
@ -13,13 +13,8 @@
|
|||
#include "RefreshRateManager.h"
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
|
||||
|
||||
#include <Application.h>
|
||||
|
||||
#include <display-plugins/hmd/HmdDisplayPlugin.h>
|
||||
|
||||
static const int VR_TARGET_RATE = 90;
|
||||
|
||||
static const std::array<std::string, RefreshRateManager::RefreshRateProfile::PROFILE_NUM> REFRESH_RATE_PROFILE_TO_STRING =
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
|
|
40
interface/src/scripting/PerformanceScriptingInterface.cpp
Normal file
40
interface/src/scripting/PerformanceScriptingInterface.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// Created by Bradley Austin Davis on 2019/05/14
|
||||
// Copyright 2013-2019 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
|
||||
#include "PerformanceScriptingInterface.h"
|
||||
|
||||
#include "../Application.h"
|
||||
|
||||
std::once_flag PerformanceScriptingInterface::registry_flag;
|
||||
|
||||
PerformanceScriptingInterface::PerformanceScriptingInterface() {
|
||||
std::call_once(registry_flag, [] {
|
||||
qmlRegisterType<PerformanceScriptingInterface>("PerformanceEnums", 1, 0, "RefreshRate");
|
||||
});
|
||||
}
|
||||
|
||||
void PerformanceScriptingInterface::setRefreshRateProfile(RefreshRateProfile refreshRateProfile) {
|
||||
qApp->getRefreshRateManager().setRefreshRateProfile((RefreshRateManager::RefreshRateProfile)refreshRateProfile);
|
||||
}
|
||||
|
||||
PerformanceScriptingInterface::RefreshRateProfile PerformanceScriptingInterface::getRefreshRateProfile() const {
|
||||
return (PerformanceScriptingInterface::RefreshRateProfile)qApp->getRefreshRateManager().getRefreshRateProfile();
|
||||
}
|
||||
|
||||
int PerformanceScriptingInterface::getActiveRefreshRate() const {
|
||||
return qApp->getRefreshRateManager().getActiveRefreshRate();
|
||||
}
|
||||
|
||||
RefreshRateManager::UXMode PerformanceScriptingInterface::getUXMode() const {
|
||||
return qApp->getRefreshRateManager().getUXMode();
|
||||
}
|
||||
|
||||
RefreshRateManager::RefreshRateRegime PerformanceScriptingInterface::getRefreshRateRegime() const {
|
||||
return qApp->getRefreshRateManager().getRefreshRateRegime();
|
||||
}
|
48
interface/src/scripting/PerformanceScriptingInterface.h
Normal file
48
interface/src/scripting/PerformanceScriptingInterface.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
//
|
||||
// Created by Bradley Austin Davis on 2019/05/14
|
||||
// Copyright 2013-2019 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#ifndef hifi_PerformanceScriptingInterface_h
|
||||
#define hifi_PerformanceScriptingInterface_h
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "../RefreshRateManager.h"
|
||||
|
||||
|
||||
class PerformanceScriptingInterface : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
// Must match RefreshRateManager enums
|
||||
enum RefreshRateProfile {
|
||||
ECO = RefreshRateManager::RefreshRateProfile::ECO,
|
||||
INTERACTIVE = RefreshRateManager::RefreshRateProfile::INTERACTIVE,
|
||||
REALTIME = RefreshRateManager::RefreshRateProfile::REALTIME,
|
||||
};
|
||||
Q_ENUM(RefreshRateProfile)
|
||||
|
||||
|
||||
PerformanceScriptingInterface();
|
||||
~PerformanceScriptingInterface() = default;
|
||||
|
||||
public slots:
|
||||
void setRefreshRateProfile(RefreshRateProfile refreshRateProfile);
|
||||
RefreshRateProfile getRefreshRateProfile() const;
|
||||
|
||||
int getActiveRefreshRate() const;
|
||||
RefreshRateManager::UXMode getUXMode() const;
|
||||
RefreshRateManager::RefreshRateRegime getRefreshRateRegime() const;
|
||||
|
||||
|
||||
private:
|
||||
static std::once_flag registry_flag;
|
||||
};
|
||||
|
||||
#endif // header guard
|
|
@ -1,46 +0,0 @@
|
|||
//
|
||||
// RefreshRateScriptingInterface.h
|
||||
// interface/src/scrfipting
|
||||
//
|
||||
// Created by Dante Ruiz on 2019-04-15.
|
||||
// Copyright 2019 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_RefreshRateScriptingInterface_h
|
||||
#define hifi_RefreshRateScriptingInterface_h
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <Application.h>
|
||||
|
||||
class RefreshRateScriptingInterface : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
RefreshRateScriptingInterface() = default;
|
||||
~RefreshRateScriptingInterface() = default;
|
||||
|
||||
public:
|
||||
Q_INVOKABLE QString getRefreshRateProfile() {
|
||||
RefreshRateManager& refreshRateManager = qApp->getRefreshRateManager();
|
||||
return QString::fromStdString(RefreshRateManager::refreshRateProfileToString(refreshRateManager.getRefreshRateProfile()));
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getRefreshRateRegime() {
|
||||
RefreshRateManager& refreshRateManager = qApp->getRefreshRateManager();
|
||||
return QString::fromStdString(RefreshRateManager::refreshRateRegimeToString(refreshRateManager.getRefreshRateRegime()));
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getUXMode() {
|
||||
RefreshRateManager& refreshRateManager = qApp->getRefreshRateManager();
|
||||
return QString::fromStdString(RefreshRateManager::uxModeToString(refreshRateManager.getUXMode()));
|
||||
}
|
||||
|
||||
Q_INVOKABLE int getActiveRefreshRate() {
|
||||
return qApp->getRefreshRateManager().getActiveRefreshRate();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -19,6 +19,7 @@
|
|||
#include <shared/QtHelpers.h>
|
||||
#include <SettingHandle.h>
|
||||
|
||||
#include <plugins/PluginManager.h>
|
||||
#include <display-plugins/CompositorHelper.h>
|
||||
#include <AddressManager.h>
|
||||
#include "AndroidHelper.h"
|
||||
|
@ -609,3 +610,31 @@ void WindowScriptingInterface::onMessageBoxSelected(int button) {
|
|||
float WindowScriptingInterface::domainLoadingProgress() {
|
||||
return qApp->getOctreePacketProcessor().domainLoadingProgress();
|
||||
}
|
||||
|
||||
int WindowScriptingInterface::getDisplayPluginCount() {
|
||||
return (int)PluginManager::getInstance()->getDisplayPlugins().size();
|
||||
}
|
||||
|
||||
QString WindowScriptingInterface::getDisplayPluginName(int index) {
|
||||
return PluginManager::getInstance()->getDisplayPlugins().at(index)->getName();
|
||||
}
|
||||
|
||||
bool WindowScriptingInterface::isDisplayPluginHmd(int index) {
|
||||
return PluginManager::getInstance()->getDisplayPlugins().at(index)->isHmd();
|
||||
}
|
||||
|
||||
int WindowScriptingInterface::getActiveDisplayPlugin() {
|
||||
auto active = qApp->getActiveDisplayPlugin();
|
||||
auto size = getDisplayPluginCount();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
if (PluginManager::getInstance()->getDisplayPlugins().at(i) == active) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void WindowScriptingInterface::setActiveDisplayPlugin(int index) {
|
||||
auto name = PluginManager::getInstance()->getDisplayPlugins().at(index)->getName();
|
||||
qApp->setActiveDisplayPlugin(name);
|
||||
}
|
||||
|
|
|
@ -558,6 +558,44 @@ public slots:
|
|||
*/
|
||||
float domainLoadingProgress();
|
||||
|
||||
/**jsdoc
|
||||
* Return the number of display plugins currently available
|
||||
* @function Window.getDisplayPluginCount
|
||||
* @returns {int} The number of currently available display plugins
|
||||
*/
|
||||
int getDisplayPluginCount();
|
||||
|
||||
/**jsdoc
|
||||
* Return the human readable name of a display plugin
|
||||
* @function Window.getDisplayPluginName
|
||||
* @param {int} index - The index of the display plugin. Must be less than the value returned by {@link Window.getDisplayPluginCount|getDisplayPluginCount}.
|
||||
* @returns {string} The name of the specified display plugin
|
||||
*/
|
||||
QString getDisplayPluginName(int index);
|
||||
|
||||
/**jsdoc
|
||||
* Return whether a given display plugin is an HMD
|
||||
* @function Window.isDisplayPluginHmd
|
||||
* @param {int} index - The index of the display plugin. Must be less than the value returned by {@link Window.getDisplayPluginCount|getDisplayPluginCount}.
|
||||
* @returns {bool} True if the specified display plugin is a HMD
|
||||
*/
|
||||
bool isDisplayPluginHmd(int index);
|
||||
|
||||
/**jsdoc
|
||||
* Return the currently active display plugin
|
||||
* @function Window.getActiveDisplayPlugin
|
||||
* @returns {int} The index of the currently active display plugin
|
||||
*/
|
||||
int getActiveDisplayPlugin();
|
||||
|
||||
/**jsdoc
|
||||
* Return the currently active display plugin
|
||||
* @function Window.setActiveDisplayPlugin
|
||||
* @param {int} index - The index of the display plugin. Must be less than the value returned by {@link Window.getDisplayPluginCount|getDisplayPluginCount}.
|
||||
*/
|
||||
void setActiveDisplayPlugin(int index);
|
||||
|
||||
|
||||
private slots:
|
||||
void onWindowGeometryChanged(const QRect& geometry);
|
||||
void onMessageBoxSelected(int button);
|
||||
|
|
Loading…
Reference in a new issue