Usermode/AxWin3 - Bugfixing rendering/layout issues
[tpg/acess2.git] / Usermode / Applications / axwin3_src / WM / input.c
index ebbad92..a35f913 100644 (file)
@@ -8,15 +8,29 @@
 #include <common.h>
 #include <acess/sys.h>
 
+// TODO: Move out to a common header
 typedef struct
 {
        int Num;
        int Value;
 } tNumValue;
-
 #define JOY_IOCTL_GETSETAXISLIMIT      6
 #define JOY_IOCTL_GETSETAXISPOSITION   7
 
+// === IMPORTS ===
+extern void    Video_SetCursorPos(short X, short Y);
+extern void    WM_Input_MouseMoved(int OldX, int OldY, int NewX, int NewY);
+extern void    WM_Input_MouseButton(int X, int Y, int Button, int Pressed);
+const char     *gsMouseDevice;
+extern int     giTerminalFD;
+extern int     giScreenWidth;
+extern int     giScreenHeight;
+
+// === GLOBALS ===
+ int   giMouseFD;
+ int   giInput_MouseButtonState;
+ int   giInput_MouseX, giInput_MouseY;
+
 // === CODE ===
 int Input_Init(void)
 {
@@ -26,16 +40,17 @@ int Input_Init(void)
        giMouseFD = open(gsMouseDevice, 3);
 
        // Set mouse limits
-       num_value.Num = 0;
-       num_value.Value = giScreenWidth;
+       // TODO: Update these if the screen resolution changes
+       num_value.Num = 0;      num_value.Value = giScreenWidth;
        ioctl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value);
        num_value.Value = giScreenWidth/2;
+       giInput_MouseX = giScreenWidth/2;
        ioctl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value);
 
-       num_value.Num = 1;
-       num_value.Value = giScreenHeight;
+       num_value.Num = 1;      num_value.Value = giScreenHeight;
        ioctl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value);
        num_value.Value = giScreenHeight/2;
+       giInput_MouseY = giScreenHeight/2;
        ioctl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value);
 
        return 0;
@@ -64,6 +79,7 @@ void Input_HandleSelect(fd_set *set)
 
        if(FD_ISSET(giMouseFD, set))
        {
+                int    i;
                struct sMouseInfo {
                        uint16_t        NAxies;
                        uint16_t        NButtons;
@@ -85,6 +101,25 @@ void Input_HandleSelect(fd_set *set)
 
                // Handle movement
                Video_SetCursorPos( mouseinfo.Axies[0].CursorPos, mouseinfo.Axies[1].CursorPos );
-//             _SysDebug("Cursor to %i,%i", mouseinfo.Axies[0].CursorPos, mouseinfo.Axies[1].CursorPos);
+
+               WM_Input_MouseMoved(
+                       giInput_MouseX, giInput_MouseY,
+                       mouseinfo.Axies[0].CursorPos, mouseinfo.Axies[1].CursorPos
+                       );
+               giInput_MouseX = mouseinfo.Axies[0].CursorPos;
+               giInput_MouseY = mouseinfo.Axies[1].CursorPos;
+
+               for( i = 0; i < mouseinfo.NButtons; i ++ )
+               {
+                       int bit = 1 << i;
+                       int cur = mouseinfo.Buttons[i] > 128;
+
+                       if( !!(giInput_MouseButtonState & bit) != cur )
+                       {
+                               WM_Input_MouseButton(giInput_MouseX, giInput_MouseY, i, cur);
+                               // Flip button state
+                               giInput_MouseButtonState ^= bit;
+                       }
+               }
        }
 }

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