summaryrefslogtreecommitdiff
path: root/grapher/FieldXY.cs
diff options
context:
space:
mode:
Diffstat (limited to 'grapher/FieldXY.cs')
-rw-r--r--grapher/FieldXY.cs82
1 files changed, 82 insertions, 0 deletions
diff --git a/grapher/FieldXY.cs b/grapher/FieldXY.cs
new file mode 100644
index 0000000..f06cc4f
--- /dev/null
+++ b/grapher/FieldXY.cs
@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace grapher
+{
+ public class FieldXY
+ {
+ public FieldXY(TextBox xBox, TextBox yBox, CheckBox lockCheckBox, Form containingForm, double defaultData)
+ {
+ XField = new Field(xBox, containingForm, defaultData);
+ YField = new Field(yBox, containingForm, defaultData);
+ LockCheckBox = lockCheckBox;
+ DefaultData = defaultData;
+ LockCheckBox.CheckedChanged += new System.EventHandler(CheckChanged);
+ SetLocked();
+ }
+ public double X
+ {
+ get => XField.Data;
+ }
+
+ public double Y
+ {
+ get
+ {
+ if (Locked)
+ {
+ return X;
+ }
+ else
+ {
+ return YField.Data;
+ }
+ }
+ }
+
+ public CheckBox LockCheckBox { get; }
+
+ private Field XField { get; }
+
+ private Field YField { get; }
+
+ private double DefaultData { get; }
+
+ private bool Locked { get; set; }
+
+ private void CheckChanged(object sender, EventArgs e)
+ {
+ if (LockCheckBox.CheckState == CheckState.Checked)
+ {
+ SetUnlocked();
+ }
+ else
+ {
+ SetLocked();
+ }
+ }
+
+ private void SetLocked()
+ {
+ Locked = true;
+ YField.SetToUnavailable();
+ }
+
+ private void SetUnlocked()
+ {
+ Locked = false;
+ if (XField.State == Field.FieldState.Default)
+ {
+ YField.SetToDefault();
+ }
+ else
+ {
+ YField.SetToEntered(XField.Data);
+ }
+ }
+ }
+}