From da872e840866dfa5d1140befdbadd0a58944be8f Mon Sep 17 00:00:00 2001 From: Florian Rival Date: Sun, 4 Jan 2015 17:03:26 +0100 Subject: [PATCH] Fixed pencil not always erasing with right click in TileMap editor + fixed crash when erasing outside the map or floodfilling with the same tile as the clicked one. --- .../TileMapObject/TileMapObjectEditorCommands.h | 6 +++++- Extensions/TileMapObject/TileMapPanel.cpp | 11 +++++------ Extensions/TileMapObject/TileMapPanel.h | 10 +++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Extensions/TileMapObject/TileMapObjectEditorCommands.h b/Extensions/TileMapObject/TileMapObjectEditorCommands.h index 0d96767895..bc410de901 100644 --- a/Extensions/TileMapObject/TileMapObjectEditorCommands.h +++ b/Extensions/TileMapObject/TileMapObjectEditorCommands.h @@ -89,10 +89,14 @@ public: virtual bool Do() { + if (m_col < 0 || m_col >= m_tileMap.GetColumnsCount() || m_row < 0 || m_row >= m_tileMap.GetRowsCount()) + return true; //Out of bound position. + m_tileChanged.clear(); m_oldTileId = m_tileMap.GetTile(m_layer, m_col, m_row); - FloodFill(m_col, m_row); + if (m_newTileId != m_oldTileId) //Beware, flood fill will loop forever if replacing a tile with the same! + FloodFill(m_col, m_row); return true; } diff --git a/Extensions/TileMapObject/TileMapPanel.cpp b/Extensions/TileMapObject/TileMapPanel.cpp index 50985cebc9..25b20f1adf 100644 --- a/Extensions/TileMapObject/TileMapPanel.cpp +++ b/Extensions/TileMapObject/TileMapPanel.cpp @@ -73,9 +73,9 @@ void TileMapPanel::FillLayer(int layer, int tile) if(!m_tilemap) return; - for (int col = 0; col < m_tilemap->GetColumnsCount(); col++) + for (unsigned int col = 0; col < m_tilemap->GetColumnsCount(); col++) { - for (int row = 0; row < m_tilemap->GetRowsCount(); row++) + for (unsigned int row = 0; row < m_tilemap->GetRowsCount(); row++) { m_tilemap->SetTile(layer, col, row, tile); } @@ -200,7 +200,7 @@ void TileMapPanel::OnMouseEvent(wxMouseEvent &event) return; //Get the current tile position (column and row) - int currentColumn, currentRow; + unsigned int currentColumn, currentRow; wxPoint mousePos = CalcUnscrolledPosition(event.GetPosition()); GetTileAt(mousePos, currentColumn, currentRow); @@ -221,8 +221,7 @@ void TileMapPanel::OnMouseEvent(wxMouseEvent &event) else if(event.RightIsDown()) { //Remove the tile - if(m_tilemap->GetTile(m_mapCurrentLayer, currentColumn, currentRow) != m_tileToBeInserted) - m_commandProcessor.Submit(new ChangeTileCommand(*m_tilemap, m_mapCurrentLayer, currentColumn, currentRow, -1)); + m_commandProcessor.Submit(new ChangeTileCommand(*m_tilemap, m_mapCurrentLayer, currentColumn, currentRow, -1)); Refresh(); } } @@ -288,7 +287,7 @@ wxPoint TileMapPanel::GetPositionOfTile(int column, int row) return wxPoint(column *(m_tileset->tileSize.x), row * (m_tileset->tileSize.y)); } -void TileMapPanel::GetTileAt(wxPoint position, int &tileCol, int &tileRow) +void TileMapPanel::GetTileAt(wxPoint position, unsigned int &tileCol, unsigned int &tileRow) { tileCol = (int)(position.x / m_tileset->tileSize.x); tileRow = (int)(position.y / m_tileset->tileSize.y); diff --git a/Extensions/TileMapObject/TileMapPanel.h b/Extensions/TileMapObject/TileMapPanel.h index 46c083cabf..b1036f2238 100644 --- a/Extensions/TileMapObject/TileMapPanel.h +++ b/Extensions/TileMapObject/TileMapPanel.h @@ -94,7 +94,7 @@ protected: private: wxPoint GetPositionOfTile(int column, int row); - void GetTileAt(wxPoint position, int &tileCol, int &tileRow); + void GetTileAt(wxPoint position, unsigned int &tileCol, unsigned int &tileRow); //Tile to be inserted int m_tileToBeInserted; @@ -108,10 +108,10 @@ private: //Some parameters for the Rectangle Mode bool m_isDrawingRectangle; - int m_beginCol; - int m_beginRow; - int m_endCol; - int m_endRow; + unsigned int m_beginCol; + unsigned int m_beginRow; + unsigned int m_endCol; + unsigned int m_endRow; //Command processor, to be able to undo/redo actions wxCommandProcessor m_commandProcessor;