summaryrefslogtreecommitdiff
path: root/grapher/Models/Options/Cap
diff options
context:
space:
mode:
authora1xd <[email protected]>2021-09-24 02:04:43 -0400
committerGitHub <[email protected]>2021-09-24 02:04:43 -0400
commit2896b8a09ce42e965705c58593b8738adc454f7f (patch)
tree71e4d0cff60b5a1ad11427d78e1f8c7b775e5690 /grapher/Models/Options/Cap
parentMerge pull request #107 from a1xd/1.5.0-fix (diff)
parentmake note clearer (diff)
downloadrawaccel-master.tar.xz
rawaccel-master.zip
Merge pull request #108 from a1xd/1.6r2HEADv1.6.0masterdark-mode
v1.6
Diffstat (limited to 'grapher/Models/Options/Cap')
-rw-r--r--grapher/Models/Options/Cap/CapOptions.cs249
-rw-r--r--grapher/Models/Options/Cap/CapTypeOptions.cs160
2 files changed, 409 insertions, 0 deletions
diff --git a/grapher/Models/Options/Cap/CapOptions.cs b/grapher/Models/Options/Cap/CapOptions.cs
new file mode 100644
index 0000000..68326e5
--- /dev/null
+++ b/grapher/Models/Options/Cap/CapOptions.cs
@@ -0,0 +1,249 @@
+using System;
+using System.Windows.Forms;
+using static grapher.Models.Options.Cap.CapTypeOptions;
+
+namespace grapher.Models.Options.Cap
+{
+ public class CapOptions : OptionBase
+ {
+ #region Constants
+
+ public const string InCapLabel = "Cap: Input";
+ public const string OutCapLabel = "Cap: Output";
+
+ #endregion Constants
+
+ #region Fields
+
+ private int _top;
+
+ #endregion Fields
+
+ #region Constructors
+
+ public CapOptions(
+ CapTypeOptions capTypeOptions,
+ Option capIn,
+ Option capOut,
+ Option slope,
+ Option disableOptionInBoth = null,
+ CheckBoxOption disableInBoth = null)
+ {
+ CapTypeOptions = capTypeOptions;
+ In = capIn;
+ Out = capOut;
+ Slope = slope;
+ DisableOptionInBoth = disableOptionInBoth;
+ DisableInBoth = disableInBoth;
+
+ ShouldShow = true;
+ _top = Slope.Top;
+ BottomElement = In;
+ CapTypeOptions.OptionsDropdown.SelectedIndexChanged += OnCapTypeDropdownSelectedItemChanged;
+ CapTypeOptions.SelectedCapOption = InCap;
+
+ if (DisableInBoth != null)
+ {
+ DisableInBoth.CheckBox.CheckedChanged += OnDisableInBothCheckedChange;
+ }
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public CapTypeOptions CapTypeOptions { get; }
+
+ public Option In { get; }
+
+ public Option Out { get; }
+
+ public Option Slope { get; }
+
+ private Option DisableOptionInBoth { get; }
+
+ private CheckBoxOption DisableInBoth { get; }
+
+ public override int Left
+ {
+ get => In.Left;
+
+ set
+ {
+ In.Left = value;
+ Out.Left = value;
+ Slope.Left = value;
+ }
+ }
+
+ public override int Top
+ {
+ get => _top;
+ set
+ {
+ _top = value;
+ Layout(value);
+ }
+ }
+
+ public override int Height
+ {
+ get => BottomElement.Top + BottomElement.Height - Top;
+ }
+
+ public override int Width
+ {
+ get => CapTypeOptions.Width;
+
+ set
+ {
+ CapTypeOptions.Width = value;
+ In.Width = value;
+ Out.Width = value;
+ Slope.Width = value;
+ }
+ }
+
+ public override bool Visible
+ {
+ get => ShouldShow;
+ }
+
+ private bool ShouldShow { get; set; }
+
+ private IOption BottomElement { get; set; }
+
+ #endregion Properties
+
+ #region Methods
+
+ public override void AlignActiveValues()
+ {
+ Slope.AlignActiveValues();
+ CapTypeOptions.AlignActiveValues();
+ In.AlignActiveValues();
+ Out.AlignActiveValues();
+ }
+
+ public override void Show(string name)
+ {
+ ShouldShow = true;
+ Layout(Top, name);
+ }
+
+ public override void Hide()
+ {
+ ShouldShow = false;
+ CapTypeOptions.Hide();
+ Slope.Hide();
+ In.Hide();
+ Out.Hide();
+ }
+
+ public void SetActiveValues(
+ double scale,
+ double inCap,
+ double outCap,
+ CapMode capMode)
+ {
+ Slope.SetActiveValue(scale);
+ In.SetActiveValue(inCap);
+ Out.SetActiveValue(outCap);
+ CapTypeOptions.SetActiveValue(capMode);
+ }
+
+ private void Layout(int top, string name = null)
+ {
+ switch (CapTypeOptions.SelectedCapType)
+ {
+ case CapType.Input:
+ if (ShouldShow)
+ {
+ Slope.Show();
+ CapTypeOptions.Show(name);
+ ShowInCap();
+ Out.Hide();
+ }
+
+ Slope.Top = top;
+ CapTypeOptions.SnapTo(Slope);
+ In.SnapTo(CapTypeOptions);
+
+ BottomElement = In;
+ break;
+ case CapType.Output:
+ if (ShouldShow)
+ {
+ Slope.Show();
+ CapTypeOptions.Show(name);
+ In.Hide();
+ ShowOutCap();
+ }
+
+ Slope.Top = top;
+ CapTypeOptions.SnapTo(Slope);
+ Out.SnapTo(CapTypeOptions);
+
+ BottomElement = Out;
+ break;
+ case CapType.Both:
+ if (ShouldShow)
+ {
+ CapTypeOptions.Show(name);
+ Slope.Hide();
+ ShowInCap();
+ ShowOutCap();
+ }
+
+ CapTypeOptions.Top = top;
+ In.SnapTo(CapTypeOptions);
+ Out.SnapTo(In);
+
+ BottomElement = Out;
+ break;
+ }
+
+ DisableBuggedOptionIfApplicable();
+ }
+
+ private void DisableBuggedOptionIfApplicable()
+ {
+ if (DisableOptionInBoth != null)
+ {
+ if (CapTypeOptions.SelectedCapType == CapType.Both &&
+ DisableInBoth != null &&
+ !DisableInBoth.CheckBox.Checked)
+ {
+ DisableOptionInBoth.Field.SetToUnavailable();
+ }
+ else
+ {
+ DisableOptionInBoth.Field.SetToDefault();
+ }
+ }
+ }
+
+ private void ShowInCap()
+ {
+ In.Show(InCapLabel);
+ }
+
+ private void ShowOutCap()
+ {
+ Out.Show(OutCapLabel);
+ }
+
+ private void OnCapTypeDropdownSelectedItemChanged(object sender, EventArgs e)
+ {
+ Layout(Top);
+ CapTypeOptions.CheckIfDefault();
+ }
+
+ private void OnDisableInBothCheckedChange(object sender, EventArgs e)
+ {
+ DisableBuggedOptionIfApplicable();
+ }
+
+ #endregion Methods
+ }
+}
diff --git a/grapher/Models/Options/Cap/CapTypeOptions.cs b/grapher/Models/Options/Cap/CapTypeOptions.cs
new file mode 100644
index 0000000..6447feb
--- /dev/null
+++ b/grapher/Models/Options/Cap/CapTypeOptions.cs
@@ -0,0 +1,160 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace grapher.Models.Options.Cap
+{
+ public class CapTypeOptions : ComboBoxOptionsBase
+ {
+ #region Enum
+
+ public enum CapType
+ {
+ Input,
+ Output,
+ Both,
+ }
+
+ #endregion Enum
+
+ #region Classes
+
+ public class CapTypeOption
+ {
+ public CapType Type { get; set; }
+
+ public string Name => Type.ToString();
+
+ public override string ToString() => Name;
+ }
+
+ #endregion Classes
+
+ #region Static
+
+ public static readonly CapTypeOption InCap = new CapTypeOption
+ {
+ Type = CapType.Input,
+ };
+
+ public static readonly CapTypeOption OutCap = new CapTypeOption
+ {
+ Type = CapType.Output,
+ };
+
+ public static readonly CapTypeOption BothCap = new CapTypeOption
+ {
+ Type = CapType.Both,
+ };
+
+ public static readonly CapTypeOption[] AllCapTypeOptions = new CapTypeOption[]
+ {
+ InCap,
+ OutCap,
+ BothCap
+ };
+
+ #endregion Static
+
+ #region Constructors
+
+ public CapTypeOptions(
+ Label label,
+ ComboBox dropdown,
+ ActiveValueLabel activeValueLabel,
+ int left)
+ : base(
+ label,
+ dropdown,
+ activeValueLabel)
+ {
+ OptionsDropdown.Items.AddRange(
+ new CapTypeOption[]
+ {
+ InCap,
+ OutCap,
+ BothCap
+ });
+
+ Default = OutCap;
+
+ label.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
+ label.Left = left;
+ label.Width = OptionsDropdown.Left - left - Constants.OptionLabelBoxSeperation;
+ label.Height = OptionsDropdown.Height;
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public CapType SelectedCapType => SelectedCapOption.Type;
+
+ public CapTypeOption SelectedCapOption
+ {
+ get
+ {
+ return OptionsDropdown.SelectedItem as CapTypeOption;
+ }
+ set
+ {
+ OptionsDropdown.SelectedItem = value;
+ }
+ }
+
+ private CapTypeOption Default { get; set; }
+
+ public CapMode GetSelectedCapMode()
+ {
+ switch(SelectedCapType)
+ {
+ case CapType.Output: return CapMode.output;
+ case CapType.Both: return CapMode.in_out;
+ case CapType.Input:
+ default: return CapMode.input;
+ }
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ public static CapTypeOption CapTypeOptionFromSettings(CapMode capMode)
+ {
+ switch (capMode)
+ {
+ case CapMode.output:
+ return OutCap;
+ case CapMode.in_out:
+ return BothCap;
+ case CapMode.input:
+ default:
+ return InCap;
+ }
+ }
+
+ public void SetActiveValue(CapMode capMode)
+ {
+ Default = CapTypeOptionFromSettings(capMode);
+ SelectedCapOption = Default;
+ ActiveValueLabel.SetValue(SelectedCapOption.Name);
+ }
+
+ public void CheckIfDefault()
+ {
+ if (SelectedCapOption.Equals(Default))
+ {
+ OptionsDropdown.ForeColor = System.Drawing.Color.Gray;
+ }
+ else
+ {
+ OptionsDropdown.ForeColor = System.Drawing.Color.Black;
+ }
+ }
+
+ #endregion Methods
+ }
+}