5 * Copyright (C) 2003, 2007 Thomas Perl <thp@perli.net>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
32 static SDL_Surface
*buffer
;
34 static Uint32 fading_start
= 0;
36 static const char* filenames
[] = {
47 void init_graphics( const char *data_dir
) {
51 char temp
[MAXPATHLEN
];
53 strcpy( temp
, data_dir
);
54 strcat( temp
, "icon.png");
55 tmp
= IMG_Load( temp
);
57 SDL_WM_SetIcon( tmp
, NULL
);
58 SDL_FreeSurface( tmp
);
61 images
= (Image
*)calloc( GR_COUNT
, sizeof( Image
));
63 for( i
=0; i
<GR_COUNT
; i
++) {
64 strcpy( temp
, data_dir
);
65 strcat( temp
, filenames
[i
]);
66 tmp
= IMG_Load( temp
);
68 fprintf( stderr
, "Error: %s\n", SDL_GetError());
72 SDL_SetColorKey( tmp
, SDL_SRCCOLORKEY
, SDL_MapRGB( tmp
->format
, 0, 0, 0));
73 data
= SDL_DisplayFormatAlpha( tmp
);
74 SDL_FreeSurface( tmp
);
77 fprintf( stderr
, "Error: %s\n", SDL_GetError());
80 images
[i
].data
= data
;
83 buffer
= SDL_CreateRGBSurface( SDL_HWSURFACE
, WIDTH
, HEIGHT
, screen
->format
->BitsPerPixel
, screen
->format
->Rmask
, screen
->format
->Gmask
, screen
->format
->Bmask
, screen
->format
->Amask
);
86 fprintf( stderr
, "Cannot create buffer surface: %s\n", SDL_GetError());
90 void uninit_graphics() {
93 for( i
=0; i
<GR_COUNT
; i
++) {
94 SDL_FreeSurface( images
[i
].data
);
98 SDL_FreeSurface( buffer
);
104 void show_sprite( unsigned int id
, int pos
, int items
, int x_offset
, int y_offset
, int opacity
) {
108 bitmap
= images
[id
].data
;
112 SDL_SetAlpha( bitmap
, SDL_SRCALPHA
| SDL_RLEACCEL
, opacity
);
114 dst
.w
= src
.w
= bitmap
->w
/items
;
115 dst
.h
= src
.h
= bitmap
->h
;
121 SDL_BlitSurface( bitmap
, &src
, screen
, &dst
);
124 void line_horiz( int y
, Uint8 r
, Uint8 g
, Uint8 b
) {
125 Uint32 color
= SDL_MapRGB( screen
->format
, r
, g
, b
);
133 SDL_FillRect( screen
, &rect
, color
);
136 void line_vert( int x
, Uint8 r
, Uint8 g
, Uint8 b
) {
137 Uint32 color
= SDL_MapRGB( screen
->format
, r
, g
, b
);
145 SDL_FillRect( screen
, &rect
, color
);
148 void rectangle( int x
, int y
, int w
, int h
, Uint8 r
, Uint8 g
, Uint8 b
) {
149 Uint32 color
= SDL_MapRGB( screen
->format
, r
, g
, b
);
157 SDL_FillRect( screen
, &rect
, color
);
160 void show_image( unsigned int id
, int x_offset
, int y_offset
, int opacity
) {
161 show_sprite( id
, 0, 1, x_offset
, y_offset
, opacity
);
164 void show_digit( int zahl
, int x_offset
, int y_offset
, int opacity
) {
165 show_sprite( GR_SCORE
, zahl
, 11, x_offset
, y_offset
, opacity
);
168 void introimage( unsigned int id
) {
171 for( i
=0; i
<256; i
+=10) {
173 show_image( id
, 0, 0, i
);
181 for( i
=255; i
>=0; i
-=10) {
183 show_image( id
, 0, 0, i
);
199 SDL_FillRect( screen
, &rect
, SDL_MapRGB( screen
->format
, 0, 0, 0));
203 int ticks
= SDL_GetTicks();
205 if( ticks
< fading_start
+FADE_DURATION
) {
206 SDL_SetAlpha( buffer
, SDL_SRCALPHA
| SDL_RLEACCEL
, 255-255*(ticks
-fading_start
)/FADE_DURATION
);
207 SDL_BlitSurface( buffer
, NULL
, screen
, NULL
);
210 SDL_UpdateRect( screen
, 0, 0, 0, 0);
215 SDL_BlitSurface( screen
, NULL
, buffer
, NULL
);
216 fading_start
= SDL_GetTicks();