Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 5168:2b1989f59674
Extended SDL_SetWindowData() to allow arbitrary named values.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 03 Feb 2011 11:16:57 -0800 |
parents | fb424691cfc7 |
children | 4d39eeaad00b |
comparison
equal
deleted
inserted
replaced
5167:97423d858a1a | 5168:2b1989f59674 |
---|---|
980 if (_this->SetWindowIcon) { | 980 if (_this->SetWindowIcon) { |
981 _this->SetWindowIcon(_this, window, icon); | 981 _this->SetWindowIcon(_this, window, icon); |
982 } | 982 } |
983 } | 983 } |
984 | 984 |
985 void | 985 void* |
986 SDL_SetWindowData(SDL_Window * window, void *userdata) | 986 SDL_SetWindowData(SDL_Window * window, const char *name, void *userdata) |
987 { | 987 { |
988 CHECK_WINDOW_MAGIC(window, ); | 988 SDL_WindowUserData *prev, *data; |
989 | 989 |
990 window->userdata = userdata; | 990 CHECK_WINDOW_MAGIC(window, NULL); |
991 | |
992 /* See if the named data already exists */ | |
993 prev = NULL; | |
994 for (data = window->data; data; prev = data, data = data->next) { | |
995 if (SDL_strcmp(data->name, name) == 0) { | |
996 void *last_value = data->data; | |
997 | |
998 if (userdata) { | |
999 /* Set the new value */ | |
1000 data->data = userdata; | |
1001 } else { | |
1002 /* Delete this value */ | |
1003 if (prev) { | |
1004 prev->next = data->next; | |
1005 } else { | |
1006 window->data = data->next; | |
1007 } | |
1008 SDL_free(data->name); | |
1009 SDL_free(data); | |
1010 } | |
1011 return last_value; | |
1012 } | |
1013 } | |
1014 | |
1015 /* Add new data to the window */ | |
1016 if (userdata) { | |
1017 data = (SDL_WindowUserData *)SDL_malloc(sizeof(*data)); | |
1018 data->name = SDL_strdup(name); | |
1019 data->data = userdata; | |
1020 data->next = window->data; | |
1021 window->data = data; | |
1022 } | |
1023 return NULL; | |
991 } | 1024 } |
992 | 1025 |
993 void * | 1026 void * |
994 SDL_GetWindowData(SDL_Window * window) | 1027 SDL_GetWindowData(SDL_Window * window, const char *name) |
995 { | 1028 { |
1029 SDL_WindowUserData *data; | |
1030 | |
996 CHECK_WINDOW_MAGIC(window, NULL); | 1031 CHECK_WINDOW_MAGIC(window, NULL); |
997 | 1032 |
998 return window->userdata; | 1033 for (data = window->data; data; data = data->next) { |
1034 if (SDL_strcmp(data->name, name) == 0) { | |
1035 return data->data; | |
1036 } | |
1037 } | |
1038 return NULL; | |
999 } | 1039 } |
1000 | 1040 |
1001 void | 1041 void |
1002 SDL_SetWindowPosition(SDL_Window * window, int x, int y) | 1042 SDL_SetWindowPosition(SDL_Window * window, int x, int y) |
1003 { | 1043 { |
1291 { | 1331 { |
1292 SDL_VideoDisplay *display; | 1332 SDL_VideoDisplay *display; |
1293 | 1333 |
1294 CHECK_WINDOW_MAGIC(window, ); | 1334 CHECK_WINDOW_MAGIC(window, ); |
1295 | 1335 |
1336 /* Restore video mode, etc. */ | |
1337 SDL_UpdateFullscreenMode(window, SDL_FALSE); | |
1338 | |
1339 if (_this->DestroyWindow) { | |
1340 _this->DestroyWindow(_this, window); | |
1341 } | |
1342 if (window->flags & SDL_WINDOW_OPENGL) { | |
1343 SDL_GL_UnloadLibrary(); | |
1344 } | |
1345 | |
1346 /* Now invalidate magic */ | |
1347 window->magic = NULL; | |
1348 | |
1349 /* Free memory associated with the window */ | |
1296 if (window->title) { | 1350 if (window->title) { |
1297 SDL_free(window->title); | 1351 SDL_free(window->title); |
1298 } | 1352 } |
1299 | 1353 while (window->data) { |
1300 /* Restore video mode, etc. */ | 1354 SDL_WindowUserData *data = window->data; |
1301 SDL_UpdateFullscreenMode(window, SDL_FALSE); | 1355 |
1302 | 1356 window->data = data->next; |
1303 if (_this->DestroyWindow) { | 1357 SDL_free(data->name); |
1304 _this->DestroyWindow(_this, window); | 1358 SDL_free(data); |
1305 } | 1359 } |
1306 if (window->flags & SDL_WINDOW_OPENGL) { | |
1307 SDL_GL_UnloadLibrary(); | |
1308 } | |
1309 | |
1310 /* Now invalidate magic */ | |
1311 window->magic = NULL; | |
1312 | 1360 |
1313 /* Unlink the window from the list */ | 1361 /* Unlink the window from the list */ |
1314 display = window->display; | 1362 display = window->display; |
1315 if (window->next) { | 1363 if (window->next) { |
1316 window->next->prev = window->prev; | 1364 window->next->prev = window->prev; |