diff options
| author | a1xd <[email protected]> | 2021-09-22 20:49:04 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-09-22 20:49:04 -0400 |
| commit | 8a4b6f57758338d5537d4671184099a4728a8cdd (patch) | |
| tree | df36529a344d5d21ff11f5ba021ec80afb4b68a4 /grapher/Models/Options/LUT | |
| parent | Merge pull request #87 from matthewstrasiotto/streamer_mode (diff) | |
| parent | improve converter + docs (diff) | |
| download | rawaccel-8a4b6f57758338d5537d4671184099a4728a8cdd.tar.xz rawaccel-8a4b6f57758338d5537d4671184099a4728a8cdd.zip | |
Merge pull request #105 from a1xd/1.5.x
v1.5
Diffstat (limited to 'grapher/Models/Options/LUT')
| -rw-r--r-- | grapher/Models/Options/LUT/LUTPanelOptions.cs | 235 | ||||
| -rw-r--r-- | grapher/Models/Options/LUT/LUTPointOption.cs | 39 | ||||
| -rw-r--r-- | grapher/Models/Options/LUT/LutApplyOptions.cs | 183 |
3 files changed, 457 insertions, 0 deletions
diff --git a/grapher/Models/Options/LUT/LUTPanelOptions.cs b/grapher/Models/Options/LUT/LUTPanelOptions.cs new file mode 100644 index 0000000..4357619 --- /dev/null +++ b/grapher/Models/Options/LUT/LUTPanelOptions.cs @@ -0,0 +1,235 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options.LUT +{ + public class LUTPanelOptions : OptionBase + { + public const int PanelPadding = 5; + public const int PanelHeight = 100; + + public LUTPanelOptions(RichTextBox pointsTextBox, RichTextBox activeValuesTextBox) + { + PointsTextBox = pointsTextBox; + PointsTextBox.Height = PanelHeight; + + ActiveValuesTextBox = activeValuesTextBox; + ActiveValuesTextBox.Height = PanelHeight; + ActiveValuesTextBox.ReadOnly = true; + } + + public RichTextBox PointsTextBox + { + get; + } + + public RichTextBox ActiveValuesTextBox + { + get; + } + + public override bool Visible + { + get + { + return PointsTextBox.Visible || ShouldShow; + } + } + + public override int Top + { + get + { + return PointsTextBox.Top; + } + set + { + PointsTextBox.Top = value; + ActiveValuesTextBox.Top = value; + } + } + + public override int Height + { + get + { + return PointsTextBox.Height; + } + } + + public override int Left + { + get + { + return PointsTextBox.Left; + } + set + { + PointsTextBox.Left = value; + AlignActivePanelToPointsTextBox(); + } + } + + public override int Width + { + get + { + return PointsTextBox.Width; + } + set + { + var panelWidth = value / 2 - PanelPadding; + PointsTextBox.Width = panelWidth; + ActiveValuesTextBox.Width = panelWidth; + AlignActivePanelToPointsTextBox(); + } + } + + private bool ShouldShow { get; set; } + + public override void Hide() + { + PointsTextBox.Hide(); + ActiveValuesTextBox.Hide(); + ShouldShow = false; + } + + public override void Show(string name) + { + PointsTextBox.Show(); + ActiveValuesTextBox.Show(); + ShouldShow = true; + } + + public override void AlignActiveValues() + { + // Nothing to do here. + } + + public void SetActiveValues(IEnumerable<Vec2<float>> activePoints, int length) + { + if (length > 0 && activePoints.First().x != 0) + { + ActiveValuesTextBox.Text = PointsToActiveValuesText(activePoints, length); + + if (string.IsNullOrWhiteSpace(PointsTextBox.Text)) + { + PointsTextBox.Text = PointsToEntryTextBoxText(activePoints, length); + } + } + else + { + ActiveValuesTextBox.Text = string.Empty; + } + } + + public (Vec2<float>[], int length) GetPoints() + { + return UserTextToPoints(PointsTextBox.Text); + } + + private static (Vec2<float>[], int length) UserTextToPoints(string userText) + { + if (string.IsNullOrWhiteSpace(userText)) + { + throw new ApplicationException("Text must be entered in text box to fill Look Up Table."); + } + + Vec2<float>[] points = new Vec2<float>[256]; + + var userTextSplit = userText.Trim().Trim(';').Split(';'); + int index = 0; + float lastX = 0; + + foreach(var pointEntry in userTextSplit) + { + var pointSplit = pointEntry.Trim().Split(','); + + if (pointSplit.Length != 2) + { + throw new ApplicationException($"Point at index {index} is malformed. Expected format: x,y; Given: {pointEntry.Trim()}"); + } + + float x; + float y; + + try + { + x = float.Parse(pointSplit[0]); + } + catch (Exception ex) + { + throw new ApplicationException($"X-value for point at index {index} is malformed. Expected: float. Given: {pointSplit[0]}", ex); + } + + if (x <= 0) + { + throw new ApplicationException($"X-value for point at index {index} is less than or equal to 0. Point (0,0) is implied and should not be specified in points text."); + } + + if (x <= lastX) + { + throw new ApplicationException($"X-value for point at index {index} is less than or equal to previous x-value. Value: {x} Previous: {lastX}"); + } + + lastX = x; + + try + { + y = float.Parse(pointSplit[1]); + } + catch (Exception ex) + { + throw new ApplicationException($"Y-value for point at index {index} is malformed. Expected: float. Given: {pointSplit[1]}", ex); + } + + if (y <= 0) + { + throw new ApplicationException($"Y-value for point at index {index} is less than or equal to 0. Value: {y}"); + } + + points[index] = new Vec2<float> { x = x, y = y }; + + index++; + } + + return (points, userTextSplit.Length); + } + + private void AlignActivePanelToPointsTextBox() + { + ActiveValuesTextBox.Left = PointsTextBox.Right + PanelPadding; + } + + private string PointsToActiveValuesText(IEnumerable<Vec2<float>> points, int length) + { + StringBuilder builder = new StringBuilder(); + + for(int i = 0; i < length; i++) + { + var point = points.ElementAt(i); + builder.AppendLine($"{point.x},{point.y};"); + } + + return builder.ToString(); + } + + private string PointsToEntryTextBoxText(IEnumerable<Vec2<float>> points, int length) + { + StringBuilder builder = new StringBuilder(); + + for(int i = 0; i < length; i++) + { + var point = points.ElementAt(i); + builder.Append($"{point.x},{point.y};"); + } + + return builder.ToString(); + } + } +} diff --git a/grapher/Models/Options/LUT/LUTPointOption.cs b/grapher/Models/Options/LUT/LUTPointOption.cs new file mode 100644 index 0000000..6afee4f --- /dev/null +++ b/grapher/Models/Options/LUT/LUTPointOption.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options.LUT +{ + public class LUTPointOption + { + public LUTPointOption(Form form) + { + FieldX = new Field(new System.Windows.Forms.TextBox(), form, 0); + FieldY = new Field(new System.Windows.Forms.TextBox(), form, 0); + } + + public double X { get => FieldX.Data; } + + public double Y { get => FieldY.Data; } + + public int Top + { + get + { + return FieldX.Top; + } + set + { + FieldX.Top = value; + FieldY.Top = value; + } + } + + private Field FieldX { get; } + + private Field FieldY { get; } + } +} diff --git a/grapher/Models/Options/LUT/LutApplyOptions.cs b/grapher/Models/Options/LUT/LutApplyOptions.cs new file mode 100644 index 0000000..7d8c737 --- /dev/null +++ b/grapher/Models/Options/LUT/LutApplyOptions.cs @@ -0,0 +1,183 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options.LUT +{ + public class LutApplyOptions : OptionBase + { + public const string LUTApplyOptionsLabelText = "Apply as:"; + public const int LUTApplyLabelDropdownSeparation = 4; + + public enum LutApplyType + { + Sensitivity, + Velocity + } + + public class LutApplyOption + { + public LutApplyType Type { get; set; } + + public string Name => Type.ToString(); + + public override string ToString() => Name; + } + + public static readonly LutApplyOption Sensitivity = new LutApplyOption + { + Type = LutApplyType.Sensitivity, + }; + + public static readonly LutApplyOption Velocity = new LutApplyOption + { + Type = LutApplyType.Velocity, + }; + + public LutApplyOptions( + Label label, + ComboBox applyOptionsDropdown, + ActiveValueLabel lutApplyActiveValue) + { + ApplyOptions = applyOptionsDropdown; + ApplyOptions.Items.Clear(); + ApplyOptions.Items.AddRange( + new LutApplyOption[] + { + Sensitivity, + Velocity, + }); + + Label = label; + Label.Text = LUTApplyOptionsLabelText; + Label.AutoSize = false; + Label.Width = 50; + + ActiveValueLabel = lutApplyActiveValue; + } + + public LutApplyType ApplyType { get => ApplyOption.Type; } + + public LutApplyOption ApplyOption { + get + { + return ApplyOptions.SelectedItem as LutApplyOption; + } + set + { + ApplyOptions.SelectedItem = value; + } + } + + public Label Label { get; } + + public ActiveValueLabel ActiveValueLabel { get; } + + public ComboBox ApplyOptions { get; } + + public override bool Visible + { + get + { + return Label.Visible || ShouldShow; + } + } + + public override int Left + { + get + { + return Label.Left; + } + set + { + Label.Left = value; + ApplyOptions.Left = Label.Left + Label.Width + LUTApplyLabelDropdownSeparation; + } + } + + public override int Height + { + get + { + return Label.Height; + } + } + + public override int Top + { + get + { + return Label.Top; + } + set + { + ApplyOptions.Top = value; + Label.Top = (ApplyOptions.Height - Label.Height) / 2 + ApplyOptions.Top; + ActiveValueLabel.Top = value; + } + } + + public override int Width + { + get + { + return Label.Width; + } + set + { + ApplyOptions.Width = value - Label.Width - Constants.OptionLabelBoxSeperation; + } + } + + private bool ShouldShow { get; set; } + + public override void Hide() + { + Label.Hide(); + ApplyOptions.Hide(); + ActiveValueLabel.Hide(); + ShouldShow = false; + } + + public override void Show(string labelText) + { + Label.Show(); + + if (!string.IsNullOrWhiteSpace(labelText)) + { + Label.Text = labelText; + } + + ApplyOptions.Show(); + ActiveValueLabel.Show(); + ShouldShow = true; + } + + public override void AlignActiveValues() + { + ActiveValueLabel.Align(); + } + + public void SetActiveValue(bool applyAsVelocity) + { + ApplyOption = ApplyOptionFromSettings(applyAsVelocity); + ActiveValueLabel.SetValue(ApplyOption.Name); + } + + public LutApplyOption ApplyOptionFromSettings(bool applyAsVelocity) + { + if (applyAsVelocity) + { + return Velocity; + } + else + { + return Sensitivity; + } + } + } +} |