windowcapture
исходный код / Helpers/GlowHelper.cs

GlowHelper.cs

25 строк · 814 байт · модуль Helpers
 1using System;
 2using System.Drawing;
 3using System.Windows.Forms;
 4
 5namespace WindowCapture.Helpers
 6{
 7    public static class GlowHelper
 8    {
 9        public static float ComputeGlow(Control ctrl, float fullRadius = 30f, float maxRadius = 150f)
10        {
11            try
12            {
13                Point sp = Cursor.Position;
14                Point cc = ctrl.PointToScreen(new Point(ctrl.Width / 2, ctrl.Height / 2));
15                float dx = sp.X - cc.X, dy = sp.Y - cc.Y;
16                float dist = (float)Math.Sqrt(dx * dx + dy * dy);
17                if (dist < fullRadius) return 1f;
18                if (dist > maxRadius) return 0f;
19                float t = (dist - fullRadius) / (maxRadius - fullRadius);
20                return 1f - t * t;
21            }
22            catch { return 0f; }
23        }
24    }
25}