mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Draw tail in speech balloon but still unable to figure out how to union both rectangle and tail
This commit is contained in:
parent
141993b5db
commit
871b583da2
5 changed files with 58 additions and 45 deletions
|
@ -58,14 +58,6 @@ public enum EImageFormat
|
|||
TIFF
|
||||
}
|
||||
|
||||
public enum TriangleAngle
|
||||
{
|
||||
Top,
|
||||
Right,
|
||||
Bottom,
|
||||
Left
|
||||
}
|
||||
|
||||
public enum HashType
|
||||
{
|
||||
[Description("CRC-32")]
|
||||
|
|
|
@ -143,38 +143,6 @@ public static void AddCapsule(this GraphicsPath graphicsPath, RectangleF rect)
|
|||
graphicsPath.CloseFigure();
|
||||
}
|
||||
|
||||
public static void AddTriangle(this GraphicsPath graphicsPath, RectangleF rect, TriangleAngle angle = TriangleAngle.Top)
|
||||
{
|
||||
PointF p1, p2, p3;
|
||||
|
||||
switch (angle)
|
||||
{
|
||||
default:
|
||||
case TriangleAngle.Top:
|
||||
p1 = new PointF(rect.X + rect.Width / 2.0f, rect.Y);
|
||||
p2 = new PointF(rect.X, rect.Y + rect.Height);
|
||||
p3 = new PointF(rect.X + rect.Width, rect.Y + rect.Height);
|
||||
break;
|
||||
case TriangleAngle.Right:
|
||||
p1 = new PointF(rect.X + rect.Width, rect.Y + rect.Height / 2.0f);
|
||||
p2 = new PointF(rect.X, rect.Y);
|
||||
p3 = new PointF(rect.X, rect.Y + rect.Height);
|
||||
break;
|
||||
case TriangleAngle.Bottom:
|
||||
p1 = new PointF(rect.X + rect.Width / 2.0f, rect.Y + rect.Height);
|
||||
p2 = new PointF(rect.X + rect.Width, rect.Y);
|
||||
p3 = new PointF(rect.X, rect.Y);
|
||||
break;
|
||||
case TriangleAngle.Left:
|
||||
p1 = new PointF(rect.X, rect.Y + rect.Height / 2.0f);
|
||||
p2 = new PointF(rect.X + rect.Width, rect.Y + rect.Height);
|
||||
p3 = new PointF(rect.X + rect.Width, rect.Y);
|
||||
break;
|
||||
}
|
||||
|
||||
graphicsPath.AddPolygon(new PointF[] { p1, p2, p3 });
|
||||
}
|
||||
|
||||
public static void AddDiamond(this GraphicsPath graphicsPath, RectangleF rect)
|
||||
{
|
||||
PointF p1 = new PointF(rect.X + rect.Width / 2.0f, rect.Y);
|
||||
|
|
|
@ -179,6 +179,7 @@ public enum ShapeType // Localized
|
|||
DrawingLine,
|
||||
DrawingArrow,
|
||||
DrawingText,
|
||||
DrawingSpeechBalloon,
|
||||
DrawingStep,
|
||||
DrawingImage,
|
||||
DrawingBlur,
|
||||
|
|
|
@ -25,12 +25,15 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
using ShareX.HelpersLib;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace ShareX.ScreenCaptureLib
|
||||
{
|
||||
public class SpeechBalloonDrawingShape : TextDrawingShape
|
||||
{
|
||||
//public override ShapeType ShapeType { get; } = ShapeType.DrawingSpeechBalloon;
|
||||
public override ShapeType ShapeType { get; } = ShapeType.DrawingSpeechBalloon;
|
||||
|
||||
public int TailWidth { get; } = 40;
|
||||
|
||||
internal ResizeNode TailNode => Manager.ResizeNodes[(int)NodePosition.Extra];
|
||||
|
||||
|
@ -51,12 +54,58 @@ public override void OnNodeVisible()
|
|||
|
||||
public override void OnDraw(Graphics g)
|
||||
{
|
||||
using (Pen pen = new Pen(BorderColor, BorderSize))
|
||||
{
|
||||
g.DrawLine(pen, Rectangle.Center(), TailNode.Position);
|
||||
}
|
||||
DrawTail(g);
|
||||
|
||||
base.OnDraw(g);
|
||||
}
|
||||
|
||||
private void DrawTail(Graphics g)
|
||||
{
|
||||
using (GraphicsPath gpTail = new GraphicsPath())
|
||||
{
|
||||
Point center = Rectangle.Center();
|
||||
int tailOrigin = TailWidth / 2;
|
||||
int tailLength = (int)MathHelpers.Distance(center, TailNode.Position);
|
||||
gpTail.AddLine(0, -tailOrigin, 0, tailOrigin);
|
||||
gpTail.AddLine(0, tailOrigin, tailLength, 0);
|
||||
gpTail.CloseFigure();
|
||||
|
||||
g.TranslateTransform(center.X, center.Y);
|
||||
float tailDegree = MathHelpers.LookAtDegree(center, TailNode.Position);
|
||||
g.RotateTransform(tailDegree);
|
||||
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
|
||||
if (FillColor.A > 0)
|
||||
{
|
||||
using (Brush brush = new SolidBrush(FillColor))
|
||||
{
|
||||
g.FillPath(brush, gpTail);
|
||||
}
|
||||
}
|
||||
|
||||
if (BorderSize > 0 && BorderColor.A > 0)
|
||||
{
|
||||
using (Pen pen = new Pen(BorderColor, BorderSize))
|
||||
{
|
||||
g.DrawPath(pen, gpTail);
|
||||
}
|
||||
}
|
||||
|
||||
g.SmoothingMode = SmoothingMode.None;
|
||||
|
||||
g.ResetTransform();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnNodeUpdate()
|
||||
{
|
||||
base.OnNodeUpdate();
|
||||
|
||||
if (TailNode.IsDragging)
|
||||
{
|
||||
TailNode.Position = InputManager.MousePosition0Based;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1300,6 +1300,9 @@ private BaseShape CreateShape(ShapeType shapeType)
|
|||
case ShapeType.DrawingText:
|
||||
shape = new TextDrawingShape();
|
||||
break;
|
||||
case ShapeType.DrawingSpeechBalloon:
|
||||
shape = new SpeechBalloonDrawingShape();
|
||||
break;
|
||||
case ShapeType.DrawingStep:
|
||||
shape = new StepDrawingShape();
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue