-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlidingRuleUI.cs
More file actions
136 lines (109 loc) · 2.62 KB
/
SlidingRuleUI.cs
File metadata and controls
136 lines (109 loc) · 2.62 KB
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
using ChunkPriorityCalculator.Rules;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing.Design;
namespace ChunkPriorityCalculator
{
public partial class SlidingRuleUI : UserControl
{
#region Properties & Fields
/// <summary>
/// The rule for the control.
/// </summary>
public AbstractSlidingRule? Rule
{
get => _rule;
set
{
_rule = value;
FillValues();
NotifyRuleChanged();
}
}
private AbstractSlidingRule? _rule;
[Category("Data"), Description("The display name of the rule.")]
public string RuleDisplayName { get => grpRule.Text; set => grpRule.Text = value; }
[Category("Data"), Description("The rule description to display as a tooltip.")]
[Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]
public string RuleTooltip { get => toolTip.GetToolTip(grpRule); set => toolTip.SetToolTip(grpRule, value); }
/// <summary>
/// Used to retrieve the new value when the slider changes.
/// </summary>
public int Value => trkSlider.Value;
/// <summary>
/// To avoid firing unnecesary events.
/// </summary>
private bool _fillingValues = false;
#endregion
#region Constructors
public SlidingRuleUI()
{
InitializeComponent();
}
#endregion
#region Events
public event EventHandler? RuleChanged;
private void NotifyRuleChanged()
{
if (RuleChanged is not null)
{
RuleChanged(this, EventArgs.Empty);
}
}
#endregion
#region Methods
private void RefreshValue()
{
if (_fillingValues)
{
return;
}
lblValue.Text = trkSlider.Value.ToString();
}
public void FillValues()
{
_fillingValues = true;
if (_rule is null)
{
nudWeight.Value = 1;
trkSlider.Minimum = -10;
trkSlider.Maximum = 10;
trkSlider.Value = 0;
}
else
{
nudWeight.Value = _rule.RuleWeightMultiplier;
trkSlider.Minimum = _rule.MinSliderValue;
trkSlider.Maximum = _rule.MaxSliderValue;
trkSlider.Value = _rule.SliderValue;
}
lblMin.Text = trkSlider.Minimum.ToString();
lblMax.Text = trkSlider.Maximum.ToString();
_fillingValues = false;
RefreshValue();
NotifyRuleChanged();
}
#endregion
#region Event handlers
private void trkSlider_ValueChanged(object sender, EventArgs e)
{
if (_fillingValues || _rule is null)
{
return;
}
_rule.SliderValue = trkSlider.Value;
RefreshValue();
NotifyRuleChanged();
}
private void nudWeight_ValueChanged(object sender, EventArgs e)
{
if (_fillingValues || _rule is null)
{
return;
}
_rule.RuleWeightMultiplier = nudWeight.Value;
NotifyRuleChanged();
}
#endregion
}
}