public static unsafe void renderAlpha(pr2.IRenderImage dest, int x, int y, pr2.IRenderImage src, int opacity, bool drawZero) { int xlen = src.Width; int ylen = src.Height; int* s = src.Buffer; int* d = dest.Buffer; int spitch = xlen; int dpitch = dest.Pitch; if (clip(ref x, ref y, ref xlen, ref ylen, ref s, ref d, spitch, dpitch, 0, dest.Width, 0, dest.Height)) { return; } for (; ylen != 0; ylen--) { for (int xx = 0; xx < xlen; xx++) { handlePixelAlpha(s[xx], ref d[xx], opacity, drawZero); } s += spitch; d += dpitch; } }
public void paintMap(MapEventInfo mei, pr2.IRenderImage img) { this.mei = mei; this.img = img; onPaint(); }
public Vsp24Tile(Vsp24 parent, pr2.IRenderImage image) { this.parent = parent; this.image = image; this.avg = GetAverageColor(); }
public void start(pr2.sharppng.Png png) { this.png = png; this.width = png.ihdr.width; this.height = png.ihdr.height; intbuf = new int[width * height]; }
public void WriteData(pr2.sharppng.Pcx pcx) { Texture2D tex = null; try { tex = new Texture2D(device, pcx.width, pcx.height, false, SurfaceFormat.Color); int[] data = new int[pcx.width*pcx.height]; int dest = 0; tex.GetData(data); //reformat the palette int[] colors = new int[256]; for (int i=0; i<256; i++) colors[i] = (int)GameEngine.MakeColor(255, pcx.palette[i*3], pcx.palette[i*3+1], pcx.palette[i*3+2]).PackedValue; //blast into image int pad = pcx.bytes_per_line - pcx.width; fixed (byte* pixels = pcx.pixels) { byte* src = pixels; if (bColor0) for (int y=0; y<pcx.height; y++) { for (int x=0; x<pcx.width; x++) { byte b = *src++; int col = colors[b]; if (b == 0) col = 0; data[dest++] = col; } src += pad; } else for (int y=0; y<pcx.height; y++) { for (int x=0; x<pcx.width; x++) data[dest++] = colors[*src++]; src += pad; } } tex.SetData<int>(data, 0, data.Length); image = new Image(GameEngine.Game.Device, tex); tex = null; } finally { if (tex != null) tex.Dispose(); } }
void renderLayer(pr2.IRenderImage backBuffer, MapLayer mapLayer, int px, int py, bool drawZero) { switch (mapLayer.type) { case LayerType.Tile: renderTileLayer(backBuffer, mapLayer, ParentMap.vsp, px, py, drawZero); break; case LayerType.Zone: renderZoneLayer(backBuffer, mapLayer, px, py); break; case LayerType.Obs: renderObstructionLayer(backBuffer, mapLayer, px, py); break; default: break; } }
private void renderTileLayer(pr2.IRenderImage backBuffer, MapLayer layer, Vsp24 vsp, int px, int py, bool drawZero) { int mtx = px / 16; int mty = py / 16; int mtox = px & 15; int mtoy = py & 15; //we add 2; one for the case where we are scrolled a little bit //(and so parts of two tiles are drawn instead of one complete) //and one for the case where the screen is a funny size and a remainder bit is shown int tw = backBuffer.Width / 16 + 2; int th = backBuffer.Height / 16 + 2; int layerWidth = layer.Width; int layerHeight = layer.Height; int cpx = -mtox; int cpy = -mtoy; tw = System.Math.Min(tw, layerWidth - mtx); th = System.Math.Min(th, layerHeight - mty); int tp; int tile; int xmin = -mtox; int xmax = xmin + tw * 16; short[] tileMap = layer.Data; if (Global.RenderOptions.bTranslucentEffects) { for (int ty = 0; ty < th; ty++, cpy += 16) { tp = (ty + mty) * layerWidth + mtx; for (cpx = xmin; cpx < xmax; cpx += 16) { tile = tileMap[tp++]; if (Global.RenderOptions.bAnimate) { tile = Global.FrameCalc.getframe(tile); } if (drawZero || tile != 0 && tile < vsp.tileCount) { Render.renderAlpha(backBuffer, cpx, cpy, vsp.GetTile(tile).Image, 100 - layer.Translucency, false); } } } } else { for (int ty = 0; ty < th; ty++, cpy += 16) { tp = (ty + mty) * layerWidth + mtx; for (cpx = xmin; cpx < xmax; cpx += 16) { tile = tileMap[tp++]; if (Global.RenderOptions.bAnimate) { tile = Global.FrameCalc.getframe(tile); } if (drawZero || tile != 0 && tile < vsp.tileCount) { Render.render(backBuffer, cpx, cpy, vsp.GetTile(tile).Image, false); } } } } }
public static unsafe void renderNumber(pr2.IRenderImage img, int x0, int y0, int number, int color) { renderText(img, x0, y0, number.ToString(), color); }
public static unsafe void renderObsTileFast(pr2.IRenderImage img, int x0, int y0, pr2.IRenderImage src, bool clearbuf) { int xlen = Global.TILE_SIZE; int ylen = Global.TILE_SIZE; const int WHITE = unchecked((int)0xFFFFFFFF); const int BLACK = unchecked((int)0xFF000000); int* pixels = src.Buffer; int* s = pixels; int* d = img.Buffer; int spitch = Global.TILE_SIZE; int dpitch = img.Pitch; if (clip(ref x0, ref y0, ref xlen, ref ylen, ref s, ref d, spitch, dpitch, 0, img.Width, 0, img.Height)) { return; } if (clearbuf) { for (; ylen > 0; ylen--) { for (int x = 0; x < xlen; x++) { d[x] = (s[x] != 0) ? WHITE : BLACK; } s += spitch; d += dpitch; } } else { for (; ylen > 0; ylen--) { for (int x = 0; x < xlen; x++) { if (s[x] != 0) d[x] = WHITE; } s += spitch; d += dpitch; } } }
public static unsafe void renderColoredTile_50Alpha(pr2.IRenderImage img, int x0, int y0, int color) { int xlen = Global.TILE_SIZE; int ylen = Global.TILE_SIZE; int* s = null; int* d = img.Buffer; int dpitch = img.Pitch; if (clip(ref x0, ref y0, ref xlen, ref ylen, ref s, ref d, 0, dpitch, 0, img.Width, 0, img.Height)) { return; } for (; ylen > 0; ylen--) { for (int x = 0; x < xlen; x++) { handlePixel(color, ref d[x], (int)Render.PixelOp.Alpha50, true, true); } d += dpitch; } }
public static unsafe void renderColorPicker(pr2.IRenderImage img, float h) { int* dst = img.Buffer; for (int y = 0; y < 256; y++) { for (int x = 0; x < 256; x++) { *dst = HsbToColor(h, (float)x / 256, (float)y / 256); dst++; } } }
public static unsafe void renderColoredTile(pr2.IRenderImage img, int x0, int y0, int color) { int xlen = Global.TILE_SIZE; int ylen = Global.TILE_SIZE; int* s = null; int* d = img.Buffer; int dpitch = img.Pitch; if (clip(ref x0, ref y0, ref xlen, ref ylen, ref s, ref d, 0, dpitch, 0, img.Width, 0, img.Height)) return; for (; ylen > 0; ylen--) { for (int x = 0; x < xlen; x++) { d[x] = color; } d += dpitch; } }
public static unsafe void renderColoredStippleTile(pr2.IRenderImage img, int x0, int y0, int color1, int color2) { int xlen = Global.TILE_SIZE; int ylen = Global.TILE_SIZE; int* s = null; int* d = img.Buffer; int dpitch = img.Pitch; if (clip(ref x0, ref y0, ref xlen, ref ylen, ref s, ref d, 0, dpitch, 0, img.Width, 0, img.Height)) { return; } for (; ylen > 0; ylen--) { for (int x = 0; x < xlen; x++) { if (((ylen ^ x) & 1) != 0) { d[x] = color1; } else { d[x] = color2; } } d += dpitch; } }
public static void renderBox(pr2.IRenderImage img, int x0, int y0, int w, int h, int color, Render.PixelOp op) { renderSolid(img, x0, y0, w, 1, color, op); renderSolid(img, x0, y0 + h - 1, w, 1, color, op); renderSolid(img, x0, y0, 1, h, color, op); renderSolid(img, x0 + w - 1, y0, 1, h, color, op); }
public void paintMap(MapEventInfo mei, pr2.IRenderImage img) { }
public static unsafe void renderSolid(pr2.IRenderImage img, int x0, int y0, int w, int h, int color, Render.PixelOp op) { int bw = img.Width; int bh = img.Height; int bp = img.Pitch; for (int y = 0; y < h; y++) { if (y + y0 >= 0 && y + y0 < bh) { for (int x = 0; x < w; x++) { if (x + x0 >= 0 && x + x0 < bw) { handlePixel(color, ref img.Buffer[(y0 + y) * bp + x0 + x], (int)op, true, true); } } } } }
private void renderEntities(pr2.IRenderImage backBuffer, MapLayer ml, int px, int py) { int mtx = px / 16; int mty = py / 16; int mtox = px & 15; int mtoy = py & 15; int tw = backBuffer.Width / 16 + 2; int th = backBuffer.Height / 16 + 2; foreach (MapEntity me in ParentMap.Entities) { int tx = me.TileX; int ty = me.TileY; if (tx >= mtx && tx <= mtx + tw && ty >= mty && ty <= mty + th) { int cx = -mtox + (tx - mtx) * 16; int cy = -mtoy + (ty - mty) * 16; Render.renderColoredTile_50Alpha(backBuffer, cx, cy, Preferences.Current.EntsColor); Render.renderNumber(backBuffer, cx + 4, cy + 4, me.ID, unchecked((int)0xFFFFFFFF)); } } }
public static unsafe void renderText(pr2.IRenderImage img, int x0, int y0, string str, int color) { int height = img.Height; int width = img.Width; int* pixels = img.Buffer; char[] digits = str.ToCharArray(); foreach (char c in digits) { byte[] ba = BiosFont.Glyph(c); int glyphWidth = ba[0]; int glyphHeight = (ba.Length - 1) / glyphWidth; for (int y = 0; y < glyphHeight; y++) { if (y0 + y < 0 || y0 + y >= height) continue; for (int x = 0; x < glyphWidth; x++) { if (x0 + x < 0 || x0 + x >= width) continue; if (ba[1 + (y * glyphWidth) + x] == 1) { pixels[(y0 + y) * width + (x0 + x)] = color; } } } x0 += glyphWidth + 1; } }
private void renderObstructionLayer(pr2.IRenderImage backBuffer, MapLayer mapLayer, int px, int py) { int mtx = px / 16; int mty = py / 16; int mtox = px & 15; int mtoy = py & 15; //we add 2; one for the case where we are scrolled a little bit //(and so parts of two tiles are drawn instead of one complete) //and one for the case where the screen is a funny size and a remainder bit is shown int tw = backBuffer.Width / 16 + 2; int th = backBuffer.Height / 16 + 2; int layerWidth = mapLayer.Width; int layerHeight = mapLayer.Height; int cpx = -mtox; int cpy = -mtoy; tw = System.Math.Min(tw, layerWidth - mtx); th = System.Math.Min(th, layerHeight - mty); int tp; int tile; int xmin = -mtox; int xmax = xmin + tw * 16; short[] tileMap = mapLayer.Data; if (Global.RenderOptions.bTranslucentEffects) { for (int ty = 0; ty < th; ty++, cpy += 16) { tp = (ty + mty) * layerWidth + mtx; for (cpx = xmin; cpx < xmax; cpx += 16) { tile = tileMap[tp++]; if (0 < tile && tile < ParentMap.vsp.ObstructionTiles.Count) { Render.renderObsTile(backBuffer, cpx, cpy, ((VspObstructionTile)ParentMap.vsp.ObstructionTiles[tile]).Image, false, Preferences.Current.ObsColor); } } } } else { for (int ty = 0; ty < th; ty++, cpy += 16) { tp = (ty + mty) * layerWidth + mtx; for (cpx = xmin; cpx < xmax; cpx += 16) { tile = tileMap[tp++]; if (0 < tile && tile < ParentMap.vsp.ObstructionTiles.Count) { Render.renderObsTileFast(backBuffer, cpx, cpy, ((VspObstructionTile)ParentMap.vsp.ObstructionTiles[tile]).Image, false); } } } } }
public static void setImage(pr2.IRenderImage img) { Bitmap bmp = img.ConvertToBitmap(); setBitmap(bmp); bmp.Dispose(); }
private void renderZoneLayer(pr2.IRenderImage backBuffer, MapLayer mapLayer, int px, int py) { int mtx = px / 16; int mty = py / 16; int mtox = px & 15; int mtoy = py & 15; //we add 2; one for the case where we are scrolled a little bit //(and so parts of two tiles are drawn instead of one complete) //and one for the case where the screen is a funny size and a remainder bit is shown int tw = backBuffer.Width / 16 + 2; int th = backBuffer.Height / 16 + 2; int layerWidth = mapLayer.Width; int layerHeight = mapLayer.Height; int cpx = -mtox; int cpy = -mtoy; tw = System.Math.Min(tw, layerWidth - mtx); th = System.Math.Min(th, layerHeight - mty); int tp; int tile; int xmin = -mtox; int xmax = xmin + tw * 16; const int WHITE = unchecked((int)0xFFFFFFFF); short[] tileMap = mapLayer.Data; for (int ty = 0; ty < th; ty++, cpy += 16) { tp = (ty + mty) * layerWidth + mtx; if (Global.RenderOptions.bTranslucentEffects) { for (cpx = xmin; cpx < xmax; cpx += 16) { if ((tile = tileMap[tp++]) != 0) { Render.renderColoredTile_50Alpha(backBuffer, cpx, cpy, Preferences.Current.ZonesColor); Render.renderNumber(backBuffer, cpx, cpy, tile, WHITE); } } } else { for (cpx = xmin; cpx < xmax; cpx += 16) { if ((tile = tileMap[tp++]) != 0) { Render.renderColoredTile(backBuffer, cpx, cpy, Preferences.Current.ZonesColor); Render.renderNumber(backBuffer, cpx, cpy, tile, WHITE); } } } } }
public static unsafe void renderObsTile(pr2.IRenderImage img, int x0, int y0, pr2.IRenderImage src, bool clearbuf, int color) { int xlen = 16; int ylen = 16; const int WHITE = unchecked((int)0xFFFFFFFF); const int BLACK = unchecked((int)0xFF000000); const int spitch = 16; int dpitch = img.Pitch; int* ptr = src.Buffer; int* s = ptr; int* d = img.Buffer; if (clip(ref x0, ref y0, ref xlen, ref ylen, ref s, ref d, spitch, dpitch, 0, img.Width, 0, img.Height)) { return; } if (clearbuf) { for (; ylen > 0; ylen--) { for (int x = 0; x < xlen; x++) { d[x] = (s[x] != 0) ? WHITE : BLACK; } s += spitch; d += dpitch; } } else { for (; ylen > 0; ylen--) { for (int x = 0; x < xlen; x++) { if (s[x] != 0) { handlePixel(color, ref d[x], (int)Render.PixelOp.Alpha50, true, true); } } s += spitch; d += dpitch; } } }