载入中...
搜索中...
未找到
Touch.cpp
浏览该文件的文档.
1
2#include "touch/sdl/Touch.h"
3
5
6#include <SDL2/SDL_events.h>
7
8#include <algorithm>
9
10#include "common/Exception.h"
11
13
14namespace eve::touch::sdl {
15
17
19
20const std::vector<TouchInfo> &Touch::getTouches() const { return touches; }
21
22const TouchInfo &Touch::getTouch(int64_t id) const {
23 for (const auto &touch : touches) {
24 if (touch.id == id) return touch;
25 }
26
27 throw Exception("Invalid active touch ID: %d", id);
28}
29
30void Touch::onEvent(uint32_t eventtype, const TouchInfo &info) {
31 auto compare = [&](const TouchInfo &touch) -> bool { return touch.id == info.id; };
32
33 switch (eventtype) {
34 case SDL_FINGERDOWN:
35 touches.erase(std::remove_if(touches.begin(), touches.end(), compare), touches.end());
36 touches.push_back(info);
37 break;
38 case SDL_FINGERMOTION: {
39 for (TouchInfo &touch : touches) {
40 if (touch.id == info.id) touch = info;
41 }
42 break;
43 }
44 case SDL_FINGERUP: touches.erase(std::remove_if(touches.begin(), touches.end(), compare), touches.end()); break;
45 default: break;
46 }
47}
48
49} // namespace eve::touch::sdl
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
void onEvent(uint32_t eventtype, const TouchInfo &info)
Updates touch state from an SDL event conversion (event module).
Definition Touch.cpp:30
Touch()
Binds this backend into the SDL event sink.
Definition Touch.cpp:16
~Touch() override
Releases active touch tracking and clears the event-sink owner.
Definition Touch.cpp:18
const std::vector< TouchInfo > & getTouches() const override
Gets all currently active touches.
Definition Touch.cpp:20
const TouchInfo & getTouch(int64_t id) const override
Gets a specific touch, using its ID.
Definition Touch.cpp:22
void bindTouchEventSinkOwner(Touch *owner) noexcept
Bind the live Touch module into the SDL event sink. @ownership Borrowed; cleared when the Touch modul...
Definition EventSink.cpp:78
One active contact; id is unique only for the duration of the press.
Definition Touch.h:20
glm::uvec4 info