diff --git a/src/plugins/score-plugin-gfx/Gfx/Graph/ScreenNode.cpp b/src/plugins/score-plugin-gfx/Gfx/Graph/ScreenNode.cpp index 8dd2d14ff7..748b09431b 100644 --- a/src/plugins/score-plugin-gfx/Gfx/Graph/ScreenNode.cpp +++ b/src/plugins/score-plugin-gfx/Gfx/Graph/ScreenNode.cpp @@ -298,6 +298,7 @@ void ScreenNode::createOutput( m_window->setVulkanInstance(staticVulkanInstance()); #endif QObject::connect(m_window.get(), &Window::mouseMove, [this] (QPointF s, QPointF w) { if(onMouseMove) onMouseMove(s,w); }); + QObject::connect(m_window.get(), &Window::tabletMove, [this] (QTabletEvent* e) { if(onTabletMove) onTabletMove(e); }); QObject::connect(m_window.get(), &Window::key, [this] (int k, const QString& t) { if(onKey) onKey(k, t); }); m_window->onUpdate = std::move(onUpdate); m_window->onWindowReady = [this, graphicsApi, onReady = std::move(onReady)] { diff --git a/src/plugins/score-plugin-gfx/Gfx/Graph/ScreenNode.hpp b/src/plugins/score-plugin-gfx/Gfx/Graph/ScreenNode.hpp index c933137cea..e28a6f5053 100644 --- a/src/plugins/score-plugin-gfx/Gfx/Graph/ScreenNode.hpp +++ b/src/plugins/score-plugin-gfx/Gfx/Graph/ScreenNode.hpp @@ -2,6 +2,7 @@ #include class QScreen; +class QTabletEvent; namespace score::gfx { /** @@ -44,6 +45,7 @@ struct SCORE_PLUGIN_GFX_EXPORT ScreenNode : OutputNode const std::shared_ptr& window() const noexcept { return m_window; } std::function onMouseMove; + std::function onTabletMove; std::function onKey; private: class BasicRenderer; diff --git a/src/plugins/score-plugin-gfx/Gfx/Graph/Window.cpp b/src/plugins/score-plugin-gfx/Gfx/Graph/Window.cpp index 044508e305..6c06c689d4 100644 --- a/src/plugins/score-plugin-gfx/Gfx/Graph/Window.cpp +++ b/src/plugins/score-plugin-gfx/Gfx/Graph/Window.cpp @@ -184,6 +184,16 @@ bool Window::event(QEvent* e) render(); break; + case QEvent::TabletMove: + { + auto ev = static_cast(e); + this->tabletMove(ev); + break; + } + case QEvent::TabletPress: + case QEvent::TabletRelease: + break; + case QEvent::MouseMove: { auto ev = static_cast(e); diff --git a/src/plugins/score-plugin-gfx/Gfx/Graph/Window.hpp b/src/plugins/score-plugin-gfx/Gfx/Graph/Window.hpp index cbd3eade39..f59f111ea1 100644 --- a/src/plugins/score-plugin-gfx/Gfx/Graph/Window.hpp +++ b/src/plugins/score-plugin-gfx/Gfx/Graph/Window.hpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace score::gfx { struct ScreenNode; @@ -39,11 +40,15 @@ class Window : public QWindow std::function onRender; std::function onResize; + void tabletMove(QTabletEvent* ev) + W_SIGNAL(tabletMove, ev); void mouseMove(QPointF screen, QPointF win) - W_SIGNAL(mouseMove, screen, win); + W_SIGNAL(mouseMove, screen, win); + void key(int key, const QString& t) - W_SIGNAL(key, key, t); + W_SIGNAL(key, key, t); + private: std::shared_ptr state; GraphicsApi m_api{}; @@ -56,3 +61,5 @@ class Window : public QWindow bool m_hasSwapChain = false; }; } + +W_REGISTER_ARGTYPE(QTabletEvent*) diff --git a/src/plugins/score-plugin-gfx/Gfx/WindowDevice.cpp b/src/plugins/score-plugin-gfx/Gfx/WindowDevice.cpp index 9cb012ca89..a2e805852e 100644 --- a/src/plugins/score-plugin-gfx/Gfx/WindowDevice.cpp +++ b/src/plugins/score-plugin-gfx/Gfx/WindowDevice.cpp @@ -141,11 +141,95 @@ class window_device : public ossia::net::device_base m_root.add_child(std::move(node)); } + // Tablet input + ossia::net::parameter_base* scaled_tablet_win{}; + ossia::net::parameter_base* abs_tablet_win{}; + { + auto node = std::make_unique("tablet", *this, m_root); + ossia::net::parameter_base* tablet_pressure{}; + ossia::net::parameter_base* tablet_z{}; + ossia::net::parameter_base* tablet_tan{}; + ossia::net::parameter_base* tablet_rot{}; + ossia::net::parameter_base* tablet_tilt_x{}; + ossia::net::parameter_base* tablet_tilt_y{}; + { + auto scale_node = std::make_unique("scaled", *this, *node); + scaled_tablet_win = scale_node->create_parameter(ossia::val_type::VEC2F); + scaled_tablet_win->set_domain(ossia::make_domain(0.f, 1.f)); + scaled_tablet_win->push_value(ossia::vec2f{0.f, 0.f}); + node->add_child(std::move(scale_node)); + } + { + auto abs_node = std::make_unique("absolute", *this, *node); + abs_tablet_win = abs_node->create_parameter(ossia::val_type::VEC2F); + abs_tablet_win->set_domain(ossia::make_domain(ossia::vec2f{0.f, 0.f}, ossia::vec2f{1280, 270.f})); + abs_tablet_win->push_value(ossia::vec2f{0.f, 0.f}); + node->add_child(std::move(abs_node)); + } + { + auto scale_node = std::make_unique("z", *this, *node); + tablet_z = scale_node->create_parameter(ossia::val_type::INT); + node->add_child(std::move(scale_node)); + } + { + auto scale_node = std::make_unique("pressure", *this, *node); + tablet_pressure = scale_node->create_parameter(ossia::val_type::FLOAT); + //tablet_pressure->set_domain(ossia::make_domain(0.f, 1.f)); + //tablet_pressure->push_value(0.f); + node->add_child(std::move(scale_node)); + } + { + auto scale_node = std::make_unique("tangential", *this, *node); + tablet_tan = scale_node->create_parameter(ossia::val_type::FLOAT); + tablet_tan->set_domain(ossia::make_domain(-1.f, 1.f)); + //tablet_tan->push_value(0.f); + node->add_child(std::move(scale_node)); + } + { + auto scale_node = std::make_unique("rotation", *this, *node); + tablet_rot = scale_node->create_parameter(ossia::val_type::FLOAT); + tablet_rot->set_unit(ossia::degree_u{}); + tablet_rot->set_domain(ossia::make_domain(-180.f, 180.f)); + node->add_child(std::move(scale_node)); + } + { + auto scale_node = std::make_unique("tilt_x", *this, *node); + tablet_tilt_x = scale_node->create_parameter(ossia::val_type::FLOAT); + tablet_tilt_x->set_domain(ossia::make_domain(-60.f, 60.f)); + tablet_tilt_x->set_unit(ossia::degree_u{}); + node->add_child(std::move(scale_node)); + } + { + auto scale_node = std::make_unique("tilt_y", *this, *node); + tablet_tilt_y = scale_node->create_parameter(ossia::val_type::FLOAT); + tablet_tilt_y->set_domain(ossia::make_domain(-60.f, 60.f)); + tablet_tilt_y->set_unit(ossia::degree_u{}); + node->add_child(std::move(scale_node)); + } + + m_screen->onTabletMove = [=] (QTabletEvent* ev){ + if(const auto& w = m_screen->window()) + { + const auto sz = w->size(); + const auto win = ev->posF(); + scaled_tablet_win->push_value(ossia::vec2f{float(win.x() / sz.width()), float(win.y() / sz.height())}); + abs_tablet_win->push_value(ossia::vec2f{float(win.x()), float(win.y())}); + tablet_pressure->push_value(ev->pressure()); + tablet_tan->push_value(ev->tangentialPressure()); + tablet_rot->push_value(ev->rotation()); + tablet_tilt_x->push_value(ossia::vec2f{float(ev->xTilt()), float(ev->yTilt())}); + tablet_tilt_y->push_value(ossia::vec2f{float(ev->xTilt()), float(ev->yTilt())}); + } + }; + + m_root.add_child(std::move(node)); + } + { auto size_node = std::make_unique("size", *this, m_root); auto size_param = size_node->create_parameter(ossia::val_type::VEC2F); size_param->push_value(ossia::vec2f{1280.f, 720.f}); - size_param->add_callback([this, abs_win] (const ossia::value& v) { + size_param->add_callback([this, abs_win, abs_tablet_win] (const ossia::value& v) { if(auto val = v.target()) { ossia::qt::run_async(&m_qtContext, [screen=this->m_screen, v=*val] { @@ -154,7 +238,10 @@ class window_device : public ossia::net::device_base auto dom = abs_win->get_domain(); ossia::set_max(dom, *val); - abs_win->set_domain(std::move(dom)); + { + abs_win->set_domain(std::move(dom)); + abs_tablet_win->set_domain(std::move(dom)); + } } });