mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-03 19:54:13 +13:00
Added speech balloon shadow
This commit is contained in:
parent
58a6707635
commit
9000cf31a7
1 changed files with 73 additions and 66 deletions
|
@ -90,26 +90,38 @@ public override void Move(int x, int y)
|
|||
}
|
||||
|
||||
public override void OnDraw(Graphics g)
|
||||
{
|
||||
if (Rectangle.Width > 10 && Rectangle.Height > 10)
|
||||
{
|
||||
DrawSpeechBalloon(g);
|
||||
DrawText(g);
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawSpeechBalloon(Graphics g)
|
||||
{
|
||||
if (Rectangle.Width > 10 && Rectangle.Height > 10)
|
||||
if (Shadow && IsBorderVisible)
|
||||
{
|
||||
DrawSpeechBalloon(g, ShadowColor, BorderSize, Color.Transparent, Rectangle.LocationOffset(ShadowOffset), TailPosition.Add(ShadowOffset));
|
||||
}
|
||||
|
||||
DrawSpeechBalloon(g, BorderColor, BorderSize, FillColor, Rectangle, TailPosition);
|
||||
}
|
||||
|
||||
protected void DrawSpeechBalloon(Graphics g, Color borderColor, int borderSize, Color fillColor, Rectangle rect, Point tailPosition)
|
||||
{
|
||||
GraphicsPath gpTail = null;
|
||||
|
||||
if (TailVisible)
|
||||
{
|
||||
gpTail = CreateTailPath();
|
||||
gpTail = CreateTailPath(rect, tailPosition);
|
||||
}
|
||||
|
||||
if (FillColor.A > 0)
|
||||
if (fillColor.A > 0)
|
||||
{
|
||||
using (Brush brush = new SolidBrush(FillColor))
|
||||
using (Brush brush = new SolidBrush(fillColor))
|
||||
{
|
||||
g.FillRectangle(brush, Rectangle);
|
||||
g.FillRectangle(brush, rect);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,11 +129,11 @@ protected void DrawSpeechBalloon(Graphics g)
|
|||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
|
||||
if (FillColor.A > 0)
|
||||
if (fillColor.A > 0)
|
||||
{
|
||||
g.ExcludeClip(Rectangle);
|
||||
g.ExcludeClip(rect);
|
||||
|
||||
using (Brush brush = new SolidBrush(FillColor))
|
||||
using (Brush brush = new SolidBrush(fillColor))
|
||||
{
|
||||
g.FillPath(brush, gpTail);
|
||||
}
|
||||
|
@ -129,11 +141,11 @@ protected void DrawSpeechBalloon(Graphics g)
|
|||
g.ResetClip();
|
||||
}
|
||||
|
||||
if (BorderSize > 0 && BorderColor.A > 0)
|
||||
if (borderSize > 0 && borderColor.A > 0)
|
||||
{
|
||||
g.ExcludeClip(Rectangle.Offset(-1));
|
||||
g.ExcludeClip(rect.Offset(-1));
|
||||
|
||||
using (Pen pen = new Pen(BorderColor, BorderSize))
|
||||
using (Pen pen = new Pen(borderColor, borderSize))
|
||||
{
|
||||
g.DrawPath(pen, gpTail);
|
||||
}
|
||||
|
@ -144,7 +156,7 @@ protected void DrawSpeechBalloon(Graphics g)
|
|||
g.SmoothingMode = SmoothingMode.None;
|
||||
}
|
||||
|
||||
if (BorderSize > 0 && BorderColor.A > 0)
|
||||
if (borderSize > 0 && borderColor.A > 0)
|
||||
{
|
||||
if (gpTail != null)
|
||||
{
|
||||
|
@ -154,11 +166,9 @@ protected void DrawSpeechBalloon(Graphics g)
|
|||
}
|
||||
}
|
||||
|
||||
Rectangle rect = Rectangle.Offset(BorderSize - 1);
|
||||
|
||||
using (Pen pen = new Pen(BorderColor, BorderSize) { Alignment = PenAlignment.Inset })
|
||||
using (Pen pen = new Pen(borderColor, borderSize) { Alignment = PenAlignment.Inset })
|
||||
{
|
||||
g.DrawRectangleProper(pen, rect);
|
||||
g.DrawRectangleProper(pen, rect.Offset(borderSize - 1));
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
@ -168,27 +178,24 @@ protected void DrawSpeechBalloon(Graphics g)
|
|||
{
|
||||
gpTail.Dispose();
|
||||
}
|
||||
|
||||
DrawText(g);
|
||||
}
|
||||
}
|
||||
|
||||
protected GraphicsPath CreateTailPath()
|
||||
protected GraphicsPath CreateTailPath(Rectangle rect, Point tailPosition)
|
||||
{
|
||||
GraphicsPath gpTail = new GraphicsPath();
|
||||
Point center = Rectangle.Center();
|
||||
int rectAverageSize = (Rectangle.Width + Rectangle.Height) / 2;
|
||||
Point center = rect.Center();
|
||||
int rectAverageSize = (rect.Width + rect.Height) / 2;
|
||||
int tailWidth = (int)(TailWidthMultiplier * rectAverageSize);
|
||||
tailWidth = Math.Min(Math.Min(tailWidth, Rectangle.Width), Rectangle.Height);
|
||||
tailWidth = Math.Min(Math.Min(tailWidth, rect.Width), rect.Height);
|
||||
int tailOrigin = tailWidth / 2;
|
||||
int tailLength = (int)MathHelpers.Distance(center, TailPosition);
|
||||
int tailLength = (int)MathHelpers.Distance(center, tailPosition);
|
||||
gpTail.AddLine(0, -tailOrigin, 0, tailOrigin);
|
||||
gpTail.AddLine(0, tailOrigin, tailLength, 0);
|
||||
gpTail.CloseFigure();
|
||||
using (Matrix matrix = new Matrix())
|
||||
{
|
||||
matrix.Translate(center.X, center.Y);
|
||||
float tailDegree = MathHelpers.LookAtDegree(center, TailPosition);
|
||||
float tailDegree = MathHelpers.LookAtDegree(center, tailPosition);
|
||||
matrix.Rotate(tailDegree);
|
||||
gpTail.Transform(matrix);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue