d72d6b681243357999c24652baead61f519daf66
[tpg/acess2.git] / Usermode / Applications / axwin3_src / WM / input.c
1 /*
2  * Acess2 GUI (AxWin) Version 3
3  * - By John Hodge (thePowersGang)
4  *
5  * input.c
6  * - Input abstraction
7  */
8 #include <common.h>
9 #include <acess/sys.h>
10
11 // TODO: Move out to a common header
12 typedef struct
13 {
14         int Num;
15         int Value;
16 } tNumValue;
17 #define JOY_IOCTL_GETSETAXISLIMIT       6
18 #define JOY_IOCTL_GETSETAXISPOSITION    7
19
20 // === IMPORTS ===
21 extern void     Video_SetCursorPos(short X, short Y);
22 // TODO: Move out
23 const char      *gsMouseDevice;
24  int    giTerminalFD;
25  int    giScreenWidth;
26  int    giScreenHeight;
27
28 // === GLOBALS ===
29  int    giMouseFD;
30
31 // === CODE ===
32 int Input_Init(void)
33 {
34         tNumValue       num_value;
35
36         // Open mouse for RW
37         giMouseFD = open(gsMouseDevice, 3);
38
39         // Set mouse limits
40         // TODO: Update these if the screen resolution changes
41         num_value.Num = 0;      num_value.Value = giScreenWidth;
42         ioctl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value);
43         num_value.Value = giScreenWidth/2;
44         ioctl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value);
45
46         num_value.Num = 1;      num_value.Value = giScreenHeight;
47         ioctl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value);
48         num_value.Value = giScreenHeight/2;
49         ioctl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value);
50
51         return 0;
52 }
53
54 void Input_FillSelect(int *nfds, fd_set *set)
55 {
56         if(*nfds < giTerminalFD)        *nfds = giTerminalFD;
57         if(*nfds < giMouseFD)   *nfds = giMouseFD;
58         FD_SET(giTerminalFD, set);
59         FD_SET(giMouseFD, set);
60 }
61
62 void Input_HandleSelect(fd_set *set)
63 {
64         if(FD_ISSET(giTerminalFD, set))
65         {
66                 uint32_t        codepoint;
67                 if( read(giTerminalFD, &codepoint, sizeof(codepoint)) != sizeof(codepoint) )
68                 {
69                         // oops, error
70                 }
71                 // TODO: pass on to message handler
72                 _SysDebug("Keypress 0x%x", codepoint);
73         }
74
75         if(FD_ISSET(giMouseFD, set))
76         {
77                 struct sMouseInfo {
78                         uint16_t        NAxies;
79                         uint16_t        NButtons;
80                         struct sMouseAxis {
81                                  int16_t        MinValue;
82                                  int16_t        MaxValue;
83                                  int16_t        CurValue;
84                                 uint16_t        CursorPos;
85                         }       Axies[2];
86                         uint8_t Buttons[3];
87                 }       mouseinfo;
88         
89                 seek(giMouseFD, 0, SEEK_SET);
90                 if( read(giMouseFD, &mouseinfo, sizeof(mouseinfo)) != sizeof(mouseinfo) )
91                 {
92                         // Not a 3 button mouse, oops
93                         return ;
94                 }
95
96                 // Handle movement
97                 Video_SetCursorPos( mouseinfo.Axies[0].CursorPos, mouseinfo.Axies[1].CursorPos );
98                 
99
100                 // TODO: Handle button presses
101         }
102 }

UCC git Repository :: git.ucc.asn.au