diff --git a/Greenshot/Drawing/CursorContainer.cs b/Greenshot/Drawing/CursorContainer.cs
index 5558508a8..1c756dd83 100644
--- a/Greenshot/Drawing/CursorContainer.cs
+++ b/Greenshot/Drawing/CursorContainer.cs
@@ -105,10 +105,6 @@ namespace Greenshot.Drawing {
cursor.DrawStretched(graphics, Bounds);
}
- public override Size DefaultSize {
- get {
- return cursor.Size;
- }
- }
+ public override Size DefaultSize => cursor?.Size ?? new Size(16, 16);
}
}
diff --git a/Greenshot/Drawing/DrawableContainer.cs b/Greenshot/Drawing/DrawableContainer.cs
index 87b555914..6c4433662 100644
--- a/Greenshot/Drawing/DrawableContainer.cs
+++ b/Greenshot/Drawing/DrawableContainer.cs
@@ -562,23 +562,11 @@ namespace Greenshot.Drawing
return ScaleHelper.ShapeAngleRoundBehavior.Instance;
}
- public virtual bool HasContextMenu {
- get {
- return true;
- }
- }
+ public virtual bool HasContextMenu => true;
- public virtual bool HasDefaultSize {
- get {
- return false;
- }
- }
+ public virtual bool HasDefaultSize => false;
- public virtual Size DefaultSize {
- get {
- throw new NotSupportedException("Object doesn't have a default size");
- }
- }
+ public virtual Size DefaultSize => throw new NotSupportedException("Object doesn't have a default size");
///
/// Allows to override the initializing of the fields, so we can actually have our own defaults
diff --git a/Greenshot/Drawing/IconContainer.cs b/Greenshot/Drawing/IconContainer.cs
index 013fb057f..2924a376f 100644
--- a/Greenshot/Drawing/IconContainer.cs
+++ b/Greenshot/Drawing/IconContainer.cs
@@ -62,7 +62,7 @@ namespace Greenshot.Drawing {
Width = value.Width;
Height = value.Height;
}
- get { return icon; }
+ get => icon;
}
/**
@@ -78,27 +78,32 @@ namespace Greenshot.Drawing {
base.Dispose(disposing);
}
- public void Load(string filename) {
- if (File.Exists(filename))
- {
- using Icon fileIcon = new Icon(filename);
- Icon = fileIcon;
- Log.Debug("Loaded file: " + filename + " with resolution: " + Height + "," + Width);
- }
+ public void Load(string filename)
+ {
+ if (!File.Exists(filename))
+ {
+ return;
+ }
+ using Icon fileIcon = new Icon(filename);
+ Icon = fileIcon;
+ Log.Debug("Loaded file: " + filename + " with resolution: " + Height + "," + Width);
}
- public override void Draw(Graphics graphics, RenderMode rm) {
- if (icon != null) {
- graphics.SmoothingMode = SmoothingMode.HighQuality;
- graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
- graphics.CompositingQuality = CompositingQuality.Default;
- graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
- graphics.DrawIcon(icon, Bounds);
+ public override void Draw(Graphics graphics, RenderMode rm)
+ {
+ if (icon == null)
+ {
+ return;
}
+ graphics.SmoothingMode = SmoothingMode.HighQuality;
+ graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
+ graphics.CompositingQuality = CompositingQuality.Default;
+ graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
+ graphics.DrawIcon(icon, Bounds);
}
public override bool HasDefaultSize => true;
- public override Size DefaultSize => icon.Size;
+ public override Size DefaultSize => icon?.Size ?? new Size(16,16);
}
}
diff --git a/Greenshot/Drawing/ImageContainer.cs b/Greenshot/Drawing/ImageContainer.cs
index 0e23855bb..2d96d12c8 100644
--- a/Greenshot/Drawing/ImageContainer.cs
+++ b/Greenshot/Drawing/ImageContainer.cs
@@ -77,11 +77,14 @@ namespace Greenshot.Drawing {
AddField(GetType(), FieldType.SHADOW, false);
}
- protected void BitmapContainer_OnFieldChanged(object sender, FieldChangedEventArgs e) {
- if (sender.Equals(this)) {
- if (FieldType.SHADOW.Equals(e.Field.FieldType)) {
- ChangeShadowField();
- }
+ protected void BitmapContainer_OnFieldChanged(object sender, FieldChangedEventArgs e)
+ {
+ if (!sender.Equals(this))
+ {
+ return;
+ }
+ if (FieldType.SHADOW.Equals(e.Field.FieldType)) {
+ ChangeShadowField();
}
}
@@ -189,12 +192,14 @@ namespace Greenshot.Drawing {
/// This checks if a shadow is already generated
///
///
- private void CheckShadow(bool shadow) {
- if (shadow && _shadowBitmap == null)
- {
- using var matrix = new Matrix();
- _shadowBitmap = ImageHelper.ApplyEffect(image, new DropShadowEffect(), matrix);
- }
+ private void CheckShadow(bool shadow)
+ {
+ if (!shadow || _shadowBitmap != null)
+ {
+ return;
+ }
+ using var matrix = new Matrix();
+ _shadowBitmap = ImageHelper.ApplyEffect(image, new DropShadowEffect(), matrix);
}
///
@@ -202,25 +207,28 @@ namespace Greenshot.Drawing {
///
///
///
- public override void Draw(Graphics graphics, RenderMode rm) {
- if (image != null) {
- bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
- graphics.SmoothingMode = SmoothingMode.HighQuality;
- graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
- graphics.CompositingQuality = CompositingQuality.HighQuality;
- graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
+ public override void Draw(Graphics graphics, RenderMode rm)
+ {
+ if (image == null)
+ {
+ return;
+ }
+ bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
+ graphics.SmoothingMode = SmoothingMode.HighQuality;
+ graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
+ graphics.CompositingQuality = CompositingQuality.HighQuality;
+ graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
- if (shadow) {
- CheckShadow(true);
- graphics.DrawImage(_shadowBitmap, Bounds);
- } else {
- graphics.DrawImage(image, Bounds);
- }
+ if (shadow) {
+ CheckShadow(true);
+ graphics.DrawImage(_shadowBitmap, Bounds);
+ } else {
+ graphics.DrawImage(image, Bounds);
}
}
public override bool HasDefaultSize => true;
- public override Size DefaultSize => image.Size;
+ public override Size DefaultSize => image?.Size ?? new Size(32, 32);
}
}