From 8c375db90f3185263c4180db78cc495d4968f199 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Wed, 15 May 2019 12:55:47 -0700 Subject: [PATCH] Add display plugin introspection to the window scripting interface --- .../scripting/WindowScriptingInterface.cpp | 33 ++++++++++++++++ .../src/scripting/WindowScriptingInterface.h | 38 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 2c1311924f..e1272d68a7 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include "AndroidHelper.h" @@ -609,3 +610,35 @@ void WindowScriptingInterface::onMessageBoxSelected(int button) { float WindowScriptingInterface::domainLoadingProgress() { return qApp->getOctreePacketProcessor().domainLoadingProgress(); } + +const DisplayPluginList& getDisplayPlugins() { + static const auto& list = PluginManager::getInstance()->getDisplayPlugins(); + return list; +} + +int WindowScriptingInterface::getDisplayPluginCount() { + return getDisplayPlugins().size(); +} + +QString WindowScriptingInterface::getDisplayPluginName(int index) { + return getDisplayPlugins().at(index)->getName(); +} + +bool WindowScriptingInterface::isDisplayPluginHmd(int index) { + return getDisplayPlugins().at(index)->isHmd(); +} + +int WindowScriptingInterface::getActiveDisplayPlugin() { + auto active = qApp->getActiveDisplayPlugin(); + auto size = getDisplayPluginCount(); + for (int i = 0; i < size; ++i) { + if (getDisplayPlugins().at(i) == active) { + return i; + } + } + return -1; +} + +void WindowScriptingInterface::setActiveDisplayPlugin(int index) { + qApp->setActiveDisplayPlugin(getDisplayPlugins().at(index)->getName()); +} diff --git a/interface/src/scripting/WindowScriptingInterface.h b/interface/src/scripting/WindowScriptingInterface.h index 77b586ec70..c165e5474e 100644 --- a/interface/src/scripting/WindowScriptingInterface.h +++ b/interface/src/scripting/WindowScriptingInterface.h @@ -575,6 +575,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);