comparison render_sdl.c @ 1804:34370330eaf3

Support controllers that have their dpad mapped to an axis
author Michael Pavone <pavone@retrodev.com>
date Tue, 26 Mar 2019 23:26:08 -0700
parents ed6c38cd288c
children c2057d79998c
comparison
equal deleted inserted replaced
1803:a851d36e24bb 1804:34370330eaf3
1862 warning("Failed to open game controller %d: %s\n", controller, SDL_GetError()); 1862 warning("Failed to open game controller %d: %s\n", controller, SDL_GetError());
1863 return RENDER_NOT_PLUGGED_IN; 1863 return RENDER_NOT_PLUGGED_IN;
1864 } 1864 }
1865 1865
1866 SDL_GameControllerButtonBind cbind; 1866 SDL_GameControllerButtonBind cbind;
1867 int32_t is_positive = RENDER_AXIS_POS;
1867 if (is_axis) { 1868 if (is_axis) {
1868 1869
1869 int sdl_axis = render_lookup_axis(name); 1870 int sdl_axis = render_lookup_axis(name);
1870 if (sdl_axis == SDL_CONTROLLER_AXIS_INVALID) { 1871 if (sdl_axis == SDL_CONTROLLER_AXIS_INVALID) {
1871 SDL_GameControllerClose(control); 1872 SDL_GameControllerClose(control);
1876 int sdl_button = render_lookup_button(name); 1877 int sdl_button = render_lookup_button(name);
1877 if (sdl_button == SDL_CONTROLLER_BUTTON_INVALID) { 1878 if (sdl_button == SDL_CONTROLLER_BUTTON_INVALID) {
1878 SDL_GameControllerClose(control); 1879 SDL_GameControllerClose(control);
1879 return RENDER_INVALID_NAME; 1880 return RENDER_INVALID_NAME;
1880 } 1881 }
1882 if (sdl_button == SDL_CONTROLLER_BUTTON_DPAD_UP || sdl_button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) {
1883 //assume these will be negative if they are an axis
1884 is_positive = 0;
1885 }
1881 cbind = SDL_GameControllerGetBindForButton(control, sdl_button); 1886 cbind = SDL_GameControllerGetBindForButton(control, sdl_button);
1882 } 1887 }
1883 SDL_GameControllerClose(control); 1888 SDL_GameControllerClose(control);
1884 switch (cbind.bindType) 1889 switch (cbind.bindType)
1885 { 1890 {
1886 case SDL_CONTROLLER_BINDTYPE_BUTTON: 1891 case SDL_CONTROLLER_BINDTYPE_BUTTON:
1887 return cbind.value.button; 1892 return cbind.value.button;
1888 case SDL_CONTROLLER_BINDTYPE_AXIS: 1893 case SDL_CONTROLLER_BINDTYPE_AXIS:
1889 return RENDER_AXIS_BIT | cbind.value.axis; 1894 return RENDER_AXIS_BIT | cbind.value.axis | is_positive;
1890 case SDL_CONTROLLER_BINDTYPE_HAT: 1895 case SDL_CONTROLLER_BINDTYPE_HAT:
1891 return RENDER_DPAD_BIT | (cbind.value.hat.hat << 4) | cbind.value.hat.hat_mask; 1896 return RENDER_DPAD_BIT | (cbind.value.hat.hat << 4) | cbind.value.hat.hat_mask;
1892 } 1897 }
1893 return RENDER_NOT_MAPPED; 1898 return RENDER_NOT_MAPPED;
1894 } 1899 }