// -----------------------------------------------------------------------
//
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
//
// -----------------------------------------------------------------------
namespace ImageProcessor.Imaging
{
#region Using
using System.Drawing;
#endregion
///
/// Encapsulates the properties required to add rounded corners to an image.
///
public class RoundedCornerLayer
{
#region Constructors
///
/// Initializes a new instance of the class.
///
public RoundedCornerLayer()
{
this.Radius = 10;
this.BackgroundColor = Color.Transparent;
this.TopLeft = true;
this.TopRight = true;
this.BottomLeft = true;
this.BottomRight = true;
}
///
/// Initializes a new instance of the class.
///
///
/// The radius at which the corner will be done.
///
///
/// Set if top left is rounded
///
///
/// Set if top right is rounded
///
///
/// Set if bottom left is rounded
///
///
/// Set if bottom right is rounded
///
public RoundedCornerLayer(int radius, bool topLeft, bool topRight, bool bottomLeft, bool bottomRight)
{
this.Radius = radius;
this.BackgroundColor = Color.Transparent;
this.TopLeft = topLeft;
this.TopRight = topRight;
this.BottomLeft = bottomLeft;
this.BottomRight = bottomRight;
}
///
/// Initializes a new instance of the class.
///
///
/// The radius at which the corner will be done.
///
///
/// The to set as the background color.
/// Used for image formats that do not support transparency
///
///
/// Set if top left is rounded
///
///
/// Set if top right is rounded
///
///
/// Set if bottom left is rounded
///
///
/// Set if bottom right is rounded
///
public RoundedCornerLayer(int radius, Color backgroundColor, bool topLeft, bool topRight, bool bottomLeft, bool bottomRight)
{
this.Radius = radius;
this.BackgroundColor = backgroundColor;
this.TopLeft = topLeft;
this.TopRight = topRight;
this.BottomLeft = bottomLeft;
this.BottomRight = bottomRight;
}
#endregion
#region Properties
///
/// Gets or sets the radius of the corners.
///
public int Radius { get; set; }
///
/// Gets or sets the background color.
///
public Color BackgroundColor { get; set; }
///
/// Gets or sets a value indicating whether top left corners are to be added.
///
public bool TopLeft { get; set; }
///
/// Gets or sets a value indicating whether top right corners are to be added.
///
public bool TopRight { get; set; }
///
/// Gets or sets a value indicating whether bottom left corners are to be added.
///
public bool BottomLeft { get; set; }
///
/// Gets or sets a value indicating whether bottom right corners are to be added.
///
public bool BottomRight { get; set; }
#endregion
///
/// Returns a value that indicates whether the specified object is an
/// object that is equivalent to
/// this object.
///
///
/// The object to test.
///
///
/// True if the given object is an object that is equivalent to
/// this object; otherwise, false.
///
public override bool Equals(object obj)
{
RoundedCornerLayer rounded = obj as RoundedCornerLayer;
if (rounded == null)
{
return false;
}
return this.Radius == rounded.Radius && this.BackgroundColor == rounded.BackgroundColor
&& this.TopLeft == rounded.TopLeft && this.TopRight == rounded.TopRight
&& this.BottomLeft == rounded.BottomLeft && this.BottomRight == rounded.BottomRight;
}
///
/// Returns a hash code value that represents this object.
///
///
/// A hash code that represents this object.
///
public override int GetHashCode()
{
return this.Radius.GetHashCode() + this.BackgroundColor.GetHashCode() +
this.TopLeft.GetHashCode() + this.TopRight.GetHashCode() +
this.BottomLeft.GetHashCode() + this.BottomRight.GetHashCode();
}
}
}