Some code improvements which make some later features possible (maybe having a bezier for a line) [skip ci]

This commit is contained in:
Robin Krom 2022-03-29 22:38:28 +02:00
commit 64c77ea8d9
No known key found for this signature in database
GPG key ID: BCC01364F1371490
12 changed files with 146 additions and 99 deletions

View file

@ -350,7 +350,7 @@ namespace Greenshot.Base.Controls
{ {
if (!Language.TryGetString(languageKey, out langString)) if (!Language.TryGetString(languageKey, out langString))
{ {
LOG.WarnFormat("Unknown language key '{0}' configured for control '{1}', this might be okay.", languageKey, applyTo.Name); LOG.DebugFormat("Unknown language key '{0}' configured for control '{1}', this might be okay.", languageKey, applyTo.Name);
return; return;
} }

View file

@ -470,7 +470,7 @@ namespace Greenshot.Base.Core
languageFile languageFile
}; };
LanguageFiles.Add(languageFile.Ietf, currentFiles); LanguageFiles.Add(languageFile.Ietf, currentFiles);
Log.InfoFormat("Added language definition {0} from: {1}", languageFile.Description, languageFile.Filepath); Log.DebugFormat("Added language definition {0} from: {1}", languageFile.Description, languageFile.Filepath);
} }
} }
} }

View file

@ -108,5 +108,10 @@ namespace Greenshot.Base.Interfaces.Drawing.Adorners
/// The color of the fill of the adorner /// The color of the fill of the adorner
/// </summary> /// </summary>
Color FillColor { get; set; } Color FillColor { get; set; }
/// <summary>
/// This is to TAG the adorner so we know the type
/// </summary>
string Tag { get; set; }
} }
} }

View file

@ -24,6 +24,7 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Windows.Forms;
using Greenshot.Base.Interfaces.Drawing.Adorners; using Greenshot.Base.Interfaces.Drawing.Adorners;
namespace Greenshot.Base.Interfaces.Drawing namespace Greenshot.Base.Interfaces.Drawing
@ -97,5 +98,13 @@ namespace Greenshot.Base.Interfaces.Drawing
/// </summary> /// </summary>
/// <param name="dpi">uint</param> /// <param name="dpi">uint</param>
void AdjustToDpi(uint dpi); void AdjustToDpi(uint dpi);
/// <summary>
/// Enable a way for elements to add a context menu entry
/// </summary>
/// <param name="menu">ContextMenuStrip</param>
/// <param name="surface">ISurface</param>
/// <param name="mouseEventArgs">MouseEventArgs</param>
void AddContextMenuItems(ContextMenuStrip menu, ISurface surface, MouseEventArgs mouseEventArgs);
} }
} }

View file

@ -101,13 +101,49 @@ namespace Greenshot.Base.Interfaces
long SaveElementsToStream(Stream stream); long SaveElementsToStream(Stream stream);
void LoadElementsFromStream(Stream stream); void LoadElementsFromStream(Stream stream);
/// <summary>
/// Provides the selected elements
/// </summary>
IDrawableContainerList SelectedElements { get; }
/// <summary>
/// Is there an element selected on the surface?
/// </summary>
bool HasSelectedElements { get; } bool HasSelectedElements { get; }
/// <summary>
/// Remove all selected elements
/// </summary>
void RemoveSelectedElements(); void RemoveSelectedElements();
/// <summary>
/// Cut the selected elements to the clipboard
/// </summary>
void CutSelectedElements(); void CutSelectedElements();
/// <summary>
/// Copy the selected elements to the clipboard
/// </summary>
void CopySelectedElements(); void CopySelectedElements();
/// <summary>
/// Paste the elements from the clipboard
/// </summary>
void PasteElementFromClipboard(); void PasteElementFromClipboard();
/// <summary>
/// Duplicate the selected elements
/// </summary>
void DuplicateSelectedElements(); void DuplicateSelectedElements();
/// <summary>
/// Deselected the specified element
/// </summary>
void DeselectElement(IDrawableContainer container, bool generateEvents = true); void DeselectElement(IDrawableContainer container, bool generateEvents = true);
/// <summary>
/// Deselected all elements
/// </summary>
void DeselectAllElements(); void DeselectAllElements();
/// <summary> /// <summary>

View file

@ -28,5 +28,7 @@ namespace Greenshot.Base.UnmanagedHelpers.Enums
{ {
REGION_ERROR = 0, REGION_ERROR = 0,
REGION_NULLREGION = 1, REGION_NULLREGION = 1,
SIMPLEREGION = 2,
COMPLEXREGION = 3
} }
} }

View file

@ -176,5 +176,10 @@ namespace Greenshot.Editor.Drawing.Adorners
public virtual void Transform(Matrix matrix) public virtual void Transform(Matrix matrix)
{ {
} }
/// <summary>
/// This is to TAG the adorner so we know the type
/// </summary>
public string Tag { get; set; }
} }
} }

View file

@ -27,7 +27,7 @@ using Greenshot.Base.Interfaces.Drawing;
namespace Greenshot.Editor.Drawing.Adorners namespace Greenshot.Editor.Drawing.Adorners
{ {
/// <summary> /// <summary>
/// This implements the special "gripper" for the Speech-Bubble tail /// This implements the special target "gripper", e.g. used for the Speech-Bubble tail
/// </summary> /// </summary>
public sealed class TargetAdorner : AbstractAdorner public sealed class TargetAdorner : AbstractAdorner
{ {
@ -41,8 +41,8 @@ namespace Greenshot.Editor.Drawing.Adorners
/// <summary> /// <summary>
/// Handle the mouse down /// Handle the mouse down
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender">object</param>
/// <param name="mouseEventArgs"></param> /// <param name="mouseEventArgs">MouseEventArgs</param>
public override void MouseDown(object sender, MouseEventArgs mouseEventArgs) public override void MouseDown(object sender, MouseEventArgs mouseEventArgs)
{ {
EditStatus = EditStatus.MOVING; EditStatus = EditStatus.MOVING;
@ -51,8 +51,8 @@ namespace Greenshot.Editor.Drawing.Adorners
/// <summary> /// <summary>
/// Handle the mouse move /// Handle the mouse move
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender">object</param>
/// <param name="mouseEventArgs"></param> /// <param name="mouseEventArgs">MouseEventArgs</param>
public override void MouseMove(object sender, MouseEventArgs mouseEventArgs) public override void MouseMove(object sender, MouseEventArgs mouseEventArgs)
{ {
if (EditStatus != EditStatus.MOVING) if (EditStatus != EditStatus.MOVING)

View file

@ -66,16 +66,14 @@ namespace Greenshot.Editor.Drawing
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS); int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
bool shadow = GetFieldValueAsBool(FieldType.SHADOW); bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
if (lineThickness > 0) if (lineThickness <= 0) return;
{
graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.None; graphics.PixelOffsetMode = PixelOffsetMode.None;
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR); Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
ArrowHeadCombination heads = (ArrowHeadCombination) GetFieldValue(FieldType.ARROWHEADS); ArrowHeadCombination heads = (ArrowHeadCombination) GetFieldValue(FieldType.ARROWHEADS);
if (lineThickness > 0)
{
if (shadow) if (shadow)
{ {
//draw shadow first //draw shadow first
@ -103,8 +101,6 @@ namespace Greenshot.Editor.Drawing
SetArrowHeads(heads, pen); SetArrowHeads(heads, pen);
graphics.DrawLine(pen, Left, Top, Left + Width, Top + Height); graphics.DrawLine(pen, Left, Top, Left + Width, Top + Height);
} }
}
}
private void SetArrowHeads(ArrowHeadCombination heads, Pen pen) private void SetArrowHeads(ArrowHeadCombination heads, Pen pen)
{ {

View file

@ -26,6 +26,7 @@ using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Linq; using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Windows.Forms;
using Greenshot.Base.IniFile; using Greenshot.Base.IniFile;
using Greenshot.Base.Interfaces; using Greenshot.Base.Interfaces;
using Greenshot.Base.Interfaces.Drawing; using Greenshot.Base.Interfaces.Drawing;
@ -448,6 +449,12 @@ namespace Greenshot.Editor.Drawing
} }
} }
/// <inheritdoc cref="IDrawableContainer"/>
public virtual void AddContextMenuItems(ContextMenuStrip menu, ISurface surface, MouseEventArgs mouseEventArgs)
{
// Empty as we do not want to add something to the context menu for every element
}
public virtual bool Contains(int x, int y) public virtual bool Contains(int x, int y)
{ {
return Bounds.Contains(x, y); return Bounds.Contains(x, y);

View file

@ -589,9 +589,10 @@ namespace Greenshot.Editor.Drawing
/// <summary> /// <summary>
/// Add items to a context menu for the selected item /// Add items to a context menu for the selected item
/// </summary> /// </summary>
/// <param name="menu"></param> /// <param name="menu">ContextMenuStrip</param>
/// <param name="surface"></param> /// <param name="surface">ISurface</param>
public virtual void AddContextMenuItems(ContextMenuStrip menu, ISurface surface) /// <param name="mouseEventArgs">MouseEventArgs</param>
public virtual void AddContextMenuItems(ContextMenuStrip menu, ISurface surface, MouseEventArgs mouseEventArgs)
{ {
bool push = surface.Elements.CanPushDown(this); bool push = surface.Elements.CanPushDown(this);
bool pull = surface.Elements.CanPullUp(this); bool pull = surface.Elements.CanPullUp(this);
@ -678,15 +679,7 @@ namespace Greenshot.Editor.Drawing
menu.Items.Add(item); menu.Items.Add(item);
// Reset // Reset
bool canReset = false; bool canReset = this.Cast<DrawableContainer>().Any(container => container.HasDefaultSize);
foreach (var drawableContainer in this)
{
var container = (DrawableContainer) drawableContainer;
if (container.HasDefaultSize)
{
canReset = true;
}
}
if (canReset) if (canReset)
{ {
@ -713,35 +706,29 @@ namespace Greenshot.Editor.Drawing
}; };
menu.Items.Add(item); menu.Items.Add(item);
} }
// "ask" the containers to add to the context menu
foreach (var surfaceElement in surface.Elements)
{
surfaceElement.AddContextMenuItems(menu, surface, mouseEventArgs);
}
} }
public virtual void ShowContextMenu(MouseEventArgs e, ISurface iSurface) public virtual void ShowContextMenu(MouseEventArgs mouseEventArgs, ISurface iSurface)
{ {
if (iSurface is not Surface surface) if (iSurface is not Surface surface)
{ {
return; return;
} }
bool hasMenu = false; bool hasMenu = this.Cast<DrawableContainer>().Any(container => container.HasContextMenu);
foreach (var drawableContainer in this)
{
var container = (DrawableContainer) drawableContainer;
if (!container.HasContextMenu)
{
continue;
}
hasMenu = true; if (!hasMenu) return;
break;
}
if (hasMenu)
{
ContextMenuStrip menu = new ContextMenuStrip(); ContextMenuStrip menu = new ContextMenuStrip();
AddContextMenuItems(menu, surface); AddContextMenuItems(menu, surface, mouseEventArgs);
if (menu.Items.Count > 0) if (menu.Items.Count <= 0) return;
{ menu.Show(surface, surface.ToSurfaceCoordinates(mouseEventArgs.Location));
menu.Show(surface, surface.ToSurfaceCoordinates(e.Location));
while (true) while (true)
{ {
if (menu.Visible) if (menu.Visible)
@ -756,15 +743,12 @@ namespace Greenshot.Editor.Drawing
} }
} }
} }
}
}
private bool _disposedValue; // To detect redundant calls private bool _disposedValue; // To detect redundant calls
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
if (!_disposedValue) if (_disposedValue) return;
{
if (disposing) if (disposing)
{ {
foreach (var drawableContainer in this) foreach (var drawableContainer in this)
@ -775,7 +759,6 @@ namespace Greenshot.Editor.Drawing
_disposedValue = true; _disposedValue = true;
} }
}
// This code added to correctly implement the disposable pattern. // This code added to correctly implement the disposable pattern.
public void Dispose() public void Dispose()

View file

@ -2036,16 +2036,21 @@ namespace Greenshot.Editor.Drawing
/// <summary> /// <summary>
/// Returns if this surface has selected elements /// Returns if this surface has selected elements
/// </summary> /// </summary>
/// <returns></returns> /// <returns>bool</returns>
public bool HasSelectedElements => (selectedElements != null && selectedElements.Count > 0); public bool HasSelectedElements => selectedElements is { Count: > 0 };
/// <summary>
/// Provides the selected elements
/// </summary>
public IDrawableContainerList SelectedElements => selectedElements;
/// <summary> /// <summary>
/// Remove all the selected elements /// Remove all the selected elements
/// </summary> /// </summary>
public void RemoveSelectedElements() public void RemoveSelectedElements()
{ {
if (HasSelectedElements) if (!HasSelectedElements) return;
{
// As RemoveElement will remove the element from the selectedElements list we need to copy the element to another list. // As RemoveElement will remove the element from the selectedElements list we need to copy the element to another list.
RemoveElements(selectedElements); RemoveElements(selectedElements);
if (_movingElementChanged != null) if (_movingElementChanged != null)
@ -2054,7 +2059,6 @@ namespace Greenshot.Editor.Drawing
_movingElementChanged(this, eventArgs); _movingElementChanged(this, eventArgs);
} }
} }
}
/// <summary> /// <summary>
/// Cut the selected elements from the surface to the clipboard /// Cut the selected elements from the surface to the clipboard