set up sixense/vive menu items with correct event forwarding

This commit is contained in:
SamGondelman 2015-07-22 11:36:31 -07:00
parent e3bc4b3b89
commit 505ef4c5cc
7 changed files with 31 additions and 14 deletions

View file

@ -4870,13 +4870,15 @@ void Application::removeMenu(const QString& menuName) {
Menu::getInstance()->removeMenu(menuName);
}
void Application::addMenuItem(const QString& path, const QString& name, std::function<void()> onClicked, bool checkable, bool checked, const QString& groupName) {
void Application::addMenuItem(const QString& path, const QString& name, std::function<void(bool)> onClicked, bool checkable, bool checked, const QString& groupName) {
auto menu = Menu::getInstance();
MenuWrapper* parentItem = menu->getMenu(path);
QAction* action = parentItem->addAction(name);
connect(action, &QAction::triggered, [=] {
onClicked();
onClicked(action->isChecked());
});
action->setCheckable(checkable);
action->setChecked(checked);
_currentDisplayPluginActions.push_back({ path, name });
_currentInputPluginActions.push_back({ path, name });
}

View file

@ -282,7 +282,7 @@ public:
// Plugin container support
virtual void addMenu(const QString& menuName);
virtual void removeMenu(const QString& menuName);
virtual void addMenuItem(const QString& path, const QString& name, std::function<void()> onClicked, bool checkable, bool checked, const QString& groupName);
virtual void addMenuItem(const QString& path, const QString& name, std::function<void(bool)> onClicked, bool checkable, bool checked, const QString& groupName);
virtual void removeMenuItem(const QString& menuName, const QString& menuItem);
virtual bool isOptionChecked(const QString& name);
virtual void setIsOptionChecked(const QString& path, bool checked);

View file

@ -19,7 +19,7 @@
#include "ControllerScriptingInterface.h"
// TODO: this needs to be removed, as well as any related controller-specific information
#include <input-plugins\SixenseManager.h>
#include <input-plugins/SixenseManager.h>
ControllerScriptingInterface::ControllerScriptingInterface() :

View file

@ -56,7 +56,6 @@ const QString SixenseManager::NAME = "Sixense";
const QString MENU_PARENT = "Avatar";
const QString MENU_NAME = "Sixense";
const QString MENU_PATH = MENU_PARENT + ">" + MENU_NAME;
const QString RENDER_CONTROLLERS = "Render Hand Controllers";
const QString TOGGLE_SMOOTH = "Smooth Sixense Movement";
SixenseManager& SixenseManager::getInstance() {
@ -91,11 +90,8 @@ void SixenseManager::activate(PluginContainer* container) {
container->addMenu(MENU_PATH);
container->addMenuItem(MENU_PATH, TOGGLE_SMOOTH,
[this, &container] { this->setFilter(container->isOptionChecked(TOGGLE_SMOOTH)); },
[this, container] (bool clicked) { this->setFilter(clicked); },
true, true);
container->addMenuItem(MENU_PATH, RENDER_CONTROLLERS,
[this, &container] { /*this->setShouldRenderController(container->isOptionChecked(RENDER_CONTROLLERS));*/ },
true, true);
#ifdef __APPLE__
@ -128,7 +124,6 @@ void SixenseManager::activate(PluginContainer* container) {
void SixenseManager::deactivate(PluginContainer* container) {
#ifdef HAVE_SIXENSE
container->removeMenuItem(MENU_NAME, RENDER_CONTROLLERS);
container->removeMenuItem(MENU_NAME, TOGGLE_SMOOTH);
container->removeMenu(MENU_PATH);

View file

@ -17,8 +17,9 @@
#include <gpu/Batch.h>
#include <gpu/Context.h>
#include <DeferredLightingEffect.h>
#include <display-plugins\openvr\OpenVrHelpers.h>
#include <display-plugins/openvr/OpenVrHelpers.h>
#include "NumericalConstants.h"
#include <plugins/PluginContainer.h>
#include "UserActivityLogger.h"
extern vr::IVRSystem* _hmd;
@ -44,12 +45,18 @@ const QString CONTROLLER_MODEL_STRING = "vr_controller_05_wireless_b";
const QString ViveControllerManager::NAME = "OpenVR";
const QString MENU_PARENT = "Avatar";
const QString MENU_NAME = "Vive Controllers";
const QString MENU_PATH = MENU_PARENT + ">" + MENU_NAME;
const QString RENDER_CONTROLLERS = "Render Hand Controllers";
ViveControllerManager::ViveControllerManager() :
InputDevice("SteamVR Controller"),
_trackedControllers(0),
_modelLoaded(false),
_leftHandRenderID(0),
_rightHandRenderID(0)
_rightHandRenderID(0),
_renderControllers(false)
{
}
@ -59,6 +66,11 @@ bool ViveControllerManager::isSupported() const {
}
void ViveControllerManager::activate(PluginContainer* container) {
container->addMenu(MENU_PATH);
container->addMenuItem(MENU_PATH, RENDER_CONTROLLERS,
[this, &container] (bool clicked) { this->setRenderControllers(clicked); },
true, true);
hmdRefCount++;
if (!_hmd) {
vr::HmdError eError = vr::HmdError_None;
@ -111,10 +123,14 @@ void ViveControllerManager::activate(PluginContainer* container) {
_texture->autoGenerateMips(-1);
_modelLoaded = true;
_renderControllers = true;
}
}
void ViveControllerManager::deactivate(PluginContainer* container) {
container->removeMenuItem(MENU_NAME, RENDER_CONTROLLERS);
container->removeMenu(MENU_PATH);
hmdRefCount--;
if (hmdRefCount == 0 && _hmd) {

View file

@ -42,7 +42,7 @@ public:
AXIS_3,
AXIS_4,
};
enum JointChannel {
LEFT_HAND = 0,
RIGHT_HAND,
@ -68,6 +68,8 @@ public:
virtual void focusOutEvent() override;
void updateRendering(RenderArgs* args, render::ScenePointer scene, render::PendingChanges pendingChanges);
void setRenderControllers(bool renderControllers) { _renderControllers = renderControllers; }
UserInputMapper::Input makeInput(unsigned int button, int index);
UserInputMapper::Input makeInput(JoystickAxisChannel axis, int index);
@ -86,6 +88,8 @@ private:
model::Geometry _modelGeometry;
gpu::TexturePointer _texture;
bool _renderControllers;
int _leftHandRenderID;
int _rightHandRenderID;

View file

@ -9,7 +9,7 @@ class PluginContainer {
public:
virtual void addMenu(const QString& menuName) = 0;
virtual void removeMenu(const QString& menuName) = 0;
virtual void addMenuItem(const QString& path, const QString& name, std::function<void()> onClicked, bool checkable = false, bool checked = false, const QString& groupName = "") = 0;
virtual void addMenuItem(const QString& path, const QString& name, std::function<void(bool)> onClicked, bool checkable = false, bool checked = false, const QString& groupName = "") = 0;
virtual void removeMenuItem(const QString& menuName, const QString& menuItem) = 0;
virtual bool isOptionChecked(const QString& name) = 0;
virtual void setIsOptionChecked(const QString& path, bool checked) = 0;