2024-05-03 22:34:10 +01:00
|
|
|
#include "TouchDevice.hpp"
|
|
|
|
|
#include "../defines.hpp"
|
2024-07-21 13:09:54 +02:00
|
|
|
#include <aquamarine/input/Input.hpp>
|
2024-05-03 22:34:10 +01:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
SP<CTouchDevice> CTouchDevice::create(SP<Aquamarine::ITouch> touch) {
|
2024-05-03 22:34:10 +01:00
|
|
|
SP<CTouchDevice> pTouch = SP<CTouchDevice>(new CTouchDevice(touch));
|
|
|
|
|
|
2025-04-29 19:51:07 +02:00
|
|
|
pTouch->m_self = pTouch;
|
2024-05-03 22:34:10 +01:00
|
|
|
|
|
|
|
|
return pTouch;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-29 19:51:07 +02:00
|
|
|
CTouchDevice::CTouchDevice(SP<Aquamarine::ITouch> touch_) : m_touch(touch_) {
|
|
|
|
|
if (!m_touch)
|
2024-05-03 22:34:10 +01:00
|
|
|
return;
|
|
|
|
|
|
2025-07-08 09:56:40 -07:00
|
|
|
m_listeners.destroy = m_touch->events.destroy.listen([this] {
|
2025-04-29 19:51:07 +02:00
|
|
|
m_events.destroy.emit();
|
|
|
|
|
m_touch.reset();
|
2024-07-21 13:09:54 +02:00
|
|
|
});
|
2024-05-03 22:34:10 +01:00
|
|
|
|
2025-07-08 09:56:40 -07:00
|
|
|
m_listeners.down = m_touch->events.down.listen([this](const Aquamarine::ITouch::SDownEvent& event) {
|
2025-04-29 19:51:07 +02:00
|
|
|
m_touchEvents.down.emit(SDownEvent{
|
2025-07-08 09:56:40 -07:00
|
|
|
.timeMs = event.timeMs,
|
|
|
|
|
.touchID = event.touchID,
|
|
|
|
|
.pos = event.pos,
|
2025-04-29 19:51:07 +02:00
|
|
|
.device = m_self.lock(),
|
2024-05-03 22:34:10 +01:00
|
|
|
});
|
2024-07-21 13:09:54 +02:00
|
|
|
});
|
2024-05-03 22:34:10 +01:00
|
|
|
|
2025-07-08 09:56:40 -07:00
|
|
|
m_listeners.up = m_touch->events.up.listen([this](const Aquamarine::ITouch::SUpEvent& event) {
|
2025-04-29 19:51:07 +02:00
|
|
|
m_touchEvents.up.emit(SUpEvent{
|
2025-07-08 09:56:40 -07:00
|
|
|
.timeMs = event.timeMs,
|
|
|
|
|
.touchID = event.touchID,
|
2024-05-03 22:34:10 +01:00
|
|
|
});
|
2024-07-21 13:09:54 +02:00
|
|
|
});
|
2024-05-03 22:34:10 +01:00
|
|
|
|
2025-07-08 09:56:40 -07:00
|
|
|
m_listeners.motion = m_touch->events.move.listen([this](const Aquamarine::ITouch::SMotionEvent& event) {
|
2025-04-29 19:51:07 +02:00
|
|
|
m_touchEvents.motion.emit(SMotionEvent{
|
2025-07-08 09:56:40 -07:00
|
|
|
.timeMs = event.timeMs,
|
|
|
|
|
.touchID = event.touchID,
|
|
|
|
|
.pos = event.pos,
|
2024-05-03 22:34:10 +01:00
|
|
|
});
|
2024-07-21 13:09:54 +02:00
|
|
|
});
|
2024-05-03 22:34:10 +01:00
|
|
|
|
2025-07-08 09:56:40 -07:00
|
|
|
m_listeners.cancel = m_touch->events.cancel.listen([this](const Aquamarine::ITouch::SCancelEvent& event) {
|
2025-04-29 19:51:07 +02:00
|
|
|
m_touchEvents.cancel.emit(SCancelEvent{
|
2025-07-08 09:56:40 -07:00
|
|
|
.timeMs = event.timeMs,
|
|
|
|
|
.touchID = event.touchID,
|
2024-05-03 22:34:10 +01:00
|
|
|
});
|
2024-07-21 13:09:54 +02:00
|
|
|
});
|
2024-05-03 22:34:10 +01:00
|
|
|
|
2025-07-08 09:56:40 -07:00
|
|
|
m_listeners.frame = m_touch->events.frame.listen([this] { m_touchEvents.frame.emit(); });
|
2024-05-03 22:34:10 +01:00
|
|
|
|
2025-04-29 19:51:07 +02:00
|
|
|
m_deviceName = m_touch->getName();
|
2024-05-03 22:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CTouchDevice::isVirtual() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
SP<Aquamarine::ITouch> CTouchDevice::aq() {
|
2025-04-29 19:51:07 +02:00
|
|
|
return m_touch.lock();
|
2024-05-03 22:34:10 +01:00
|
|
|
}
|