mirror of
https://github.com/greenshot/greenshot
synced 2025-08-22 14:24:43 -07:00
BUG-2707: Reducing the amount of NPE issues
This commit is contained in:
parent
d434edd71b
commit
7bf2b7c092
4 changed files with 58 additions and 61 deletions
|
@ -105,10 +105,6 @@ namespace Greenshot.Drawing {
|
||||||
cursor.DrawStretched(graphics, Bounds);
|
cursor.DrawStretched(graphics, Bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Size DefaultSize {
|
public override Size DefaultSize => cursor?.Size ?? new Size(16, 16);
|
||||||
get {
|
|
||||||
return cursor.Size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -562,23 +562,11 @@ namespace Greenshot.Drawing
|
||||||
return ScaleHelper.ShapeAngleRoundBehavior.Instance;
|
return ScaleHelper.ShapeAngleRoundBehavior.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool HasContextMenu {
|
public virtual bool HasContextMenu => true;
|
||||||
get {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual bool HasDefaultSize {
|
public virtual bool HasDefaultSize => false;
|
||||||
get {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual Size DefaultSize {
|
public virtual Size DefaultSize => throw new NotSupportedException("Object doesn't have a default size");
|
||||||
get {
|
|
||||||
throw new NotSupportedException("Object doesn't have a default size");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows to override the initializing of the fields, so we can actually have our own defaults
|
/// Allows to override the initializing of the fields, so we can actually have our own defaults
|
||||||
|
|
|
@ -62,7 +62,7 @@ namespace Greenshot.Drawing {
|
||||||
Width = value.Width;
|
Width = value.Width;
|
||||||
Height = value.Height;
|
Height = value.Height;
|
||||||
}
|
}
|
||||||
get { return icon; }
|
get => icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,27 +78,32 @@ namespace Greenshot.Drawing {
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Load(string filename) {
|
public void Load(string filename)
|
||||||
if (File.Exists(filename))
|
|
||||||
{
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
using Icon fileIcon = new Icon(filename);
|
using Icon fileIcon = new Icon(filename);
|
||||||
Icon = fileIcon;
|
Icon = fileIcon;
|
||||||
Log.Debug("Loaded file: " + filename + " with resolution: " + Height + "," + Width);
|
Log.Debug("Loaded file: " + filename + " with resolution: " + Height + "," + Width);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw(Graphics graphics, RenderMode rm) {
|
public override void Draw(Graphics graphics, RenderMode rm)
|
||||||
if (icon != null) {
|
{
|
||||||
|
if (icon == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
|
graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
|
||||||
graphics.CompositingQuality = CompositingQuality.Default;
|
graphics.CompositingQuality = CompositingQuality.Default;
|
||||||
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||||
graphics.DrawIcon(icon, Bounds);
|
graphics.DrawIcon(icon, Bounds);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public override bool HasDefaultSize => true;
|
public override bool HasDefaultSize => true;
|
||||||
|
|
||||||
public override Size DefaultSize => icon.Size;
|
public override Size DefaultSize => icon?.Size ?? new Size(16,16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,13 +77,16 @@ namespace Greenshot.Drawing {
|
||||||
AddField(GetType(), FieldType.SHADOW, false);
|
AddField(GetType(), FieldType.SHADOW, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void BitmapContainer_OnFieldChanged(object sender, FieldChangedEventArgs e) {
|
protected void BitmapContainer_OnFieldChanged(object sender, FieldChangedEventArgs e)
|
||||||
if (sender.Equals(this)) {
|
{
|
||||||
|
if (!sender.Equals(this))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (FieldType.SHADOW.Equals(e.Field.FieldType)) {
|
if (FieldType.SHADOW.Equals(e.Field.FieldType)) {
|
||||||
ChangeShadowField();
|
ChangeShadowField();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void ChangeShadowField() {
|
public void ChangeShadowField() {
|
||||||
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
|
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
|
||||||
|
@ -189,12 +192,14 @@ namespace Greenshot.Drawing {
|
||||||
/// This checks if a shadow is already generated
|
/// This checks if a shadow is already generated
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="shadow"></param>
|
/// <param name="shadow"></param>
|
||||||
private void CheckShadow(bool shadow) {
|
private void CheckShadow(bool shadow)
|
||||||
if (shadow && _shadowBitmap == null)
|
|
||||||
{
|
{
|
||||||
|
if (!shadow || _shadowBitmap != null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
using var matrix = new Matrix();
|
using var matrix = new Matrix();
|
||||||
_shadowBitmap = ImageHelper.ApplyEffect(image, new DropShadowEffect(), matrix);
|
_shadowBitmap = ImageHelper.ApplyEffect(image, new DropShadowEffect(), matrix);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -202,8 +207,12 @@ namespace Greenshot.Drawing {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="graphics"></param>
|
/// <param name="graphics"></param>
|
||||||
/// <param name="rm"></param>
|
/// <param name="rm"></param>
|
||||||
public override void Draw(Graphics graphics, RenderMode rm) {
|
public override void Draw(Graphics graphics, RenderMode rm)
|
||||||
if (image != null) {
|
{
|
||||||
|
if (image == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
|
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
|
||||||
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
|
@ -217,10 +226,9 @@ namespace Greenshot.Drawing {
|
||||||
graphics.DrawImage(image, Bounds);
|
graphics.DrawImage(image, Bounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public override bool HasDefaultSize => true;
|
public override bool HasDefaultSize => true;
|
||||||
|
|
||||||
public override Size DefaultSize => image.Size;
|
public override Size DefaultSize => image?.Size ?? new Size(32, 32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue