diff options
| author | Jacob Palecki <[email protected]> | 2021-01-11 00:34:56 -0800 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2021-01-11 00:34:56 -0800 |
| commit | 6196cee980c7b8021b752b684cbe14bf7c41b657 (patch) | |
| tree | 2d54af5c0d9ae994892c68fb48725d043e09b932 | |
| parent | Implement direcitonality UI (diff) | |
| download | rawaccel-6196cee980c7b8021b752b684cbe14bf7c41b657.tar.xz rawaccel-6196cee980c7b8021b752b684cbe14bf7c41b657.zip | |
Some fixes
| -rw-r--r-- | common/accel-base.hpp | 4 | ||||
| -rw-r--r-- | common/rawaccel-settings.h | 4 | ||||
| -rw-r--r-- | common/rawaccel.hpp | 30 | ||||
| -rw-r--r-- | grapher/Constants/Constants.cs | 2 | ||||
| -rw-r--r-- | grapher/Models/Options/Directionality/DirectionalityOptions.cs | 64 |
5 files changed, 68 insertions, 36 deletions
diff --git a/common/accel-base.hpp b/common/accel-base.hpp index f98a36d..42b3bb1 100644 --- a/common/accel-base.hpp +++ b/common/accel-base.hpp @@ -17,8 +17,8 @@ namespace rawaccel { double speed_cap = 0; }; - struct stigma_args { - vec2d sigmas = { 1, 1 }; + struct domain_args { + vec2d domain_weights = { 1, 1 }; double lp_norm = 2; }; diff --git a/common/rawaccel-settings.h b/common/rawaccel-settings.h index 8dd446f..755fa2c 100644 --- a/common/rawaccel-settings.h +++ b/common/rawaccel-settings.h @@ -22,8 +22,8 @@ namespace rawaccel { vec2<accel_args> argsv; vec2d sens = { 1, 1 }; vec2d dir_multipliers = {}; - vec2d directional_weights = { 1, 1 }; - stigma_args args_stigma = stigma_args(); + domain_args domain_args = {}; + vec2d range_weights = { 1, 1 }; milliseconds time_min = DEFAULT_TIME_MIN; }; diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index d1cafdd..c617bed 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -225,17 +225,17 @@ namespace rawaccel { accelerator() = default; }; - struct stigma_distance { + struct weighted_distance { double p = 2.0; double p_inverse = 0.5; bool lp_norm_infinity = false; double sigma_x = 1.0; double sigma_y = 1.0; - stigma_distance(stigma_args args) + weighted_distance(domain_args args) { - sigma_x = args.sigmas.x; - sigma_y = args.sigmas.y; + sigma_x = args.domain_weights.x; + sigma_y = args.domain_weights.y; if (args.lp_norm <= 0) { lp_norm_infinity = true; @@ -252,12 +252,20 @@ namespace rawaccel { double calculate(double x, double y) { - double x_scaled = x * sigma_x; - double y_scaled = y * sigma_y; + double abs_x = fabs(x); + double abs_y = fabs(y); + + if (lp_norm_infinity) + { + return abs_x > abs_y ? abs_x : abs_y; + } + + double x_scaled = abs_x * sigma_x; + double y_scaled = abs_y * sigma_y; return pow(pow(x_scaled, p) + pow(y_scaled, p), p_inverse); } - stigma_distance() = default; + weighted_distance() = default; }; struct direction_weight { @@ -299,7 +307,7 @@ namespace rawaccel { bool apply_accel = false; bool combine_magnitudes = true; rotator rotate; - stigma_distance stigma; + weighted_distance distance; direction_weight directional; vec2<accelerator> accels; vec2d sensitivity = { 1, 1 }; @@ -328,8 +336,8 @@ namespace rawaccel { accels.x = accelerator(args.argsv.x, args.modes.x, luts.x); accels.y = accelerator(args.argsv.y, args.modes.y, luts.y); - stigma = stigma_distance(args.args_stigma); - directional = direction_weight(args.directional_weights); + distance = weighted_distance(args.domain_args); + directional = direction_weight(args.range_weights); apply_accel = true; } @@ -350,7 +358,7 @@ namespace rawaccel { milliseconds time = time_supp(); if (combine_magnitudes) { - double mag = stigma.calculate(movement.x, movement.y); + double mag = distance.calculate(movement.x, movement.y); double speed = mag / time; double scale = accels.x.apply(speed); diff --git a/grapher/Constants/Constants.cs b/grapher/Constants/Constants.cs index 69b0bbb..7ebb2cc 100644 --- a/grapher/Constants/Constants.cs +++ b/grapher/Constants/Constants.cs @@ -62,7 +62,7 @@ namespace grapher public const int ButtonVerticalOffset = 60; /// <summary> Padding between directionality title and containing panel </summary> - public const int DirectionalityTitlePad = 2; + public const int DirectionalityTitlePad = 4; public const float SmallButtonSizeFactor = 0.666f; diff --git a/grapher/Models/Options/Directionality/DirectionalityOptions.cs b/grapher/Models/Options/Directionality/DirectionalityOptions.cs index 3de93b4..df1b4de 100644 --- a/grapher/Models/Options/Directionality/DirectionalityOptions.cs +++ b/grapher/Models/Options/Directionality/DirectionalityOptions.cs @@ -32,8 +32,10 @@ namespace grapher.Models.Options.Directionality ByComponentCheckBox = byComponentCheckBox; ContainingPanel.Paint += panel_Paint; + directionalityLabel.Click += title_click; DirectionalityLabel.Left = ContainingPanel.Left + Constants.DirectionalityTitlePad; DirectionalityLabel.Top = ContainingPanel.Top + Constants.DirectionalityTitlePad; + IsHidden = false; ToWhole(); Hide(); } @@ -56,6 +58,8 @@ namespace grapher.Models.Options.Directionality public CheckBox ByComponentCheckBox { get; } + private bool IsHidden { get; set; } + public DomainArgs GetDomainArgs() { if (!ByComponentCheckBox.Checked) @@ -115,14 +119,34 @@ namespace grapher.Models.Options.Directionality public void Hide() { - DirectionalityX.Hide(); - DirectionalityY.Hide(); - LpNorm.Hide(); - Domain.Hide(); - Range.Hide(); - WholeCheckBox.Hide(); - ByComponentCheckBox.Hide(); - DrawHidden(); + if (!IsHidden) + { + DirectionalityX.Hide(); + DirectionalityY.Hide(); + LpNorm.Hide(); + Domain.Hide(); + Range.Hide(); + WholeCheckBox.Hide(); + ByComponentCheckBox.Hide(); + DrawHidden(); + IsHidden = true; + } + } + + public void Show() + { + if (IsHidden) + { + DirectionalityX.Hide(); + DirectionalityY.Hide(); + LpNorm.Hide(); + Domain.Hide(); + Range.Hide(); + WholeCheckBox.Hide(); + ByComponentCheckBox.Hide(); + DrawShown(); + IsHidden = false; + } } public void ToByComponent() @@ -139,18 +163,6 @@ namespace grapher.Models.Options.Directionality Range.SetToAvailable(); } - public void Show() - { - DirectionalityX.Hide(); - DirectionalityY.Hide(); - LpNorm.Hide(); - Domain.Hide(); - Range.Hide(); - WholeCheckBox.Hide(); - ByComponentCheckBox.Hide(); - DrawShown(); - } - private void DrawHidden() { ContainingPanel.Height = DirectionalityLabel.Height + 2 * Constants.DirectionalityTitlePad; @@ -168,5 +180,17 @@ namespace grapher.Models.Options.Directionality int thickness = 2; ControlPaint.DrawBorder(e.Graphics, this.ContainingPanel.ClientRectangle, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs); } + + private void title_click(object sender, EventArgs e) + { + if (IsHidden) + { + Show(); + } + else + { + Hide(); + } + } } } |