diff --git a/Imaging/IImageRender.cs b/Imaging/IImageRender.cs
index c9cc64a..906edb6 100644
--- a/Imaging/IImageRender.cs
+++ b/Imaging/IImageRender.cs
@@ -127,6 +127,22 @@ internal interface IImageRender
///
Bitmap CutBitmap(Bitmap image, int x, int y, int height, int width);
+ ///
+ /// Cuts the bitmap.
+ ///
+ /// The image.
+ /// The width.
+ /// The height.
+ /// The shape.
+ /// The shape parameters.
+ /// The start point.
+ ///
+ /// The cut Image, based on the shape
+ ///
+ ///
+ Bitmap CutBitmap(Bitmap image, int width, int height, MaskShape shape, object shapeParams = null,
+ Point? startPoint = null);
+
///
/// Cuts a bitmap.
///
diff --git a/Imaging/ITextureGenerator.cs b/Imaging/ITextureGenerator.cs
index a41c46d..ca54cbb 100644
--- a/Imaging/ITextureGenerator.cs
+++ b/Imaging/ITextureGenerator.cs
@@ -94,7 +94,7 @@ Bitmap GenerateTexture(
int width,
int height,
TextureType filter,
- TextureShape shape,
+ MaskShape shape,
Point? startPoint = null,
object shapeParams = null);
}
diff --git a/Imaging/ImageMask.cs b/Imaging/ImageMask.cs
new file mode 100644
index 0000000..cf3207c
--- /dev/null
+++ b/Imaging/ImageMask.cs
@@ -0,0 +1,85 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: Imaging
+ * FILE: Imaging/ImageMask.cs
+ * PURPOSE: Helper class to handle some shape operations on an Image
+ * PROGRAMER: Peter Geinitz (Wayfarer)
+ */
+
+using System.Drawing;
+
+namespace Imaging
+{
+ ///
+ /// Handle all the possible selections on an Image
+ ///
+ internal static class ImageMask
+ {
+ ///
+ /// Applies the rectangle mask.
+ ///
+ /// The bitmap.
+ /// The width of the rectangle.
+ /// The height of the rectangle.
+ /// The starting point (top-left corner) of the rectangle.
+ /// Rectangle Bitmap
+ internal static Bitmap ApplyRectangleMask(Image bitmap, int width, int height, Point startPoint)
+ {
+ // Create a new bitmap to work on
+ var rectBitmap = new Bitmap(bitmap.Width, bitmap.Height);
+
+ // Use graphics to apply the mask
+ using var g = Graphics.FromImage(rectBitmap);
+ // Clear the background to transparent
+ g.Clear(Color.Transparent);
+
+ // Create a texture brush with the original bitmap
+ using var brush = new TextureBrush(bitmap);
+ // Fill a rectangle starting from the given start point
+ g.FillRectangle(brush, new Rectangle(startPoint.X, startPoint.Y, width, height));
+
+ return rectBitmap;
+ }
+
+
+ ///
+ /// Applies the circle mask.
+ ///
+ /// The bitmap.
+ /// The width.
+ /// The height.
+ /// The start point.
+ ///
+ /// Circle Bitmap
+ ///
+ internal static Bitmap ApplyCircleMask(Image bitmap, int width, int height, Point startPoint)
+ {
+ var circleBitmap = new Bitmap(bitmap.Width, bitmap.Height);
+ using var g = Graphics.FromImage(circleBitmap);
+ g.Clear(Color.Transparent);
+ using var brush = new TextureBrush(bitmap);
+
+ // Fill the ellipse starting at the specified start point
+ g.FillEllipse(brush, startPoint.X, startPoint.Y, width, height);
+
+ return circleBitmap;
+ }
+
+ ///
+ /// Applies the polygon mask.
+ ///
+ /// The bitmap.
+ /// The points.
+ /// Polygon Bitmap
+ internal static Bitmap ApplyPolygonMask(Image bitmap, Point[] points)
+ {
+ var polyBitmap = new Bitmap(bitmap.Width, bitmap.Height);
+ using var g = Graphics.FromImage(polyBitmap);
+ g.Clear(Color.Transparent);
+ using var brush = new TextureBrush(bitmap);
+ g.FillPolygon(brush, points);
+
+ return polyBitmap;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Imaging/ImageRender.cs b/Imaging/ImageRender.cs
index baf385a..48042aa 100644
--- a/Imaging/ImageRender.cs
+++ b/Imaging/ImageRender.cs
@@ -178,6 +178,41 @@ public Bitmap CutBitmap(Bitmap image, int x, int y, int height, int width)
return ImageStream.CutBitmap(image, x, y, height, width);
}
+ ///
+ ///
+ /// Cuts the bitmap.
+ ///
+ /// The image.
+ /// The width.
+ /// The height.
+ /// The shape.
+ /// The shape parameters.
+ /// The start point.
+ /// The selected Image area.
+ /// shape - null
+ public Bitmap CutBitmap(Bitmap image, int width, int height, MaskShape shape, object shapeParams = null, Point? startPoint = null)
+ {
+ var btm= ImageStream.CutBitmap(image, 0, 0, image.Height, image.Width);
+
+ // If no start point is provided, default to (0, 0)
+ var actualStartPoint = startPoint ?? new Point(0, 0);
+
+ switch (shape)
+ {
+ case MaskShape.Rectangle:
+ return ImageMask.ApplyRectangleMask(btm, width, height, actualStartPoint);
+
+ case MaskShape.Circle:
+ return ImageMask.ApplyCircleMask(btm, width, height, actualStartPoint);
+
+ case MaskShape.Polygon:
+ return ImageMask.ApplyPolygonMask(btm, (Point[])shapeParams);
+
+ default:
+ throw new ArgumentOutOfRangeException(nameof(shape), shape, null);
+ }
+ }
+
///
///
/// Cuts a bitmap.
diff --git a/Imaging/TextureShape.cs b/Imaging/MaskShape.cs
similarity index 89%
rename from Imaging/TextureShape.cs
rename to Imaging/MaskShape.cs
index 6c0d95c..02c6391 100644
--- a/Imaging/TextureShape.cs
+++ b/Imaging/MaskShape.cs
@@ -1,7 +1,7 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: Imaging
- * FILE: Imaging/TextureShape.cs
+ * FILE: Imaging/MaskShape.cs
* PURPOSE: Enum that shows all allowed shapes
* PROGRAMER: Peter Geinitz (Wayfarer)
*/
@@ -13,7 +13,7 @@ namespace Imaging
///
/// Texture Shapes
///
- public enum TextureShape
+ public enum MaskShape
{
///
/// The rectangle
diff --git a/Imaging/TextureAreas.cs b/Imaging/TextureAreas.cs
index 1909c96..7e6237c 100644
--- a/Imaging/TextureAreas.cs
+++ b/Imaging/TextureAreas.cs
@@ -38,7 +38,7 @@ internal static class TextureAreas
internal static Bitmap GenerateTexture(int width,
int height,
TextureType texture,
- TextureShape shape,
+ MaskShape shape,
ImageRegister imageSettings,
object shapeParams = null,
Point? startPoint = null)
@@ -107,85 +107,18 @@ internal static Bitmap GenerateTexture(int width,
// Apply the texture to the specified area shape
switch (shape)
{
- case TextureShape.Rectangle:
- return ApplyRectangleMask(textureBitmap, width, height, actualStartPoint);
+ case MaskShape.Rectangle:
+ return ImageMask.ApplyRectangleMask(textureBitmap, width, height, actualStartPoint);
- case TextureShape.Circle:
- return ApplyCircleMask(textureBitmap, width, height, actualStartPoint);
+ case MaskShape.Circle:
+ return ImageMask.ApplyCircleMask(textureBitmap, width, height, actualStartPoint);
- case TextureShape.Polygon:
- return ApplyPolygonMask(textureBitmap, (Point[])shapeParams);
+ case MaskShape.Polygon:
+ return ImageMask.ApplyPolygonMask(textureBitmap, (Point[])shapeParams);
default:
throw new ArgumentOutOfRangeException(nameof(shape), shape, null);
}
}
-
- ///
- /// Applies the rectangle mask.
- ///
- /// The bitmap.
- /// The width of the rectangle.
- /// The height of the rectangle.
- /// The starting point (top-left corner) of the rectangle.
- /// Rectangle Bitmap
- private static Bitmap ApplyRectangleMask(Image bitmap, int width, int height, Point startPoint)
- {
- // Create a new bitmap to work on
- var rectBitmap = new Bitmap(bitmap.Width, bitmap.Height);
-
- // Use graphics to apply the mask
- using var g = Graphics.FromImage(rectBitmap);
- // Clear the background to transparent
- g.Clear(Color.Transparent);
-
- // Create a texture brush with the original bitmap
- using var brush = new TextureBrush(bitmap);
- // Fill a rectangle starting from the given start point
- g.FillRectangle(brush, new Rectangle(startPoint.X, startPoint.Y, width, height));
-
- return rectBitmap;
- }
-
-
- ///
- /// Applies the circle mask.
- ///
- /// The bitmap.
- /// The width.
- /// The height.
- /// The start point.
- ///
- /// Circle Bitmap
- ///
- private static Bitmap ApplyCircleMask(Image bitmap, int width, int height, Point startPoint)
- {
- var circleBitmap = new Bitmap(bitmap.Width, bitmap.Height);
- using var g = Graphics.FromImage(circleBitmap);
- g.Clear(Color.Transparent);
- using var brush = new TextureBrush(bitmap);
-
- // Fill the ellipse starting at the specified start point
- g.FillEllipse(brush, startPoint.X, startPoint.Y, width, height);
-
- return circleBitmap;
- }
-
- ///
- /// Applies the polygon mask.
- ///
- /// The bitmap.
- /// The points.
- /// Polygon Bitmap
- private static Bitmap ApplyPolygonMask(Image bitmap, Point[] points)
- {
- var polyBitmap = new Bitmap(bitmap.Width, bitmap.Height);
- using var g = Graphics.FromImage(polyBitmap);
- g.Clear(Color.Transparent);
- using var brush = new TextureBrush(bitmap);
- g.FillPolygon(brush, points);
-
- return polyBitmap;
- }
}
}
\ No newline at end of file
diff --git a/Imaging/TextureGenerator.cs b/Imaging/TextureGenerator.cs
index b8d5e84..e73bbf5 100644
--- a/Imaging/TextureGenerator.cs
+++ b/Imaging/TextureGenerator.cs
@@ -152,7 +152,7 @@ public Bitmap GenerateWoodBitmap(int width, int height)
/// The Start point.
/// The shape parameters.
/// Texture Bitmap
- public Bitmap GenerateTexture(int width, int height, TextureType filter, TextureShape shape,
+ public Bitmap GenerateTexture(int width, int height, TextureType filter, MaskShape shape,
Point? startPoint = null,
object shapeParams = null)
{
diff --git a/SlimViewer/MainWindow.xaml b/SlimViewer/MainWindow.xaml
index 321cd85..0214261 100644
--- a/SlimViewer/MainWindow.xaml
+++ b/SlimViewer/MainWindow.xaml
@@ -42,10 +42,9 @@
-
-
-
+
+
@@ -243,11 +242,11 @@
ItemsSource="{Binding Selections}" SelectedItem="{Binding SelectedForm}" />
-
-
+
diff --git a/SlimViews/FillTypeVisibilityConverter .cs b/SlimViews/FillTypeVisibilityConverter .cs
new file mode 100644
index 0000000..ec2dbc6
--- /dev/null
+++ b/SlimViews/FillTypeVisibilityConverter .cs
@@ -0,0 +1,33 @@
+using System;
+using System.Globalization;
+using System.Windows;
+using System.Windows.Data;
+
+namespace SlimViews
+{
+ public class FillTypeVisibilityConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is int selectedIndex && parameter is string targetFillType)
+ {
+ switch (targetFillType)
+ {
+ case "SolidColor":
+ return selectedIndex == 0 ? Visibility.Visible : Visibility.Collapsed;
+ case "Texture":
+ return selectedIndex == 1 ? Visibility.Visible : Visibility.Collapsed;
+ case "Filter":
+ return selectedIndex == 2 ? Visibility.Visible : Visibility.Collapsed;
+ }
+ }
+
+ return Visibility.Collapsed;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
\ No newline at end of file
diff --git a/SlimViews/ImageProcessor.cs b/SlimViews/ImageProcessor.cs
index c6812c0..80b00a0 100644
--- a/SlimViews/ImageProcessor.cs
+++ b/SlimViews/ImageProcessor.cs
@@ -243,7 +243,7 @@ internal static Bitmap Texture(Bitmap bitmap, TextureType texture)
try
{
//just overlay the whole image with the texture, will be changed later
- var btm = Generator.GenerateTexture(bitmap.Width, bitmap.Height, texture, TextureShape.Rectangle);
+ var btm = Generator.GenerateTexture(bitmap.Width, bitmap.Height, texture, MaskShape.Rectangle);
//overlay both images
bitmap = Render.CombineBitmap(bitmap, btm, 0, 0);
}
diff --git a/SlimViews/ImageTools.cs b/SlimViews/ImageTools.cs
index cd21e32..eb70803 100644
--- a/SlimViews/ImageTools.cs
+++ b/SlimViews/ImageTools.cs
@@ -23,16 +23,6 @@ public enum ImageTools
///
Erase = 1,
- ///
- /// The texture
- ///
- Texture = 2,
-
- ///
- /// The filter
- ///
- Filter = 3,
-
///
/// The cut
///
@@ -41,11 +31,11 @@ public enum ImageTools
///
/// The color select
///
- ColorSelect = 5,
+ ColorSelect = 2,
///
/// The area
///
- Area = 6
+ Area = 3
}
}
\ No newline at end of file
diff --git a/SlimViews/Templates/SelectionToVisibilityConverter .cs b/SlimViews/Templates/SelectionToVisibilityConverter .cs
new file mode 100644
index 0000000..b8bc332
--- /dev/null
+++ b/SlimViews/Templates/SelectionToVisibilityConverter .cs
@@ -0,0 +1,54 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: SlimViewer
+ * FILE: SlimViews/Templates/SelectionToVisibilityConverter.cs
+ * PURPOSE: Handle Visibility in our template
+ * PROGRAMER: Peter Geinitz (Wayfarer)
+ */
+
+using System;
+using System.Globalization;
+using System.Windows;
+using System.Windows.Data;
+
+namespace SlimViews.Templates
+{
+ ///
+ ///
+ /// Handles Visibility of the Tool Combobox
+ ///
+ ///
+ public sealed class SelectionToVisibilityConverter : IValueConverter
+ {
+ ///
+ /// Converts a value.
+ ///
+ /// The value produced by the binding source.
+ /// The type of the binding target property.
+ /// The converter parameter to use.
+ /// The culture to use in the converter.
+ ///
+ /// A converted value. If the method returns , the valid null value is used.
+ ///
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return value != null ? Visibility.Visible : Visibility.Collapsed;
+ }
+
+ ///
+ /// Converts a value.
+ ///
+ /// The value that is produced by the binding target.
+ /// The type to convert to.
+ /// The converter parameter to use.
+ /// The culture to use in the converter.
+ ///
+ /// A converted value. If the method returns , the valid null value is used.
+ ///
+ ///
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
\ No newline at end of file
diff --git a/SlimViews/ToolOptionsTemplateSelector.cs b/SlimViews/Templates/ToolOptionsTemplateSelector.cs
similarity index 85%
rename from SlimViews/ToolOptionsTemplateSelector.cs
rename to SlimViews/Templates/ToolOptionsTemplateSelector.cs
index 4ce9136..9a0d4a4 100644
--- a/SlimViews/ToolOptionsTemplateSelector.cs
+++ b/SlimViews/Templates/ToolOptionsTemplateSelector.cs
@@ -1,7 +1,7 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: SlimViewer
- * FILE: SlimViews/TextureConfigView.cs
+ * FILE: SlimViews/Templates/TextureConfigView.cs
* PURPOSE: The view for Texture Configuration
* PROGRAMER: Peter Geinitz (Wayfarer)
*/
@@ -9,7 +9,7 @@
using System.Windows;
using System.Windows.Controls;
-namespace SlimViews
+namespace SlimViews.Templates
{
///
///
@@ -26,6 +26,14 @@ public sealed class ToolOptionsTemplateSelector : DataTemplateSelector
///
public DataTemplate PaintToolTemplate { get; set; }
+ ///
+ /// Gets or sets the erase tool options.
+ ///
+ ///
+ /// The erase tool options.
+ ///
+ public DataTemplate EraseToolTemplate { get; set; }
+
///
/// Gets or sets the color select tool template.
///
@@ -58,6 +66,7 @@ public override DataTemplate SelectTemplate(object item, DependencyObject contai
return toolType switch
{
ImageTools.Paint => PaintToolTemplate,
+ ImageTools.Erase => EraseToolTemplate,
ImageTools.ColorSelect => ColorSelectToolTemplate,
ImageTools.Area => AreaSelectToolTemplate,
_ => null
diff --git a/SlimViews/Templates/ToolOptionsTemplates.xaml b/SlimViews/Templates/ToolOptionsTemplates.xaml
index 77cbeab..af598c5 100644
--- a/SlimViews/Templates/ToolOptionsTemplates.xaml
+++ b/SlimViews/Templates/ToolOptionsTemplates.xaml
@@ -1,47 +1,150 @@
+ xmlns:slimViews="clr-namespace:SlimViews"
+ xmlns:templates="clr-namespace:SlimViews.Templates">
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
\ No newline at end of file
+