windowcapture
исходный код / Models/TextBlock.cs

TextBlock.cs

72 строк · 2,428 байт · модуль Models
 1using System;
 2using System.Drawing;
 3
 4namespace WindowCapture.Models
 5{
 6    public class TextBlock
 7    {
 8        public Point Location;
 9        public string Text = "";
10        public Font TextFont;
11        public Color TextColor;
12        public Color ShadowColor;
13        public int ShadowOffset;
14        public float ShadowAngle; // Direction of shadow in radians (0 = right, PI/2 = down)
15        public bool IsEditing;
16
17        // Pseudo-3D rotation (perspective simulation)
18        public float RotationX; // Tilt forward/backward (-60 to 60 degrees)
19        public float RotationY; // Tilt left/right (-60 to 60 degrees)
20
21        // 3D effect settings
22        public int Depth3D; // Depth of 3D extrusion (0 = no 3D sides)
23        public Color SideColor; // Color of 3D side faces
24
25        // Outline/stroke
26        public bool HasOutline;
27        public Color OutlineColor;
28        public float OutlineWidth;
29
30        public TextBlock(Point location)
31        {
32            Location = location;
33            TextFont = new Font(Settings.TextBlockFont, Settings.TextBlockFontSize);
34            TextColor = Settings.TextBlockColor;
35            ShadowColor = Settings.TextBlockShadowColor;
36            ShadowOffset = Settings.TextBlockShadowOffset;
37            ShadowAngle = (float)(Math.PI / 4); // Default: 45 degrees (bottom-right)
38            IsEditing = true;
39
40            // 3D defaults
41            Depth3D = 20;
42            SideColor = Color.FromArgb(255, 40, 40, 45);
43
44            // Outline defaults
45            HasOutline = false;
46            OutlineColor = Color.FromArgb(255, 30, 30, 35);
47            OutlineWidth = 2f;
48        }
49
50        // Get shadow offset as X,Y based on angle
51        public PointF GetShadowOffset()
52        {
53            return new PointF(
54                (float)(ShadowOffset * Math.Cos(ShadowAngle)),
55                (float)(ShadowOffset * Math.Sin(ShadowAngle)));
56        }
57
58        public Rectangle GetBounds(Graphics g)
59        {
60            if (string.IsNullOrEmpty(Text))
61                return new Rectangle(Location.X, Location.Y, 100, 30); // Minimum size for editing
62
63            var size = g.MeasureString(Text, TextFont);
64            return new Rectangle(Location.X, Location.Y, (int)size.Width + ShadowOffset, (int)size.Height + ShadowOffset);
65        }
66
67        public bool Contains(Point pt, Graphics g)
68        {
69            return GetBounds(g).Contains(pt);
70        }
71    }
72}