public static SDL_Surface CreateSurface(int w, int h, bool f) { SDL_Surface sur = new SDL_Surface(); /* SDL_PixelFormat* spf = SDL_GetVideoSurface()->format; if ((sur = SDL_CreateRGBSurface(f, w, h, spf->BitsPerPixel, spf->Rmask, spf->Gmask, spf->Bmask, spf->Amask)) == 0) { fprintf(stderr, "ERR: ssur_create: not enough memory to create surface...\n"); exit(1); } */ /* if (f & SDL_HWSURFACE && !(sur->flags & SDL_HWSURFACE)) fprintf(stderr, "unable to create surface (%ix%ix%i) in hardware memory...\n", w, h, spf->BitsPerPixel);*/ // SDL_SetColorKey(sur, SDL_SRCCOLORKEY, 0x0); // SDL_SetAlpha(sur, 0, 0); /* no alpha */ sur.Bitmap = new System.Drawing.Bitmap(w, h); sur.name ="Creado vacio"; return sur; }
public static void copy_image(SDL_Surface dest, int xdest, int ydest, int w, int h, SDL_Surface src, int xsrc, int ysrc, int alpha) { Graphics graphic; if (dest.surf != null && dest.bitmap == null) graphic = dest.surf; else graphic = Graphics.FromImage(dest.bitmap); set_alpha(alpha); graphic.DrawImage(src.bitmap, new Rectangle(xdest, ydest, w, h), xsrc, ysrc, w, h, GraphicsUnit.Pixel, imageAttr); }
public static Anim anim_create(SDL_Surface surf) { return new Anim(); }
public static void SDL_SetColorKey(SDL_Surface dest, Color color_key) { try{ Color[] c = dest.bitmap.GetPixels(); for (int i=0; i<c.Length; i++){ if (c[i]==color_key){ c[i].b = c[i].b; c[i].r = c[i].r; c[i].g = c[i].g; c[i].a = 0; } else{ c[i].b = c[i].b; c[i].r = c[i].r; c[i].g = c[i].g; c[i].a = 1; } } dest.bitmap.SetPixels(c); dest.bitmap.Apply(); dest.bitmapMaterial=new Material(Shader.Find("Transparent/Cutout/Diffuse")); dest.bitmapMaterial.mainTexture = dest.bitmap; } catch(Exception e){ Debug.LogError(e.Message); } }
public void unitToFile() { try { foreach (Unit_Lib_Entry unit in this.unit_lib) { int e = TextureTable.elegirImgUnit (unit); SDL_Surface sdl = SDL_Surface.LoadSurface ("Textures/units/pg1", false); SDL_Surface dest = new SDL_Surface (); if (e == 1) { int o = (sdl.h - unit.offset_img - unit.icon_h); if (o >= 0) { SDL_Surface.copy_image (dest, unit.icon_w, unit.icon_h, sdl, 0, o); byte[] bytes = dest.bitmap.EncodeToPNG (); File.WriteAllBytes (Application.dataPath + "/../Unit/" + unit.id + ".png", bytes); } else { Debug.Log (unit.name); } } else if (e == 2) { SDL_Surface sdl2 = SDL_Surface.LoadSurface ("Textures/units/pg2", false); int v = unit.offset_img + 2 - sdl.h + unit.icon_h; int v2 = sdl2.h - v; if (v2 >= 0) { SDL_Surface.copy_image (dest, unit.icon_w, unit.icon_h, sdl2, 0, v2); byte[] bytes = dest.bitmap.EncodeToPNG (); File.WriteAllBytes (Application.dataPath + "/../Unit/" + unit.id + ".png", bytes); } else { Debug.Log (unit.name); } } } } catch (Exception e) { Debug.LogError (e.Message); } }
public static void nationstofile() { for (int i=0; i<nations.Length;i++){ Debug.Log(nations[i].name+" "+nations[i].flag_offset); SDL_Surface dest = new SDL_Surface(); SDL_Surface.copy_image(dest,Nation.nation_flag_width, Nation.nation_flag_height,Nation.nation_flags,0, (Nation.nation_flags.h-nations[i].flag_offset-Nation.nation_flag_height),false); byte[] bytes = dest.bitmap.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/../Imagenes/"+nations[i].name+".png", bytes); } }
public static void full_copy_image(SDL_Surface dest, SDL_Surface src) { if (src==null || dest==null) throw new Exception("the source or destination image is null"); try{ Texture2D nueva = new Texture2D(src.w,src.h,TextureFormat.RGB24,false); for (int i=0;i<src.w;i++){ for (int j=0; j<src.h;j++){ Color c = src.bitmap.GetPixel(i,j); nueva.SetPixel(i,j,c); } } nueva.Apply(); dest = new SDL_Surface(); dest.bitmap = nueva; dest.w = src.w; dest.h = src.h; } catch(Exception e){ Debug.LogError("Problems with the copy of image: " + e.Message); } }
public static void copy_image(SDL_Surface dest, int w, int h, SDL_Surface src, int xsrc, int ysrc) { if (src==null || dest==null) throw new Exception("the source or destination image is null"); try{ Color[] pixels = src.bitmap.GetPixels(xsrc,ysrc,w,h); Texture2D tex = new Texture2D (w, h,TextureFormat.RGB24,false); tex.SetPixels (pixels); tex.Apply (); dest.bitmap = tex; dest.w = w; dest.h = h; } catch(Exception e){ Debug.LogError("Problems with the copy of image: " + e.Message); } }
public static void copy_image(SDL_Surface dest, SDL_Surface src,int xdest, int ydest,int wsrc, int hsrc, int xsrc, int ysrc) { try{ if (src==null || dest==null) throw new Exception("the source or destination image is null"); Color[] c = src.bitmap.GetPixels(xsrc,ysrc,wsrc,hsrc); dest.bitmap.SetPixels(xdest,ydest,wsrc, hsrc,c); dest.bitmap.Apply(); } catch(Exception e){ Debug.LogError("Problems with the copy: "+ e.Message); } }
public static void copy_image_without_key(SDL_Surface dest,SDL_Surface src,int xdest, int ydest,Color key) { try{ for (int i=0; i<src.w;i++){ for (int j=0; j<src.h;j++){ Color c = src.bitmap.GetPixel(i,j); if (c!=key){ dest.bitmap.SetPixel(xdest+i,ydest+j,c); } } } dest.bitmap.Apply(); } catch(Exception e){ Debug.LogError(e.Message); } }
private void AddTextureTerrain(GameObject hex, Map_Tile tile) { int offset; string path; if (tile.terrain.name.ToLower () == "mountain") { print ("entra"); int numT = TextureTable.elegirImgTex (tile.strat_image_offset); path = pathTexTerrain + tile.terrain.name.ToLower () + numT; offset = 0; if (numT == 1) { offset = tile.strat_image_offset * Config.hex_w - Config.hex_w; } else { offset = (tile.strat_image_offset - 39) * Config.hex_w - Config.hex_w; } } else { path = pathTexTerrain + tile.terrain.name.ToLower (); offset = (tile.strat_image_offset * Config.hex_w) - Config.hex_w; } SDL_Surface terraintex = SDL_Surface.LoadSurface (path, false); SDL_Surface hextex = new SDL_Surface (); SDL_Surface.copy_image (hextex, Config.hex_w, Config.hex_h, terraintex, offset, 0); //Add texture flag if (tile.nation != null) { Nation.nation_draw_flag(tile.nation,hextex); } hex.renderer.material.mainTexture = hextex.bitmap; }
/// <summary> /// Draw a map tile terrain to surface. (fogged if mask::fog is set) /// </summary> /// <param name="surf"></param> /// <param name="map_x"></param> /// <param name="map_y"></param> /// <param name="x"></param> /// <param name="y"></param> public SDL_Surface map_draw_terrain (int map_x, int map_y) { int cur_weather = 0; int offset; string path; Map_Tile tile; if (map_x < 0 || map_y < 0 || map_x >= map_w || map_y >= map_h) throw new Exception ("Position of the tile out of the map"); tile = map [map_x, map_y]; if (tile.terrain.name.ToLower () == "mountain") { int numT = TextureTable.elegirImgTex (tile.strat_image_offset); path = Config.PathTexTerrain + tile.terrain.name.ToLower () + numT; offset = 0; if (numT == 1) { offset = tile.strat_image_offset * Config.hex_w - Config.hex_w; } else { offset = (tile.strat_image_offset - 39) * Config.hex_w - Config.hex_w; } } else { path = Config.PathTexTerrain + tile.terrain.name.ToLower (); offset = (tile.strat_image_offset * Config.hex_w) - Config.hex_w; } SDL_Surface terraintex = SDL_Surface.LoadSurface (path, false); SDL_Surface hextex = new SDL_Surface (); SDL_Surface.copy_image (hextex, Config.hex_w, Config.hex_h, terraintex, offset, 0); //Add texture flag if (tile.nation != null) { hextex = Nation.nation_draw_flag (tile.nation, hextex); } return hextex; #if TODO_RR /* terrain */ if (mask [map_x, map_y].fog) { SDL_Surface sdl = SDL_Surface.LoadSurface(tile.terrain.images_fogged [cur_weather]); surf.surf.DrawImage (sdl.bitmap, x, y, new Rectangle (tile.image_offset, 0, hex_w, hex_h), GraphicsUnit.Pixel); } else { SDL_Surface sdl = tile.terrain.images [cur_weather]; surf.surf.DrawImage (sdl.bitmap, x, y, new Rectangle (tile.image_offset, 0, hex_w, hex_h), GraphicsUnit.Pixel); } /* grid */ if (Config.grid) { SDL_Surface.copy_image (surf, x, y, hex_w, hex_h, Engine.terrain.terrainIcons.grid, 0, 0); } #endif }
/// <summary> /// Draw tile units. If mask::fog is set no units are drawn. /// If 'ground' is True the ground unit is drawn as primary /// and the air unit is drawn small (and vice versa). /// If 'select' is set a selection frame is added. /// </summary> /// <param name="surf"></param> /// <param name="map_x"></param> /// <param name="map_y"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="ground"></param> /// <param name="select"></param> public SDL_Surface map_draw_units (SDL_Surface hexTex, int map_x, int map_y,bool ground) { Player cur_player = Engine.cur_player; Unit unit = null; Map_Tile tile; if (map_x < 0 || map_y < 0 || map_x >= map_w || map_y >= map_h) throw new Exception ("Position out of map"); tile = map [map_x, map_y]; /* units */ if (MAP_CHECK_VIS (map_x, map_y)) { if (tile.g_unit != null) { unit = tile.g_unit; bool resize = (ground || tile.a_unit == null)?false:true; draw_unit_on_texture(hexTex,unit,resize); } if (tile.a_unit != null) { unit = tile.a_unit; bool resize = (!ground || tile.g_unit == null)?false:true; draw_unit_on_texture(hexTex,unit,resize); } /* unit info icons */ if (unit != null && Config.show_bar) { /* strength */ if (unit.player.ctrl==PLAYERCONTROL.PLAYER_CTRL_HUMAN){ //TODO_RR if ((cur_player != null) && Player.player_is_ally (cur_player, unit.player)){ string name = Unit.DeleteOrdinal (unit.name); SDL_Surface sdl_str = SDL_Surface.LoadSurface(DB.UnitLib.unit_info_icons.str_img_name,false); int offset = DB.UnitLib.unit_info_icons.str_h*(unit.str+15); offset = sdl_str.h-offset; SDL_Surface str = new SDL_Surface(); SDL_Surface.copy_image(str,DB.UnitLib.unit_info_icons.str_w, DB.UnitLib.unit_info_icons.str_h,sdl_str,0,offset); int xdest = (Config.hex_w-DB.UnitLib.unit_info_icons.str_w)/2; SDL_Surface.copy_image(hexTex,str,xdest,3,DB.UnitLib.unit_info_icons.str_w, DB.UnitLib.unit_info_icons.str_h,0,0); } else{ string name = Unit.DeleteOrdinal (unit.name); SDL_Surface sdl_str = SDL_Surface.LoadSurface(DB.UnitLib.unit_info_icons.str_img_name,false); int offset = DB.UnitLib.unit_info_icons.str_h*(unit.str); offset = sdl_str.h-offset; SDL_Surface str = new SDL_Surface(); SDL_Surface.copy_image(str,DB.UnitLib.unit_info_icons.str_w, DB.UnitLib.unit_info_icons.str_h,sdl_str,0,offset); int xdest = (Config.hex_w-DB.UnitLib.unit_info_icons.str_w)/2; SDL_Surface.copy_image(hexTex,str,xdest,3,DB.UnitLib.unit_info_icons.str_w, DB.UnitLib.unit_info_icons.str_h,0,0); } /* for current player only */ if (unit.player.ctrl==PLAYERCONTROL.PLAYER_CTRL_HUMAN){ //TODO_RR if (unit.player == cur_player) { string name = Unit.DeleteOrdinal(unit.name); Unit_Lib_Entry entry = DB.UnitLib.unit_lib_find_by_name(name); /* attack */ if (entry.atk_count>0){ //TODO_RR if (unit.cur_atk_count > 0) { SDL_Surface atk = SDL_Surface.LoadSurface(DB.UnitLib.unit_info_icons.atk_img_name,false); SDL_Surface.copy_image_without_key(hexTex,atk,15,3,Color.black); } /* move */ if (entry.mov>0){ //TODO_RR if (unit.cur_mov > 0) { SDL_Surface mov = SDL_Surface.LoadSurface(DB.UnitLib.unit_info_icons.mov_img_name,false); SDL_Surface.copy_image_without_key(hexTex,mov,37,3,Color.black); } #if TODO_RR /* guarding */ if (unit.is_guarding) { SDL_Surface.copy_image (surf.surf, x + ((hex_w - DB.UnitLib.unit_info_icons.guard.w) >> 1), y + hex_h - DB.UnitLib.unit_info_icons.guard.h, DB.UnitLib.unit_info_icons.guard.w, DB.UnitLib.unit_info_icons.guard.h, DB.UnitLib.unit_info_icons.guard, 0, 0); } #endif } } } #if TODO_RR }
public static void copy_image(Graphics graphic, int xdest, int ydest, int w, int h, SDL_Surface src, int xsrc, int ysrc) { graphic.DrawImage(src.bitmap, xdest, ydest, new Rectangle(xsrc, ysrc, w, h), GraphicsUnit.Pixel); }
public static Color GetPixel(SDL_Surface surf, int x, int y) { return surf.bitmap.GetPixel(x, y); }
public static Int32 SetPixel(SDL_Surface surf, int x, int y, int pixel) { surf.bitmap.SetPixel(x, y, Color.FromArgb(pixel)); return surf.bitmap.GetPixel(x, y).ToArgb(); }
/* load a surface from file putting it in soft or hardware mem */ public static SDL_Surface LoadSurface(string fname, bool applyTransparency) { SDL_Surface sdl = new SDL_Surface(); try { if (fname != null) { sdl.bitmap = Resources.Load(fname) as Texture2D; sdl.w = sdl.bitmap.width; sdl.h = sdl.bitmap.height; sdl.name = fname; sdl.w = sdl.bitmap.width; sdl.h = sdl.bitmap.height; #if TODO_RR if (applyTransparency){ Color[] c = sdl.bitmap.GetPixels(); for (int i=0; i<c.Length; i++){ if (c[i]==Color.black){ c[i].b = c[i].b; c[i].r = c[i].r; c[i].g = c[i].g; c[i].a = 0; } else{ c[i].b = c[i].b; c[i].r = c[i].r; c[i].g = c[i].g; c[i].a = 1; } } sdl.bitmap.SetPixels(c); sdl.bitmap.Apply(); sdl.bitmapMaterial = new Material(Shader.Find("Transparent/Cutout/Diffuse")); sdl.bitmapMaterial.mainTexture = sdl.bitmap; } else{ sdl.bitmapMaterial = new Material(Shader.Find("Diffuse")); sdl.bitmapMaterial.mainTexture = sdl.bitmap; } #endif sdl.bitmapMaterial = new Material(Shader.Find("Diffuse")); sdl.bitmapMaterial.mainTexture = sdl.bitmap; } return sdl; } catch (Exception e) { Debug.LogError("error trying to load and create a Texture2D " + fname); Debug.LogError(e.Message); return sdl; //throw e; } }
static void SDL_FreeSurface(SDL_Surface s) { throw new System.NotImplementedException (); }
public static void putPixelBlack(SDL_Surface surf) { try{ surf.bitmap.SetPixel(0,0,Color.black); surf.bitmap.SetPixel(surf.bitmap.width,surf.bitmap.height-1,Color.black); surf.bitmap.SetPixel(surf.bitmap.width,surf.bitmap.height-2,Color.black); surf.bitmap.SetPixel(surf.bitmap.width-1,surf.bitmap.height-1,Color.black); surf.bitmap.SetPixel(surf.bitmap.width-1,surf.bitmap.height-2,Color.black); surf.bitmap.SetPixel(0,surf.bitmap.height-1,Color.black); surf.bitmap.Apply(); } catch(Exception e){ Debug.LogError(e.Message); } }
/* ==================================================================== Locals ==================================================================== */ /* ==================================================================== Get the geometry of an icon in surface 'icons' by using the three measure dots in the left upper, right upper, left lower corner. ==================================================================== */ static void unit_get_icon_geometry(int icon_id, SDL_Surface icons, out int width, out int height, out int offset, out Int32 key) { Int32 mark; int y; int count = icon_id * 2; /* there are two pixels for one icon */ /* nada white dot! take the first pixel found in the upper left corner as mark */ mark = SDL_Surface.GetPixel(icons, 0, 0); /* compute offset */ for (y = 0; y < icons.h; y++) if (SDL_Surface.GetPixel(icons, 0, y) == mark) { if (count == 0) break; count--; } offset = y; /* compute height */ y++; while (y < icons.h && SDL_Surface.GetPixel(icons, 0, y) != mark) y++; height = y - offset + 1; /* compute width */ y = offset; width = 1; while (SDL_Surface.GetPixel(icons, width, y) != mark) width++; width++; /* pixel beside left upper measure key is color key */ key = SDL_Surface.GetPixel(icons, 1, offset); }
public static SDL_Surface nation_draw_flag(Nation nation, SDL_Surface surf) { if (surf==null){ throw new Exception("the Surface is null"); } SDL_Surface.copy_image(surf,Nation.nation_flags,20,3,Nation.nation_flag_width, Nation.nation_flag_height,0,(Nation.nation_flags.h-nation.flag_offset-Nation.nation_flag_height)); return surf; }