|
@@ -13,35 +13,40 @@ internal class ChangeBrightness_UpdateableChange : UpdateableChange
|
|
|
private readonly float correctionFactor;
|
|
|
private readonly int strokeWidth;
|
|
|
private readonly List<VecI> positions = new();
|
|
|
- private bool ignoreUpdate = false;
|
|
|
private readonly bool repeat;
|
|
|
private int frame;
|
|
|
+ private int lastAppliedPointIndex = -1;
|
|
|
|
|
|
private List<VecI> ellipseLines;
|
|
|
-
|
|
|
+
|
|
|
private CommittedChunkStorage? savedChunks;
|
|
|
|
|
|
[GenerateUpdateableChangeActions]
|
|
|
- public ChangeBrightness_UpdateableChange(Guid layerGuid, VecI pos, float correctionFactor, int strokeWidth, bool repeat, int frame)
|
|
|
+ public ChangeBrightness_UpdateableChange(Guid layerGuid, VecI pos, float correctionFactor, int strokeWidth,
|
|
|
+ bool repeat, int frame)
|
|
|
{
|
|
|
this.layerGuid = layerGuid;
|
|
|
this.correctionFactor = correctionFactor;
|
|
|
this.strokeWidth = strokeWidth;
|
|
|
this.repeat = repeat;
|
|
|
this.frame = frame;
|
|
|
- // TODO: pos is unused, check if it should be added to positions
|
|
|
-
|
|
|
- ellipseLines = EllipseHelper.SplitEllipseIntoLines((EllipseHelper.GenerateEllipseFromRect(new RectI(0, 0, strokeWidth, strokeWidth), 0)));
|
|
|
+ positions.Add(pos);
|
|
|
+
|
|
|
+ ellipseLines =
|
|
|
+ EllipseHelper.SplitEllipseIntoLines(
|
|
|
+ (EllipseHelper.GenerateEllipseFromRect(new RectI(0, 0, strokeWidth, strokeWidth), 0)));
|
|
|
}
|
|
|
|
|
|
[UpdateChangeMethod]
|
|
|
public void Update(VecI pos)
|
|
|
{
|
|
|
- ignoreUpdate = positions.Count > 0 && positions[^1] == pos;
|
|
|
- if (!ignoreUpdate)
|
|
|
- positions.Add(pos);
|
|
|
+ if (positions.Count > 0)
|
|
|
+ {
|
|
|
+ var bresenham = BresenhamLineHelper.GetBresenhamLine(positions[^1], pos);
|
|
|
+ positions.AddRange(bresenham);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public override bool InitializeAndValidate(Document target)
|
|
|
{
|
|
|
if (!DrawingChangeHelper.IsValidForDrawing(target, layerGuid, false))
|
|
@@ -54,23 +59,28 @@ internal class ChangeBrightness_UpdateableChange : UpdateableChange
|
|
|
|
|
|
public override OneOf<None, IChangeInfo, List<IChangeInfo>> ApplyTemporarily(Document target)
|
|
|
{
|
|
|
- if (ignoreUpdate)
|
|
|
- return new None();
|
|
|
- VecI pos = positions[^1];
|
|
|
ImageLayerNode node = target.FindMemberOrThrow<ImageLayerNode>(layerGuid);
|
|
|
|
|
|
var layerImage = node.GetLayerImageAtFrame(frame);
|
|
|
int queueLength = layerImage.QueueLength;
|
|
|
-
|
|
|
- ChangeBrightness(ellipseLines, strokeWidth, pos + new VecI(-strokeWidth / 2), correctionFactor, repeat, layerImage);
|
|
|
-
|
|
|
+
|
|
|
+ for (int i = Math.Max(lastAppliedPointIndex, 0); i < positions.Count; i++)
|
|
|
+ {
|
|
|
+ VecI pos = positions[i];
|
|
|
+ ChangeBrightness(ellipseLines, strokeWidth, pos + new VecI(-strokeWidth / 2), correctionFactor, repeat,
|
|
|
+ layerImage);
|
|
|
+ }
|
|
|
+
|
|
|
var affected = layerImage.FindAffectedArea(queueLength);
|
|
|
-
|
|
|
+
|
|
|
+ lastAppliedPointIndex = positions.Count - 1;
|
|
|
+
|
|
|
return new LayerImageArea_ChangeInfo(layerGuid, affected);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private static void ChangeBrightness(
|
|
|
- List<VecI> circleLines, int circleDiameter, VecI offset, float correctionFactor, bool repeat, ChunkyImage layerImage)
|
|
|
+ List<VecI> circleLines, int circleDiameter, VecI offset, float correctionFactor, bool repeat,
|
|
|
+ ChunkyImage layerImage)
|
|
|
{
|
|
|
// TODO: Circle diameter is unused, check if it should be used
|
|
|
|
|
@@ -79,14 +89,15 @@ internal class ChangeBrightness_UpdateableChange : UpdateableChange
|
|
|
VecI left = circleLines[i];
|
|
|
VecI right = circleLines[i + 1];
|
|
|
int y = left.Y;
|
|
|
-
|
|
|
+
|
|
|
for (VecI pos = new VecI(left.X, y); pos.X <= right.X; pos.X++)
|
|
|
{
|
|
|
layerImage.EnqueueDrawPixel(
|
|
|
pos + offset,
|
|
|
(commitedColor, upToDateColor) =>
|
|
|
{
|
|
|
- Color newColor = ColorHelper.ChangeColorBrightness(repeat ? upToDateColor : commitedColor, correctionFactor);
|
|
|
+ Color newColor = ColorHelper.ChangeColorBrightness(repeat ? upToDateColor : commitedColor,
|
|
|
+ correctionFactor);
|
|
|
return ColorHelper.ChangeColorBrightness(newColor, correctionFactor);
|
|
|
},
|
|
|
BlendMode.Src);
|
|
@@ -94,22 +105,24 @@ internal class ChangeBrightness_UpdateableChange : UpdateableChange
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public override OneOf<None, IChangeInfo, List<IChangeInfo>> Apply(Document target, bool firstApply, out bool ignoreInUndo)
|
|
|
+ public override OneOf<None, IChangeInfo, List<IChangeInfo>> Apply(Document target, bool firstApply,
|
|
|
+ out bool ignoreInUndo)
|
|
|
{
|
|
|
var layer = target.FindMemberOrThrow<ImageLayerNode>(layerGuid);
|
|
|
ignoreInUndo = false;
|
|
|
|
|
|
if (savedChunks is not null)
|
|
|
throw new InvalidOperationException("Trying to apply while there are saved chunks");
|
|
|
-
|
|
|
+
|
|
|
var layerImage = layer.GetLayerImageAtFrame(frame);
|
|
|
-
|
|
|
+
|
|
|
if (!firstApply)
|
|
|
{
|
|
|
DrawingChangeHelper.ApplyClipsSymmetriesEtc(target, layerImage, layerGuid, false);
|
|
|
foreach (VecI pos in positions)
|
|
|
{
|
|
|
- ChangeBrightness(ellipseLines, strokeWidth, pos + new VecI(-strokeWidth / 2), correctionFactor, repeat, layerImage);
|
|
|
+ ChangeBrightness(ellipseLines, strokeWidth, pos + new VecI(-strokeWidth / 2), correctionFactor, repeat,
|
|
|
+ layerImage);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -123,7 +136,8 @@ internal class ChangeBrightness_UpdateableChange : UpdateableChange
|
|
|
|
|
|
public override OneOf<None, IChangeInfo, List<IChangeInfo>> Revert(Document target)
|
|
|
{
|
|
|
- var affected = DrawingChangeHelper.ApplyStoredChunksDisposeAndSetToNull(target, layerGuid, false, frame, ref savedChunks);
|
|
|
+ var affected =
|
|
|
+ DrawingChangeHelper.ApplyStoredChunksDisposeAndSetToNull(target, layerGuid, false, frame, ref savedChunks);
|
|
|
return new LayerImageArea_ChangeInfo(layerGuid, affected);
|
|
|
}
|
|
|
}
|