1 module des.app.ftouch;
2 
3 import derelict.sdl2.sdl;
4 
5 import des.util.arch;
6 import des.app.evproc;
7 
8 /// finger touch event
9 struct FTouchEvent
10 {
11     ///
12     enum Type
13     {
14         MOTION = SDL_FINGERMOTION, /// SDL_FINGERMOTION,
15         DOWN   = SDL_FINGERDOWN,   /// SDL_FINGERDOWN,
16         UP     = SDL_FINGERUP      /// SDL_FINGERUP
17     }
18 
19     ///
20     Type type;
21 
22     /// touch device index
23     size_t touch_id;
24 
25     /// finger index
26     size_t finger_id;
27 
28     /// position [(0,0)..(1,1)]
29     vec2 pos;
30 
31     /// moved distance [(0,0)..(1,1)]
32     vec2 rel;
33 
34     ///
35     float pressure;
36 }
37 
38 ///
39 alias in_FTouchEvent = ref const(FTouchEvent);
40 
41 /// finger touch event processor
42 class FTouchEventProcessor : BaseSDLEventProcessor
43 {
44     ///
45     Signal!( in_FTouchEvent ) signal;
46 
47     ///
48     alias signal this;
49 
50     bool procSDLEvent( in SDL_Event ev )
51     {
52         switch( ev.type )
53         {
54             case SDL_FINGERMOTION:
55             case SDL_FINGERDOWN:
56             case SDL_FINGERUP:
57                 with( ev.tfinger )
58                     signal( FTouchEvent(
59                                 cast(FTouchEvent.Type)ev.type,
60                                 touchId,
61                                 fingerId,
62                                 vec2(x,y),
63                                 vec2(dx,dy),
64                                 pressure )
65                           );
66                 return true;
67             default: return false;
68         }
69     }
70 }