2#ifndef GRAMODS_TOUCH_TOUCHSTATE
3#define GRAMODS_TOUCH_TOUCHSTATE
5#include <gmTouch/config.hh>
7#include <gmMisc/EFFOAW.hh>
16#include <unordered_map>
17#include <unordered_set>
21BEGIN_NAMESPACE_GMTOUCH;
76 typedef std::chrono::steady_clock
clock;
95 static const unsigned char NONE = 0;
98 static const unsigned char DRAG = 0x01 << 0;
101 static const unsigned char HOLD = 0x01 << 1;
107 static const unsigned char MULTI = 0x01 << 2;
111 static const unsigned char TOUCH_DOWN = 0x01 << 3;
114 static const unsigned char RELEASE = 0x01 << 4;
118 static const unsigned char CLICK = 0x01 << 5;
219 bool empty()
const {
return current_state.empty(); }
227 int getTouchPoints(TouchPoints ¤t)
const;
238 int getTouchPoints(TouchPoints ¤t, TouchPoints &previous)
const;
252 int getTouchPoints(
void *ass, TouchPoints ¤t)
const;
270 int getTouchPoints(
void *ass, TouchPoints ¤t, TouchPoints &previous)
const;
279 int getTouchPoints(std::map<void*, TouchPoints> ¤t)
const;
290 int getTouchPoints(std::map<void*, TouchPoints> ¤t,
291 std::map<void*, TouchPoints> &previous)
const;
300 bool setAssociation(TouchPointId
id,
void* pt);
310 bool unsetAssociation(TouchPointId
id,
void* pt);
323 bool getAssociation(TouchPointId
id,
void** pt)
const;
349 void setCurrentProjection(Eigen::Matrix4f WPV_inv);
365 virtual void init(
int width,
int height);
389 void setCurrentProjection(Eigen::Matrix4f WPV_inv);
404 T & getCameraAdaptor();
414 bool getTouchLines(
TouchLines ¤t)
const;
436 bool getTouchLines(
void *ass,
TouchLines ¤t)
const;
458 bool getTouchLines(std::map<void*, TouchLines> ¤t)
const;
470 bool getTouchLines(std::map<void*, TouchLines> ¤t,
471 std::map<void*, TouchLines> &previous)
const;
483 float getMouseWheel()
const;
488 bool getMouseDown()
const;
493 void getMousePoint(
int &x,
int &y)
const;
499 bool getMouseLine(Eigen::Vector3f &x,
500 Eigen::Vector3f &v)
const;
515 void setSmoothing(
float r);
521 float getSmoothing();
528 void setRemoveMouseUponTouch(
bool on);
534 bool getRemoveMouseUponTouch();
547 void setMoveMagnitude(
float dist);
553 float getMoveMagnitude();
559 void setHoldTime(clock::duration time);
565 clock::duration getHoldTime();
571 void setClickTime(clock::duration time);
577 clock::duration getClickTime();
584 void setMultiClickTime(clock::duration time);
590 clock::duration getMultiClickTime();
613 virtual void init(
int,
int);
634 void removeTouchState(
TouchPointId id,
float x,
float y);
640 void addMouseState(
float x,
float y,
bool mouse_down);
645 void addMouseWheel(
float s);
660 T & getEventAdaptor();
669 void eventsInit(
int width,
int height);
681 struct HistoryState {
683 clock::time_point time;
695 void addTouchState(TouchPointId
id,
float x,
float y);
700 void removeTouchState(TouchPointId
id,
float x,
float y);
706 void addMouseState(
float x,
float y,
bool mouse_down);
711 void addMouseWheel(
float s);
716 void addState(TouchPointId
id,
float x,
float y);
718 clock::time_point start_time = clock::time_point::min();
720 float velocity_reestimation_rate;
723 float move_magnitude;
724 clock::duration hold_time;
725 clock::duration click_time;
726 clock::duration multi_time;
728 bool remove_mouse_upon_touch =
true;
729 bool use_mouse =
true;
731 std::map<TouchPointId, TouchPoint> current_state;
732 std::map<TouchPointId, TouchPoint> previous_state;
734 std::map<TouchPointId, void*> last_association;
735 std::map<TouchPointId, void*> current_association;
737 std::map<TouchPointId, HistoryState> history;
746 void check_multi(TouchPoint &new_pt);
755 void check_drag(HistoryState hist, TouchPoint &new_pt);
764 void check_hold(HistoryState hist, TouchPoint &new_pt);
773 void check_click(HistoryState hist, TouchPoint &new_pt);
779 void clearReleasedStates();
787 TouchLine touchPointToTouchLine(TouchPoint pt, Eigen::Matrix4f WPV_inv)
const;
789 Eigen::Matrix4f current_WPV_inv;
790 bool current_WPV_inv_valid =
false;
792 Eigen::Matrix4f previous_WPV_inv;
793 bool previous_WPV_inv_valid =
false;
795 int current_height = -1;
796 int previous_height = -1;
797 int current_width = -1;
798 int previous_width = -1;
800 float mouse_wheel = 0.f;
801 bool mouse_down =
false;
802 int mouse_point_x = 0;
803 int mouse_point_y = 0;
805 std::unordered_map<std::type_index, EventAdaptor*> event_adaptors;
806 std::unordered_map<std::type_index, CameraAdaptor*> camera_adaptors;
811T & TouchState::getEventAdaptor() {
812 if (event_adaptors.find(
typeid(T)) == event_adaptors.end()) {
813 event_adaptors[
typeid(T)] =
new T;
814 event_adaptors[
typeid(T)]->owner =
this;
816 assert(
dynamic_cast<T*
>(event_adaptors[
typeid(T)]));
817 return *
dynamic_cast<T*
>(event_adaptors[
typeid(T)]);
821T & TouchState::getCameraAdaptor() {
822 if (camera_adaptors.find(
typeid(T)) == camera_adaptors.end()) {
823 camera_adaptors[
typeid(T)] =
new T;
824 camera_adaptors[
typeid(T)]->owner =
this;
826 assert(
dynamic_cast<T*
>(camera_adaptors[
typeid(T)]));
827 return *
dynamic_cast<T*
>(camera_adaptors[
typeid(T)]);
830END_NAMESPACE_GMTOUCH;
This is an end-fitting first-order adaptive window estimator of velocity from samples allowing jitter...
Definition EFFOAW.hh:34
The TouchState class represent the internal states during touch interaction.
Definition TouchState.hh:65
std::chrono::steady_clock clock
The clock used in this class.
Definition TouchState.hh:76
std::vector< TouchLine > TouchLines
List of touch lines.
Definition TouchState.hh:209
int64_t TouchPointId
The internal type of a touch point id.
Definition TouchState.hh:83
static const TouchPointId MOUSE_STATE_ID
The touch point id used for mouse pointer simulating touch.
Definition TouchState.hh:88
bool empty() const
Checks whether the TouchState is empty of touch points.
Definition TouchState.hh:219
std::vector< TouchPoint > TouchPoints
List of touch points.
Definition TouchState.hh:176
Base type for camera adaptors providing means to input camera data from different scenegraph or graph...
Definition TouchState.hh:358
Base type for event adaptors providing means to input events from different platforms and window libr...
Definition TouchState.hh:606
Touch states that can be bitwise combined (except NONE).
Definition TouchState.hh:94
A 3D line representation of a touch point.
Definition TouchState.hh:181
TouchPointId id
internal id of the touch point.
Definition TouchState.hh:190
unsigned int clicks
The number of times this position was clicked in succession, for example two (2) for a double click.
Definition TouchState.hh:203
unsigned char state
State of the touch point expressed as a bitwise combination.
Definition TouchState.hh:197
Eigen::Vector3f x
The origin of the 3D line.
Definition TouchState.hh:184
Eigen::Vector3f v
The direction of the 3D line.
Definition TouchState.hh:187
A single (potentially smoothed) touch point.
Definition TouchState.hh:124
float y
y position in (sub) pixels from top edge.
Definition TouchState.hh:136
float vy
y velocity in pixels per second from top edge.
Definition TouchState.hh:142
unsigned char state
State of the touch point expressed as a bitwise combination.
Definition TouchState.hh:164
float ey
y position estimated by the recent motion.
Definition TouchState.hh:148
TouchPointId id
internal id of the touch point.
Definition TouchState.hh:157
float sx
smoothed version of the x position.
Definition TouchState.hh:151
float ex
x position estimated by the recent motion.
Definition TouchState.hh:145
float x
x position in (sub) pixels from left edge.
Definition TouchState.hh:133
float vx
x velocity in pixels per second from left edge.
Definition TouchState.hh:139
float sy
smoothed version of the y position.
Definition TouchState.hh:154
unsigned int clicks
The number of times this position was clicked in succession, for example two (2) for a double click.
Definition TouchState.hh:170