summaryrefslogtreecommitdiff
path: root/grapher/Models/Options
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2021-06-30 23:52:31 -0700
committerJacob Palecki <[email protected]>2021-06-30 23:52:31 -0700
commitdc76635349577f9dd95ab347fb79652dad2abb30 (patch)
treedfd8c10f22da30499e0fe9d0c8db7ba0749cee9f /grapher/Models/Options
parentAdd class for LUT apply type (diff)
downloadrawaccel-dc76635349577f9dd95ab347fb79652dad2abb30.tar.xz
rawaccel-dc76635349577f9dd95ab347fb79652dad2abb30.zip
Better-written LUT panels
Diffstat (limited to 'grapher/Models/Options')
-rw-r--r--grapher/Models/Options/AccelTypeOptions.cs3
-rw-r--r--grapher/Models/Options/LUT/LUTPanelOptions.cs149
2 files changed, 129 insertions, 23 deletions
diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs
index cc2480c..08ab111 100644
--- a/grapher/Models/Options/AccelTypeOptions.cs
+++ b/grapher/Models/Options/AccelTypeOptions.cs
@@ -40,6 +40,7 @@ namespace grapher
Option midpoint,
TextOption lutText,
LUTPanelOptions lutPanelOptions,
+ LutApplyOptions lutApplyOptions,
Button writeButton,
ActiveValueLabel accelTypeActiveValue)
{
@@ -73,6 +74,7 @@ namespace grapher
AccelTypeActiveValue = accelTypeActiveValue;
LutText = lutText;
LutPanel = lutPanelOptions;
+ LutApply = lutApplyOptions;
AccelTypeActiveValue.Left = AccelDropdown.Left + AccelDropdown.Width;
AccelTypeActiveValue.Height = AccelDropdown.Height;
@@ -237,6 +239,7 @@ namespace grapher
Limit.SetActiveValue(args.limit);
Exponent.SetActiveValue(args.exponent);
Midpoint.SetActiveValue(args.midpoint);
+ LutPanel.SetActiveValues(args.tableData.points);
LutApply.SetActiveValue(args.tableData.velocity);
}
diff --git a/grapher/Models/Options/LUT/LUTPanelOptions.cs b/grapher/Models/Options/LUT/LUTPanelOptions.cs
index e723dcd..6425d91 100644
--- a/grapher/Models/Options/LUT/LUTPanelOptions.cs
+++ b/grapher/Models/Options/LUT/LUTPanelOptions.cs
@@ -10,39 +10,33 @@ namespace grapher.Models.Options.LUT
{
public class LUTPanelOptions : OptionBase
{
- public const string ApplyAsSensTitle = "Apply as sensitivity";
- public const string ApplyAsVelocityTitle = "Apply as velocity";
- public const int TitlePadding = 5;
+ public const int PanelPadding = 5;
public const int PanelHeight = 100;
- public LUTPanelOptions(Panel activePanel)
+ public LUTPanelOptions(Panel activePanel, RichTextBox pointsTextBox)
{
+ PointsTextBox = pointsTextBox;
+
ActivePanel = activePanel;
ActivePanel.Height = PanelHeight;
ActivePanel.Paint += Panel_Paint;
- ApplyAsSens = new CheckBox();
- ApplyAsSens.Text = ApplyAsSensTitle;
- ApplyAsVelocity = new CheckBox();
- ApplyAsVelocity.Text = ApplyAsVelocityTitle;
- }
-
- public Panel ActivePanel
- {
- get;
+ ActiveValuesTextBox = new RichTextBox();
+ ActiveValuesTextBox.ReadOnly = true;
+ ActivePanel.Controls.Add(ActiveValuesTextBox);
}
- public Label Title
+ public RichTextBox PointsTextBox
{
get;
}
- public CheckBox ApplyAsSens
+ public RichTextBox ActiveValuesTextBox
{
get;
}
- public CheckBox ApplyAsVelocity
+ public Panel ActivePanel
{
get;
}
@@ -51,7 +45,7 @@ namespace grapher.Models.Options.LUT
{
get
{
- return ActivePanel.Visible || ShouldShow;
+ return PointsTextBox.Visible || ShouldShow;
}
}
@@ -59,10 +53,11 @@ namespace grapher.Models.Options.LUT
{
get
{
- return ActivePanel.Top;
+ return PointsTextBox.Top;
}
set
{
+ PointsTextBox.Top = value;
ActivePanel.Top = value;
}
}
@@ -71,7 +66,7 @@ namespace grapher.Models.Options.LUT
{
get
{
- return ActivePanel.Height;
+ return PointsTextBox.Height;
}
}
@@ -79,11 +74,12 @@ namespace grapher.Models.Options.LUT
{
get
{
- return ActivePanel.Left;
+ return PointsTextBox.Left;
}
set
{
- ActivePanel.Left = value;
+ PointsTextBox.Left = value;
+ AlignActivePanelToPointsTextBox();
}
}
@@ -91,11 +87,14 @@ namespace grapher.Models.Options.LUT
{
get
{
- return ActivePanel.Width;
+ return PointsTextBox.Width;
}
set
{
- ActivePanel.Width = value;
+ var panelWidth = value / 2 - PanelPadding;
+ PointsTextBox.Width = panelWidth;
+ ActivePanel.Width = panelWidth;
+ AlignActivePanelToPointsTextBox();
}
}
@@ -103,12 +102,14 @@ namespace grapher.Models.Options.LUT
public override void Hide()
{
+ PointsTextBox.Hide();
ActivePanel.Hide();
ShouldShow = false;
}
public override void Show(string name)
{
+ PointsTextBox.Show();
ActivePanel.Show();
ShouldShow = true;
}
@@ -118,6 +119,108 @@ namespace grapher.Models.Options.LUT
// Nothing to do here.
}
+ public void SetActiveValues(IEnumerable<Vec2<float>> activePoints)
+ {
+ if (activePoints.Any() && activePoints.First().x != 0)
+ {
+ ActiveValuesTextBox.Text = PointsToActiveValuesText(activePoints);
+ }
+ else
+ {
+ ActiveValuesTextBox.Text = string.Empty;
+ }
+ }
+
+ public Vec2<float>[] GetPoints()
+ {
+ return UserTextToPoints(PointsTextBox.Text);
+ }
+
+ private static Vec2<float>[] UserTextToPoints(string userText)
+ {
+ if (string.IsNullOrWhiteSpace(userText))
+ {
+ throw new Exception("Text must be entered in text box to fill Look Up Table.");
+ }
+
+ Vec2<float>[] points = new Vec2<float>[256];
+
+ var userTextSplit = userText.Split(';');
+ int index = 0;
+ float lastX = 0;
+
+ foreach(var pointEntry in userTextSplit)
+ {
+ var pointSplit = pointEntry.Trim().Split(',');
+
+ if (pointSplit.Length != 2)
+ {
+ throw new Exception($"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 Exception($"X-value for point at index {index} is malformed. Expected: float. Given: {pointSplit[0]}", ex);
+ }
+
+ if (x <= 0)
+ {
+ throw new Exception($"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 Exception($"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 Exception($"Y-value for point at index {index} is malformed. Expected: float. Given: {pointSplit[1]}", ex);
+ }
+
+ if (y <= 0)
+ {
+ throw new Exception($"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;
+ }
+
+ private void AlignActivePanelToPointsTextBox()
+ {
+ ActivePanel.Left = PointsTextBox.Right + PanelPadding;
+ }
+
+ private string PointsToActiveValuesText(IEnumerable<Vec2<float>> points)
+ {
+ StringBuilder builder = new StringBuilder();
+
+ foreach(var point in points)
+ {
+ builder.AppendLine($"{point.x},{point.y};");
+ }
+
+ return builder.ToString();
+ }
+
private void Panel_Paint(object sender, PaintEventArgs e)
{
Color col = Color.DarkGray;