|
@@ -1,47 +1,47 @@
|
|
|
-using System;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Windows.Controls;
|
|
|
-using System.Windows.Input;
|
|
|
-using System.Windows.Media;
|
|
|
-using PixiEditor.Models.Colors;
|
|
|
-using PixiEditor.Models.DataHolders;
|
|
|
-using PixiEditor.Models.Enums;
|
|
|
-using PixiEditor.Models.Layers;
|
|
|
-using PixiEditor.Models.Position;
|
|
|
-using PixiEditor.Models.Tools.ToolSettings.Settings;
|
|
|
-using PixiEditor.Models.Tools.ToolSettings.Toolbars;
|
|
|
-
|
|
|
-namespace PixiEditor.Models.Tools.Tools
|
|
|
-{
|
|
|
- public class BrightnessTool : BitmapOperationTool
|
|
|
- {
|
|
|
- private const float CorrectionFactor = 5f; // Initial correction factor
|
|
|
-
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Windows.Controls;
|
|
|
+using System.Windows.Input;
|
|
|
+using System.Windows.Media;
|
|
|
+using PixiEditor.Models.Colors;
|
|
|
+using PixiEditor.Models.DataHolders;
|
|
|
+using PixiEditor.Models.Enums;
|
|
|
+using PixiEditor.Models.Layers;
|
|
|
+using PixiEditor.Models.Position;
|
|
|
+using PixiEditor.Models.Tools.ToolSettings.Settings;
|
|
|
+using PixiEditor.Models.Tools.ToolSettings.Toolbars;
|
|
|
+
|
|
|
+namespace PixiEditor.Models.Tools.Tools
|
|
|
+{
|
|
|
+ public class BrightnessTool : BitmapOperationTool
|
|
|
+ {
|
|
|
+ private const float CorrectionFactor = 5f; // Initial correction factor
|
|
|
+
|
|
|
private List<Coordinates> pixelsVisited = new List<Coordinates>();
|
|
|
|
|
|
- public BrightnessTool()
|
|
|
- {
|
|
|
- Tooltip = "Makes pixel brighter or darker pixel (U). Hold Ctrl to make pixel darker.";
|
|
|
- Toolbar = new BrightnessToolToolbar(CorrectionFactor);
|
|
|
- }
|
|
|
-
|
|
|
- public override ToolType ToolType => ToolType.Brightness;
|
|
|
+ public BrightnessTool()
|
|
|
+ {
|
|
|
+ Tooltip = "Makes pixel brighter or darker pixel (U). Hold Ctrl to make pixel darker.";
|
|
|
+ Toolbar = new BrightnessToolToolbar(CorrectionFactor);
|
|
|
+ }
|
|
|
+
|
|
|
+ public override ToolType ToolType => ToolType.Brightness;
|
|
|
+
|
|
|
+ public BrightnessMode Mode { get; set; } = BrightnessMode.Default;
|
|
|
+
|
|
|
+ public override void OnRecordingLeftMouseDown(MouseEventArgs e)
|
|
|
+ {
|
|
|
+ pixelsVisited.Clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
|
|
|
+ {
|
|
|
+ int toolSize = Toolbar.GetSetting<SizeSetting>("ToolSize").Value;
|
|
|
+ float correctionFactor = Toolbar.GetSetting<FloatSetting>("CorrectionFactor").Value;
|
|
|
+ Enum.TryParse((Toolbar.GetSetting<DropdownSetting>("BrightnessMode")?.Value as ComboBoxItem)?.Content as string, out BrightnessMode mode);
|
|
|
+ Mode = mode;
|
|
|
|
|
|
- public BrightnessMode Mode { get; set; } = BrightnessMode.Default;
|
|
|
-
|
|
|
- public override void OnRecordingLeftMouseDown(MouseEventArgs e)
|
|
|
- {
|
|
|
- pixelsVisited.Clear();
|
|
|
- }
|
|
|
-
|
|
|
- public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
|
|
|
- {
|
|
|
- int toolSize = Toolbar.GetSetting<SizeSetting>("ToolSize").Value;
|
|
|
- float correctionFactor = Toolbar.GetSetting<FloatSetting>("CorrectionFactor").Value;
|
|
|
- Enum.TryParse((Toolbar.GetSetting<DropdownSetting>("Mode")?.Value as ComboBoxItem)?.Content as string, out BrightnessMode mode);
|
|
|
- Mode = mode;
|
|
|
-
|
|
|
- LayerChange[] layersChanges = new LayerChange[1];
|
|
|
+ LayerChange[] layersChanges = new LayerChange[1];
|
|
|
if (Keyboard.IsKeyDown(Key.LeftCtrl))
|
|
|
{
|
|
|
layersChanges[0] = new LayerChange(ChangeBrightness(layer, coordinates[0], toolSize, -correctionFactor), layer);
|
|
@@ -51,41 +51,41 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
layersChanges[0] = new LayerChange(ChangeBrightness(layer, coordinates[0], toolSize, correctionFactor), layer);
|
|
|
}
|
|
|
|
|
|
- return layersChanges;
|
|
|
- }
|
|
|
-
|
|
|
- public BitmapPixelChanges ChangeBrightness(Layer layer, Coordinates coordinates, int toolSize, float correctionFactor)
|
|
|
- {
|
|
|
- DoubleCords centeredCoords = CoordinatesCalculator.CalculateThicknessCenter(coordinates, toolSize);
|
|
|
+ return layersChanges;
|
|
|
+ }
|
|
|
+
|
|
|
+ public BitmapPixelChanges ChangeBrightness(Layer layer, Coordinates coordinates, int toolSize, float correctionFactor)
|
|
|
+ {
|
|
|
+ DoubleCords centeredCoords = CoordinatesCalculator.CalculateThicknessCenter(coordinates, toolSize);
|
|
|
Coordinates[] rectangleCoordinates = CoordinatesCalculator.RectangleToCoordinates(
|
|
|
- centeredCoords.Coords1.X,
|
|
|
- centeredCoords.Coords1.Y,
|
|
|
- centeredCoords.Coords2.X,
|
|
|
- centeredCoords.Coords2.Y);
|
|
|
- BitmapPixelChanges changes = new BitmapPixelChanges(new Dictionary<Coordinates, Color>());
|
|
|
-
|
|
|
- for (int i = 0; i < rectangleCoordinates.Length; i++)
|
|
|
- {
|
|
|
- if (Mode == BrightnessMode.Default)
|
|
|
- {
|
|
|
+ centeredCoords.Coords1.X,
|
|
|
+ centeredCoords.Coords1.Y,
|
|
|
+ centeredCoords.Coords2.X,
|
|
|
+ centeredCoords.Coords2.Y);
|
|
|
+ BitmapPixelChanges changes = new BitmapPixelChanges(new Dictionary<Coordinates, Color>());
|
|
|
+
|
|
|
+ for (int i = 0; i < rectangleCoordinates.Length; i++)
|
|
|
+ {
|
|
|
+ if (Mode == BrightnessMode.Default)
|
|
|
+ {
|
|
|
if (pixelsVisited.Contains(rectangleCoordinates[i]))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- pixelsVisited.Add(rectangleCoordinates[i]);
|
|
|
- }
|
|
|
-
|
|
|
- Color pixel = layer.GetPixelWithOffset(rectangleCoordinates[i].X, rectangleCoordinates[i].Y);
|
|
|
+ pixelsVisited.Add(rectangleCoordinates[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ Color pixel = layer.GetPixelWithOffset(rectangleCoordinates[i].X, rectangleCoordinates[i].Y);
|
|
|
Color newColor = ExColor.ChangeColorBrightness(
|
|
|
- Color.FromArgb(pixel.A, pixel.R, pixel.G, pixel.B),
|
|
|
- correctionFactor);
|
|
|
+ Color.FromArgb(pixel.A, pixel.R, pixel.G, pixel.B),
|
|
|
+ correctionFactor);
|
|
|
changes.ChangedPixels.Add(
|
|
|
- new Coordinates(rectangleCoordinates[i].X, rectangleCoordinates[i].Y),
|
|
|
- newColor);
|
|
|
- }
|
|
|
-
|
|
|
- return changes;
|
|
|
- }
|
|
|
- }
|
|
|
+ new Coordinates(rectangleCoordinates[i].X, rectangleCoordinates[i].Y),
|
|
|
+ newColor);
|
|
|
+ }
|
|
|
+
|
|
|
+ return changes;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|