tangxu
2024-12-24 91105b77c916d06dd30380e20594e29f85eae3da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Colors;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Util
{
    #region HopeUtil
 
    public static class HopeStringAlign
    {
        public static StringFormat TopLeft => new() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near };
 
        public static StringFormat TopCenter => new() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Near };
 
        public static StringFormat TopRight => new() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Near };
 
        public static StringFormat Left => new() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center };
 
        public static StringFormat Center => new() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
 
        public static StringFormat Right => new() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Center };
 
        public static StringFormat BottomLeft => new() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Far };
 
        public static StringFormat BottomCenter => new() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Far };
 
        public static StringFormat BottomRight => new() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Far };
    }
 
    public enum HopeButtonType
    {
        Default = 0,
        Primary = 1,
        Success = 2,
        Info = 3,
        Warning = 4,
        Danger = 5
    }
 
    namespace HopeBase
    {
        public class ToolStripRender : ToolStripProfessionalRenderer
        {
            public ToolStripRender()
            {
                base.RoundedEdges = true;
            }
 
            protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
            {
                e.ToolStrip.ForeColor = HopeColors.MainText;
                if (e.ToolStrip is ToolStripDropDown)
                {
                    Graphics g = e.Graphics;
                    g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    g.SmoothingMode = SmoothingMode.HighQuality;
                    g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                    g.Clear(Color.White);
                    GraphicsPath bg = RoundRectangle.CreateRoundRect(0.5f, 0.5f, e.AffectedBounds.Width - 1, e.AffectedBounds.Height - 1, 3);
                    g.DrawPath(new(HopeColors.OneLevelBorder, 1), bg);
                    g.FillPath(new SolidBrush(Color.White), bg);
                }
                else
                {
                    base.OnRenderToolStripBackground(e);
                }
            }
 
            protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
            {
                if (e.ToolStrip is MenuStrip)
                {
                    if (e.Item.Selected || e.Item.Pressed)
                    {
                        e.Graphics.FillRectangle(new SolidBrush(HopeColors.FourLevelBorder), 0, 0, e.Item.Size.Width, e.Item.Height);
                    }
                    else
                    {
                        base.OnRenderMenuItemBackground(e);
                    }
                }
                else if (e.ToolStrip is ToolStripDropDown)
                {
                    if (e.Item.Selected)
                    {
                        e.Graphics.FillRectangle(new SolidBrush(HopeColors.FourLevelBorder), 0, 0, e.Item.Size.Width, e.Item.Height);
                    }
                }
                else
                {
                    base.OnRenderMenuItemBackground(e);
                }
            }
 
            protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e)
            {
                e.Graphics.DrawLine(new(HopeColors.OneLevelBorder, 1.5f), 5, 2.75f, e.Item.Width - 5, 2.75f);
            }
 
            protected override void OnRenderImageMargin(ToolStripRenderEventArgs e)
            {
                e.Graphics.Clear(Color.White);
            }
 
            protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
            {
                Graphics g = e.Graphics;
                g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
 
                Rectangle itemRect = GetItemRect(e.Item);
                Rectangle textRect = new(0, itemRect.Y, itemRect.Width, itemRect.Height);
                g.DrawString(e.Text, new Font("Segoe UI", 11f), new SolidBrush(e.Item.Selected ? HopeColors.PrimaryColor : HopeColors.RegularText), textRect, HopeStringAlign.Center);
            }
 
            protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
            {
                Graphics g = e.Graphics;
                g.DrawRectangle(new(HopeColors.OneLevelBorder), new Rectangle(e.AffectedBounds.X, e.AffectedBounds.Y, e.AffectedBounds.Width - 1, e.AffectedBounds.Height - 1));
            }
 
            protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
            {
                e.ArrowColor = HopeColors.PlaceholderText;
                base.OnRenderArrow(e);
            }
 
            private static Rectangle GetItemRect(ToolStripItem item)
            {
                return new Rectangle(0, item.ContentRectangle.Y, item.ContentRectangle.Width + 4, item.ContentRectangle.Height);
            }
        }
 
        public class DateRectHopeBase
        {
            public RectangleF Rect;
            public bool Drawn = false;
            public DateTime Date;
 
            public DateRectHopeBase(RectangleF pRect)
            {
                Rect = pRect;
            }
        }
    }
 
    #endregion
}