Mercurial > sdl-ios-xcode
comparison test/common.c @ 4527:3ce59cbecaa3
Added support for testing window manager icons
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 14 Jul 2010 21:25:15 -0700 |
parents | 7b5e4396bcaa |
children | 12a9cf73596a |
comparison
equal
deleted
inserted
replaced
4526:c04dd942610d | 4527:3ce59cbecaa3 |
---|---|
4 #include <stdio.h> | 4 #include <stdio.h> |
5 | 5 |
6 #include "common.h" | 6 #include "common.h" |
7 | 7 |
8 #define VIDEO_USAGE \ | 8 #define VIDEO_USAGE \ |
9 "[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display N] [--fullscreen | --windows N] [--title title] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab] [--double] [--triple]" | 9 "[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display N] [--fullscreen | --windows N] [--title title] [--icon icon.bmp] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab] [--double] [--triple]" |
10 | 10 |
11 #define AUDIO_USAGE \ | 11 #define AUDIO_USAGE \ |
12 "[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]" | 12 "[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]" |
13 | 13 |
14 struct pformat { | 14 struct pformat { |
190 return -1; | 190 return -1; |
191 } | 191 } |
192 state->window_title = argv[index]; | 192 state->window_title = argv[index]; |
193 return 2; | 193 return 2; |
194 } | 194 } |
195 if (SDL_strcasecmp(argv[index], "--icon") == 0) { | |
196 ++index; | |
197 if (!argv[index]) { | |
198 return -1; | |
199 } | |
200 state->window_icon = argv[index]; | |
201 return 2; | |
202 } | |
195 if (SDL_strcasecmp(argv[index], "--center") == 0) { | 203 if (SDL_strcasecmp(argv[index], "--center") == 0) { |
196 state->window_x = SDL_WINDOWPOS_CENTERED; | 204 state->window_x = SDL_WINDOWPOS_CENTERED; |
197 state->window_y = SDL_WINDOWPOS_CENTERED; | 205 state->window_y = SDL_WINDOWPOS_CENTERED; |
198 return 1; | 206 return 1; |
199 } | 207 } |
607 | 615 |
608 if (info->max_texture_width || info->max_texture_height) { | 616 if (info->max_texture_width || info->max_texture_height) { |
609 fprintf(stderr, " Max Texture Size: %dx%d\n", | 617 fprintf(stderr, " Max Texture Size: %dx%d\n", |
610 info->max_texture_width, info->max_texture_height); | 618 info->max_texture_width, info->max_texture_height); |
611 } | 619 } |
620 } | |
621 | |
622 static SDL_Surface * | |
623 LoadIcon(const char *file) | |
624 { | |
625 SDL_Surface *icon; | |
626 | |
627 /* Load the icon surface */ | |
628 icon = SDL_LoadBMP(file); | |
629 if (icon == NULL) { | |
630 fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError()); | |
631 return (NULL); | |
632 } | |
633 | |
634 if (icon->format->palette == NULL) { | |
635 fprintf(stderr, "Icon must have a palette!\n"); | |
636 SDL_FreeSurface(icon); | |
637 return (NULL); | |
638 } | |
639 | |
640 /* Set the colorkey */ | |
641 SDL_SetColorKey(icon, 1, *((Uint8 *) icon->pixels)); | |
642 | |
643 return (icon); | |
612 } | 644 } |
613 | 645 |
614 SDL_bool | 646 SDL_bool |
615 CommonInit(CommonState * state) | 647 CommonInit(CommonState * state) |
616 { | 648 { |
789 if (SDL_SetWindowDisplayMode(state->windows[i], &fullscreen_mode) < 0) { | 821 if (SDL_SetWindowDisplayMode(state->windows[i], &fullscreen_mode) < 0) { |
790 fprintf(stderr, "Can't set up fullscreen display mode: %s\n", | 822 fprintf(stderr, "Can't set up fullscreen display mode: %s\n", |
791 SDL_GetError()); | 823 SDL_GetError()); |
792 return SDL_FALSE; | 824 return SDL_FALSE; |
793 } | 825 } |
826 | |
827 if (state->window_icon) { | |
828 SDL_Surface *icon = LoadIcon(state->window_icon); | |
829 if (icon) { | |
830 SDL_SetWindowIcon(state->windows[i], icon); | |
831 SDL_FreeSurface(icon); | |
832 } | |
833 } | |
834 | |
794 SDL_ShowWindow(state->windows[i]); | 835 SDL_ShowWindow(state->windows[i]); |
795 | 836 |
796 if (!state->skip_renderer | 837 if (!state->skip_renderer |
797 && (state->renderdriver | 838 && (state->renderdriver |
798 || !(state->window_flags & SDL_WINDOW_OPENGL))) { | 839 || !(state->window_flags & SDL_WINDOW_OPENGL))) { |