From edb96ea4d28590b9b26e827a67873704b31c431b Mon Sep 17 00:00:00 2001 From: nodoteve Date: Sat, 17 Jul 2021 21:06:23 +0300 Subject: [PATCH] added pointerCount to MouseEvent, some /* comments */ --- .vscode/settings.json | 72 ++++++++++++++++++++++ src/Magnum/Platform/AndroidApplication.cpp | 17 +++-- src/Magnum/Platform/AndroidApplication.h | 10 ++- 3 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..c20977176 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,72 @@ +{ + "files.associations": { + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "csignal": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "array": "cpp", + "atomic": "cpp", + "strstream": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "chrono": "cpp", + "cinttypes": "cpp", + "compare": "cpp", + "complex": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdint": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "ostream": "cpp", + "ranges": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cfenv": "cpp", + "typeindex": "cpp", + "typeinfo": "cpp", + "valarray": "cpp", + "variant": "cpp" + } +} \ No newline at end of file diff --git a/src/Magnum/Platform/AndroidApplication.cpp b/src/Magnum/Platform/AndroidApplication.cpp index 4682e87eb..1fb5cb1ad 100644 --- a/src/Magnum/Platform/AndroidApplication.cpp +++ b/src/Magnum/Platform/AndroidApplication.cpp @@ -287,12 +287,17 @@ std::int32_t AndroidApplication::inputEvent(android_app* state, AInputEvent* eve // always >= 1 const std::size_t pointerCount = AMotionEvent_getPointerCount(event); - // Get the persistent id from the index (for what if we have a pointerIndex?) + // Get the persistent id from the index + // (for what if we have a pointerIndex? + // They are a bit different. + // Pointer id saves the order of touch events, + // so if you would _release_ them in various orders, + // the 'pointerId' will have the value of initial 'pointerIndex', which might be useful. + // Btw, somehow 'pointerId' does not tell you the last released touch initial index) std::int32_t pointerId = AMotionEvent_getPointerId(event, pointerIndex); - - - // pointerId = (pointerId < 0 ? 0 : (size_t)pointerId); - + // I suppose pointerId less or eq to pointerIndex max val + + //MouseMoveEvent does not support id for now, but it probably should (see AMOTION_EVENT_ACTION_MOVE) if(pointerId >= arraySize(app._previousMouseMovePosition)) Containers::arrayAppend(app._previousMouseMovePosition, @@ -302,7 +307,7 @@ std::int32_t AndroidApplication::inputEvent(android_app* state, AInputEvent* eve app._previousMouseMovePosition[pointerId] = {Int(AMotionEvent_getX(event, pointerIndex)), Int(AMotionEvent_getY(event, pointerIndex))}; - MouseEvent e(event, pointerIndex, pointerId); + MouseEvent e(event, pointerIndex, pointerId, pointerCount); action == AMOTION_EVENT_ACTION_POINTER_DOWN ? app.mousePressEvent(e) : app.mouseReleaseEvent(e); return e.isAccepted() ? 1 : 0; diff --git a/src/Magnum/Platform/AndroidApplication.h b/src/Magnum/Platform/AndroidApplication.h index 92a7b0767..c7b8997e8 100644 --- a/src/Magnum/Platform/AndroidApplication.h +++ b/src/Magnum/Platform/AndroidApplication.h @@ -815,6 +815,7 @@ class AndroidApplication::MouseEvent: public InputEvent { } /** @brief Pointer Index Do we need both of them? + * Do we really need brief descriptions for index, id, count? * Index != Id */ std::size_t pointerIndex() const { return _pointerIndex; } @@ -824,14 +825,19 @@ class AndroidApplication::MouseEvent: public InputEvent { */ std::size_t pointerId() const { return _pointerId; } + /** @brief Pointer count */ + std::size_t pointerCount() const { return _pointerCount; } + private: // Did it almost like MouseMoveEvent with _relativePosition - explicit MouseEvent(AInputEvent* event, std::size_t pointerIndex = 0, std::int32_t pointerId = 0): + explicit MouseEvent(AInputEvent* event, std::size_t pointerIndex = 0, std::int32_t pointerId = 0, std::size_t pointerCount = 1): /* why not {}, but () instead? */ InputEvent(event), - _pointerId{pointerId},_pointerIndex{pointerIndex} {} + _pointerId{pointerId},_pointerIndex{pointerIndex},_pointerCount{pointerCount} {} const std::int32_t _pointerId; const std::size_t _pointerIndex; + const std::size_t _pointerCount; + }; /**