Пример #1
0
/**
 * Lataa kuvat ja keymappaa RGB 0xFF, 0, 0xFF (255,0,255) värikoodin pois (pinkki)
 */
SDL_Surface* load_image(std::string filename, int r, int g, int b) {

	SDL_Surface* loaded_image = NULL;

	SDL_Surface* optimized_image = NULL;

	loaded_image = IMG_Load(filename.c_str());

	// tarkistetaan saatiinko ladattua kuva
	if (loaded_image != NULL) {
		// optimoidaan
		optimized_image = SDL_DisplayFormat(loaded_image);
		// poistetaan vanha kuva memorysta
		SDL_FreeSurface( loaded_image );
		if (optimized_image != NULL) {
			// color key
			Uint32 key = SDL_MapRGB(optimized_image->format, r, g, b);
			SDL_SetColorKey(optimized_image, SDL_SRCCOLORKEY,  key);
		}
	}

	return optimized_image;
}
Пример #2
0
	// Optimize image on load to reduce processing.
	SDL_Surface *load_image(const char *file)
	{
		SDL_Surface *image_format;
		SDL_Surface *screen_format;

		// Load image
		image_format = IMG_Load(file);

		/*
		    DOES THE FILE EVEN EXIST?
		*/

		if(image_format != 0)
		{
		    // Optimize
		    screen_format = SDL_DisplayFormat(image_format);
		
		    // Release old image
		    SDL_FreeSurface(image_format);
		}

		return screen_format;
	}
Пример #3
0
SDL_Surface *load_image(std::string filename){
	// Temporary storage for the image that's loaded
	SDL_Surface* loadedImage = NULL;
	
	// The optimized image that will be used
	SDL_Surface* optimizedImage = NULL;
	
	// Load the image
	loadedImage = SDL_LoadBMP( filename.c_str() );
	
	// If nothing went wrong in loading the image
	if( loadedImage != NULL )
	{
		// Create an optimized image
		optimizedImage = SDL_DisplayFormat(loadedImage);
		
		// Free the old image
		SDL_FreeSurface(loadedImage);
	}

	// Return the optimized image
	return optimizedImage;
}
Пример #4
0
//load the file, convert it to the screen's display format
//apply the colorKey (i.e. make all magenta transparent)
//Then free the temp image and return the final
SDL_Surface* ImageCache::loadIMG(const std::string filename) const
{
    SDL_Surface* tempImg = IMG_Load(filename.c_str());
    if(!tempImg)
    {
		throw(SDL_GetError());
	}

    SDL_Surface* finalImg = SDL_DisplayFormat(tempImg);
    if(!finalImg)
    {
		throw(SDL_GetError());
	}

    if( SDL_SetColorKey(finalImg, SDL_SRCCOLORKEY, SDL_MapRGB( finalImg->format, 255, 0, 255)) == -1)
    {
		throw(SDL_GetError());
	}

    SDL_FreeSurface(tempImg);

    return finalImg;
}
Пример #5
0
int surf_Load(SDL_Surface **image, char *name, int autoFreeID)
{
    char *imageLoc;
	SDL_Surface *optimizedImage = NULL;

    imageLoc = (char *)mem_Malloc(strlen(surf_C.surfacesDIR) + strlen(name) + 1, __LINE__, __FILE__);

    strcpy(imageLoc, surf_C.surfacesDIR);
    strcat(imageLoc, name);

    *image = IMG_Load(imageLoc);

	mem_Free(imageLoc);

	if(*image == NULL)
	{
	    printf("\nError - could not load image\n\t%s. (%s)\n", name, SDL_GetError());
        file_Log(ker_Log(), 0, "\nError - could not load image\n\t%s. (%s)\n", name, SDL_GetError());
		return 1;
	}

	optimizedImage = SDL_DisplayFormat(*image);

	SDL_FreeSurface(*image);

	if(optimizedImage == NULL)
		return 2;

	SDL_SetColorKey(optimizedImage, SDL_SRCCOLORKEY | SDL_RLEACCEL, *ker_colourKey());

	*image = optimizedImage;

	if(autoFreeID == A_FREE)
		list_Push(&surf_C.surfaceList, *image, autoFreeID);

	return 0;
}
Пример #6
0
Sprites* ChargerImages()
{
    Sprites* S;
    int i;

    S = malloc(NbSprites*sizeof(Sprites));

    S[0].sprite = IMG_Load("images/sky.png");
    S[1].sprite = IMG_Load("images/sol.png");
    S[2].sprite = IMG_Load("images/block.png");
    S[3].sprite = IMG_Load("images/boite.png");
    S[4].sprite = IMG_Load("images/tuyau1.png");
    S[5].sprite = IMG_Load("images/tuyau2.png");
    S[6].sprite = IMG_Load("images/tuyau3.png");
    S[7].sprite = IMG_Load("images/tuyau4.png");
    S[8].sprite = IMG_Load("images/fin1.png");
    S[9].sprite = IMG_Load("images/fin2.png");
    S[10].sprite = IMG_Load("images/pique.png");

    for(i=0;i<NbSprites;i++){
    S[i].sprite = SDL_DisplayFormat(S[i].sprite);
    }

    S[0].traverser = 0;
    S[1].traverser = 1;
    S[2].traverser = 1;
    S[3].traverser = 1;
    S[4].traverser = 1;
    S[5].traverser = 1;
    S[6].traverser = 1;
    S[7].traverser = 1;
    S[8].traverser = 0;
    S[9].traverser = 0;
    S[10].traverser = 1;

    return S;
}
Пример #7
0
static SDL_Surface *loadImage(char *name)
{
	/* Load the image using SDL Image */

	SDL_Surface *temp;
	SDL_Surface *image;

	temp = IMG_Load(name);

	if (temp == NULL)
	{
		printf("Failed to load image %s", name);

		exit(1);
	}

	/* Make the background transparent */

	SDL_SetColorKey(temp, SDL_SRCCOLORKEY|SDL_RLEACCEL, SDL_MapRGB(temp->format, TRANS_R, TRANS_G, TRANS_B));

	/* Convert the image to the screen's native format */

	image = SDL_DisplayFormat(temp);

	SDL_FreeSurface(temp);

	if (image == NULL)
	{
		printf("Failed to convert image %s to native format", name);

		exit(1);
	}

	/* Return the processed image */

	return image;
}
Пример #8
0
bool NXFont::InitChars(TTF_Font *font, uint32_t color)
{
SDL_Color fgcolor;
SDL_Surface *letter;

	fgcolor.r = (uint8_t)(color >> 16);
	fgcolor.g = (uint8_t)(color >> 8);
	fgcolor.b = (uint8_t)(color);

#ifdef _L10N_CP1251
    char utf8_str[2];
#endif
	
	char str[2];
	str[1] = 0;
	
	for(int i=1;i<NUM_LETTERS_RENDERED;i++)
	{
		str[0] = i;
#ifndef _L10N_CP1251
        letter = TTF_RenderUTF8_Solid(font, str, fgcolor);
#else
        win1251_to_utf8(str, utf8_str);
        letter = TTF_RenderUTF8_Solid(font, utf8_str, fgcolor);
#endif
		if (!letter)
		{
			staterr("InitChars: failed to render character %d: %s", i, TTF_GetError());
			return 1;
		}
		
		letters[i] = SDL_DisplayFormat(letter);
		SDL_FreeSurface(letter);
	}
	
	return 0;
}
Пример #9
0
/**
 * Creates a new SDL surface with the specified dimensions, per-surface alpha
 * value, and the specified color_key. If color_key is equal to -1, then color
 * keys are turned off for the surface. The new surface will be exclusively a
 * software surface. Returns NULL if there was a problem creating the surface.
 * Note that it is also up to the user to call SDL_FreeSurface when they are
 * done with the surface. 
 *
 * @param width the width of the new surface, in pixels
 * @param height the height of the new surface, in pixels
 * @param alpha the alpha blend value of the entire surface
 * @param color_key the key to use as a color key for the surface
 * @returns the newly created surface
 */
SDL_Surface *
screen_create_surface(int width, int height, int alpha, Uint32 color_key)
{
    Uint32 rmask, gmask, bmask, amask;
    SDL_Surface *tempsurface, *newsurface;

    #if SDL_BYTEORDER == SDL_BIG_ENDIAN
        rmask = 0xff000000;
        gmask = 0x00ff0000;
        bmask = 0x0000ff00;
        amask = 0x000000ff;
    #else
        rmask = 0x000000ff;
        gmask = 0x0000ff00;
        bmask = 0x00ff0000;
        amask = 0xff000000;
    #endif

    tempsurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, 
                                    screen_width, screen_height, SCREEN_DEPTH,
                                    rmask, gmask, bmask, amask);
    newsurface = SDL_DisplayFormat(tempsurface);
    SDL_FreeSurface(tempsurface);

    if (newsurface == NULL) {
        printf("Error: unable to create new surface\n");
    } 
    else {
        SDL_SetAlpha(newsurface, SDL_SRCALPHA, alpha);
        if (color_key != -1) {
            SDL_SetColorKey(newsurface, SDL_SRCCOLORKEY, color_key);
        }
        screen_clear(newsurface, COLOR_BLACK);
    }

    return newsurface;
}
Пример #10
0
SDL_Surface *gfx_new_surface(int width, int height, int alpha)
{
    Uint32 rmask, gmask, bmask;
    SDL_Surface *tmp = NULL;
    SDL_Surface *dispform = NULL;

    if (width <= 0 || height <= 0)
        return NULL;

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
#else
    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
#endif

    tmp = SDL_CreateRGBSurface(SDL_SWSURFACE | (alpha ? SDL_SRCALPHA : 0),
                               width, height, 16, rmask, gmask, bmask, 0);

    if (!tmp)
        return NULL;

    if (alpha)
    {
        SDL_SetAlpha(tmp, SDL_SRCALPHA, 0);
        dispform = SDL_DisplayFormatAlpha(tmp);
    }
    else
        dispform = SDL_DisplayFormat(tmp);

    SDL_FreeSurface(tmp);

    return dispform;
}
Пример #11
0
SDL_Surface* loadOptimizedImage(char* fileName)
{

	SDL_Surface* loadedImg = NULL;
	SDL_Surface* optimizedImg = NULL;

	loadedImg = IMG_Load(fileName);

	if(loadedImg!=NULL)
	{

		//Create an optimized image
		optimizedImg = SDL_DisplayFormat( loadedImg );

		//Free the old image
		SDL_FreeSurface( loadedImg );


		if(optimizedImg!=NULL)
		{
			//Map the color key
			Uint32 colorkey = SDL_MapRGB( optimizedImg->format, 0xFF,0xFF,0xFF);
			//Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent
			SDL_SetColorKey( optimizedImg, SDL_SRCCOLORKEY, colorkey );
		}


	}

	else
	{
		printf("\n Loaded Img is null!");

	}

	return optimizedImg;
}
Пример #12
0
SDL_Surface* ChargeImage(const char *fichier) 
{
  // Surface tampon qui nous servira pour charger l'image 
  SDL_Surface* loadedImage = NULL; 

  // L'image optimisee qu'on va utiliser 
  SDL_Surface* optimizedImage = NULL;

  // Chargement de l'image
  loadedImage = SDL_LoadBMP(fichier);

  // Si le chargement se passe bien
  if(loadedImage != NULL) 
  { 
    // Création de l'image optimisée 
    optimizedImage = SDL_DisplayFormat(loadedImage); 
		
    // Libération de l'ancienne image
    SDL_FreeSurface(loadedImage); 
  }
	
  // On retourne l'image optimisée 
  return optimizedImage; 
}
Пример #13
0
/** Constructor, load the cursorimage and set upp all surfaces to buffer
 * background in etc.
 */
Cursor::Cursor()
{
    SDL_Surface *tmp;

    curimg = 0;
    nimgs = 1;

    cursorimg = new Dune2Image("mouse.shp", -1);
    if (getConfig().gamenum == GAME_RA) {
        transicn = new TemplateImage("trans.icn", mapscaleq, 1);
        nsoff = CUR_RA_NOSCROLL_OFFSET;
    } else {
        transicn = new TemplateImage("trans.icn", mapscaleq);
        nsoff = CUR_NOSCROLL_OFFSET;
    }

    image[curimg] = cursorimg->getImage(0);

    /* All cursors loaded */

    tmp = SDL_CreateRGBSurface (SDL_SWSURFACE, image[0]->w, image[0]->h, 16, 0xff, 0xff, 0xff, 0);
    bg = SDL_DisplayFormat( tmp );
    SDL_FreeSurface( tmp );

    currentcursor = CUR_STANDARD;
    x = 0;
    y = 0;
    cursor_offset = 0;

    cursorpool = new CursorPool("cursors.ini");
    ci = NULL;

    transw = transicn->getImage(0);
    transy = transicn->getImage(1);
    transr = transicn->getImage(2);
}
Пример #14
0
SDL_Surface *load_image( std::string filename )
{

        //The image that's loaded
    SDL_Surface* loadedImage = NULL;

    //The optimized image that will be used
    SDL_Surface* optimizedImage = NULL;

    //Load the image
    loadedImage = IMG_Load( filename.c_str() );

    //If the image loaded
    if( loadedImage != NULL )
    {
        //Create an optimized image
        optimizedImage = SDL_DisplayFormat( loadedImage );

        //Free the old image
        SDL_FreeSurface( loadedImage );

        //If the image was optimized just fine
        if( optimizedImage != NULL )
        {
            //Map the color key
            Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF );

            //Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent
            SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey );
        }
    }

    //Return the optimized image
    return optimizedImage;

}
Пример #15
0
CAnimdata::CAnimdata(const char* path)
{
  mW = 0; mH = 0;
  SDL_Surface* temp;
  char buf[255],name[255];
  int ppause = 0, r = 0, g = 0, b = 0, count = 0;
  char FileName[255];
  sprintf(FileName,"%s/info",path);
  FILE* fp = fopen(FileName,"r");
  if (!fp)
    {
      printf("Error: Can't open file: %s\n",FileName);
      exit(1);
    }
  fgets(buf,255,fp);
  sscanf(buf,"FILES: %d",&mNumFrames);
  mBuilt = 1;
  while(!feof(fp) && count<mNumFrames)
    {
      fgets(buf,255,fp);
      if(buf[0]!='#' && buf[0]!='\r' && buf[0]!='\n' && buf[0]!='\0' && strlen(buf)!=0)
	{
	  sscanf(buf,"%s %d %d %d %d",name,&ppause,&r,&g,&b);
	  sprintf(FileName,"%s/%s",path,name);
	  if((temp = SDL_LoadBMP(FileName)) == NULL) exit(1);
	  if(r>=0) SDL_SetColorKey(temp,SDL_SRCCOLORKEY,SDL_MapRGB(temp->format,r,g,b));
	  image.push_back(SDL_DisplayFormat(temp));
	  SDL_FreeSurface(temp);
	  pause.push_back(ppause);
	  if(!mW) mW = image[count]->w;
	  if(!mH) mH = image[count]->h;
	  ++count;
	}
    }
  fclose(fp);
}
Пример #16
0
// Helper function to load and optimize graphics.
// Note to Students: This function has a "double pointer" as the first parameter! 
//                   This was explained in the lecture when the game was announced.
bool COutputManagerNITHris::_LoadAndFormatBMP( SDL_Surface** r_ppoBitmapSurface, 
											   const char*   szBitmapName       ) const
{
	bool r_bRetVal = true;

	// First we load the bitmap into a temporary storage.
	SDL_Surface *poTempSurface = SDL_LoadBMP(szBitmapName);
	if(!poTempSurface) 
	{
		cout << "COutputManagerNITHris::Init - File not Found: " << szBitmapName << endl;
		r_bRetVal = false;
	}
	else
	{
		// Then we convert the temporary stored bitmap to the ideal format and put it in the variable pointed to in the param list.
		*r_ppoBitmapSurface = SDL_DisplayFormat(poTempSurface);

		// Finally, we free the dynamically created temporary storage again.
		SDL_FreeSurface(poTempSurface);
	}

	return r_bRetVal;

}  // END _LoadAndFormatBMP
Пример #17
0
void CIntroState::Init()
{
    SDL_Surface* temp = SDL_LoadBMP("intro.bmp");

    bg = SDL_DisplayFormat(temp);

    SDL_FreeSurface(temp);

    // create the fader surface like the background with alpha
    fader = SDL_CreateRGBSurface( SDL_SRCALPHA, bg->w, bg->h,
                                  bg->format->BitsPerPixel,
                                  bg->format->Rmask, bg->format->Gmask,
                                  bg->format->Bmask, bg->format->Amask );

    // fill the fader surface with black
    SDL_FillRect (fader, NULL, SDL_MapRGB (bg->format, 0, 0, 0)) ;

    // start off opaque
    alpha = 255;

    SDL_SetAlpha(fader, SDL_SRCALPHA, alpha);

    printf("CIntroState Init\n");
}
Пример #18
0
BLIT sdl_chromakey(void *src, SDL_Rect *src_rect,
		   SDL_Surface *dst, SDL_Rect *dst_rect,
		   Geometry *geo, Linklist<Parameter> *params) {


  // TODO color

  sdl_surf = SDL_CreateRGBSurfaceFrom
    (src, geo->w, geo->h, geo->bpp,
     geo->bytewidth, red_bitmask, green_bitmask, blue_bitmask, alpha_bitmask);
  
  // TODO
  SDL_SetColorKey( sdl_surf, SDL_SRCCOLORKEY | SDL_RLEACCEL, NULL);
  
  //  SDL_SetAlpha(sdl_surf, SDL_RLEACCEL, 0);
  
  SDL_Surface *colorkey_surf = SDL_DisplayFormat(sdl_surf);
  
  SDL_BlitSurface( colorkey_surf, src_rect, dst, dst_rect );
  
  SDL_FreeSurface( sdl_surf );
  SDL_FreeSurface( colorkey_surf );

}
Пример #19
0
// Loads an image then converts it to same format as the screen
// Example 24 bpp -> 32 bpp
SDL_Surface *load_image(std::string filename)
{
  SDL_Surface* loadedImage = NULL;
  SDL_Surface* optimizedImage = NULL;

  // Can load BMP,PNG,JPEG,TGA,GIF,PNM,XPM,LBM,PCX
  loadedImage = IMG_Load(filename.c_str());

  if (loadedImage !=NULL)
  {
    optimizedImage = SDL_DisplayFormat(loadedImage);
    SDL_FreeSurface(loadedImage);

    // color key for transparency
    if(optimizedImage != NULL)
    {
      // Set teal to color key in this case
      Uint32 colorkey = SDL_MapRGB(optimizedImage->format,0,0xFF,0xFF);
      SDL_SetColorKey(optimizedImage,SDL_SRCCOLORKEY,colorkey);
    }
  }

  return optimizedImage;
}
Пример #20
0
SDL_Surface *loadImage( const char *filename, int r, int g, int b ) 
{ 
	SDL_Surface* loadedImage = NULL; 
	SDL_Surface* optimizedImage = NULL;

	// load the image from disk
	std::string image_path = getResourcePath(filename);
	loadedImage = IMG_Load(image_path.c_str());

	if( loadedImage == NULL ) 
	{ 
		std::cout << "loadImage error: " << filename << " could not be loaded\n";
		return NULL;
	}

	// creates optimized version of the image, matching the screen's bit-depth
	optimizedImage = SDL_DisplayFormat( loadedImage ); 
	SDL_FreeSurface( loadedImage );

	if(optimizedImage == NULL)
	{ 
		std::cout << "loadImage error: " << filename << " could not be optimized\n";
		return NULL;
	}

	// if a color key has been provided, mask that color out from the image.
	if(r != -1 || g != -1 || b != -1 ) 
	{ 
		Uint32 colorkey = SDL_MapRGB( optimizedImage->format, r, g, b );
		
		//Set all pixels matching the color key to transparent
		SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey ); 
	}

	return optimizedImage; 
}
Пример #21
0
SDL_Surface *load_image( std::string filename )
{
    //The image that's loaded
    SDL_Surface* loadedImage = NULL;

    //The optimized image that will be used
    SDL_Surface* optimizedImage = NULL;

    //Load the image
    loadedImage = IMG_Load( filename.c_str() );

    //If the image loaded
    if( loadedImage != NULL )
    {
        //Create an optimized image
        optimizedImage = SDL_DisplayFormat( loadedImage );

        //Free the old image
        SDL_FreeSurface( loadedImage );
    }

    //Return the optimized image
    return optimizedImage;
}
Пример #22
0
SDL_Surface*
sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, int use_alpha)
{
  SDL_Surface* sdl_surface;
  Uint32 saved_flags;
  Uint8  saved_alpha;

  /* Save the alpha blending attributes */
  saved_flags = sdl_surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
  saved_alpha = sdl_surf->format->alpha;
  if ( (saved_flags & SDL_SRCALPHA)
       == SDL_SRCALPHA )
  {
    SDL_SetAlpha(sdl_surf, 0, 0);
  }

  if(use_alpha == IGNORE_ALPHA && !use_gl)
    sdl_surface = SDL_DisplayFormat(sdl_surf);
  else
    sdl_surface = SDL_DisplayFormatAlpha(sdl_surf);

  /* Restore the alpha blending attributes */
  if ( (saved_flags & SDL_SRCALPHA)
       == SDL_SRCALPHA )
  {
    SDL_SetAlpha(sdl_surface, saved_flags, saved_alpha);
  }

  if (sdl_surface == NULL)
    st_abort("Can't covert to display format", "SURFACE");

  if (use_alpha == IGNORE_ALPHA && !use_gl)
    SDL_SetAlpha(sdl_surface, 0, 0);

  return sdl_surface;
}
Пример #23
0
/* load picture from file to surface and convert it to right display format */
SDL_Surface *load_pic(char *filename)
{
	SDL_Surface *tmp1, *tmp2;
	Uint32 ck;

//	tmp1 = SDL_LoadBMP(filename);
	tmp1 = IMG_Load(filename);
	if (!tmp1)
	{
		error("cant load pic %s \n", filename);
		return NULL;
	}
	tmp2 = SDL_DisplayFormat(tmp1);
	if (!tmp2)
	{
		error("cant SDL_DisplayFormat %s \n", filename);
		return NULL;
	}
	/* set colorkey */
	ck = SDL_MapRGB(tmp2->format,0xFF,0,0xFF);
	SDL_SetColorKey(tmp2,SDL_SRCCOLORKEY,ck);
	SDL_FreeSurface(tmp1);
	return tmp2;
}
Пример #24
0
// special access at imagebank buffer colorkeyclipped
int baseimageCC(int bank,int n)
{

    if (SDLimageCC[n]!=NULL){

	SDL_FreeSurface(SDLimageCC[n]);
	SDLimageCC[n]=SDL_DisplayFormat(SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_HWACCEL,SDLimage[n]->w,SDLimage[n]->h,32,0,0,0,0));

	SDL_BlitSurface( SDLimage[n], NULL ,SDLimageCC[n], NULL);
	Image_colorkey(SDLimageCC[n]);


	membank[bank]=(char*)SDLimageCC[n]->pixels;
	banksize[bank]=SDLimageCC[n]->w * SDLimageCC[n]->h * SDLimageCC[n]->format->BytesPerPixel;
	curbank=bank;

	return 0;
    }
    else {
	error_description="membank Error:image not found ";
	error_type=1;
	return -1;
    }
}
Пример #25
0
Checkbox::Checkbox(int x, int y, int w, int h, Font *font, int r, int g, int b,
    const std::wstring &bg, bool &chk): left(x), top(y), width(w),
        height(h), checked(chk), mouseInside(false)
{
    SDL_Surface *s = screen.getSurface();
    image = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 
            s->format->BitsPerPixel, s->format->Rmask, s->format->Gmask,
            s->format->Bmask, s->format->Amask);

    SDL_Surface *tile = loadImage(bg);
    SDL_Rect src = { 0, 0, tile->w, tile->h };
    SDL_Rect dst = { 0, 0, tile->w, tile->h };
    for (int j = 0; j < height; j += tile->h)
        for (int i = 0; i < width; i += tile->w) {
            dst.x = i;
            dst.y = j;
            SDL_BlitSurface(tile, &src, image, &dst);
        }
    SDL_FreeSurface(tile);

    SDL_LockSurface(image);
    drawBevel(image, 0, 0, width, height, false, 1);
    drawBevel(image, 1, 1, width - 2, height - 2, true, 1);
    SDL_UnlockSurface(image);
    
    highlighted = adjustBrightness(image, 1.5, false);
    
    checkedImage = SDL_DisplayFormat(image);
    int tW, tH;
    font->getSize(L"X", tW, tH);
    tH += 2;
    tW += 2;
    font->draw(checkedImage, (width - tW) / 2, (height - tH) / 2, r, g, b, 
            true, L"X");
    checkedHighlighted = adjustBrightness(checkedImage, 1.5, false);
}
Пример #26
0
SDL_Surface 
*load_image( std::string filename )
{
    SDL_Surface *loadedImage = NULL;

    SDL_Surface *optimizedImage = NULL;

    loadedImage = IMG_Load( filename.c_str() );

    if( loadedImage != NULL ){
        optimizedImage = SDL_DisplayFormat( loadedImage );

        if( optimizedImage != NULL ){
            //Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF );
            Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0xFF, 0, 0xFF );
            SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey );
            //SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey );
        }

        SDL_FreeSurface( loadedImage );
    }

    return optimizedImage;
}
Пример #27
0
SDL_Surface* Utility::loadImage(string filename)
{
    SDL_Surface* loadedImage = NULL;
    SDL_Surface* optimizedImage = NULL;

    loadedImage = IMG_Load(filename.c_str());

    if ( loadedImage != NULL )
    {
	optimizedImage = SDL_DisplayFormat(loadedImage);
	SDL_FreeSurface(loadedImage);

	if ( optimizedImage != NULL )
	{
	    Uint32 colorkey = SDL_MapRGB(optimizedImage->format, 0, 0xFF, 0);
	    SDL_SetColorKey(optimizedImage, SDL_SRCCOLORKEY, colorkey);
	}
	else
	    cout << "Error: (Utility.cpp loadImage(string) Optimized image is NULL" << endl;
    }
    else
	cout << "Error: (Utility.cpp) image at path "<<filename<<" failed to load"<<endl;
    return optimizedImage;
}
Пример #28
0
SDL_Surface * SDL_load_image(const char * filename)
{
	/* Temporary storage for the image that's loaded */
	SDL_Surface * loadedImage = NULL;

	/* The optimized image that will be used */
	SDL_Surface * optimizedImage = NULL;

	/* Load the image */
	loadedImage = SDL_LoadBMP(filename);

	/* If nothing went wrong in loading the image */
	if (loadedImage != NULL)
	{
		/* Create an optimized image */
		optimizedImage = SDL_DisplayFormat(loadedImage);

		/* Free the old image */
		SDL_FreeSurface(loadedImage);
	}

	/* Return the optimized image */
	return optimizedImage;
}
Пример #29
0
void gui_display (int shortcut){

	void* stor = display ? malloc(display->h * display->pitch) : 0;
	if (stor) memcpy(stor, display->pixels, display->h * display->pitch);

	if (tmpSDLScreen == NULL) {
		tmpSDLScreen = SDL_DisplayFormat(display);
		if (tmpSDLScreen == NULL) {
			write_log ("SDLUI: Failed to create temp screen\n");
			abort();
		} else {
			write_log ("SDLUI: Created temp screen %dx%dx%d\n", display->w, display->h, display->format->BitsPerPixel);
		}
	}
	SDL_Event event;

	int menu_exitcode = -1;
	int mainloopdone = 0;
	int mouse_x = 30;
	int mouse_y = 40;
	int kup = 0;
	int kdown = 0;
	int kleft = 0;
	int kright = 0;
	int ksel = 0;
	int iconpos_x = 0;
	int iconpos_y = 0;

	if (getcwd (launchDir, 256)) {
		strcpy (yol, launchDir);
		write_log ("SDLUI: current dir: %s\n", launchDir);
	} else {
		write_log("getcwd failed with errno %d\n", errno);
		return;
	}

	/* set a proper keyboard delay so we can move through lists without having
	   hammer the keyboard... */
	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

	int need_redraw = 1;
	while (!mainloopdone) {
		while (SDL_PollEvent(&event)) {
			need_redraw = 1;
			switch(event.type) {
				case SDL_QUIT:
					mainloopdone = 1; break;
				case SDL_JOYBUTTONDOWN:
					switch (event.jbutton.button) {
						case PLATFORM_BUTTON_R: break;
						case PLATFORM_BUTTON_L: break;
						case PLATFORM_BUTTON_UP: kup = 1; break;
						case PLATFORM_BUTTON_DOWN: kdown = 1; break;
						case PLATFORM_BUTTON_LEFT: kleft = 1; break;
						case PLATFORM_BUTTON_RIGHT: kright = 1; break;
						case PLATFORM_BUTTON_CLICK: ksel = 1; break;
						case PLATFORM_BUTTON_B: ksel = 1; break;
						case PLATFORM_BUTTON_Y: break;
						case PLATFORM_BUTTON_START: mainloopdone = 1; break;
					}
					break;
				case SDL_KEYDOWN:
	    				switch (event.key.keysym.sym) {
						case SDLK_RETURN:
						if((event.key.keysym.mod & KMOD_LALT) ||
						   (event.key.keysym.mod & KMOD_RALT)) {
							toggle_fullscreen(0);
							//SDL_Delay(100);
							break;
						} else {
							// enter to select
							ksel = 1; break;
						}
						case SDLK_ESCAPE:	mainloopdone = 1; break;
					 	case SDLK_UP:		kup = 1; break;
						case SDLK_DOWN:		kdown = 1; break;
						case SDLK_LEFT:		kleft = 1; break;
						case SDLK_RIGHT:	kright = 1; break;
						// space to run default
						case SDLK_SPACE:	selected_item = menu_sel_run; ksel =1; break;
						default: break;
					}
					break;
				case SDL_MOUSEMOTION:
					mouse_x += event.motion.xrel;
					mouse_y += event.motion.yrel;
					break;
				case SDL_MOUSEBUTTONDOWN:
					if (selected_item == 0) {
						if (mouse_x >= 0 && mouse_x <= 20) {
							if (mouse_y >= 0 && mouse_y <= 20) {
								mainloopdone = 1;
							}
						}
					} else {
						ksel = 1; break;
					}
					break;
				case SDL_ACTIVEEVENT: case SDL_KEYUP: break;
				default:
					dprintf(2, "got event %lu\n", (long) event.type);
					need_redraw = 0;
			}
		}
		if(!need_redraw) { SDL_Delay(20); continue; }
		if (ksel == 1) {
			if (selected_item == menu_sel_expansion) {
				sprintf (msg, "%s", "Select KickStart ROM");
				sprintf (msg_status, "%s", "EXIT: Back/ESC");
				sprintf (yol, "%s/roms", launchDir);
				dirz(1);
			}
			if (selected_item == menu_sel_floppy) {
				sprintf (msg, "%s", "Select Disk Image");
				sprintf (msg_status, "%s", "DF0: B  DF1: A");
				sprintf (yol, "%s/disks", launchDir);
				dirz(0);
			}
			if (selected_item == menu_sel_prefs) {
				sprintf (msg, "%s", "Emulation Configuration");
				sprintf (msg_status, "%s", "EXIT: Back/ESC");
				prefz(0);
			}
			if (selected_item == menu_sel_reset) {
				uae_reset(0, 1);
				menu_exitcode = 2;
				mainloopdone = 1;
			}
			if (selected_item == menu_sel_keymaps) {
			}
/*			if (selected_item == menu_sel_tweaks) {
				sprintf(msg,"%s","Tweaks");
				sprintf(msg_status,"%s","L/R = -/+  B: Apply");
				tweakz(0);
			}*/
			if (selected_item == menu_sel_storage) {
				strcpy(msg, "Savestates");
				strcpy(msg_status, "LOAD: A SAVE: B");
				sprintf (yol, "%s/saves", launchDir);
				dirz(2);
			}
			if (selected_item == menu_sel_run) {
				menu_exitcode = 1;
				mainloopdone = 1;
			}
			if (selected_item == menu_sel_exit) {
				SDL_Quit();
				exit(0);
			}
			ksel = 0;
		}
	// background
		SDL_BlitSurface (pMenu_Surface, NULL, tmpSDLScreen, NULL);

	// icons
        	iconpos_x = 10;
	        iconpos_y = 33;

        	selected_hilite (iconpos_x, iconpos_y, mouse_x, mouse_y, icon_floppy, menu_sel_floppy);
	        blit_image (icon_floppy, iconpos_x, iconpos_y);

	        iconpos_x += iconsizex + bosluk;
        	selected_hilite (iconpos_x, iconpos_y, mouse_x, mouse_y, icon_preferences, menu_sel_prefs);
	        blit_image (icon_preferences, iconpos_x, iconpos_y);

//	        iconpos_x += iconsizex + bosluk;
//        	selected_hilite (iconpos_x, iconpos_y, mouse_x, mouse_y, icon_tweaks, menu_sel_tweaks);
//	        blit_image (icon_tweaks, iconpos_x, iconpos_y);

        	iconpos_x += iconsizex + bosluk;
	        selected_hilite (iconpos_x, iconpos_y, mouse_x, mouse_y, icon_keymaps, menu_sel_keymaps);
        	blit_image (icon_keymaps, iconpos_x, iconpos_y);

	        iconpos_x += iconsizex + bosluk;
	        selected_hilite (iconpos_x, iconpos_y, mouse_x, mouse_y, icon_expansion, menu_sel_expansion);
        	blit_image (icon_expansion, iconpos_x, iconpos_y);

        	iconpos_x = 10;
	        iconpos_y = iconpos_y + iconsizey + bosluk;

        	selected_hilite (iconpos_x,iconpos_y,mouse_x,mouse_y,icon_storage, menu_sel_storage);
	        blit_image (icon_storage, iconpos_x, iconpos_y);

	        iconpos_x += iconsizex + bosluk;
	        selected_hilite (iconpos_x,iconpos_y,mouse_x,mouse_y, icon_reset, menu_sel_reset);
        	blit_image (icon_reset, iconpos_x, iconpos_y);

	        iconpos_x += iconsizex + bosluk;
        	selected_hilite (iconpos_x,iconpos_y,mouse_x,mouse_y, icon_run, menu_sel_run);
	        blit_image (icon_run, iconpos_x, iconpos_y);

        	iconpos_x += iconsizex + bosluk;
	        selected_hilite (iconpos_x,iconpos_y,mouse_x,mouse_y, icon_exit, menu_sel_exit);
        	blit_image (icon_exit, iconpos_x, iconpos_y);
	// texts
		write_text (TITLE_X, TITLE_Y, "PUAE //GnoStiC");

	// mouse pointer ------------------------------
		if (kleft == 1) {
	                mouse_x -= (iconsizex + bosluk);
        	        kleft = 0;
		}
		if (kright == 1) {
	                mouse_x += (iconsizex + bosluk);
	                kright = 0;
		}
	        if (kup == 1) {
	                mouse_y -= (iconsizey + bosluk);
	                kup = 0;
		}
		if (kdown == 1) {
        	        kdown = 0;
	                mouse_y += (iconsizey + bosluk);
		}

#define _MENU_X 640
#define _MENU_Y 480

		if (mouse_x < 1) { mouse_x = 1; }
		if (mouse_y < 1) { mouse_y = 1; }
/* pMainMenu_Surface->w */
#define MOUSE_MAX_X (_MENU_X - pMouse_Pointer->w)
#define MOUSE_MAX_Y (_MENU_Y - pMouse_Pointer->h)
		if (mouse_x > MOUSE_MAX_X) { mouse_x = MOUSE_MAX_X; }
		if (mouse_y > MOUSE_MAX_Y) { mouse_y = MOUSE_MAX_Y; }
		rect.x = mouse_x;
		rect.y = mouse_y;
		//rect.w = pMouse_Pointer->w;
		//rect.h = pMouse_Pointer->h;
		SDL_BlitSurface (pMouse_Pointer, NULL, tmpSDLScreen, &rect);
		// mouse pointer-end

		SDL_BlitSurface (tmpSDLScreen, NULL, display, NULL);
#ifdef USE_GL
		flush_gl_buffer (&glbuffer, 0, display->h - 1);
		render_gl_buffer (&glbuffer, 0, display->h - 1);
		glFlush ();
		SDL_GL_SwapBuffers ();
#else
		SDL_Flip (display);
#endif
		need_redraw = 0;
		SDL_Delay(20);
	} //while done

	if (stor) {
		memcpy(display->pixels, stor, display->h * display->pitch);
		free(stor);
		SDL_Flip(display);
	}

	SDL_EnableKeyRepeat(0, 0); /* disable keyrepeat again */
//	return menu_exitcode;
}
Пример #30
0
void mainLoop(SDL_Surface* screen, int x, int y, const int xC, const int yC, const int zC, int*** mapTable, int xSize, int ySize)
{
    ///Chargement des images
        SDL_Surface* map [15] = {NULL};
        map[0] = IMG_Load("graph/Pac/Wall.png");
        map[1] = IMG_Load("graph/Pac/Coin.png");
            SDL_Surface* tmp = IMG_Load("graph/Pac/Glass.png");
        map[2] = SDL_DisplayFormat(tmp);
            SDL_FreeSurface(tmp);
        SDL_Surface* uP = IMG_Load("graph/Pac/Main/Up.png");
        SDL_Surface* dP = IMG_Load("graph/Pac/Main/Down.png");
        SDL_Surface* rP = IMG_Load("graph/Pac/Main/Right.png");
        SDL_Surface* lP = IMG_Load("graph/Pac/Main/Left.png");
        SDL_Surface** Papercraft = &uP;
        Block glass(1,1,1,true,map[2]);

    ///Fin.

    ///Initialisation des positions.
        SDL_Rect position;
            position.x = (0);
            position.y = (0);
        SDL_Rect mainPosition;
            mainPosition.x = x;
            mainPosition.y = y;
    ///Fin.
    int score(0);
    bool done(false);
    bool start(false);
    SDL_EnableKeyRepeat(100, 100);

    ///Boucle principale.
    while (!done)
    {
        //Attente d'un événement
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            switch (event.type) //Verification du type
            {
                case SDL_QUIT: //Fenêtre fermé (croix rouge)
                    done = true;
                    break;

                // check for keypresses
                case SDL_KEYDOWN://Vérification du clavier 'touche pressé'

                    if (event.key.keysym.sym == SDLK_ESCAPE)
                            {done = true;}
                    if (event.key.keysym.sym == SDLK_KP2)
                    {
                        switch (mapTable[mainPosition.x][mainPosition.y+1][0])
                        {
                            case '0':
                                sKeyDown(&mainPosition);
                                Papercraft = &dP;
                                break;
                            case 'c':
                                sKeyDown(&mainPosition);
                                Papercraft = &dP;
                                score++;
                                mapTable[mainPosition.x][mainPosition.y][0] = '0';
                                break;
                        }
                    }
                    if (event.key.keysym.sym == SDLK_KP8)
                    {
                        switch(mapTable[mainPosition.x][mainPosition.y-1][0])
                        {
                            case '0':
                                zKeyDown(&mainPosition);
                                Papercraft =&uP;
                                break;
                            case 'c':
                                zKeyDown(&mainPosition);
                                Papercraft =&uP;
                                score++;
                                mapTable[mainPosition.x][mainPosition.y][0] = '0';
                                break;
                        }
                    }
                    if (event.key.keysym.sym == SDLK_KP4)
                    {
                        switch (mapTable[mainPosition.x-1][mainPosition.y][0])
                        {
                            case '0':
                                qKeyDown(&mainPosition);
                                Papercraft =&lP;
                                break;
                            case 'c':
                                qKeyDown(&mainPosition);
                                Papercraft =&lP;
                                score++;
                                mapTable[mainPosition.x][mainPosition.y][0] = '0';
                                break;
                        }
                    }
                    if (event.key.keysym.sym == SDLK_KP6)
                    {
                        switch(mapTable[mainPosition.x+1][mainPosition.y][0])
                        {
                            case '0':
                                dKeyDown(&mainPosition);
                                Papercraft=&rP;
                                break;
                            case 'c':
                                dKeyDown(&mainPosition);
                                Papercraft=&rP;
                                score++;
                                mapTable[mainPosition.x][mainPosition.y][0] = '0';
                                break;
                        }
                    }
                        start = true;
                break;

            }

            if (start)//Ne pas actualiser l'écran tant qu'une touche n'a pas été pressée.
            {
                screen = displayLoop(screen, xC, yC, zC, mapTable, xSize, ySize, position, mainPosition, &map[0], Papercraft, score, glass);
                SDL_Flip(screen);
            }


        }

    }
    ///Fin de la boucle.

    ///Libération de la mémoire.
    for (x=0;x<15;x++)
    {
        SDL_FreeSurface(map[x]);
    }
    SDL_FreeSurface(uP);
    SDL_FreeSurface(dP);
    SDL_FreeSurface(rP);
    SDL_FreeSurface(lP);
}