3#include <Gfx/GfxExecContext.hpp>
4#include <Gfx/GfxInputDevice.hpp>
5#include <Gfx/Graph/PointerState.hpp>
6#include <Gfx/Graph/TouchHistoryNode.hpp>
8#include <ossia/network/base/device.hpp>
9#include <ossia/network/base/node_attributes.hpp>
10#include <ossia/network/generic/generic_node.hpp>
38 ossia::net::parameter_base* clip{};
39 ossia::net::parameter_base* points{};
41 std::shared_ptr<score::gfx::PointerState>
pointers
42 = std::make_shared<score::gfx::PointerState>();
45 void add_clip(ossia::net::device_base& dev, ossia::net::node_base& cursor)
47 auto node = std::make_unique<ossia::net::generic_node>(
"clip", dev, cursor);
48 clip = node->create_parameter(ossia::val_type::VEC2F);
49 clip->set_domain(ossia::make_domain(-1.f, 1.f));
50 clip->push_value(ossia::vec2f{0.f, 0.f});
51 ossia::net::set_description(*node,
"Clip space, [-1, 1], y up");
52 cursor.add_child(std::move(node));
57 ossia::net::device_base& dev, ossia::net::node_base& root,
60 auto touch = std::make_unique<ossia::net::generic_node>(
"touch", dev, root);
62 auto node = std::make_unique<ossia::net::generic_node>(
"points", dev, *touch);
63 points = node->create_parameter(ossia::val_type::LIST);
64 ossia::net::set_description(
65 *node,
"32 pointers, [x, y, pressure] in clip space, y up; slot 0 is the "
66 "mouse or first finger");
67 points->set_value_quiet(to_value(
pointers->snapshot()));
68 points->add_callback([p =
pointers](
const ossia::value& v) { from_value(*p, v); });
69 touch->add_child(std::move(node));
73 auto node = std::make_unique<ossia::net::generic_node>(
"history", dev, *touch);
74 ossia::net::set_description(
75 *node,
"vertexshaderart's touch history: the last 240 frames of "
76 "touch/points, 32x240 RGBA32F (x, y, pressure, time), newest at v = 0");
77 node->set_parameter(std::make_unique<simple_texture_input_parameter>(
79 touch->add_child(std::move(node));
81 root.add_child(std::move(touch));
88 points->push_value(to_value(state.snapshot()));
95 if(!points || slot < 0 || slot >= score::gfx::PointerState::slots)
97 const ossia::value cur = points->value();
98 std::vector<ossia::value> l;
99 if(
auto* p = cur.target<std::vector<ossia::value>>())
101 l.resize(score::gfx::PointerState::slots, ossia::vec3f{0.f, 0.f, 0.f});
102 float pressure = 0.f;
103 if(
auto* p = l[slot].target<ossia::vec3f>())
105 l[slot] = ossia::vec3f{x, y, pressure};
106 points->push_value(std::move(l));
109 void set_clip(
float x,
float y)
112 clip->push_value(ossia::vec2f{x, y});
116 to_value(
const std::array<score::gfx::PointerState::Slot, score::gfx::PointerState::slots>& s)
118 std::vector<ossia::value> l;
120 for(
const auto& p : s)
121 l.emplace_back(ossia::vec3f{p.x, p.y, p.pressure});
127 auto* l = v.target<std::vector<ossia::value>>();
130 const int n = std::min<int>(
int(l->size()), score::gfx::PointerState::slots);
131 for(
int i = 0; i < n; i++)
133 const auto& e = (*l)[i];
134 if(
auto* p = e.target<ossia::vec3f>())
136 state.move(i, (*p)[0], (*p)[1]);
137 state.press(i, (*p)[2]);
139 else if(
auto* q = e.target<ossia::vec2f>())
141 state.move(i, (*q)[0], (*q)[1]);
143 else if(
auto* sub = e.target<std::vector<ossia::value>>(); sub && sub->size() >= 2)
145 state.move(i, ossia::convert<float>((*sub)[0]), ossia::convert<float>((*sub)[1]));
147 state.press(i, ossia::convert<float>((*sub)[2]));
Definition GfxExecContext.hpp:19
Binds the rendering pipeline to ossia processes.
Definition AssetTable.cpp:7
Definition PointerAddresses.hpp:37
void move_slot(int slot, float x, float y)
Definition PointerAddresses.hpp:93
void publish(const score::gfx::PointerState &state)
Publish the window's decoded pointers on touch/points.
Definition PointerAddresses.hpp:85
void add_touch(ossia::net::device_base &dev, ossia::net::node_base &root, GfxExecutionAction *context)
touch/points and touch/history, under root.
Definition PointerAddresses.hpp:56
void add_clip(ossia::net::device_base &dev, ossia::net::node_base &cursor)
cursor/clip, under an existing cursor node.
Definition PointerAddresses.hpp:45
std::shared_ptr< score::gfx::PointerState > pointers
What touch/history records; touch/points writes it.
Definition PointerAddresses.hpp:42
Definition PointerState.hpp:24
The pointers of an output as a texture: vertexshaderart's touch history (greggman/vertexshaderart,...
Definition TouchHistoryNode.hpp:46