public void Release(ScreenDrawingSurface surface)
{
held = false;
var g = surface.GetToolLayerGraphics();
if (g != null)
{
g.Clear(Color.Transparent);
surface.ReturnToolLayerGraphics(g);
}
int x_start = Math.Min(tx1, tx2);
int x_end = Math.Max(tx1, tx2) - 1;
int y_start = Math.Min(ty1, ty2);
int y_end = Math.Max(ty1, ty2) - 1;
startTiles = new int?[surface.Screen.Width, surface.Screen.Height];
endTiles = new int?[surface.Screen.Width, surface.Screen.Height];
for (int y = y_start; y <= y_end; y += brush.Height)
{
for (int x = x_start; x <= x_end; x += brush.Width)
{
Draw(surface, x, y);
}
}
var changes = new List<TileChange>();
for (int y = 0; y < surface.Screen.Height; y++)
{
for (int x = 0; x < surface.Screen.Width; x++)
{
if (startTiles[x, y].HasValue && endTiles[x, y].HasValue && startTiles[x, y].Value != endTiles[x, y].Value)
{
changes.Add(new TileChange(x, y, startTiles[x, y].Value, endTiles[x, y].Value, surface));
}
}
}
if (changes.Count > 0) surface.EditedWithAction(new DrawAction("Rectangle", changes, surface));
}