From 0cf5ce3762926fa556418572e9661d79cbbaa240 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Sun, 25 Apr 2021 23:05:44 -0700 Subject: Start of LUT points editing --- grapher/Models/Options/LUT/LUTPanelOptions.cs | 136 ++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 grapher/Models/Options/LUT/LUTPanelOptions.cs (limited to 'grapher/Models/Options/LUT/LUTPanelOptions.cs') diff --git a/grapher/Models/Options/LUT/LUTPanelOptions.cs b/grapher/Models/Options/LUT/LUTPanelOptions.cs new file mode 100644 index 0000000..a6b894b --- /dev/null +++ b/grapher/Models/Options/LUT/LUTPanelOptions.cs @@ -0,0 +1,136 @@ +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 string LUTPanelTitle = "LookupTable Points"; + public const string ApplyAsSensTitle = "Apply as sensitivity"; + public const string ApplyAsVelocityTitle = "Apply as velocity"; + public const int TitlePadding = 5; + public const int PanelHeight = 40; + + public LUTPanelOptions(Panel panel) + { + Panel = panel; + Panel.Height = PanelHeight; + Panel.Paint += Panel_Paint; + + Title = new Label(); + Title.Text = LUTPanelTitle; + ApplyAsSens = new CheckBox(); + ApplyAsSens.Text = ApplyAsSensTitle; + ApplyAsVelocity = new CheckBox(); + ApplyAsVelocity.Text = ApplyAsVelocityTitle; + + Panel.Controls.Add(Title); + Title.Left = TitlePadding; + Title.Top = TitlePadding; + } + + public Panel Panel + { + get; + } + + public Label Title + { + get; + } + + public CheckBox ApplyAsSens + { + get; + } + + public CheckBox ApplyAsVelocity + { + get; + } + + public override bool Visible + { + get + { + return Panel.Visible || ShouldShow; + } + } + + public override int Top + { + get + { + return Panel.Top; + } + set + { + Panel.Top = value; + } + } + + public override int Height + { + get + { + return Panel.Height; + } + } + + public override int Left + { + get + { + return Panel.Left; + } + set + { + Panel.Left = value; + } + } + + public override int Width + { + get + { + return Panel.Width; + } + set + { + Panel.Width = value; + } + } + + private bool ShouldShow { get; set; } + + public override void Hide() + { + Panel.Hide(); + ShouldShow = false; + } + + public override void Show(string name) + { + Panel.Show(); + ShouldShow = true; + } + + public override void AlignActiveValues() + { + // Nothing to do here. + } + + private void Panel_Paint(object sender, PaintEventArgs e) + { + Color col = Color.DarkGray; + ButtonBorderStyle bbs = ButtonBorderStyle.Dashed; + int thickness = 2; + ControlPaint.DrawBorder(e.Graphics, Panel.ClientRectangle, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs); + } + } +} -- cgit v1.2.3 From 08e3b9e32b76bbd74b8878e8afed56ad4689e8c4 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 28 Jun 2021 23:26:49 -0700 Subject: Fix high DPI issue --- grapher/Models/Options/LUT/LUTPanelOptions.cs | 41 +++++++++++---------------- 1 file changed, 17 insertions(+), 24 deletions(-) (limited to 'grapher/Models/Options/LUT/LUTPanelOptions.cs') diff --git a/grapher/Models/Options/LUT/LUTPanelOptions.cs b/grapher/Models/Options/LUT/LUTPanelOptions.cs index a6b894b..e723dcd 100644 --- a/grapher/Models/Options/LUT/LUTPanelOptions.cs +++ b/grapher/Models/Options/LUT/LUTPanelOptions.cs @@ -10,31 +10,24 @@ namespace grapher.Models.Options.LUT { public class LUTPanelOptions : OptionBase { - public const string LUTPanelTitle = "LookupTable Points"; public const string ApplyAsSensTitle = "Apply as sensitivity"; public const string ApplyAsVelocityTitle = "Apply as velocity"; public const int TitlePadding = 5; - public const int PanelHeight = 40; + public const int PanelHeight = 100; - public LUTPanelOptions(Panel panel) + public LUTPanelOptions(Panel activePanel) { - Panel = panel; - Panel.Height = PanelHeight; - Panel.Paint += Panel_Paint; + ActivePanel = activePanel; + ActivePanel.Height = PanelHeight; + ActivePanel.Paint += Panel_Paint; - Title = new Label(); - Title.Text = LUTPanelTitle; ApplyAsSens = new CheckBox(); ApplyAsSens.Text = ApplyAsSensTitle; ApplyAsVelocity = new CheckBox(); ApplyAsVelocity.Text = ApplyAsVelocityTitle; - - Panel.Controls.Add(Title); - Title.Left = TitlePadding; - Title.Top = TitlePadding; } - public Panel Panel + public Panel ActivePanel { get; } @@ -58,7 +51,7 @@ namespace grapher.Models.Options.LUT { get { - return Panel.Visible || ShouldShow; + return ActivePanel.Visible || ShouldShow; } } @@ -66,11 +59,11 @@ namespace grapher.Models.Options.LUT { get { - return Panel.Top; + return ActivePanel.Top; } set { - Panel.Top = value; + ActivePanel.Top = value; } } @@ -78,7 +71,7 @@ namespace grapher.Models.Options.LUT { get { - return Panel.Height; + return ActivePanel.Height; } } @@ -86,11 +79,11 @@ namespace grapher.Models.Options.LUT { get { - return Panel.Left; + return ActivePanel.Left; } set { - Panel.Left = value; + ActivePanel.Left = value; } } @@ -98,11 +91,11 @@ namespace grapher.Models.Options.LUT { get { - return Panel.Width; + return ActivePanel.Width; } set { - Panel.Width = value; + ActivePanel.Width = value; } } @@ -110,13 +103,13 @@ namespace grapher.Models.Options.LUT public override void Hide() { - Panel.Hide(); + ActivePanel.Hide(); ShouldShow = false; } public override void Show(string name) { - Panel.Show(); + ActivePanel.Show(); ShouldShow = true; } @@ -130,7 +123,7 @@ namespace grapher.Models.Options.LUT Color col = Color.DarkGray; ButtonBorderStyle bbs = ButtonBorderStyle.Dashed; int thickness = 2; - ControlPaint.DrawBorder(e.Graphics, Panel.ClientRectangle, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs); + ControlPaint.DrawBorder(e.Graphics, ActivePanel.ClientRectangle, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs); } } } -- cgit v1.2.3 From dc76635349577f9dd95ab347fb79652dad2abb30 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 30 Jun 2021 23:52:31 -0700 Subject: Better-written LUT panels --- grapher/Models/Options/LUT/LUTPanelOptions.cs | 149 ++++++++++++++++++++++---- 1 file changed, 126 insertions(+), 23 deletions(-) (limited to 'grapher/Models/Options/LUT/LUTPanelOptions.cs') 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> activePoints) + { + if (activePoints.Any() && activePoints.First().x != 0) + { + ActiveValuesTextBox.Text = PointsToActiveValuesText(activePoints); + } + else + { + ActiveValuesTextBox.Text = string.Empty; + } + } + + public Vec2[] GetPoints() + { + return UserTextToPoints(PointsTextBox.Text); + } + + private static Vec2[] UserTextToPoints(string userText) + { + if (string.IsNullOrWhiteSpace(userText)) + { + throw new Exception("Text must be entered in text box to fill Look Up Table."); + } + + Vec2[] points = new Vec2[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 { x = x, y = y }; + + index++; + } + + return points; + } + + private void AlignActivePanelToPointsTextBox() + { + ActivePanel.Left = PointsTextBox.Right + PanelPadding; + } + + private string PointsToActiveValuesText(IEnumerable> 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; -- cgit v1.2.3 From ac0a6eb86c8d783c21cb246d688a221913b15789 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 1 Jul 2021 19:13:12 -0700 Subject: Mostly working --- grapher/Models/Options/LUT/LUTPanelOptions.cs | 53 ++++++++++----------------- 1 file changed, 19 insertions(+), 34 deletions(-) (limited to 'grapher/Models/Options/LUT/LUTPanelOptions.cs') diff --git a/grapher/Models/Options/LUT/LUTPanelOptions.cs b/grapher/Models/Options/LUT/LUTPanelOptions.cs index 6425d91..6b13cdc 100644 --- a/grapher/Models/Options/LUT/LUTPanelOptions.cs +++ b/grapher/Models/Options/LUT/LUTPanelOptions.cs @@ -13,17 +13,14 @@ namespace grapher.Models.Options.LUT public const int PanelPadding = 5; public const int PanelHeight = 100; - public LUTPanelOptions(Panel activePanel, RichTextBox pointsTextBox) + public LUTPanelOptions(RichTextBox pointsTextBox, RichTextBox activeValuesTextBox) { PointsTextBox = pointsTextBox; + PointsTextBox.Height = PanelHeight; - ActivePanel = activePanel; - ActivePanel.Height = PanelHeight; - ActivePanel.Paint += Panel_Paint; - - ActiveValuesTextBox = new RichTextBox(); + ActiveValuesTextBox = activeValuesTextBox; + ActiveValuesTextBox.Height = PanelHeight; ActiveValuesTextBox.ReadOnly = true; - ActivePanel.Controls.Add(ActiveValuesTextBox); } public RichTextBox PointsTextBox @@ -36,11 +33,6 @@ namespace grapher.Models.Options.LUT get; } - public Panel ActivePanel - { - get; - } - public override bool Visible { get @@ -58,7 +50,7 @@ namespace grapher.Models.Options.LUT set { PointsTextBox.Top = value; - ActivePanel.Top = value; + ActiveValuesTextBox.Top = value; } } @@ -93,7 +85,7 @@ namespace grapher.Models.Options.LUT { var panelWidth = value / 2 - PanelPadding; PointsTextBox.Width = panelWidth; - ActivePanel.Width = panelWidth; + ActiveValuesTextBox.Width = panelWidth; AlignActivePanelToPointsTextBox(); } } @@ -103,14 +95,14 @@ namespace grapher.Models.Options.LUT public override void Hide() { PointsTextBox.Hide(); - ActivePanel.Hide(); + ActiveValuesTextBox.Hide(); ShouldShow = false; } public override void Show(string name) { PointsTextBox.Show(); - ActivePanel.Show(); + ActiveValuesTextBox.Show(); ShouldShow = true; } @@ -119,11 +111,11 @@ namespace grapher.Models.Options.LUT // Nothing to do here. } - public void SetActiveValues(IEnumerable> activePoints) + public void SetActiveValues(IEnumerable> activePoints, int length) { - if (activePoints.Any() && activePoints.First().x != 0) + if (length > 0 && activePoints.First().x != 0) { - ActiveValuesTextBox.Text = PointsToActiveValuesText(activePoints); + ActiveValuesTextBox.Text = PointsToActiveValuesText(activePoints, length); } else { @@ -131,12 +123,12 @@ namespace grapher.Models.Options.LUT } } - public Vec2[] GetPoints() + public (Vec2[], int length) GetPoints() { return UserTextToPoints(PointsTextBox.Text); } - private static Vec2[] UserTextToPoints(string userText) + private static (Vec2[], int length) UserTextToPoints(string userText) { if (string.IsNullOrWhiteSpace(userText)) { @@ -145,7 +137,7 @@ namespace grapher.Models.Options.LUT Vec2[] points = new Vec2[256]; - var userTextSplit = userText.Split(';'); + var userTextSplit = userText.Trim().Trim(';').Split(';'); int index = 0; float lastX = 0; @@ -201,32 +193,25 @@ namespace grapher.Models.Options.LUT index++; } - return points; + return (points, userTextSplit.Length); } private void AlignActivePanelToPointsTextBox() { - ActivePanel.Left = PointsTextBox.Right + PanelPadding; + ActiveValuesTextBox.Left = PointsTextBox.Right + PanelPadding; } - private string PointsToActiveValuesText(IEnumerable> points) + private string PointsToActiveValuesText(IEnumerable> points, int length) { StringBuilder builder = new StringBuilder(); - foreach(var point in points) + for(int i = 0; i < length; i++) { + var point = points.ElementAt(i); builder.AppendLine($"{point.x},{point.y};"); } return builder.ToString(); } - - private void Panel_Paint(object sender, PaintEventArgs e) - { - Color col = Color.DarkGray; - ButtonBorderStyle bbs = ButtonBorderStyle.Dashed; - int thickness = 2; - ControlPaint.DrawBorder(e.Graphics, ActivePanel.ClientRectangle, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs); - } } } -- cgit v1.2.3