void ViewerDialog::createMenuAndActions() { title->getToolBar()->setVisible(true); mMenu = new QMenu(this); aBack = new QAction("&Previus", this); aBack->setStatusTip("Show previus item"); aBack->setIcon(QIcon(":/res/resources/back.png")); title->getToolBar()->addAction(aBack); mMenu->addAction(aBack); connect(aBack, SIGNAL(triggered()), this, SLOT(backEvent())); aNext = new QAction("&Next", this); aNext->setStatusTip("Show next item"); aNext->setIcon(QIcon(":/res/resources/next.png")); title->getToolBar()->addAction(aNext); mMenu->addAction(aNext); connect(aNext, SIGNAL(triggered()), this, SLOT(nextEvent())); aSlide = new QAction("&Start slide show", this); aSlide->setStatusTip("Start slide show"); aSlide->setIcon(QIcon(":/res/resources/play.png")); title->getToolBar()->addAction(aSlide); mMenu->addAction(aSlide); connect(aSlide, SIGNAL(triggered()), this, SLOT(slideEvent())); connect(title->getCloseAction(), SIGNAL(triggered()), this, SLOT(closeEvent())); }
void SDL2Manager::pluginUpdate(float deltaTime, bool jointsCaptured) { #ifdef HAVE_SDL2 if (_isInitialized) { auto userInputMapper = DependencyManager::get<UserInputMapper>(); for (auto joystick : _openJoysticks) { joystick->update(deltaTime, jointsCaptured); } PerformanceTimer perfTimer("SDL2Manager::update"); SDL_GameControllerUpdate(); SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_CONTROLLERAXISMOTION) { Joystick* joystick = _openJoysticks[event.caxis.which]; if (joystick) { joystick->handleAxisEvent(event.caxis); } } else if (event.type == SDL_CONTROLLERBUTTONDOWN || event.type == SDL_CONTROLLERBUTTONUP) { Joystick* joystick = _openJoysticks[event.cbutton.which]; if (joystick) { joystick->handleButtonEvent(event.cbutton); } if (event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK) { // this will either start or stop a global back event QEvent::Type backType = (event.type == SDL_CONTROLLERBUTTONDOWN) ? HFBackEvent::startType() : HFBackEvent::endType(); HFBackEvent backEvent(backType); qApp->sendEvent(qApp, &backEvent); } } else if (event.type == SDL_CONTROLLERDEVICEADDED) { SDL_GameController* controller = SDL_GameControllerOpen(event.cdevice.which); SDL_JoystickID id = getInstanceId(controller); if (!_openJoysticks.contains(id)) { Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller); _openJoysticks[id] = joystick; joystick->registerToUserInputMapper(*userInputMapper); joystick->assignDefaultInputMapping(*userInputMapper); emit joystickAdded(joystick); } } else if (event.type == SDL_CONTROLLERDEVICEREMOVED) { Joystick* joystick = _openJoysticks[event.cdevice.which]; _openJoysticks.remove(event.cdevice.which); userInputMapper->removeDevice(joystick->getDeviceID()); emit joystickRemoved(joystick); } } } #endif }
void JoystickScriptingInterface::update() { #ifdef HAVE_SDL2 if (_isInitialized) { PerformanceTimer perfTimer("JoystickScriptingInterface::update"); SDL_GameControllerUpdate(); SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_CONTROLLERAXISMOTION) { Joystick* joystick = _openJoysticks[event.caxis.which]; if (joystick) { joystick->handleAxisEvent(event.caxis); } } else if (event.type == SDL_CONTROLLERBUTTONDOWN || event.type == SDL_CONTROLLERBUTTONUP) { Joystick* joystick = _openJoysticks[event.cbutton.which]; if (joystick) { joystick->handleButtonEvent(event.cbutton); } if (event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK) { // this will either start or stop a global back event QEvent::Type backType = (event.type == SDL_CONTROLLERBUTTONDOWN) ? HFBackEvent::startType() : HFBackEvent::endType(); HFBackEvent backEvent(backType); qApp->sendEvent(qApp, &backEvent); } else if (event.cbutton.button == SDL_CONTROLLER_BUTTON_A) { // this will either start or stop a global action event QEvent::Type actionType = (event.type == SDL_CONTROLLERBUTTONDOWN) ? HFActionEvent::startType() : HFActionEvent::endType(); // global action events fire in the center of the screen HFActionEvent actionEvent(actionType, Application::getInstance()->getCamera()->computeViewPickRay(0.5f, 0.5f)); qApp->sendEvent(qApp, &actionEvent); } } else if (event.type == SDL_CONTROLLERDEVICEADDED) { SDL_GameController* controller = SDL_GameControllerOpen(event.cdevice.which); SDL_JoystickID id = getInstanceId(controller); Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller); _openJoysticks[id] = joystick; emit joystickAdded(joystick); } else if (event.type == SDL_CONTROLLERDEVICEREMOVED) { Joystick* joystick = _openJoysticks[event.cdevice.which]; _openJoysticks.remove(event.cdevice.which); emit joystickRemoved(joystick); } } } #endif }