windowcapture
исходный код / UI/EditorForm.Indicators.cs

EditorForm.Indicators.cs

129 строк · 5,420 байт · модуль UI
  1using System;
  2using System.Collections.Generic;
  3using System.Drawing;
  4using System.Drawing.Drawing2D;
  5using System.Drawing.Imaging;
  6using System.Drawing.Text;
  7using System.IO;
  8using System.Linq;
  9using System.Runtime.InteropServices;
 10using System.Windows.Forms;
 11using WindowCapture.App;
 12using WindowCapture.Detection;
 13using WindowCapture.Effects;
 14using WindowCapture.Helpers;
 15using WindowCapture.Integration;
 16using WindowCapture.Models;
 17using WindowCapture.Native;
 18
 19namespace WindowCapture.UI
 20{
 21    public partial class EditorForm
 22    {
 23        // ===== Glass indicators (volume, filename, element glow) =====
 24
 25        // Proximity glow for video control elements (same quadratic falloff as glass buttons)
 26        private float CalcElementGlow(Point cursor, PointF elementCenter, float maxRadius)
 27        {
 28            float dx = cursor.X - elementCenter.X;
 29            float dy = cursor.Y - elementCenter.Y;
 30            float dist = (float)Math.Sqrt(dx * dx + dy * dy);
 31            if (dist <= GlowFullRadius) return 1.0f;
 32            if (dist >= maxRadius) return 0.0f;
 33            float t = (dist - GlowFullRadius) / (maxRadius - GlowFullRadius);
 34            return 1.0f - t * t;
 35        }
 36
 37        // Glass volume indicator (Vertical aesthetic popup)
 38        private void PaintVolumeIndicator(Graphics g)
 39        {
 40            if (volumeIndicatorAlpha <= 0.01f) return;
 41
 42            // Fade logic
 43            double elapsed = (DateTime.Now - volumeLastChangeTime).TotalMilliseconds;
 44            if (elapsed > 1500)
 45            {
 46                float fadeT = (float)((elapsed - 1500) / 800.0);
 47                volumeIndicatorAlpha = Math.Max(0f, 1f - fadeT);
 48            }
 49            if (volumeIndicatorAlpha <= 0.01f) return;
 50
 51            float a = volumeIndicatorAlpha;
 52            var panel = videoOverlay != null ? (Control)videoOverlay : scrollContainer;
 53            int cx = panel.Width / 2;
 54            int cy = panel.Height / 2;
 55
 56            // Sleek vertical bar
 57            int barW = 4, barH = 140;
 58            int bx = cx - barW / 2, by = cy - barH / 2;
 59
 60            g.CompositingQuality = CompositingQuality.HighQuality;
 61            g.SmoothingMode = SmoothingMode.AntiAlias;
 62
 63            // 1. Background track (minimalist dark)
 64            using (var brush = new SolidBrush(Color.FromArgb((int)(a * 50), 0, 0, 0)))
 65                g.FillRectangle(brush, bx, by, barW, barH);
 66
 67            // 2. Volume fill
 68            float vol = videoMuted ? 0f : videoVolume;
 69            int fillH = (int)(barH * vol);
 70            if (fillH > 0)
 71            {
 72                using (var brush = new SolidBrush(Color.FromArgb((int)(a * 255), 255, 255, 255)))
 73                    g.FillRectangle(brush, bx, by + barH - fillH, barW, fillH);
 74                
 75                // Glow point
 76                using (var brush = new SolidBrush(Color.FromArgb((int)(a * 255), 255, 255, 255)))
 77                    g.FillEllipse(brush, bx - 3, by + barH - fillH - 5, 10, 10);
 78            }
 79
 80            // 3. Percentage text (Bebas)
 81            string volStr = videoMuted ? "MUTE" : ((int)(videoVolume * 100)) + "%";
 82            using (var font = new Font(FontHelper.BebasFont ?? FontFamily.GenericSansSerif, 24f, FontStyle.Regular, GraphicsUnit.Pixel))
 83            {
 84                g.TextRenderingHint = TextRenderingHint.AntiAlias;
 85                var sz = g.MeasureString(volStr, font);
 86                using (var brush = new SolidBrush(Color.FromArgb((int)(a * 255), 255, 255, 255)))
 87                    g.DrawString(volStr, font, brush, cx - sz.Width / 2, by + barH + 15);
 88            }
 89        }
 90
 91        // Glass file name indicator (replaces plain Label)
 92        private void PaintFileNameIndicator(Graphics g)
 93        {
 94            if (fileNameAlpha <= 0.01f || currentFilePath == null) return;
 95            float a = fileNameAlpha;
 96
 97            string name = Path.GetFileName(currentFilePath);
 98            int idx = currentFileIndex + 1;
 99            int total = folderFiles != null ? folderFiles.Length : 1;
100            string text = name + "  (" + idx + "/" + total + ")";
101
102            using (var font = new Font("Segoe UI", 12f, FontStyle.Regular, GraphicsUnit.Pixel))
103            {
104                var sz = g.MeasureString(text, font);
105                float boxW = sz.Width + 20;
106                float boxH = sz.Height + 10;
107                float bx = 10, by = 8;
108
109                // Glass fill
110                using (var brush = new SolidBrush(Color.FromArgb((int)(a * 18), 200, 210, 230)))
111                    g.FillRectangle(brush, bx, by, boxW, boxH);
112                // Glass edges
113                using (var pen = new Pen(Color.FromArgb((int)(a * 70), 225, 232, 245), 1f))
114                    g.DrawRectangle(pen, bx, by, boxW, boxH);
115
116                // Dynamic: sample actual image brightness behind indicator
117                var indicatorRect = new Rectangle((int)bx, (int)by, (int)boxW, (int)boxH);
118                float brightness = SampleImageBrightnessAt(indicatorRect);
119                Color textC = brightness < 0.55f
120                    ? Color.FromArgb((int)(a * 200), 220, 228, 242)
121                    : Color.FromArgb((int)(a * 200), 30, 30, 40);
122
123                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
124                using (var brush = new SolidBrush(textC))
125                    g.DrawString(text, font, brush, bx + 10, by + 5);
126            }
127        }
128    }
129}