1 module Dgame.System.Touch;
2 
3 private:
4 
5 import derelict.sdl2.sdl;
6 
7 public:
8 
9 /**
10  * The Finger structure
11  */
12 struct Finger {
13     /**
14      * The Finger ID
15      */
16     long id; // TODO: change to (u)int?
17     /**
18      * The x coordinate in range of 0 .. 1
19      * Multiply it with the width of the Window to get the real x coordinate
20      */
21     float x;
22     /**
23      * The y coordinate in range of 0 .. 1
24      * Multiply it with the height of the Window to get the real y coordinate
25      */
26     float y;
27     /**
28      * The quantity of pressure applied in range of 0 .. 1
29      */
30     float pressure;
31 }
32 
33 /**
34  * Represent Touch-Events
35  *
36  * Author: Randy Schuett (rswhite4@googlemail.com)
37  */
38 interface Touch {
39     /**
40      * Returns of many Touch-Devices exist
41      */
42     @nogc
43     static int getNumOfDevices() nothrow {
44         return SDL_GetNumTouchDevices();
45     }
46 
47     /**
48      * Returns the Touch-ID of the Touch-Device with the given index
49      */
50     @nogc
51     static long getDevice(int index) nothrow {
52         return SDL_GetTouchDevice(index);
53     }
54 
55     /**
56      * Returns the amount of (supported) fingers for the Touch-Device with the given ID
57      */
58     @nogc
59     static int getNumOfFingers(long touchId) nothrow {
60         return SDL_GetNumTouchFingers(touchId);
61     }
62 
63     /**
64      * Returns the Finger with the given index of the Touch.Device with the given ID
65      */
66     @nogc
67     static Finger getFinger(long touchId, int index) nothrow {
68         const SDL_Finger* sdl_finger = SDL_GetTouchFinger(touchId, index);
69 
70         return Finger(sdl_finger.id, sdl_finger.x, sdl_finger.y, sdl_finger.pressure);
71     }
72 }