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.

This commit is contained in:
Florian Rival
2015-01-04 17:03:26 +01:00
parent d4f8062cef
commit da872e8408
3 changed files with 15 additions and 12 deletions

View File

@@ -89,9 +89,13 @@ 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);
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;

View File

@@ -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,7 +221,6 @@ 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));
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);

View File

@@ -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;