From cc531c79f2bd664551071ef315a54814bd9ab914 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 12 Aug 2020 19:22:21 -0700 Subject: Reorganized solution into directories --- grapher/Models/Fields/FieldXY.cs | 130 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 grapher/Models/Fields/FieldXY.cs (limited to 'grapher/Models/Fields/FieldXY.cs') diff --git a/grapher/Models/Fields/FieldXY.cs b/grapher/Models/Fields/FieldXY.cs new file mode 100644 index 0000000..87e0b9c --- /dev/null +++ b/grapher/Models/Fields/FieldXY.cs @@ -0,0 +1,130 @@ +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 const int DefaultSeparation = 4; + + public const string ShortenedFormatString = "0.###"; + + public FieldXY(TextBox xBox, TextBox yBox, CheckBox lockCheckBox, Form containingForm, double defaultData) + { + XField = new Field(xBox, containingForm, defaultData); + YField = new Field(yBox, containingForm, defaultData); + YField.FormatString = ShortenedFormatString; + LockCheckBox = lockCheckBox; + LockCheckBox.CheckedChanged += new System.EventHandler(CheckChanged); + + XField.Box.Width = (YField.Box.Left + YField.Box.Width - XField.Box.Left - DefaultSeparation) / 2; + YField.Box.Width = XField.Box.Width; + + DefaultWidthX = XField.Box.Width; + DefaultWidthY = YField.Box.Width; + + YField.Box.Left = XField.Box.Left + XField.Box.Width + DefaultSeparation; + + CombinedWidth = DefaultWidthX + DefaultWidthY + YField.Box.Left - (XField.Box.Left + DefaultWidthX); + SetCombined(); + } + public double X + { + get => XField.Data; + } + + public double Y + { + get + { + if (Combined) + { + return X; + } + else + { + return YField.Data; + } + } + } + + public CheckBox LockCheckBox { get; } + + public Field XField { get; } + + public Field YField { get; } + + private bool Combined { get; set; } + + private int DefaultWidthX { get; } + + private int DefaultWidthY { get; } + + private int CombinedWidth { get; } + + private void CheckChanged(object sender, EventArgs e) + { + if (LockCheckBox.CheckState == CheckState.Checked) + { + SetCombined(); + } + else + { + SetSeparate(); + } + } + + public void SetCombined() + { + Combined = true; + YField.SetToUnavailable(); + YField.Box.Hide(); + XField.Box.Width = CombinedWidth; + XField.FormatString = Field.DefaultFormatString; + } + + public void SetSeparate() + { + Combined = false; + + XField.Box.Width = DefaultWidthX; + YField.Box.Width = DefaultWidthY; + + XField.FormatString = ShortenedFormatString; + + if (XField.State == Field.FieldState.Default) + { + YField.SetToDefault(); + } + else + { + YField.SetToEntered(XField.Data); + } + + if (XField.Box.Visible) + { + YField.Box.Show(); + } + } + + public void Show() + { + XField.Box.Show(); + + if (!Combined) + { + YField.Box.Show(); + } + } + + public void Hide() + { + XField.Box.Hide(); + YField.Box.Hide(); + } + } +} -- cgit v1.2.3 From 30e1391b224ae028f4476e06a07415a0285ac6c9 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 12 Aug 2020 20:39:53 -0700 Subject: Almost working --- grapher/Models/Fields/FieldXY.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'grapher/Models/Fields/FieldXY.cs') diff --git a/grapher/Models/Fields/FieldXY.cs b/grapher/Models/Fields/FieldXY.cs index 87e0b9c..609af9d 100644 --- a/grapher/Models/Fields/FieldXY.cs +++ b/grapher/Models/Fields/FieldXY.cs @@ -13,13 +13,14 @@ namespace grapher public const string ShortenedFormatString = "0.###"; - public FieldXY(TextBox xBox, TextBox yBox, CheckBox lockCheckBox, Form containingForm, double defaultData) + public FieldXY(TextBox xBox, TextBox yBox, CheckBox lockCheckBox, Form containingForm, double defaultData, AccelCharts accelCharts) { XField = new Field(xBox, containingForm, defaultData); YField = new Field(yBox, containingForm, defaultData); YField.FormatString = ShortenedFormatString; LockCheckBox = lockCheckBox; LockCheckBox.CheckedChanged += new System.EventHandler(CheckChanged); + AccelCharts = accelCharts; XField.Box.Width = (YField.Box.Left + YField.Box.Width - XField.Box.Left - DefaultSeparation) / 2; YField.Box.Width = XField.Box.Width; @@ -58,6 +59,8 @@ namespace grapher public Field YField { get; } + private AccelCharts AccelCharts { get; } + private bool Combined { get; set; } private int DefaultWidthX { get; } @@ -76,6 +79,8 @@ namespace grapher { SetSeparate(); } + + AccelCharts.RefreshXY(); } public void SetCombined() -- cgit v1.2.3