using System; using System.Drawing; using System.Drawing.Drawing2D; using System.IO; using System.Reflection; using System.Windows.Forms; namespace DbxNotifier { /// 그리기 도우미 — 둥근 사각형, 종 아이콘, 색 섞기, 내장 아이콘. internal static class Gfx { public static GraphicsPath Round(RectangleF r, float radius) { var p = new GraphicsPath(); float d = Math.Min(radius * 2, Math.Min(r.Width, r.Height)); if (d <= 0.5f) { p.AddRectangle(r); return p; } p.AddArc(r.X, r.Y, d, d, 180, 90); p.AddArc(r.Right - d, r.Y, d, d, 270, 90); p.AddArc(r.Right - d, r.Bottom - d, d, d, 0, 90); p.AddArc(r.X, r.Bottom - d, d, d, 90, 90); p.CloseFigure(); return p; } public static Color Mix(Color a, Color b, double t) => Color.FromArgb( (int)(a.A + (b.A - a.A) * t), (int)(a.R + (b.R - a.R) * t), (int)(a.G + (b.G - a.G) * t), (int)(a.B + (b.B - a.B) * t)); public static Color Hex(string hex, int alpha = 255) { int v = Convert.ToInt32(hex.TrimStart('#'), 16); return Color.FromArgb(alpha, (v >> 16) & 255, (v >> 8) & 255, v & 255); } /// 울리는 종(웹 팝업 머리의 notifications_active 와 같은 느낌) — 24 격자를 r 에 맞춰 그린다. public static void Bell(Graphics g, RectangleF r, Color color) { GraphicsState st = g.Save(); g.TranslateTransform(r.X, r.Y); g.ScaleTransform(r.Width / 24f, r.Height / 24f); using (var b = new SolidBrush(color)) using (var body = new GraphicsPath()) { body.AddLine(5f, 17f, 6.6f, 15.2f); body.AddLine(6.6f, 15.2f, 6.6f, 10.6f); body.AddBezier(6.6f, 10.6f, 6.6f, 7.2f, 9.0f, 4.9f, 12f, 4.9f); body.AddBezier(12f, 4.9f, 15.0f, 4.9f, 17.4f, 7.2f, 17.4f, 10.6f); body.AddLine(17.4f, 10.6f, 17.4f, 15.2f); body.AddLine(17.4f, 15.2f, 19f, 17f); body.CloseFigure(); g.FillPath(b, body); g.FillEllipse(b, 10.1f, 16.7f, 3.8f, 3.8f); g.FillEllipse(b, 10.9f, 3.3f, 2.2f, 2.2f); } using (var pen = new Pen(color, 1.7f) { StartCap = LineCap.Round, EndCap = LineCap.Round }) { g.DrawArc(pen, 2.4f, 1.0f, 19.2f, 19.2f, 198, 40); g.DrawArc(pen, 2.4f, 1.0f, 19.2f, 19.2f, 302, 40); } g.Restore(st); } /// exe 에 넣은 app.ico 에서 원하는 크기 아이콘(트레이 = 작은 아이콘 크기). public static Icon AppIcon(Size size) { using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("DbxNotifier.app.ico")) return s == null ? SystemIcons.Information : new Icon(s, size); } public static Icon TrayIcon() => AppIcon(SystemInformation.SmallIconSize); public static float SystemScale() { using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) return Math.Max(1f, g.DpiX / 96f); } } }