MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / WatchGameController

Function WatchGameController

deps/SDL2/test/testgamecontroller.c:174–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172}
173
174SDL_bool
175WatchGameController(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 */

Callers 1

mainFunction · 0.85

Calls 15

SDL_GameControllerNameFunction · 0.85
SDL_strlenFunction · 0.85
SDL_mallocFunction · 0.85
SDL_snprintfFunction · 0.85
SDL_CreateWindowFunction · 0.85
SDL_freeFunction · 0.85
SDL_LogErrorFunction · 0.85
SDL_GetErrorFunction · 0.85
SDL_CreateRendererFunction · 0.85
SDL_DestroyWindowFunction · 0.85
SDL_SetRenderDrawColorFunction · 0.85
SDL_RenderClearFunction · 0.85

Tested by

no test coverage detected