1 /*
2     GUILIB:  An example GUI framework library for use with SDL
3 */
4 
5 /* This is a very simple image widget */
6 
7 #include "GUI_image.h"
8 
9 /* Passed the position and BMP image file */
GUI_Image(int x,int y,char * file)10 GUI_Image:: GUI_Image(int x, int y, char *file)
11  : GUI_Widget(NULL)
12 {
13 	SDL_Surface *picture;
14 
15 	picture = SDL_LoadBMP(file);
16 	if ( picture == NULL ) {
17 		SetError("Couldn't load %s: %s", file, SDL_GetError());
18 		return;
19 	}
20 //*****	GUI_Image(x, y, picture, 1); ***ERROR*** another constructor****
21 //*****	instead: set size manually...
22 	SetRect(x,y,picture->w,picture->h);
23 	image=picture;
24 	free_image=1;
25 }
26 
27 /* Passed the position and image */
GUI_Image(int x,int y,SDL_Surface * pic,int shouldfree)28 GUI_Image:: GUI_Image(int x, int y, SDL_Surface *pic, int shouldfree)
29  : GUI_Widget(NULL, x, y, pic->w, pic->h)
30 {
31 	image = pic;
32 	free_image = shouldfree;
33 }
34 
~GUI_Image()35 GUI_Image::~GUI_Image()
36 {
37 	if ( free_image ) {
38 		SDL_FreeSurface(image);
39 	}
40 }
41 
42 /* Show the widget  */
43 void
Display(void)44 GUI_Image:: Display(void)
45 {
46 	SDL_BlitSurface(image, NULL, screen, &area);
47 }
48