25 static constexpr int slots = 32;
28 float x{}, y{}, pressure{};
32 static QPointF
toClip(QPointF win, QSizeF sz)
noexcept
34 const double w = sz.width() > 0 ? sz.width() : 1.;
35 const double h = sz.height() > 0 ? sz.height() : 1.;
36 return {win.x() / w * 2. - 1., win.y() / h * -2. + 1.};
39 void move(
int slot,
float x,
float y)
noexcept
41 if(slot < 0 || slot >= slots)
43 std::lock_guard l{m_mtx};
48 void press(
int slot,
float pressure)
noexcept
50 if(slot < 0 || slot >= slots)
52 std::lock_guard l{m_mtx};
53 m_slots[slot].pressure = pressure;
60 std::lock_guard l{m_mtx};
62 for(
int i = 0; i < slots; i++)
64 if(m_touchIds[i] ==
id)
66 if(free < 0 && m_touchIds[i] == noTouch)
71 m_touchIds.fill(noTouch);
74 m_touchIds[free] = id;
78 void releaseTouch(
int id)
noexcept
80 std::lock_guard l{m_mtx};
81 for(
int i = 0; i < slots; i++)
82 if(m_touchIds[i] ==
id)
84 m_touchIds[i] = noTouch;
85 m_slots[i].pressure = 0.f;
89 std::array<Slot, slots> snapshot() const noexcept
91 std::lock_guard l{m_mtx};
96 static constexpr int noTouch = -1;
97 mutable std::mutex m_mtx;
98 std::array<Slot, slots> m_slots{};
99 std::array<int, slots> m_touchIds = [] {
100 std::array<int, slots> a;
static QPointF toClip(QPointF win, QSizeF sz) noexcept
Window position -> clip space over a window of size sz.
Definition PointerState.hpp:32