/// <summary> /// Handle a mouse move while the mouse button is held down. /// </summary> /// <param name="pxX"></param> /// <param name="pxY"></param> /// <param name="tool"></param> /// <returns>True if we need to update the map display.</returns> public bool HandleMouse(int pxX, int pxY, Toolbox.ToolType tool) { Sprite spriteSelected = m_ss.CurrentSprite; if (spriteSelected == null) { return(false); } if (pxX < 0 || pxY < 0) { return(false); } // Convert screen pixel (x,y) to map coordinate (x,y). int x = pxX / Tile.SmallBitmapScreenSize; int y = pxY / Tile.SmallBitmapScreenSize; if (x >= k_nMaxMapTilesX || y >= k_nMaxMapTilesY) { return(false); } if (tool == Toolbox.ToolType.FloodFill) { return(FloodFillClick(x, y)); } if (tool == Toolbox.ToolType.RubberStamp) { bool fUpdate = false; int nIndex = 0; for (int iy = 0; iy < spriteSelected.TileHeight; iy++) { if (y + iy >= k_nMaxMapTilesY) { nIndex++; continue; } for (int ix = 0; ix < spriteSelected.TileWidth; ix++) { if (x + ix >= k_nMaxMapTilesX) { nIndex++; continue; } m_map.SetTile(x + ix, y + iy, spriteSelected.FirstTileId + nIndex, spriteSelected.SubpaletteID); nIndex++; fUpdate = true; } } return(fUpdate); } return(false); }
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); }
/// <summary> /// Finish an editing operation. /// </summary> private void FinishEdit(Toolbox.ToolType tool) { switch (tool) { case Toolbox.ToolType.Eraser: case Toolbox.ToolType.Eyedropper: case Toolbox.ToolType.FloodFill: case Toolbox.ToolType.Pencil: // These are immediate tools - nothing to finish up. return; } //return m_Tiles[nTileIndex].Click(pxX, pxY, tool == Toolbox.ToolType.Eraser); }
private void pbMap_MouseMove(object sender, MouseEventArgs e) { if (m_fEditBackgroundMap_Selecting) { Toolbox.ToolType tool = m_toolbox.CurrentToolType; if (HandleMouse(e.X, e.Y, tool)) { m_parent.HandleMapDataChange(m_map); } } // Update boundary rect for currently selected sprite. if (HandleMouseMove(e.X, e.Y)) { pbMap.Invalidate(); } }
private void pbSprite_MouseUp(object sender, MouseEventArgs e) { if (m_fEditSprite_Selecting) { Toolbox.ToolType tool = m_toolbox.CurrentToolType; // Close out the edit action. FinishEdit(tool); // Record the undo action. string strTool = ""; bool fRecordUndo = false; switch (tool) { //case Toolbox.ToolType.Select - no undo case Toolbox.ToolType.Pencil: strTool = "pencil"; fRecordUndo = true; break; //case Toolbox.ToolType.Eyedropper - no undo case Toolbox.ToolType.FloodFill: strTool = "bucket"; fRecordUndo = true; break; case Toolbox.ToolType.Eraser: strTool = "eraser"; break; } if (fRecordUndo) { Sprite s = m_ss.CurrentSprite; if (s != null) { s.RecordUndoAction(strTool, m_parent.ActiveUndo()); } } } m_fEditSprite_Selecting = false; }
private void pbSprite_MouseMove(object sender, MouseEventArgs e) { if (m_fEditSprite_Selecting) { Toolbox.ToolType tool = m_toolbox.CurrentToolType; if (m_fEditSprite_Erase) { tool = Toolbox.ToolType.Eraser; } if (HandleMouseMove(e.X, e.Y, tool)) { if (tool == Toolbox.ToolType.Eyedropper) { m_parent.HandleColorSelectChange(m_ss.Palette); } else { m_sprite.FlushBitmaps(); m_parent.HandleSpriteDataChanged(m_ss); } } } }