| 172 | } |
| 173 | |
| 174 | SDL_bool |
| 175 | WatchGameController(SDL_GameController * gamecontroller) |
| 176 | { |
| 177 | const char *name = SDL_GameControllerName(gamecontroller); |
| 178 | const char *basetitle = "Game Controller Test: "; |
| 179 | const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1; |
| 180 | char *title = (char *)SDL_malloc(titlelen); |
| 181 | SDL_Window *window = NULL; |
| 182 | |
| 183 | retval = SDL_FALSE; |
| 184 | done = SDL_FALSE; |
| 185 | |
| 186 | if (title) { |
| 187 | SDL_snprintf(title, titlelen, "%s%s", basetitle, name); |
| 188 | } |
| 189 | |
| 190 | /* Create a window to display controller state */ |
| 191 | window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, |
| 192 | SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, |
| 193 | SCREEN_HEIGHT, 0); |
| 194 | SDL_free(title); |
| 195 | title = NULL; |
| 196 | if (window == NULL) { |
| 197 | SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError()); |
| 198 | return SDL_FALSE; |
| 199 | } |
| 200 | |
| 201 | screen = SDL_CreateRenderer(window, -1, 0); |
| 202 | if (screen == NULL) { |
| 203 | SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError()); |
| 204 | SDL_DestroyWindow(window); |
| 205 | return SDL_FALSE; |
| 206 | } |
| 207 | |
| 208 | SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE); |
| 209 | SDL_RenderClear(screen); |
| 210 | SDL_RenderPresent(screen); |
| 211 | SDL_RaiseWindow(window); |
| 212 | |
| 213 | /* scale for platforms that don't give you the window size you asked for. */ |
| 214 | SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT); |
| 215 | |
| 216 | background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE); |
| 217 | button = LoadTexture(screen, "button.bmp", SDL_TRUE); |
| 218 | axis = LoadTexture(screen, "axis.bmp", SDL_TRUE); |
| 219 | |
| 220 | if (!background || !button || !axis) { |
| 221 | SDL_DestroyRenderer(screen); |
| 222 | SDL_DestroyWindow(window); |
| 223 | return SDL_FALSE; |
| 224 | } |
| 225 | SDL_SetTextureColorMod(button, 10, 255, 21); |
| 226 | SDL_SetTextureColorMod(axis, 10, 255, 21); |
| 227 | |
| 228 | /* !!! FIXME: */ |
| 229 | /*SDL_RenderSetLogicalSize(screen, background->w, background->h);*/ |
| 230 | |
| 231 | /* Print info about the controller we are watching */ |
no test coverage detected