Example #1
0
        private static float READTYPE_ReadFloat(MonoGameJoystickValue input, IntPtr device)
        {
            float inputMask = input.INPUT_INVERT ? -1.0f : 1.0f;

            if (input.INPUT_TYPE == InputType.Axis)
            {
                // SDL2 clamps to 32767 on both sides.
                float maxRange = input.INPUT_INVERT ? -32767.0f : 32767.0f;
                return(((float)SDL.SDL_JoystickGetAxis(device, input.INPUT_ID)) / maxRange);
            }
            else if (input.INPUT_TYPE == InputType.Button)
            {
                return(SDL.SDL_JoystickGetButton(device, input.INPUT_ID) * inputMask);
            }
            else if (input.INPUT_TYPE == InputType.PovUp ||
                     input.INPUT_TYPE == InputType.PovDown ||
                     input.INPUT_TYPE == InputType.PovLeft ||
                     input.INPUT_TYPE == InputType.PovRight)
            {
                return((SDL.SDL_JoystickGetHat(device, input.INPUT_ID) & (byte)input.INPUT_TYPE) * inputMask);
            }
            return(0.0f);
        }
Example #2
0
 private static bool READTYPE_ReadBool(MonoGameJoystickValue input, IntPtr device, short deadZone)
 {
     if (input.INPUT_TYPE == InputType.Axis)
     {
         short axis = SDL.SDL_JoystickGetAxis(device, input.INPUT_ID);
         if (input.INPUT_INVERT)
         {
             return(axis < -deadZone);
         }
         return(axis > deadZone);
     }
     else if (input.INPUT_TYPE == InputType.Button)
     {
         return((SDL.SDL_JoystickGetButton(device, input.INPUT_ID) > 0) ^ input.INPUT_INVERT);
     }
     else if (input.INPUT_TYPE == InputType.PovUp ||
              input.INPUT_TYPE == InputType.PovDown ||
              input.INPUT_TYPE == InputType.PovLeft ||
              input.INPUT_TYPE == InputType.PovRight)
     {
         return(((SDL.SDL_JoystickGetHat(device, input.INPUT_ID) & (byte)input.INPUT_TYPE) > 0) ^ input.INPUT_INVERT);
     }
     return(false);
 }
Example #3
0
 private static float READTYPE_ReadFloat(MonoGameJoystickValue input, IntPtr device)
 {
     float inputMask = input.INPUT_INVERT ? -1.0f : 1.0f;
     if (input.INPUT_TYPE == InputType.Axis)
     {
         // SDL2 clamps to 32767 on both sides.
         float maxRange = input.INPUT_INVERT ? -32767.0f : 32767.0f;
         return ((float) SDL.SDL_JoystickGetAxis(device, input.INPUT_ID)) / maxRange;
     }
     else if (input.INPUT_TYPE == InputType.Button)
     {
         return SDL.SDL_JoystickGetButton(device, input.INPUT_ID) * inputMask;
     }
     else if (	input.INPUT_TYPE == InputType.PovUp ||
             input.INPUT_TYPE == InputType.PovDown ||
             input.INPUT_TYPE == InputType.PovLeft ||
             input.INPUT_TYPE == InputType.PovRight	)
     {
         return (SDL.SDL_JoystickGetHat(device, input.INPUT_ID) & (byte) input.INPUT_TYPE) * inputMask;
     }
     return 0.0f;
 }
Example #4
0
 private static void INTERNAL_ClearButton(ref MonoGameJoystickValue value)
 {
     value.INPUT_TYPE   = InputType.None;
     value.INPUT_ID     = -1;
     value.INPUT_INVERT = false;
 }
Example #5
0
 private static bool READTYPE_ReadBool(MonoGameJoystickValue input, IntPtr device, short deadZone)
 {
     if (input.INPUT_TYPE == InputType.Axis)
     {
         short axis = SDL.SDL_JoystickGetAxis(device, input.INPUT_ID);
         if (input.INPUT_INVERT)
         {
             return (axis < -deadZone);
         }
         return (axis > deadZone);
     }
     else if (input.INPUT_TYPE == InputType.Button)
     {
         return ((SDL.SDL_JoystickGetButton(device, input.INPUT_ID) > 0) ^ input.INPUT_INVERT);
     }
     else if (	input.INPUT_TYPE == InputType.PovUp ||
             input.INPUT_TYPE == InputType.PovDown ||
             input.INPUT_TYPE == InputType.PovLeft ||
             input.INPUT_TYPE == InputType.PovRight	)
     {
         return (((SDL.SDL_JoystickGetHat(device, input.INPUT_ID) & (byte) input.INPUT_TYPE) > 0) ^ input.INPUT_INVERT);
     }
     return false;
 }