tangxu
2025-02-26 2fc64c1af548596c4719d4a3abdc10de7a1d7e8f
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
#region Imports
 
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region ParrotSegment
 
    public class ParrotSegment : Control
    {
        public ParrotSegment()
        {
            base.Size = new Size(240, 30);
            Cursor = Cursors.Hand;
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The items, split by ','.")]
        public string Items
        {
            get => items;
            set
            {
                items = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The selected index")]
        public int SelectedIndex
        {
            get => selectedIndex;
            set
            {
                selectedIndex = value;
                OnIndexChanged();
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The segment style")]
        public Style SegmentStyle
        {
            get => segmentStyle;
            set
            {
                segmentStyle = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The segment selected base color")]
        public Color SegmentColor
        {
            get => segmentColor;
            set
            {
                segmentColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The segment back color")]
        public Color SegmentBackColor
        {
            get => segmentBackColor;
            set
            {
                segmentBackColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The active segment text color")]
        public Color SegmentActiveTextColor
        {
            get => segmentActiveTextColor;
            set
            {
                segmentActiveTextColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The active segment android font color")]
        public Color SegmentActiveFontColor
        {
            get => segmentActiveFontColor;
            set
            {
                segmentActiveFontColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Theinactive segment android font color")]
        public Color SegmentInactiveFontColor
        {
            get => segmentInactiveFontColor;
            set
            {
                segmentInactiveFontColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The active segment ios back color")]
        public Color SegmentActiveBackColor
        {
            get => segmentActiveBackColor;
            set
            {
                segmentActiveBackColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Theinactive segment text color")]
        public Color SegmentInactiveTextColor
        {
            get => segmentInactiveTextColor;
            set
            {
                segmentInactiveTextColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Theinactive segment ios border color")]
        public Color SegmentInactiveBorderColor
        {
            get => segmentInactiveBorderColor;
            set
            {
                segmentInactiveBorderColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Theinactive segment android normal color")]
        public Color SegmentNormalBackColor
        {
            get => segmentNormalBackColor;
            set
            {
                segmentNormalBackColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The active segment android line color")]
        public Color SegmentActiveLineColor
        {
            get => segmentActiveLineColor;
            set
            {
                segmentActiveLineColor = value;
                Invalidate();
            }
        }
 
        private InterpolationMode _InterpolationType = InterpolationMode.HighQualityBilinear;
        [Category("Parrot")]
        [Browsable(true)]
        public InterpolationMode InterpolationType
        {
            get => _InterpolationType;
            set
            {
                _InterpolationType = value;
                Invalidate();
            }
        }
 
        private CompositingQuality _CompositingQualityType = CompositingQuality.HighQuality;
        [Category("Parrot")]
        [Browsable(true)]
        public CompositingQuality CompositingQualityType
        {
            get => _CompositingQualityType;
            set
            {
                _CompositingQualityType = value;
                Invalidate();
            }
        }
 
        private TextRenderingHint _TextRenderingType = TextRenderingHint.ClearTypeGridFit;
        [Category("Parrot")]
        [Browsable(true)]
        public TextRenderingHint TextRenderingType
        {
            get => _TextRenderingType;
            set
            {
                _TextRenderingType = value;
                Invalidate();
            }
        }
 
        public event EventHandler IndexChanged;
 
        protected virtual void OnIndexChanged()
        {
            IndexChanged?.Invoke(this, new EventArgs());
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            e.Graphics.InterpolationMode = InterpolationType;
            e.Graphics.CompositingQuality = CompositingQualityType;
            e.Graphics.TextRenderingHint = TextRenderingType;
            int num = 0;
            foreach (string text in items.Split(new char[]
            {
                ','
            }))
            {
                num++;
            }
            int num2 = base.Width / num;
            int num3 = 0;
            int num4 = 0;
            if (segmentStyle == Style.iOS)
            {
                foreach (string s in items.Split(new char[]
                {
                    ','
                }))
                {
                    if (num3 <= num)
                    {
                        Rectangle r = new(num4, 0, num2, base.Height);
                        StringFormat stringFormat = new()
                        {
                            LineAlignment = StringAlignment.Center,
                            Alignment = StringAlignment.Center
                        };
                        e.Graphics.DrawRectangle(new Pen(SegmentInactiveBorderColor, 1f), 0, 0, base.Width - 1, base.Height - 1);
                        if (selectedIndex == num3)
                        {
                            e.Graphics.FillRectangle(new SolidBrush(SegmentActiveBackColor), num4, 0, num2, base.Height);
                            e.Graphics.DrawString(s, Font, new SolidBrush(SegmentActiveTextColor), r, stringFormat);
                        }
                        else
                        {
                            e.Graphics.DrawRectangle(new Pen(SegmentInactiveBorderColor, 1f), num4, 0, num4 + num2, base.Height - 1);
                            e.Graphics.DrawString(s, Font, new SolidBrush(SegmentInactiveBorderColor), r, stringFormat);
                        }
                    }
                    num4 += num2;
                    num3++;
                }
            }
            if (segmentStyle == Style.Android)
            {
                e.Graphics.FillRectangle(new SolidBrush(SegmentNormalBackColor), 0, 0, base.Width, base.Height);
                foreach (string s2 in items.Split(new char[]
                {
                    ','
                }))
                {
                    if (num3 <= num)
                    {
                        Rectangle r2 = new(num4, 0, num2, base.Height - 5);
                        StringFormat stringFormat2 = new()
                        {
                            LineAlignment = StringAlignment.Center,
                            Alignment = StringAlignment.Center
                        };
                        if (selectedIndex == num3)
                        {
                            e.Graphics.FillRectangle(new SolidBrush(SegmentActiveLineColor), num4, base.Height - 3, num2, 3);
                            e.Graphics.DrawString(s2, Font, new SolidBrush(SegmentActiveFontColor), r2, stringFormat2);
                        }
                        else
                        {
                            e.Graphics.DrawString(s2, Font, new SolidBrush(SegmentInactiveFontColor), r2, stringFormat2);
                        }
                    }
                    num4 += num2;
                    num3++;
                }
            }
            if (segmentStyle == Style.Material)
            {
                e.Graphics.FillRectangle(new SolidBrush(segmentBackColor), 0, 0, base.Width, base.Height);
                foreach (string s3 in items.Split(new char[]
                {
                    ','
                }))
                {
                    if (num3 <= num)
                    {
                        Rectangle r3 = new(num4, 0, num2, base.Height - 5);
                        StringFormat stringFormat3 = new()
                        {
                            LineAlignment = StringAlignment.Center,
                            Alignment = StringAlignment.Center
                        };
                        if (selectedIndex == num3)
                        {
                            e.Graphics.FillRectangle(new SolidBrush(segmentColor), num4, base.Height - 3, num2, 3);
                            e.Graphics.DrawString(s3, Font, new SolidBrush(segmentActiveTextColor), r3, stringFormat3);
                        }
                        else
                        {
                            e.Graphics.DrawString(s3, Font, new SolidBrush(segmentInactiveTextColor), r3, stringFormat3);
                        }
                    }
                    num4 += num2;
                    num3++;
                }
            }
        }
 
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            int num = 0;
            int num2 = 0;
            foreach (string text in items.Split(new char[]
            {
                ','
            }))
            {
                num2++;
            }
            int num3 = base.Width / num2;
            if (e.X > 0)
            {
                num = 0;
            }
            if (e.X > num3)
            {
                num = 1;
            }
            if (e.X > num3 * 2)
            {
                num = 2;
            }
            if (e.X > num3 * 3)
            {
                num = 3;
            }
            if (e.X > num3 * 4)
            {
                num = 4;
            }
            if (e.X > num3 * 5)
            {
                num = 5;
            }
            if (e.X > num3 * 6)
            {
                num = 6;
            }
            if (e.X > num3 * 7)
            {
                num = 7;
            }
            if (e.X > num3 * 8)
            {
                num = 8;
            }
            if (e.X > num3 * 9)
            {
                num = 9;
            }
            if (e.X > num3 * 10)
            {
                num = 10;
            }
            if (num != selectedIndex)
            {
                SelectedIndex = num;
            }
        }
 
        private string items = "Contacts, Recents, Messages, Dialer";
 
        private int selectedIndex;
 
        private Style segmentStyle = Style.Material;
 
        private Color segmentColor = Color.White;
 
        private Color segmentBackColor = Color.FromArgb(0, 150, 135);
 
        private Color segmentActiveTextColor = Color.White;
 
        private Color segmentActiveFontColor = Color.FromArgb(65, 130, 205);
 
        private Color segmentActiveBackColor = Color.FromArgb(0, 120, 255);
 
        private Color segmentActiveLineColor = Color.FromArgb(65, 130, 205);
 
        private Color segmentInactiveTextColor = Color.FromArgb(150, 210, 210);
 
        private Color segmentInactiveFontColor = Color.FromArgb(153, 153, 153);
 
        private Color segmentInactiveBorderColor = Color.FromArgb(0, 120, 255);
 
        private Color segmentNormalBackColor = Color.White;
 
        public enum Style
        {
            iOS,
            Android,
            Material
        }
    }
 
    #endregion
}