diff options
| author | a1xd <[email protected]> | 2021-09-24 02:04:43 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-09-24 02:04:43 -0400 |
| commit | 2896b8a09ce42e965705c58593b8738adc454f7f (patch) | |
| tree | 71e4d0cff60b5a1ad11427d78e1f8c7b775e5690 /grapher/Models/Options/Cap/CapOptions.cs | |
| parent | Merge pull request #107 from a1xd/1.5.0-fix (diff) | |
| parent | make note clearer (diff) | |
| download | rawaccel-1.6.0.tar.xz rawaccel-1.6.0.zip | |
v1.6
Diffstat (limited to 'grapher/Models/Options/Cap/CapOptions.cs')
| -rw-r--r-- | grapher/Models/Options/Cap/CapOptions.cs | 249 |
1 files changed, 249 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 + } +} |