Skip to content

Commit

Permalink
[gfx] Add support for tablet events in window input
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Jun 13, 2022
1 parent fab5337 commit 3f4b1d8
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/plugins/score-plugin-gfx/Gfx/Graph/ScreenNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)] {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/score-plugin-gfx/Gfx/Graph/ScreenNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Gfx/Graph/OutputNode.hpp>

class QScreen;
class QTabletEvent;
namespace score::gfx
{
/**
Expand Down Expand Up @@ -44,6 +45,7 @@ struct SCORE_PLUGIN_GFX_EXPORT ScreenNode : OutputNode
const std::shared_ptr<Window>& window() const noexcept { return m_window; }

std::function<void(QPointF, QPointF)> onMouseMove;
std::function<void(QTabletEvent*)> onTabletMove;
std::function<void(int, const QString&)> onKey;
private:
class BasicRenderer;
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/score-plugin-gfx/Gfx/Graph/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@ bool Window::event(QEvent* e)
render();
break;

case QEvent::TabletMove:
{
auto ev = static_cast<QTabletEvent*>(e);
this->tabletMove(ev);
break;
}
case QEvent::TabletPress:
case QEvent::TabletRelease:
break;

case QEvent::MouseMove:
{
auto ev = static_cast<QMouseEvent*>(e);
Expand Down
11 changes: 9 additions & 2 deletions src/plugins/score-plugin-gfx/Gfx/Graph/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Gfx/Graph/RenderState.hpp>
#include <verdigris>
#include <QWindow>
#include <QTabletEvent>
namespace score::gfx
{
struct ScreenNode;
Expand Down Expand Up @@ -39,11 +40,15 @@ class Window : public QWindow
std::function<void(QRhiCommandBuffer&)> onRender;
std::function<void()> 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<RenderState> state;
GraphicsApi m_api{};
Expand All @@ -56,3 +61,5 @@ class Window : public QWindow
bool m_hasSwapChain = false;
};
}

W_REGISTER_ARGTYPE(QTabletEvent*)
91 changes: 89 additions & 2 deletions src/plugins/score-plugin-gfx/Gfx/WindowDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ossia::net::generic_node>("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<ossia::net::generic_node>("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<ossia::net::generic_node>("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<ossia::net::generic_node>("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<ossia::net::generic_node>("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<ossia::net::generic_node>("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<ossia::net::generic_node>("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<ossia::net::generic_node>("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<ossia::net::generic_node>("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<ossia::net::generic_node>("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::vec2f>())
{
ossia::qt::run_async(&m_qtContext, [screen=this->m_screen, v=*val] {
Expand All @@ -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));
}
}
});

Expand Down

0 comments on commit 3f4b1d8

Please sign in to comment.