Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5131 | clevermous | 1 | |
2 | |||
3 | |||
4 | #include |
||
5 | #include |
||
6 | |||
7 | |||
8 | #include "picture.xbm" |
||
9 | |||
10 | |||
11 | { |
||
12 | SDL_Surface *bitmap; |
||
13 | Uint8 *line; |
||
14 | |||
15 | |||
16 | bitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 1, 0, 0, 0, 0); |
||
17 | if ( bitmap == NULL ) { |
||
18 | fprintf(stderr, "Couldn't allocate bitmap: %s\n", |
||
19 | SDL_GetError()); |
||
20 | return(NULL); |
||
21 | } |
||
22 | |||
23 | |||
24 | line = (Uint8 *)bitmap->pixels; |
||
25 | w = (w+7)/8; |
||
26 | while ( h-- ) { |
||
27 | memcpy(line, bits, w); |
||
28 | /* X11 Bitmap images have the bits reversed */ |
||
29 | { int i, j; Uint8 *buf, byte; |
||
30 | for ( buf=line, i=0; i |
||
31 | byte = *buf; |
||
32 | *buf = 0; |
||
33 | for ( j=7; j>=0; --j ) { |
||
34 | *buf |= (byte&0x01)< |
||
35 | byte >>= 1; |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 | line += bitmap->pitch; |
||
40 | bits += w; |
||
41 | } |
||
42 | return(bitmap); |
||
43 | } |
||
44 | |||
45 | |||
46 | { |
||
47 | SDL_Surface *screen; |
||
48 | SDL_Surface *bitmap; |
||
49 | Uint8 video_bpp; |
||
50 | Uint32 videoflags; |
||
51 | Uint8 *buffer; |
||
52 | int i, done; |
||
53 | SDL_Event event; |
||
54 | |||
55 | |||
56 | if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { |
||
57 | fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); |
||
58 | exit(1); |
||
59 | } |
||
60 | atexit(SDL_Quit); |
||
61 | |||
62 | |||
63 | videoflags = SDL_SWSURFACE; |
||
64 | /* Set 640x480 video mode */ |
||
65 | if ( (screen=SDL_SetVideoMode(640,480,video_bpp,videoflags)) == NULL ) { |
||
66 | fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n", |
||
67 | video_bpp, SDL_GetError()); |
||
68 | exit(2); |
||
69 | } |
||
70 | |||
71 | |||
72 | if ( SDL_LockSurface(screen) < 0 ) { |
||
73 | fprintf(stderr, "Couldn't lock the display surface: %s\n", |
||
74 | SDL_GetError()); |
||
75 | exit(2); |
||
76 | } |
||
77 | buffer=(Uint8 *)screen->pixels; |
||
78 | for ( i=0; i |
||
79 | memset(buffer,(i*255)/screen->h, screen->pitch); |
||
80 | buffer += screen->pitch; |
||
81 | } |
||
82 | SDL_UnlockSurface(screen); |
||
83 | SDL_UpdateRect(screen, 0, 0, 0, 0); |
||
84 | |||
85 | |||
86 | bitmap = LoadXBM(screen, picture_width, picture_height, |
||
87 | (Uint8 *)picture_bits); |
||
88 | if ( bitmap == NULL ) { |
||
89 | exit(1); |
||
90 | } |
||
91 | |||
92 | |||
93 | done = 0; |
||
94 | while ( !done ) { |
||
95 | /* Check for events */ |
||
96 | while ( SDL_PollEvent(&event) ) { |
||
97 | switch (event.type) { |
||
98 | case SDL_MOUSEBUTTONDOWN: { |
||
99 | SDL_Rect dst; |
||
100 | |||
101 | |||
102 | dst.y = event.button.y - bitmap->h/2; |
||
103 | dst.w = bitmap->w; |
||
104 | dst.h = bitmap->h; |
||
105 | SDL_BlitSurface(bitmap, NULL, |
||
106 | screen, &dst); |
||
107 | SDL_UpdateRects(screen,1,&dst); |
||
108 | } |
||
109 | break; |
||
110 | case SDL_KEYDOWN: |
||
111 | /* Any key press quits the app... */ |
||
112 | done = 1; |
||
113 | break; |
||
114 | case SDL_QUIT: |
||
115 | done = 1; |
||
116 | break; |
||
117 | default: |
||
118 | break; |
||
119 | } |
||
120 | } |
||
121 | } |
||
122 | SDL_FreeSurface(bitmap); |
||
123 | return(0); |
||
124 | }>> |
||
125 | > |