//Sous fonction qui charge les tiles dans un tableau void LoadMap_tiles(FILE* Fichier,Map* map) { int nbtile, i, j; char tab[TAB_MAX]; char tab1[TAB_MAX]; // Tableaux pour stocker lignes Fichier fscanf(Fichier, "%s", tab); // #images_tiles fscanf(Fichier, "%s", tab); // nom image bmp map->tileset = Load_image(tab); //On charge l'image indiquée dans le txt fscanf(Fichier, "%d %d", &map->nbtilesX, &map->nbtilesY); map->tile_width = map->tileset->w / map->nbtilesX; //on obtient la largeur d'un tile map->tile_height = map->tileset->h / map->nbtilesY; //on obtient la hauteur d'un tile map->tab_props = malloc(map->nbtilesX * map->nbtilesY * sizeof(TileProp)); for(j = 0, nbtile = 0; j < map->nbtilesY; j++) { for(i = 0; i < map->nbtilesX; i++, nbtile++) { map->tab_props[nbtile].R.w = map->tile_width; map->tab_props[nbtile].R.h = map->tile_height; map->tab_props[nbtile].R.x = i * map->tile_width; map->tab_props[nbtile].R.y = j * map->tile_height; fscanf(Fichier,"%s %s",tab,tab1); map->tab_props[nbtile].type = CHEMIN; if (strcmp(tab1,"terrain")==0) map->tab_props[nbtile].type = TERRAIN; if (strcmp(tab1,"obstacle")==0) map->tab_props[nbtile].type = OBSTACLE; } } fscanf(Fichier, "%d %d", &map->nbtiles_largeur_monde, &map->nbtiles_hauteur_monde); //largeur et hauteur du tableau monde }
/* * === FUNCTION ====================================================================== * Name: DrawImge * Description: Draw the images and display them on the screen * ===================================================================================== */ int DrawImage(SDL_Surface * m_screen, T_Image *image_info) { // Check the input parameters assert(NULL!=m_screen); assert(NULL!=image_info); // Open the image file in the specific path char *image_path_file_name = NULL; int len_image_path_file_name = 0; len_image_path_file_name = strlen(image_info->file) + strlen(image_info->path); image_path_file_name =(char*)malloc(len_image_path_file_name + 1 ); assert(NULL!=image_path_file_name); memset(image_path_file_name,0, len_image_path_file_name); sprintf(image_path_file_name, "%s%s", image_info->path, image_info->file); // Display the images SDL_Surface *image = NULL; image = Load_image( image_path_file_name ); if ( image != NULL && 1 == image_info->color_enable ) { //Map the color key SDL_Color m_clrKey; m_clrKey.r = (image_info->color_key&0xff0000)>>16; m_clrKey.g = (image_info->color_key&0x00ff00)>>8; m_clrKey.b = (image_info->color_key&0x0000ff); Uint32 colorkey = SDL_MapRGB( image->format, m_clrKey.r, m_clrKey.g, m_clrKey.b ); //Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent SDL_SetColorKey(image, SDL_SRCCOLORKEY, colorkey ); }
int main(int argc, char *argv[]) { Uint32 flags; SDL_Surface *screen, *image; int depth, done; SDL_Event event; /* Check command line usage */ if ( ! argv[1] ) { fprintf(stderr, "Usage: %s <image_file>, (int) size\n", argv[0]); return(1); } if ( ! argv[2] ) { fprintf(stderr, "Usage: %s <image_file>, (int) size\n", argv[0]); return(1); } /* Initialize the SDL library */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); return(255); } flags = SDL_SWSURFACE; image = Load_image( argv[1] ); printf( "\n\nImage properts:\n" ); printf( "BitsPerPixel = %i \n", image->format->BitsPerPixel ); printf( "BytesPerPixel = %i \n", image->format->BytesPerPixel ); printf( "width %d ,height %d \n\n", image->w, image->h ); SDL_WM_SetCaption(argv[1], "showimage"); /* Create a display for the image */ depth = SDL_VideoModeOK(image->w, image->h, 32, flags); /* Use the deepest native mode, except that we emulate 32bpp for viewing non-indexed images on 8bpp screens */ if ( depth == 0 ) { if ( image->format->BytesPerPixel > 1 ) { depth = 32; } else { depth = 8; } } else if ( (image->format->BytesPerPixel > 1) && (depth == 8) ) { depth = 32; } if(depth == 8) flags |= SDL_HWPALETTE; screen = SDL_SetVideoMode(image->w, image->h, depth, flags); if ( screen == NULL ) { fprintf(stderr,"Couldn't set %dx%dx%d video mode: %s\n", image->w, image->h, depth, SDL_GetError()); } /* Set the palette, if one exists */ if ( image->format->palette ) { SDL_SetColors(screen, image->format->palette->colors, 0, image->format->palette->ncolors); } /* Display the image */ Paint(image, screen); done = 0; int size =atoi( argv[2] ); printf("Actual size is: %d\n", size); while ( ! done ) { if ( SDL_PollEvent(&event) ) { switch (event.type) { case SDL_KEYUP: switch (event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_TAB: case SDLK_q: done = 1; break; case SDLK_SPACE: case SDLK_f: SDL_LockSurface(image); printf("Start filtering... "); Filter(image->pixels,image->w,image->h, size, image->format->BytesPerPixel ); printf("Done.\n"); SDL_UnlockSurface(image); printf("Repainting after filtered... "); Paint(image, screen); printf("Done.\n"); break; case SDLK_r: printf("Reloading image... "); image = Load_image( argv[1] ); Paint(image,screen); printf("Done.\n"); break; case SDLK_PAGEDOWN: case SDLK_DOWN: case SDLK_KP_MINUS: size--; if (size==0) size--; printf("Actual size is: %d\n", size); break; case SDLK_PAGEUP: case SDLK_UP: case SDLK_KP_PLUS: size++; if (size==0) size++; printf("Actual size is: %d\n", size); break; case SDLK_s: printf("Saving surface at nowy.bmp ..."); SDL_SaveBMP(image, "nowy.bmp" ); printf("Done.\n"); default: break; } break; // case SDL_MOUSEBUTTONDOWN: // done = 1; // break; case SDL_QUIT: done = 1; break; default: break; } } else { SDL_Delay(10); } } SDL_FreeSurface(image); /* We're done! */ SDL_Quit(); return(0); }
void cargando_interface() { int i; char c[100]; for(i=0; i<4; i++) { sprintf(c,"imagenes/flechader%d.png",i); Load_image(&flechader[i],&c[0]); sprintf(c,"imagenes/flechaizq%d.png",i); Load_image(&flechaizq[i],&c[0]); } for(i=0; i<2; i++) { sprintf(c,"imagenes/botones/inorder%d.png",i); Load_image(&tipos_recorridos[0][i],&c[0]); sprintf(c,"imagenes/botones/preorder%d.png",i); Load_image(&tipos_recorridos[1][i],&c[0]); sprintf(c,"imagenes/botones/posorder%d.png",i); Load_image(&tipos_recorridos[2][i],&c[0]); } Load_image(&window_alerta,"imagenes/alerta.png"); Load_image(&window_acerca,"imagenes/acercade.png"); Load_image(&window_ayuda,"imagenes/ayuda.png"); Load_image(&window_explicacion,"imagenes/explicacion.png"); Load_image(&fondo,"imagenes/interface1.png"); Load_image(&img_principal,"imagenes/interface.png"); Load_image(&m_principal,"imagenes/interface.png"); Load_image(&icon_add,"imagenes/add.png"); Load_image(&nodo_img,"imagenes/dibujo.png"); Load_image(&texto,"imagenes/texto.jpg"); Load_image(&icon_del,"imagenes/del.png"); Load_image(&mini_window,"imagenes/mini_windows.png"); Load_image(&boton_aceptar[0],"imagenes/botones/aceptar0.png"); Load_image(&boton_aceptar[1],"imagenes/botones/aceptar1.png"); Load_image(&boton_cancelar[0],"imagenes/botones/cancelar0.png"); Load_image(&boton_cancelar[1],"imagenes/botones/cancelar1.png"); Load_image(&boton_eliminar[0],"imagenes/botones/eliminar0.png"); Load_image(&nodo_visitado,"imagenes/nodo_visitado.png"); Load_image(&boton_eliminar[1],"imagenes/botones/eliminar1.png"); Load_image(&boton_ino[0],"imagenes/botones/inorder0.png"); Load_image(&boton_ino[1],"imagenes/botones/inorder1.png"); Load_image(&boton_insertar[0],"imagenes/botones/insertar0.png"); Load_image(&boton_insertar[1],"imagenes/botones/insertar1.png"); Load_image(&boton_ok[0],"imagenes/botones/ok0.png"); Load_image(&boton_pos[0],"imagenes/botones/posorder0.png"); Load_image(&boton_pos[1],"imagenes/botones/posorder1.png"); Load_image(&boton_pre[0],"imagenes/botones/preorder0.png"); Load_image(&boton_pre[1],"imagenes/botones/preorder1.png"); Load_image(&boton_recorridos[0],"imagenes/botones/recorrido0.png"); Load_image(&boton_recorridos[1],"imagenes/botones/recorrido1.png"); Load_image(&boton_salir[0],"imagenes/botones/salir0.png"); Load_image(&boton_salir[1],"imagenes/botones/salir1.png"); }