src/joystick/SDL_gamecontroller.c
changeset 7080 7353267a2ce2
parent 7055 76323a708ea5
child 7081 ab543a0ef80c
equal deleted inserted replaced
7079:99d6803195fe 7080:7353267a2ce2
   155 			{
   155 			{
   156 				if ( controllerlist->joystick->instance_id == event->jaxis.which )
   156 				if ( controllerlist->joystick->instance_id == event->jaxis.which )
   157 				{
   157 				{
   158 					if ( controllerlist->mapping.raxes[event->jaxis.axis] >= 0 ) // simple axis to axis, send it through
   158 					if ( controllerlist->mapping.raxes[event->jaxis.axis] >= 0 ) // simple axis to axis, send it through
   159 					{
   159 					{
   160 						SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.raxes[event->jaxis.axis], event->jaxis.value );
   160 						SDL_GameControllerAxis axis = controllerlist->mapping.raxes[event->jaxis.axis];
       
   161                         Sint16 value = event->jaxis.value;
       
   162 						switch (axis)
       
   163 						{
       
   164 							case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
       
   165 							case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
       
   166 								/* Shift it to be 0 - 32767. */
       
   167 								value = ( value + 32768 ) / 2;
       
   168 							default:
       
   169 								break;
       
   170 						}
       
   171 						SDL_PrivateGameControllerAxis( controllerlist, axis, value );
   161 					}
   172 					}
   162 					else if ( controllerlist->mapping.raxesasbutton[event->jaxis.axis] >= 0 ) // simlate an axis as a button
   173 					else if ( controllerlist->mapping.raxesasbutton[event->jaxis.axis] >= 0 ) // simlate an axis as a button
   163 					{
   174 					{
   164 						SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.raxesasbutton[event->jaxis.axis], ABS(event->jaxis.value) > 32768/2 ? SDL_PRESSED : SDL_RELEASED );
   175 						SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.raxesasbutton[event->jaxis.axis], ABS(event->jaxis.value) > 32768/2 ? SDL_PRESSED : SDL_RELEASED );
   165 					}
   176 					}
   185 					{
   196 					{
   186 						SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rbuttons[event->jbutton.button], event->jbutton.state );
   197 						SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rbuttons[event->jbutton.button], event->jbutton.state );
   187 					}
   198 					}
   188 					else if ( controllerlist->mapping.rbuttonasaxis[event->jbutton.button] >= 0 ) // an button pretending to be an axis
   199 					else if ( controllerlist->mapping.rbuttonasaxis[event->jbutton.button] >= 0 ) // an button pretending to be an axis
   189 					{
   200 					{
   190 						SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32768 : 0 );
   201 						SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32767 : 0 );
   191 					}
   202 					}
   192 					break;
   203 					break;
   193 				}
   204 				}
   194 				controllerlist = controllerlist->next;
   205 				controllerlist = controllerlist->next;
   195 			}
   206 			}