tangxu
2024-11-25 0a2c59670b82d61d3fa79f51a54e82e7bd0134c4
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Enum.Crown;
using DPumpHydr.WinFrmUI.RLT.Forms;
using System;
using System.Drawing;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Docking.Crown
{
    #region CrownDockSplitterDocking
 
    public class CrownDockSplitter
    {
        #region Field Region
 
        private readonly Control _parentControl;
        private readonly Control _control;
 
        private readonly SplitterType _splitterType;
 
        private int _minimum;
        private int _maximum;
        private CrownTranslucentForm _overlayForm;
 
        #endregion
 
        #region Property Region
 
        public Rectangle Bounds { get; set; }
 
        public Cursor ResizeCursor { get; private set; }
 
        #endregion
 
        #region Constructor Region
 
        public CrownDockSplitter(Control parentControl, Control control, SplitterType splitterType)
        {
            _parentControl = parentControl;
            _control = control;
            _splitterType = splitterType;
 
            switch (_splitterType)
            {
                case SplitterType.Left:
                case SplitterType.Right:
                    ResizeCursor = Cursors.SizeWE;
                    break;
                case SplitterType.Top:
                case SplitterType.Bottom:
                    ResizeCursor = Cursors.SizeNS;
                    break;
            }
        }
 
        #endregion
 
        #region Method Region
 
        public void ShowOverlay()
        {
            _overlayForm = new CrownTranslucentForm(Color.Black)
            {
                Visible = true
            };
 
            UpdateOverlay(new Point(0, 0));
        }
 
        public void HideOverlay()
        {
            _overlayForm.Visible = false;
        }
 
        public void UpdateOverlay(Point difference)
        {
            Rectangle bounds = new(Bounds.Location, Bounds.Size);
 
            switch (_splitterType)
            {
                case SplitterType.Left:
                    int leftX = Math.Max(bounds.Location.X - difference.X, _minimum);
 
                    if (_maximum != 0 && leftX > _maximum)
                    {
                        leftX = _maximum;
                    }
 
                    bounds.Location = new(leftX, bounds.Location.Y);
                    break;
                case SplitterType.Right:
                    int rightX = Math.Max(bounds.Location.X - difference.X, _minimum);
 
                    if (_maximum != 0 && rightX > _maximum)
                    {
                        rightX = _maximum;
                    }
 
                    bounds.Location = new(rightX, bounds.Location.Y);
                    break;
                case SplitterType.Top:
                    int topY = Math.Max(bounds.Location.Y - difference.Y, _minimum);
 
                    if (_maximum != 0 && topY > _maximum)
                    {
                        topY = _maximum;
                    }
 
                    bounds.Location = new(bounds.Location.X, topY);
                    break;
                case SplitterType.Bottom:
                    int bottomY = Math.Max(bounds.Location.Y - difference.Y, _minimum);
 
                    if (_maximum != 0 && bottomY > _maximum)
                    {
                        topY = _maximum;
                    }
 
                    bounds.Location = new(bounds.Location.X, bottomY);
                    break;
            }
 
            _overlayForm.Bounds = bounds;
        }
 
        public void Move(Point difference)
        {
            switch (_splitterType)
            {
                case SplitterType.Left:
                    _control.Width += difference.X;
                    break;
                case SplitterType.Right:
                    _control.Width -= difference.X;
                    break;
                case SplitterType.Top:
                    _control.Height += difference.Y;
                    break;
                case SplitterType.Bottom:
                    _control.Height -= difference.Y;
                    break;
            }
 
            UpdateBounds();
        }
 
        public void UpdateBounds()
        {
            Rectangle bounds = _parentControl.RectangleToScreen(_control.Bounds);
 
            switch (_splitterType)
            {
                case SplitterType.Left:
                    Bounds = new(bounds.Left - 2, bounds.Top, 5, bounds.Height);
                    _maximum = bounds.Right - 2 - _control.MinimumSize.Width;
                    break;
                case SplitterType.Right:
                    Bounds = new(bounds.Right - 2, bounds.Top, 5, bounds.Height);
                    _minimum = bounds.Left - 2 + _control.MinimumSize.Width;
                    break;
                case SplitterType.Top:
                    Bounds = new(bounds.Left, bounds.Top - 2, bounds.Width, 5);
                    _maximum = bounds.Bottom - 2 - _control.MinimumSize.Height;
                    break;
                case SplitterType.Bottom:
                    Bounds = new(bounds.Left, bounds.Bottom - 2, bounds.Width, 5);
                    _minimum = bounds.Top - 2 + _control.MinimumSize.Height;
                    break;
            }
        }
 
        #endregion
    }
 
    #endregion
}