黄学彪
2021-01-28 1fcf2302f79f9cbea5ef17c3688311ed65cfabb4
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
using Shared;
using HDL_ON.UI.CSS;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace HDL_ON.Stan
{
    /// <summary>
    /// 左右滑动的进度条控件
    /// </summary>
    public class SeekBarImageControl : DiyImageSeekBar
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 进度值改变,如果要设置初始进度值,此变量要在设置初始进度值之前进行设置(第一个参数0:滑动的时候,1:手指弹起的时候)
        /// </summary>
        public Action<int, int> ProgressChangedEvent = null;
        /// <summary>
        /// 进度条可用时的背景色
        /// </summary>
        private uint ProgressBarEnableColor = 0;
        /// <summary>
        /// 进度条不可用时的背景色(默认灰色)
        /// </summary>
        public uint ProgressBarUnEnableColor = 0xffe8e8e8;
        /// <summary>
        /// 当前可用状态
        /// </summary>
        private bool nowEnable = true;
        /// <summary>
        /// 控件能否使用
        /// </summary>
        public new bool Enable
        {
            set
            {
                //状态没有改变
                if (nowEnable == value) { return; }
                nowEnable = value;
 
                this.IsClickable = value;
                if (value == true)
                {
                    //原来的颜色
                    base.ProgressBarColor = ProgressBarEnableColor;
                }
                else
                {
                    //灰色
                    base.ProgressBarColor = ProgressBarUnEnableColor;
                }
            }
        }
 
        /// <summary>
        /// 进度条颜色
        /// </summary>
        public new uint ProgressBarColor
        {
            set
            {
                ProgressBarEnableColor = value;
                base.ProgressBarColor = value;
            }
        }
 
        private int m_SeekBarPadding = Application.GetRealWidth(20);
        /// <summary>
        /// 进度条与左右两边的边框的边距(重写底层属性)
        /// </summary>
        public new int SeekBarPadding
        {
            set
            {
                m_SeekBarPadding = value;
                base.SeekBarPadding = value;
            }
            get
            {
                return m_SeekBarPadding;
            }
        }
 
        private int m_MaxValue = 0;
        /// <summary>
        /// 进度条最大值(重写底层属性)
        /// </summary>
        public new int MaxValue
        {
            set
            {
                m_MaxValue = value;
                base.MaxValue = value;
            }
        }
 
        private int m_MinValue = 0;
        /// <summary>
        /// 进度条最小值(重写底层属性)
        /// </summary>
        public new int MinValue
        {
            set
            {
                m_MinValue = value;
                base.MinValue = value;
            }
        }
        /// <summary>
        /// 上方显示的文本
        /// </summary>
        private Button btnTopView = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 左右滑动的进度条控件(高度为54 左右间距为20)
        /// </summary>
        /// <param name="i_width">宽度,非真实值,实际宽度会加上左右间距</param>
        public SeekBarImageControl(int i_width)
        {
            this.Width = Application.GetRealWidth(i_width) + Application.GetRealWidth(20) * 2;
            this.Height = Application.GetRealHeight(54);
            //圆球的高度
            this.ThumbImageHeight = Application.GetRealHeight(54);
            this.ThumbImagePath = "Public/ThumbImage.png";
            //进度条的高度度
            this.SeekBarViewHeight = Application.GetRealHeight(8);
            //上方是否显示文本
            this.IsProgressTextShow = false;
            this.Gravity = Gravity.CenterHorizontal;
            //进度条颜色
            this.ProgressBarColor = CSS_Color.MainColor;
            //左右边距(最好不要改这个数值,一旦改了,可能会干扰到其他界面)
            this.SeekBarPadding = Application.GetRealWidth(20);
 
            //进度条值改变事件
            this.OnProgressChangedEvent += this.MyProgressChangedEvent;
            //手指弹起事件
            this.OnStopTrackingTouchEvent += this.MyStopTrackingTouchEvent;
        }
 
        #endregion
 
        #region ■ 事件_______________________________
 
        /// <summary>
        /// 进度条值改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="value"></param>
        private void MyProgressChangedEvent(object sender, int value)
        {
            if (this.ProgressChangedEvent == null)
            {
                this.OnProgressChangedEvent -= this.MyProgressChangedEvent;
                return;
            }
 
            this.ProgressChangedEvent(0, value);
        }
 
        /// <summary>
        /// 手指弹起事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="value"></param>
        private void MyStopTrackingTouchEvent(object sender, int value)
        {
            if (this.ProgressChangedEvent == null)
            {
                this.OnStopTrackingTouchEvent -= this.MyStopTrackingTouchEvent;
                return;
            }
            //弹起事件不需要判断时间
            this.ProgressChangedEvent(1, value);
        }
 
        #endregion
 
        #region ■ 自定义上方显示文本_________________
 
        /// <summary>
        /// 在上方显示自定义文本
        /// </summary>
        /// <param name="i_width">宽度(真实值)</param>
        /// <param name="textSize">文字大小</param>
        /// <param name="textColor">文字颜色</param>
        public void ShowCustomTextView(int i_width, int textSize, uint textColor)
        {
            if (this.btnTopView != null) { return; }
 
            int contrHeight = Application.GetRealHeight(24);
            this.btnTopView = new Button();
            btnTopView.Width = i_width;
            btnTopView.Height = contrHeight;
            btnTopView.TextColor = textColor;
            btnTopView.TextSize = textSize;
            btnTopView.TextAlignment = TextAlignment.Center;
            btnTopView.Y = this.Y - contrHeight + Application.GetRealHeight(20);
            //初始化时,X轴可以不用理会
 
            this.Parent.AddChidren(btnTopView);
        }
 
        /// <summary>
        /// 设置自定义文本信息
        /// </summary>
        /// <param name="i_text"></param>
        public void SetCustomText(string i_text)
        {
            if (this.btnTopView == null) { return; }
 
            this.btnTopView.Text = i_text;
            //滑条最左边的距离
            int XX = this.X + this.m_SeekBarPadding;
            //当前滑条所在的大致百分比
            int tempValue = this.Progress - this.m_MinValue;
            if (tempValue < 0) { tempValue = 0; }
            decimal persent = (decimal)tempValue / (this.m_MaxValue - this.m_MinValue);
            //当前滑条所在的大致位置
            XX += (int)((this.Width - this.m_SeekBarPadding * 2) * persent);
            //因为要居中,所以减掉自定义控件的宽度的一般
            XX = XX - this.btnTopView.Width / 2;
 
            this.btnTopView.X = XX;
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 控件摧毁
        /// </summary>
        public override void RemoveFromParent()
        {
            this.ProgressChangedEvent = null;
            base.RemoveFromParent();
        }
 
        #endregion
    }
}