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 images
= (Image
*)calloc( GR_COUNT
, sizeof( Image
));
55 for( i
=0; i
<GR_COUNT
; i
++) {
56 strcpy( temp
, data_dir
);
57 strcat( temp
, filenames
[i
]);
58 tmp
= IMG_Load( temp
);
60 fprintf( stderr
, "Error: %s\n", SDL_GetError());
64 SDL_SetColorKey( tmp
, SDL_SRCCOLORKEY
, SDL_MapRGB( tmp
->format
, 0, 0, 0));
65 data
= SDL_DisplayFormatAlpha( tmp
);
66 SDL_FreeSurface( tmp
);
69 fprintf( stderr
, "Error: %s\n", SDL_GetError());
72 images
[i
].data
= data
;
75 buffer
= SDL_CreateRGBSurface( SDL_HWSURFACE
, WIDTH
, HEIGHT
, screen
->format
->BitsPerPixel
, screen
->format
->Rmask
, screen
->format
->Gmask
, screen
->format
->Bmask
, screen
->format
->Amask
);
78 fprintf( stderr
, "Cannot create buffer surface: %s\n", SDL_GetError());
82 void uninit_graphics() {
85 for( i
=0; i
<GR_COUNT
; i
++) {
86 SDL_FreeSurface( images
[i
].data
);
90 SDL_FreeSurface( buffer
);
96 void show_sprite( unsigned int id
, int pos
, int items
, int x_offset
, int y_offset
, int opacity
) {
100 bitmap
= images
[id
].data
;
104 SDL_SetAlpha( bitmap
, SDL_SRCALPHA
| SDL_RLEACCEL
, opacity
);
106 dst
.w
= src
.w
= bitmap
->w
/items
;
107 dst
.h
= src
.h
= bitmap
->h
;
113 SDL_BlitSurface( bitmap
, &src
, screen
, &dst
);
116 void line_horiz( int y
, Uint8 r
, Uint8 g
, Uint8 b
) {
117 Uint32 color
= SDL_MapRGB( screen
->format
, r
, g
, b
);
125 SDL_FillRect( screen
, &rect
, color
);
128 void line_vert( int x
, Uint8 r
, Uint8 g
, Uint8 b
) {
129 Uint32 color
= SDL_MapRGB( screen
->format
, r
, g
, b
);
137 SDL_FillRect( screen
, &rect
, color
);
140 void rectangle( int x
, int y
, int w
, int h
, Uint8 r
, Uint8 g
, Uint8 b
) {
141 Uint32 color
= SDL_MapRGB( screen
->format
, r
, g
, b
);
149 SDL_FillRect( screen
, &rect
, color
);
152 void show_image( unsigned int id
, int x_offset
, int y_offset
, int opacity
) {
153 show_sprite( id
, 0, 1, x_offset
, y_offset
, opacity
);
156 void show_digit( int zahl
, int x_offset
, int y_offset
, int opacity
) {
157 show_sprite( GR_SCORE
, zahl
, 11, x_offset
, y_offset
, opacity
);
160 void introimage( unsigned int id
) {
163 for( i
=0; i
<256; i
+=10) {
165 show_image( id
, 0, 0, i
);
173 for( i
=255; i
>=0; i
-=10) {
175 show_image( id
, 0, 0, i
);
191 SDL_FillRect( screen
, &rect
, SDL_MapRGB( screen
->format
, 0, 0, 0));
195 int ticks
= SDL_GetTicks();
197 if( ticks
< fading_start
+FADE_DURATION
) {
198 SDL_SetAlpha( buffer
, SDL_SRCALPHA
| SDL_RLEACCEL
, 255-255*(ticks
-fading_start
)/FADE_DURATION
);
199 SDL_BlitSurface( buffer
, NULL
, screen
, NULL
);
202 SDL_UpdateRect( screen
, 0, 0, 0, 0);
207 SDL_BlitSurface( screen
, NULL
, buffer
, NULL
);
208 fading_start
= SDL_GetTicks();