You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GestureHandler.h 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Copyright 2019 Aaron Sowry for Cendio AB
  2. * Copyright 2020 Pierre Ossman for Cendio AB
  3. *
  4. * This is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this software; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. * USA.
  18. */
  19. #ifndef __GESTUREHANDLER_H__
  20. #define __GESTUREHANDLER_H__
  21. #include <set>
  22. #include <map>
  23. #include <rfb/Timer.h>
  24. #include "GestureEvent.h"
  25. class GestureHandler : public rfb::Timer::Callback {
  26. public:
  27. GestureHandler();
  28. virtual ~GestureHandler();
  29. void handleTouchBegin(int id, double x, double y);
  30. void handleTouchUpdate(int id, double x, double y);
  31. void handleTouchEnd(int id);
  32. protected:
  33. virtual void handleGestureEvent(const GestureEvent& event) = 0;
  34. private:
  35. bool hasDetectedGesture();
  36. virtual bool handleTimeout(rfb::Timer* t);
  37. void longpressTimeout();
  38. void twoTouchTimeout();
  39. void pushEvent(GestureEventType t);
  40. GestureEventGesture stateToGesture(unsigned char state);
  41. void getPosition(double *firstX, double *firstY,
  42. double *lastX, double *lastY);
  43. void getAverageMovement(double *h, double *v);
  44. void getAverageDistance(double *firstX, double *firstY,
  45. double *lastX, double *lastY);
  46. private:
  47. struct GHTouch {
  48. struct timeval started;
  49. bool active;
  50. double firstX;
  51. double firstY;
  52. double lastX;
  53. double lastY;
  54. int angle;
  55. };
  56. unsigned char state;
  57. std::map<int, GHTouch> tracked;
  58. std::set<int> ignored;
  59. bool waitingRelease;
  60. struct timeval releaseStart;
  61. rfb::Timer longpressTimer;
  62. rfb::Timer twoTouchTimer;
  63. };
  64. #endif // __GESTUREHANDLER_H__