public void Test_LoadXML_OLD_sprite_1x1() { Palette p = m_doc.Palettes.AddPalette16(Options.DefaultPaletteName, 0, ""); Assert.IsNotNull(p); Spriteset ss = m_doc.Spritesets.AddSpriteset(Options.DefaultSpritesetName, 0, "", p); Assert.IsNotNull(ss); Sprite s = ss.AddSprite(1, 1, "sample", 0, "", 0, null); Assert.IsNotNull(s); XmlElement xnSprite = m_xd.CreateElement("sprite"); Test_LoadXML_OLD_sprite_AddTile(xnSprite, 0); Assert.IsTrue(m_filer.LoadXML_OLD_sprite(s, xnSprite.ChildNodes)); // Verify the data is the same as the XML // Pixel 0 is the same as the tileid Assert.AreEqual(0, s.GetTile(0).GetPixel(0, 0)); // Other pixels = x+y Assert.AreEqual(3, s.GetTile(0).GetPixel(1, 2)); Assert.AreEqual(14, s.GetTile(0).GetPixel(7, 7)); }
public void Test_LoadXML_sprite16_1x1() { Palette p = m_doc.Palettes.AddPalette16(Options.DefaultPaletteName, 0, ""); Assert.IsNotNull(p); Spriteset ss = m_doc.Spritesets.AddSpriteset(Options.DefaultSpritesetName, 0, "", p); Assert.IsNotNull(ss); Sprite s = ss.AddSprite(1, 1, "sample", 0, "", 0, null); Assert.IsNotNull(s); XmlElement xnSprite = m_xd.CreateElement("sprite16"); // Note: <sprite16> attributes not needed for test. Test_LoadXML_sprite16_AddTile(xnSprite, 0, 8, 8); Assert.IsTrue(s.LoadXML_sprite16(xnSprite, 0)); // Verify the data is the same as the XML // Pixel 0 is the same as the tileid Assert.AreEqual(0, s.GetTile(0).GetPixel(0, 0)); // Other pixels = x+y Assert.AreEqual(9, s.GetTile(0).GetPixel(4, 5)); Assert.AreEqual(14, s.GetTile(0).GetPixel(7, 7)); }
private bool HandleMouseMove(int pxX, int pxY, Toolbox.ToolType tool) { if (m_sprite == null || pxX < 0 || pxY < 0) { return(false); } // Convert screen pixel (x,y) to sprite pixel index (x,y). int pxSpriteX = pxX / BigBitmapPixelSize; int pxSpriteY = pxY / BigBitmapPixelSize; // Ignore if pixel is outside bounds of current sprite. if (pxSpriteX >= m_sprite.PixelWidth || pxSpriteY >= m_sprite.PixelHeight) { return(false); } if (tool == Toolbox.ToolType.FloodFill) { return(m_sprite.FloodFillClick(pxSpriteX, pxSpriteY)); } // Convert sprite pixel coords (x,y) into tile index (x,y) and tile pixel coords (x,y). int tileX = pxSpriteX / Tile.TileSize; int pxTileX = pxSpriteX % Tile.TileSize; int tileY = pxSpriteY / Tile.TileSize; int pxTileY = pxSpriteY % Tile.TileSize; int nTileIndex = (tileY * m_sprite.TileWidth) + tileX; Palette p = m_parent.ActivePalette(); if (tool == Toolbox.ToolType.Eyedropper) { int nCurrColor = m_sprite.GetPixel(pxSpriteX, pxSpriteY); if (nCurrColor == p.CurrentColor()) { return(false); } p.SetCurrentColor(nCurrColor); return(true); } Tile t = m_sprite.GetTile(nTileIndex); int nColor = (tool == Toolbox.ToolType.Eraser ? 0 : p.CurrentColor()); // Same color - no need to update. if (t.GetPixel(pxTileX, pxTileY) == nColor) { return(false); } // Set the new color. t.SetPixel(pxTileX, pxTileY, nColor); return(true); }
public void Test_LoadXML_sprite16_2x4() { Palette p = m_doc.Palettes.AddPalette16(Options.DefaultPaletteName, 0, ""); Assert.IsNotNull(p); Spriteset ss = m_doc.Spritesets.AddSpriteset(Options.DefaultSpritesetName, 0, "", p); Assert.IsNotNull(ss); Sprite s = ss.AddSprite(2, 4, "sample", 0, "", 0, null); Assert.IsNotNull(s); XmlElement xnSprite = m_xd.CreateElement("sprite16"); for (int i = 0; i < 8; i++) { Test_LoadXML_sprite16_AddTile(xnSprite, i, 8, 8); } Assert.IsTrue(s.LoadXML_sprite16(xnSprite, 0)); // Verify the data is the same as the XML // Pixel 0 is the same as the tileid Assert.AreEqual(0, s.GetTile(0).GetPixel(0, 0)); Assert.AreEqual(3, s.GetTile(3).GetPixel(0, 0)); Assert.AreEqual(7, s.GetTile(7).GetPixel(0, 0)); // Other pixels = x+y Assert.AreEqual(9, s.GetTile(0).GetPixel(4, 5)); Assert.AreEqual(3, s.GetTile(4).GetPixel(0, 3)); Assert.AreEqual(14, s.GetTile(7).GetPixel(7, 7)); }
private void pbMap_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; int pxX = 0; int pxY = 0; for (int ix = 0; ix < k_nMaxMapTilesX; ix++) { pxY = 0; for (int iy = 0; iy < k_nMaxMapTilesY; iy++) { bool fDrawn = false; int nTileId, nSubpalette; m_map.GetTile(ix, iy, out nTileId, out nSubpalette); Sprite s = m_map.Spriteset.FindSprite(nTileId); if (s != null) { Tile t = s.GetTile(nTileId - s.FirstTileId); if (t != null) { t.DrawSmallTile(g, pxX, pxY); fDrawn = true; } } if (!fDrawn) { int pxInset = Tile.SmallBitmapScreenSize / 4; int pxX0i = pxX + pxInset; int pxY0i = pxY + pxInset; int pxX1i = pxX + Tile.SmallBitmapScreenSize - pxInset; int pxY1i = pxY + Tile.SmallBitmapScreenSize - pxInset; g.DrawLine(Pens.Firebrick, pxX0i, pxY0i, pxX1i, pxY1i); g.DrawLine(Pens.Firebrick, pxX0i, pxY1i, pxX1i, pxY0i); } pxY += Tile.SmallBitmapScreenSize; } pxX += Tile.SmallBitmapScreenSize; } // Draw the grid and border. int pxTileSize = Tile.SmallBitmapScreenSize; pxX = 0; pxY = 0; int pxWidth = pxTileSize * k_nMaxMapTilesX; int pxHeight = pxTileSize * k_nMaxMapTilesY; if (Options.BackgroundMap_ShowGrid) { Pen penTileBorder = Pens.LightGray; // Draw a border around each tile. for (int i = pxX + pxTileSize; i < pxWidth; i += pxTileSize) { g.DrawLine(penTileBorder, i, pxY, i, pxHeight); } for (int i = pxY + pxTileSize; i < pxHeight; i += pxTileSize) { g.DrawLine(penTileBorder, pxX, i, pxWidth, i); } } // Draw the outer border. g.DrawRectangle(Pens.Black, pxX, pxY, pxWidth, pxHeight); if (Options.BackgroundMap_ShowScreen) { if (Options.Platform == Options.PlatformType.GBA) { pxWidth = pxTileSize * k_nGBAScreenTilesX; pxHeight = pxTileSize * k_nGBAScreenTilesY; } else { pxWidth = pxTileSize * k_nNDSScreenTilesX; pxHeight = pxTileSize * k_nNDSScreenTilesY; } g.DrawRectangle(m_penHilight, pxX, pxY, pxWidth, pxHeight); g.DrawRectangle(m_penHilight2, pxX, pxY, pxWidth, pxHeight); } // Draw a border around the current background "sprite". Sprite spriteSelected = m_ss.CurrentSprite; if (m_tileSpriteX != -1 && m_tileSpriteY != -1 && spriteSelected != null) { pxX = m_tileSpriteX * pxTileSize; pxY = m_tileSpriteY * pxTileSize; pxWidth = spriteSelected.TileWidth * pxTileSize; pxHeight = spriteSelected.TileHeight * pxTileSize; g.DrawRectangle(m_penHilight, pxX, pxY, pxWidth, pxHeight); g.DrawRectangle(m_penHilight2, pxX, pxY, pxWidth, pxHeight); } }