Enhanced the adorner interface and the drawing to make it easier to configure with different colors. [skip ci]

This commit is contained in:
Robin Krom 2022-03-28 14:53:17 +02:00
parent 2721ee06a2
commit d6055416c8
No known key found for this signature in database
GPG key ID: BCC01364F1371490
7 changed files with 42 additions and 62 deletions

View file

@ -98,5 +98,15 @@ namespace Greenshot.Base.Interfaces.Drawing.Adorners
/// </summary>
/// <param name="dpi"></param>
void AdjustToDpi(uint dpi);
/// <summary>
/// The color of the lines around the adorner
/// </summary>
Color OutlineColor { get; set; }
/// <summary>
/// The color of the fill of the adorner
/// </summary>
Color FillColor { get; set; }
}
}

View file

@ -137,12 +137,36 @@ namespace Greenshot.Editor.Drawing.Adorners
_size = DpiHelper.ScaleWithDpi(DefaultSize, dpi);
}
public Color OutlineColor { get; set; } = Color.White;
public Color FillColor { get; set; } = Color.Black;
/// <summary>
/// Draw the adorner
/// </summary>
/// <param name="paintEventArgs">PaintEventArgs</param>
public virtual void Paint(PaintEventArgs paintEventArgs)
{
Graphics targetGraphics = paintEventArgs.Graphics;
var bounds = BoundsOnSurface;
GraphicsState state = targetGraphics.Save();
targetGraphics.CompositingMode = CompositingMode.SourceCopy;
try
{
using var fillBrush = new SolidBrush(FillColor);
targetGraphics.FillRectangle(fillBrush, bounds);
using var lineBrush = new SolidBrush(OutlineColor);
using var pen = new Pen(lineBrush);
targetGraphics.DrawRectangle(pen, bounds);
}
catch
{
// Ignore, BUG-2065
}
targetGraphics.Restore(state);
}
/// <summary>

View file

@ -136,31 +136,5 @@ namespace Greenshot.Editor.Drawing.Adorners
return new Point(x, y);
}
}
/// <summary>
/// Draw the adorner
/// </summary>
/// <param name="paintEventArgs">PaintEventArgs</param>
public override void Paint(PaintEventArgs paintEventArgs)
{
Graphics targetGraphics = paintEventArgs.Graphics;
var bounds = BoundsOnSurface;
GraphicsState state = targetGraphics.Save();
targetGraphics.CompositingMode = CompositingMode.SourceCopy;
try
{
targetGraphics.FillRectangle(Brushes.Black, bounds);
targetGraphics.DrawRectangle(new Pen(Brushes.White), bounds);
}
catch
{
// Ignore, BUG-2065
}
targetGraphics.Restore(state);
}
}
}

View file

@ -164,23 +164,5 @@ namespace Greenshot.Editor.Drawing.Adorners
return new Point(x, y);
}
}
/// <summary>
/// Draw the adorner
/// </summary>
/// <param name="paintEventArgs">PaintEventArgs</param>
public override void Paint(PaintEventArgs paintEventArgs)
{
Graphics targetGraphics = paintEventArgs.Graphics;
var bounds = BoundsOnSurface;
GraphicsState state = targetGraphics.Save();
targetGraphics.CompositingMode = CompositingMode.SourceCopy;
targetGraphics.FillRectangle(Brushes.Black, bounds);
targetGraphics.DrawRectangle(new Pen(Brushes.White), bounds);
targetGraphics.Restore(state);
}
}
}

View file

@ -29,11 +29,13 @@ namespace Greenshot.Editor.Drawing.Adorners
/// <summary>
/// This implements the special "gripper" for the Speech-Bubble tail
/// </summary>
public class TargetAdorner : AbstractAdorner
public sealed class TargetAdorner : AbstractAdorner
{
public TargetAdorner(IDrawableContainer owner, Point location) : base(owner)
public TargetAdorner(IDrawableContainer owner, Point location, Color? fillColor = null, Color? outlineColor = null) : base(owner)
{
Location = location;
FillColor = fillColor ?? Color.Green;
OutlineColor = outlineColor ?? Color.White;
}
/// <summary>
@ -90,19 +92,6 @@ namespace Greenshot.Editor.Drawing.Adorners
Owner.Invalidate();
}
/// <summary>
/// Draw the adorner
/// </summary>
/// <param name="paintEventArgs">PaintEventArgs</param>
public override void Paint(PaintEventArgs paintEventArgs)
{
Graphics targetGraphics = paintEventArgs.Graphics;
var bounds = BoundsOnSurface;
targetGraphics.FillRectangle(Brushes.Green, bounds);
targetGraphics.DrawRectangle(new Pen(Brushes.White), bounds);
}
/// <summary>
/// Made sure this adorner is transformed
/// </summary>

View file

@ -363,7 +363,8 @@ namespace Greenshot.Editor.Drawing
/// <summary>
/// Initialize a target gripper
/// </summary>
protected void InitAdorner(Color gripperColor, Point location)
/// <param name="location">Point</param>
protected void InitTargetAdorner(Point location)
{
_targetAdorner = new TargetAdorner(this, location);
Adorners.Add(_targetAdorner);

View file

@ -62,7 +62,7 @@ namespace Greenshot.Editor.Drawing
protected override void OnDeserialized(StreamingContext streamingContext)
{
base.OnDeserialized(streamingContext);
InitAdorner(Color.Green, _storedTargetGripperLocation);
InitTargetAdorner(_storedTargetGripperLocation);
}
public SpeechbubbleContainer(ISurface parent) : base(parent)
@ -95,7 +95,7 @@ namespace Greenshot.Editor.Drawing
if (TargetAdorner == null)
{
_initialGripperPoint = new Point(mouseX, mouseY);
InitAdorner(Color.Green, new Point(mouseX, mouseY));
InitTargetAdorner(new Point(mouseX, mouseY));
}
return base.HandleMouseDown(mouseX, mouseY);