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