|
@@ -32,6 +32,8 @@ namespace PixiEditor.Models.Layers
|
|
|
|
|
|
private string layerHighlightColor = "#666666";
|
|
|
|
|
|
+ private BitmapPixelChanges singleCache = BitmapPixelChanges.Empty;
|
|
|
+
|
|
|
public Layer(string name)
|
|
|
{
|
|
|
Name = name;
|
|
@@ -287,6 +289,16 @@ namespace PixiEditor.Models.Layers
|
|
|
return LayerBitmap.GetPixel(x, y);
|
|
|
}
|
|
|
|
|
|
+ public void SetPixelWithOffset(Coordinates coordinates, Color color)
|
|
|
+ {
|
|
|
+ LayerBitmap.SetPixel(coordinates.X - OffsetX, coordinates.Y - OffsetY, color);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SetPixelWithOffset(int x, int y, Color color)
|
|
|
+ {
|
|
|
+ LayerBitmap.SetPixel(x - OffsetX, y - OffsetY, color);
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Applies pixel to layer.
|
|
|
/// </summary>
|
|
@@ -296,7 +308,8 @@ namespace PixiEditor.Models.Layers
|
|
|
/// <param name="applyOffset">Converts pixels coordinates to relative to bitmap.</param>
|
|
|
public void SetPixel(Coordinates coordinates, Color color, bool dynamicResize = true, bool applyOffset = true)
|
|
|
{
|
|
|
- SetPixels(BitmapPixelChanges.FromSingleColoredArray(new[] { coordinates }, color), dynamicResize, applyOffset);
|
|
|
+ singleCache.ChangedPixels[coordinates] = color;
|
|
|
+ SetPixels(singleCache, dynamicResize, applyOffset);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -375,15 +388,7 @@ namespace PixiEditor.Models.Layers
|
|
|
|
|
|
if (!(pixels.WasBuiltAsSingleColored && pixels.ChangedPixels.First().Value.A == 0))
|
|
|
{
|
|
|
- if ((newMaxX + 1 > Width && Width < MaxWidth) || (newMaxY + 1 > Height && Height < MaxHeight))
|
|
|
- {
|
|
|
- IncreaseSizeToBottomAndRight(newMaxX, newMaxY);
|
|
|
- }
|
|
|
-
|
|
|
- if ((newMinX < 0 && Width < MaxWidth) || (newMinY < 0 && Height < MaxHeight))
|
|
|
- {
|
|
|
- IncreaseSizeToTopAndLeft(newMinX, newMinY);
|
|
|
- }
|
|
|
+ DynamicResize(newMaxX, newMaxY, newMinX, newMinY);
|
|
|
}
|
|
|
|
|
|
// if clip is requested
|
|
@@ -393,6 +398,22 @@ namespace PixiEditor.Models.Layers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Resizes canvas to fit pixels outside current bounds. Clamped to MaxHeight and MaxWidth.
|
|
|
+ /// </summary>
|
|
|
+ public void DynamicResize(int newMaxX, int newMaxY, int newMinX, int newMinY)
|
|
|
+ {
|
|
|
+ if ((newMaxX + 1 > Width && Width < MaxWidth) || (newMaxY + 1 > Height && Height < MaxHeight))
|
|
|
+ {
|
|
|
+ IncreaseSizeToBottomAndRight(newMaxX, newMaxY);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((newMinX < 0 && Width < MaxWidth) || (newMinY < 0 && Height < MaxHeight))
|
|
|
+ {
|
|
|
+ IncreaseSizeToTopAndLeft(newMinX, newMinY);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Changes size of bitmap to fit content.
|
|
|
/// </summary>
|