summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-07-31 12:20:11 -0700
committerJacob Palecki <[email protected]>2020-07-31 12:20:11 -0700
commit6537db04f7e717eda2f21e007cdba7e13b7f559e (patch)
treeefb65bf3f305f376ea75f4f687b08bf8998c020f
parentAdd class for storing settings from file (diff)
parentMerge pull request #6 from a1xd/st-refactor (diff)
downloadrawaccel-6537db04f7e717eda2f21e007cdba7e13b7f559e.tar.xz
rawaccel-6537db04f7e717eda2f21e007cdba7e13b7f559e.zip
Show no settings for off, remove unused class for PR
-rw-r--r--common/accel-base.hpp69
-rw-r--r--common/accel-classic.hpp29
-rw-r--r--common/accel-error.hpp (renamed from common/Error.hpp)5
-rw-r--r--common/accel-linear.hpp14
-rw-r--r--common/accel-logarithmic.hpp20
-rw-r--r--common/accel-natural.hpp31
-rw-r--r--common/accel-noaccel.hpp14
-rw-r--r--common/accel-power.hpp41
-rw-r--r--common/accel-sigmoid.hpp32
-rw-r--r--common/accel_classic.cpp21
-rw-r--r--common/accel_linear.cpp21
-rw-r--r--common/accel_logarithmic.cpp21
-rw-r--r--common/accel_natural.cpp23
-rw-r--r--common/accel_noaccel.cpp15
-rw-r--r--common/accel_power.cpp24
-rw-r--r--common/accel_sigmoid.cpp21
-rw-r--r--common/accel_types.hpp130
-rw-r--r--common/common.vcxitems20
-rw-r--r--common/external/nillable.h30
-rw-r--r--common/external/tagged-union-single.h2
-rw-r--r--common/rawaccel-userspace.hpp53
-rw-r--r--common/rawaccel.hpp93
-rw-r--r--common/x64-util.hpp10
-rw-r--r--grapher/AccelOptions.cs36
-rw-r--r--grapher/AccelerationSettings.cs35
-rw-r--r--grapher/Form1.cs76
-rw-r--r--grapher/Layouts/ClassicLayout.cs5
-rw-r--r--grapher/Layouts/DefaultLayout.cs8
-rw-r--r--grapher/Layouts/LayoutBase.cs32
-rw-r--r--grapher/Layouts/LinearLayout.cs5
-rw-r--r--grapher/Layouts/LogLayout.cs5
-rw-r--r--grapher/Layouts/NaturalLayout.cs5
-rw-r--r--grapher/Layouts/OffLayout.cs22
-rw-r--r--grapher/Layouts/PowerLayout.cs5
-rw-r--r--grapher/Layouts/SigmoidLayout.cs5
-rw-r--r--grapher/Option.cs3
-rw-r--r--grapher/OptionXY.cs6
-rw-r--r--grapher/grapher.csproj2
-rw-r--r--wrapper/wrapper.cpp12
-rw-r--r--wrapper/wrapper.hpp20
40 files changed, 562 insertions, 459 deletions
diff --git a/common/accel-base.hpp b/common/accel-base.hpp
new file mode 100644
index 0000000..da2c96b
--- /dev/null
+++ b/common/accel-base.hpp
@@ -0,0 +1,69 @@
+#pragma once
+
+#include "vec2.h"
+
+namespace rawaccel {
+
+ // Error throwing calls std libraries which are unavailable in kernel mode.
+ void error(const char* s);
+
+ using milliseconds = double;
+
+ /// <summary> Struct to hold arguments for an acceleration function. </summary>
+ struct accel_args {
+ double offset = 0;
+ double accel = 0;
+ double limit = 2;
+ double exponent = 2;
+ double midpoint = 0;
+ double power_scale = 1;
+ vec2d weight = { 1, 1 };
+ };
+
+ /// <summary>
+ /// Struct to hold common acceleration curve implementation details.
+ /// </summary>
+ struct accel_base {
+
+ /// <summary> Coefficients applied to acceleration per axis.</summary>
+ vec2d weight = { 1, 1 };
+
+ /// <summary> Generally, the acceleration ramp rate.
+ double speed_coeff = 0;
+
+ accel_base(const accel_args& args) {
+ verify(args);
+
+ speed_coeff = args.accel;
+ weight = args.weight;
+ }
+
+ /// <summary>
+ /// Default transformation of speed -> acceleration.
+ /// </summary>
+ inline double accelerate(double speed) const {
+ return speed_coeff * speed;
+ }
+
+ /// <summary>
+ /// Default transformation of acceleration -> mouse input multipliers.
+ /// </summary>
+ inline vec2d scale(double accel_val) const {
+ return {
+ weight.x * accel_val + 1,
+ weight.y * accel_val + 1
+ };
+ }
+
+ /// <summary>
+ /// Verifies arguments as valid. Errors if not.
+ /// </summary>
+ /// <param name="args">Arguments to verified.</param>
+ void verify(const accel_args& args) const {
+ if (args.accel < 0) error("accel can not be negative, use a negative weight to compensate");
+ }
+
+ accel_base() = default;
+ };
+
+}
diff --git a/common/accel-classic.hpp b/common/accel-classic.hpp
new file mode 100644
index 0000000..1a2adca
--- /dev/null
+++ b/common/accel-classic.hpp
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <math.h>
+
+#include "accel-base.hpp"
+
+namespace rawaccel {
+
+ /// <summary> Struct to hold "classic" (linear raised to power) acceleration implementation. </summary>
+ struct accel_classic : accel_base {
+ double exponent;
+
+ accel_classic(const accel_args& args) : accel_base(args) {
+ verify(args);
+
+ exponent = args.exponent - 1;
+ }
+
+ inline double accelerate(double speed) const {
+ //f(x) = (mx)^k
+ return pow(speed_coeff * speed, exponent);
+ }
+
+ void verify(const accel_args& args) const {
+ if (args.exponent <= 1) error("exponent must be greater than 1");
+ }
+ };
+
+}
diff --git a/common/Error.hpp b/common/accel-error.hpp
index ed87090..fa1f999 100644
--- a/common/Error.hpp
+++ b/common/accel-error.hpp
@@ -1,10 +1,11 @@
#pragma once
-#include <iostream>
-
+#include <stdexcept>
namespace rawaccel {
+
void error(const char* s) {
throw std::domain_error(s);
}
+
}
diff --git a/common/accel-linear.hpp b/common/accel-linear.hpp
new file mode 100644
index 0000000..5cbb7c6
--- /dev/null
+++ b/common/accel-linear.hpp
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "accel-base.hpp"
+
+namespace rawaccel {
+
+ /// <summary> Struct to hold linear acceleration implementation. </summary>
+ struct accel_linear : accel_base {
+
+ using accel_base::accel_base;
+
+ };
+
+}
diff --git a/common/accel-logarithmic.hpp b/common/accel-logarithmic.hpp
new file mode 100644
index 0000000..928eda9
--- /dev/null
+++ b/common/accel-logarithmic.hpp
@@ -0,0 +1,20 @@
+#pragma once
+
+#include <math.h>
+
+#include "accel-base.hpp"
+
+namespace rawaccel {
+
+ /// <summary> Struct to hold logarithmic acceleration implementation. </summary>
+ struct accel_logarithmic : accel_base {
+
+ using accel_base::accel_base;
+
+ inline double accelerate(double speed) const {
+ //f(x) = log(m*x+1)
+ return log(speed_coeff * speed + 1);
+ }
+ };
+
+}
diff --git a/common/accel-natural.hpp b/common/accel-natural.hpp
new file mode 100644
index 0000000..c87fda8
--- /dev/null
+++ b/common/accel-natural.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <math.h>
+
+#include "accel-base.hpp"
+
+namespace rawaccel {
+
+ /// <summary> Struct to hold "natural" (vanishing difference) acceleration implementation. </summary>
+ struct accel_natural : accel_base {
+ double limit = 1;
+ double midpoint = 0;
+
+ accel_natural(const accel_args& args) : accel_base(args) {
+ verify(args);
+
+ limit = args.limit - 1;
+ speed_coeff /= limit;
+ }
+
+ inline double accelerate(double speed) const {
+ // f(x) = k(1-e^(-mx))
+ return limit - (limit * exp(-speed_coeff * speed));
+ }
+
+ void verify(const accel_args& args) const {
+ if (args.limit <= 1) error("limit must be greater than 1");
+ }
+ };
+
+}
diff --git a/common/accel-noaccel.hpp b/common/accel-noaccel.hpp
new file mode 100644
index 0000000..b7f730b
--- /dev/null
+++ b/common/accel-noaccel.hpp
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "accel-base.hpp"
+
+namespace rawaccel {
+
+ /// <summary> Struct to hold acceleration implementation which applies no acceleration. </summary>
+ struct accel_noaccel : accel_base {
+
+ accel_noaccel(const accel_args&) : accel_base() {}
+
+ };
+
+}
diff --git a/common/accel-power.hpp b/common/accel-power.hpp
new file mode 100644
index 0000000..7f4c220
--- /dev/null
+++ b/common/accel-power.hpp
@@ -0,0 +1,41 @@
+#pragma once
+
+#include <math.h>
+
+#include "accel-base.hpp"
+
+namespace rawaccel {
+
+ /// <summary> Struct to hold power (non-additive) acceleration implementation. </summary>
+ struct accel_power : accel_base {
+ double exponent;
+ double offset;
+
+ accel_power(const accel_args& args) {
+ verify(args);
+
+ weight = args.weight;
+ speed_coeff = args.power_scale;
+ exponent = args.exponent;
+ offset = args.offset;
+ }
+
+ inline double accelerate(double speed) const {
+ // f(x) = (mx)^k
+ return (offset > 0 && speed < 1) ? 1 : pow(speed * speed_coeff, exponent);
+ }
+
+ inline vec2d scale(double accel_val) const {
+ return {
+ weight.x * accel_val,
+ weight.y * accel_val
+ };
+ }
+
+ void verify(const accel_args& args) const {
+ if (args.power_scale <= 0) error("scale must be positive");
+ if (args.exponent <= 0) error("exponent must be greater than 0");
+ }
+ };
+
+}
diff --git a/common/accel-sigmoid.hpp b/common/accel-sigmoid.hpp
new file mode 100644
index 0000000..7cfa6c4
--- /dev/null
+++ b/common/accel-sigmoid.hpp
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <math.h>
+
+#include "accel-base.hpp"
+
+namespace rawaccel {
+
+ /// <summary> Struct to hold sigmoid (s-shaped) acceleration implementation. </summary>
+ struct accel_sigmoid : accel_base {
+ double limit = 1;
+ double midpoint = 0;
+
+ accel_sigmoid(const accel_args& args) : accel_base(args) {
+ verify(args);
+
+ limit = args.limit - 1;
+ midpoint = args.midpoint;
+ }
+
+ inline double accelerate(double speed) const {
+ //f(x) = k/(1+e^(-m(c-x)))
+ return limit / (exp(-speed_coeff * (speed - midpoint)) + 1);
+ }
+
+ void verify(const accel_args& args) const {
+ if (args.limit <= 1) error("exponent must be greater than 1");
+ if (args.midpoint < 0) error("midpoint must not be negative");
+ }
+ };
+
+}
diff --git a/common/accel_classic.cpp b/common/accel_classic.cpp
deleted file mode 100644
index 323cd3b..0000000
--- a/common/accel_classic.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-
-#define _USE_MATH_DEFINES
-#include <math.h>
-
-#include "accel_types.hpp"
-
-namespace rawaccel {
- inline accel_classic::accel_classic(accel_args args)
- : accel_implentation(args) {}
-
- inline double accel_classic::accelerate(double speed) {
- //f(x) = (mx)^k
- return pow(curve_constant_one * speed, curve_constant_two);
- }
-
- inline void accel_classic::verify(accel_args args) {
- accel_implentation::verify(args);
- if (args.lim_exp <= 1) error("exponent must be greater than 1");
- }
-}
diff --git a/common/accel_linear.cpp b/common/accel_linear.cpp
deleted file mode 100644
index 307e33e..0000000
--- a/common/accel_linear.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-
-#define _USE_MATH_DEFINES
-#include <math.h>
-
-#include "accel_types.hpp"
-
-namespace rawaccel {
- inline accel_linear::accel_linear(accel_args args)
- : accel_implentation(args) {}
-
- inline double accel_linear::accelerate(double speed) {
- //f(x) = mx
- return curve_constant_one * speed;
- }
-
- inline void accel_linear::verify(accel_args args) {
- accel_implentation::verify(args);
- if (args.lim_exp <= 1) error("limit must be greater than 1");
- }
-}
diff --git a/common/accel_logarithmic.cpp b/common/accel_logarithmic.cpp
deleted file mode 100644
index 64808a1..0000000
--- a/common/accel_logarithmic.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-
-#define _USE_MATH_DEFINES
-#include <math.h>
-
-#include "accel_types.hpp"
-
-namespace rawaccel {
- inline accel_logarithmic::accel_logarithmic(accel_args args)
- : accel_implentation(args) {}
-
- inline double accel_logarithmic::accelerate(double speed) {
- //f(x) = log(m*x+1)
- return log(speed * curve_constant_one + 1);
- }
-
- inline void accel_logarithmic::verify(accel_args args) {
- accel_implentation::verify(args);
- if (args.lim_exp <= 1) error("exponent must be greater than 1");
- }
-}
diff --git a/common/accel_natural.cpp b/common/accel_natural.cpp
deleted file mode 100644
index c6f14b4..0000000
--- a/common/accel_natural.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-
-#pragma once
-
-#define _USE_MATH_DEFINES
-#include <math.h>
-
-#include "accel_types.hpp"
-
-namespace rawaccel {
- inline accel_natural::accel_natural(accel_args args)
- : accel_implentation(args)
- { curve_constant_one /= curve_constant_two; }
-
- inline double accel_natural::accelerate(double speed) {
- // f(x) = k(1-e^(-mx))
- return curve_constant_two - (curve_constant_two * exp(-curve_constant_one * speed));;
- }
-
- inline void accel_natural::verify(accel_args args) {
- accel_implentation::verify(args);
- if (args.lim_exp <= 1) error("exponent must be greater than 1");
- }
-}
diff --git a/common/accel_noaccel.cpp b/common/accel_noaccel.cpp
deleted file mode 100644
index fce5dd4..0000000
--- a/common/accel_noaccel.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-
-#define _USE_MATH_DEFINES
-#include <math.h>
-
-#include "accel_types.hpp"
-
-namespace rawaccel {
- inline accel_noaccel::accel_noaccel(accel_args args)
- : accel_implentation(args) {}
-
- inline double accel_noaccel::accelerate(double speed) { return 0; }
-
- inline void accel_noaccel::verify(accel_args args) { }
-}
diff --git a/common/accel_power.cpp b/common/accel_power.cpp
deleted file mode 100644
index f104554..0000000
--- a/common/accel_power.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#pragma once
-
-#define _USE_MATH_DEFINES
-#include <math.h>
-
-#include "accel_types.hpp"
-
-namespace rawaccel {
- inline accel_power::accel_power(accel_args args)
- : accel_implentation(args)
- { curve_constant_two++; }
-
- inline double accel_power::accelerate(double speed) {
- // f(x) = (mx)^k - 1
- // The subtraction of 1 occurs with later addition of 1 in mind,
- // so that the input vector is directly multiplied by (mx)^k (if unweighted)
- return (offset > 0 && speed < 1) ? 0 : pow(speed * curve_constant_one, curve_constant_two) - 1;
- }
-
- inline void accel_power::verify(accel_args args) {
- accel_implentation::verify(args);
- if (args.lim_exp <= 0) error("exponent must be greater than 0");
- }
-}
diff --git a/common/accel_sigmoid.cpp b/common/accel_sigmoid.cpp
deleted file mode 100644
index d3b8ab7..0000000
--- a/common/accel_sigmoid.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-
-#define _USE_MATH_DEFINES
-#include <math.h>
-
-#include "accel_types.hpp"
-
-namespace rawaccel {
- inline accel_sigmoid::accel_sigmoid(accel_args args)
- : accel_implentation(args) {}
-
- inline double accel_sigmoid::accelerate(double speed) {
- //f(x) = k/(1+e^(-m(c-x)))
- return curve_constant_two / (exp(-curve_constant_one * (speed - curve_constant_three)) + 1);
- }
-
- inline void accel_sigmoid::verify(accel_args args) {
- accel_implentation::verify(args);
- if (args.lim_exp <= 1) error("exponent must be greater than 1");
- }
-}
diff --git a/common/accel_types.hpp b/common/accel_types.hpp
deleted file mode 100644
index 15f5a50..0000000
--- a/common/accel_types.hpp
+++ /dev/null
@@ -1,130 +0,0 @@
-#pragma once
-
-#define _USE_MATH_DEFINES
-#include <math.h>
-
-namespace rawaccel {
-
-// Error throwing calls std libraries which are unavailable in kernel mode.
-#ifdef _KERNEL_MODE
- inline void error(const char*) {}
-#else
- void error(const char* s);
-#endif
-
- using milliseconds = double;
-
- /// <summary> Struct to hold arguments for an acceleration function. </summary>
- struct accel_args {
- milliseconds time_min = 0.4;
- double offset = 0;
- double accel = 0;
- double lim_exp = 2;
- double midpoint = 0;
- };
-
- /// <summary>
- /// Struct to hold acceleration curve implementation details.
- /// </summary>
- /// <typeparam name="T">Type of acceleration.</typeparam>
- template <typename T>
- struct accel_implentation {
-
- /// <summary> First constant for use in acceleration curves. Generally, the acceleration ramp rate.</summary>
- double curve_constant_one = 0;
-
- /// <summary> Second constant for use in acceleration curves. Generally, the limit or exponent in the curve. </summary>
- double curve_constant_two = 0;
-
- /// <summary> Third constant for use in acceleration curves. The midpoint in sigmoid mode. </summary>
- double curve_constant_three = 0;
-
- /// <summary> The offset past which acceleration is applied. Used in power mode. </summary>
- double offset = 0;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="accel_implementation{T}"/> struct.
- /// </summary>
- /// <param name="args"></param>
- /// <returns></returns>
- accel_implentation(accel_args args)
- {
- curve_constant_one = args.accel;
- curve_constant_two = args.lim_exp - 1;
- curve_constant_three = args.midpoint;
- offset = args.offset;
- }
-
- /// <summary>
- /// Returns accelerated value of speed as a ratio of magnitude.
- /// </summary>
- /// <param name="speed">Mouse speed at which to calculate acceleration.</param>
- /// <returns>Ratio of accelerated movement magnitude to input movement magnitude.</returns>
- double accelerate(double speed) { return 0; }
-
- /// <summary>
- /// Verifies arguments as valid. Errors if not.
- /// </summary>
- /// <param name="args">Arguments to verified.</param>
- void verify(accel_args args) {
- if (args.accel < 0) error("accel can not be negative, use a negative weight to compensate");
- if (args.time_min <= 0) error("min time must be positive");
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- accel_implentation() = default;
- };
-
- /// <summary> Struct to hold linear acceleration implementation. </summary>
- struct accel_linear : accel_implentation<accel_linear> {
- accel_linear(accel_args args);
- double accelerate(double speed);
- void verify(accel_args args);
- };
-
- /// <summary> Struct to hold "classic" (linear raised to power) acceleration implementation. </summary>
- struct accel_classic : accel_implentation<accel_classic> {
- accel_classic(accel_args args);
- double accelerate(double speed);
- void verify(accel_args args);
- };
-
- /// <summary> Struct to hold "natural" (vanishing difference) acceleration implementation. </summary>
- struct accel_natural : accel_implentation<accel_natural> {
- accel_natural(accel_args args);
- double accelerate(double speed);
- void verify(accel_args args);
- };
-
- /// <summary> Struct to hold logarithmic acceleration implementation. </summary>
- struct accel_logarithmic : accel_implentation<accel_logarithmic> {
- accel_logarithmic(accel_args args);
- double accelerate(double speed);
- void verify(accel_args args);
- };
-
- /// <summary> Struct to hold sigmoid (s-shaped) acceleration implementation. </summary>
- struct accel_sigmoid : accel_implentation<accel_sigmoid> {
- accel_sigmoid(accel_args args);
- double accelerate(double speed);
- void verify(accel_args args);
- };
-
- /// <summary> Struct to hold power (non-additive) acceleration implementation. </summary>
- struct accel_power : accel_implentation<accel_power> {
- accel_power(accel_args args);
- double accelerate(double speed);
- void verify(accel_args args);
- };
-
- /// <summary> Struct to hold acceleration implementation which applies no acceleration. </summary>
- struct accel_noaccel : accel_implentation<accel_noaccel> {
- accel_noaccel(accel_args args);
- double accelerate(double speed);
- void verify(accel_args args);
- };
-
-}
diff --git a/common/common.vcxitems b/common/common.vcxitems
index f33d8e1..d1e8db0 100644
--- a/common/common.vcxitems
+++ b/common/common.vcxitems
@@ -14,20 +14,18 @@
<ProjectCapability Include="SourceItemsFromImports" />
</ItemGroup>
<ItemGroup>
- <ClInclude Include="$(MSBuildThisFileDirectory)accel_types.hpp" />
- <ClInclude Include="$(MSBuildThisFileDirectory)Error.hpp" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)accel-base.hpp" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)accel-classic.hpp" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)accel-linear.hpp" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)accel-logarithmic.hpp" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)accel-natural.hpp" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)accel-noaccel.hpp" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)accel-power.hpp" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)accel-sigmoid.hpp" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)accel-error.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-userspace.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)x64-util.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)vec2.h" />
</ItemGroup>
- <ItemGroup>
- <ClCompile Include="$(MSBuildThisFileDirectory)accel_classic.cpp" />
- <ClCompile Include="$(MSBuildThisFileDirectory)accel_linear.cpp" />
- <ClCompile Include="$(MSBuildThisFileDirectory)accel_logarithmic.cpp" />
- <ClCompile Include="$(MSBuildThisFileDirectory)accel_natural.cpp" />
- <ClCompile Include="$(MSBuildThisFileDirectory)accel_noaccel.cpp" />
- <ClCompile Include="$(MSBuildThisFileDirectory)accel_power.cpp" />
- <ClCompile Include="$(MSBuildThisFileDirectory)accel_sigmoid.cpp" />
- </ItemGroup>
</Project> \ No newline at end of file
diff --git a/common/external/nillable.h b/common/external/nillable.h
new file mode 100644
index 0000000..40cf01c
--- /dev/null
+++ b/common/external/nillable.h
@@ -0,0 +1,30 @@
+inline constexpr struct nil_t {} nil;
+
+// Requirements: T is default-constructible and trivially-destructible
+template<typename T>
+struct nillable {
+ bool has_value = false;
+ T value;
+
+ nillable() = default;
+
+ nillable(nil_t) : nillable() {}
+ nillable(const T& v) : has_value(true), value(v) {}
+
+ nillable& operator=(nil_t) {
+ has_value = false;
+ return *this;
+ }
+ nillable& operator=(const T& v) {
+ value = v;
+ has_value = true;
+ return *this;
+ }
+
+ const T* operator->() const { return &value; }
+ T* operator->() { return &value; }
+
+ explicit operator bool() const { return has_value; }
+};
+
+template<typename T> nillable(T)->nillable<T>;
diff --git a/common/external/tagged-union-single.h b/common/external/tagged-union-single.h
index bcfc1cf..3353325 100644
--- a/common/external/tagged-union-single.h
+++ b/common/external/tagged-union-single.h
@@ -137,7 +137,7 @@ struct tagged_union {
int tag = 0;
struct storage_t {
- alignas(max_align_of<First, Rest...>) char bytes[max_size_of<First, Rest...>];
+ alignas(max_align_of<First, Rest...>) char bytes[max_size_of<First, Rest...>] = "";
template <typename T>
inline constexpr T& as() {
diff --git a/common/rawaccel-userspace.hpp b/common/rawaccel-userspace.hpp
index 3e8886f..c80262c 100644
--- a/common/rawaccel-userspace.hpp
+++ b/common/rawaccel-userspace.hpp
@@ -4,6 +4,7 @@
#include "external/clipp.h"
+#include "accel-error.hpp"
#include "rawaccel.hpp"
namespace rawaccel {
@@ -12,12 +13,14 @@ inline constexpr int SYSTEM_ERROR = -1;
inline constexpr int PARSE_ERROR = 1;
inline constexpr int INVALID_ARGUMENT = 2;
-void error(const char* s) {
- throw std::domain_error(s);
+template<typename Accel, typename StrFirst, typename... StrRest>
+clipp::parameter make_accel_cmd(modifier_args& args, StrFirst&& first_flag, StrRest&&... rest) {
+ return clipp::command(first_flag, rest...)
+ .set(args.acc_fn_args.accel_mode, accel_impl_t::id<Accel>);
}
mouse_modifier parse(int argc, char** argv) {
- modifier_args modifier_args{};
+ modifier_args args{};
auto make_opt_vec = [](vec2d& v, auto first_flag, auto... rest) {
return clipp::option(first_flag, rest...) & (
@@ -38,64 +41,64 @@ mouse_modifier parse(int argc, char** argv) {
};
// default options
- auto opt_sens = "sensitivity (default = 1)" % make_opt_vec(modifier_args.sens, "sens");
+ auto opt_sens = "sensitivity (default = 1)" % make_opt_vec(args.sens, "sens");
auto opt_rot = "counter-clockwise rotation (default = 0)" % (
clipp::option("rotate") &
- clipp::number("degrees", modifier_args.degrees)
+ clipp::number("degrees", args.degrees)
);
// mode-independent accel options
auto opt_weight = "accel multiplier (default = 1)" %
- make_opt_vec(modifier_args.acc_fn_args.weight, "weight");
+ make_opt_vec(args.acc_fn_args.acc_args.weight, "weight");
auto opt_offset = "speed (dots/ms) where accel kicks in (default = 0)" % (
- clipp::option("offset") & clipp::number("speed", modifier_args.acc_fn_args.acc_args.offset)
+ clipp::option("offset") & clipp::number("speed", args.acc_fn_args.acc_args.offset)
);
auto opt_cap = "accel scale cap (default = 9)" %
- make_opt_vec(modifier_args.acc_fn_args.cap, "cap");
+ make_opt_vec(args.acc_fn_args.cap, "cap");
auto opt_tmin = "minimum time between polls (default = 0.4)" % (
clipp::option("tmin") &
- clipp::number("ms", modifier_args.acc_fn_args.acc_args.time_min)
+ clipp::number("ms", args.acc_fn_args.time_min)
);
- auto accel_var = (clipp::required("accel") & clipp::number("num", modifier_args.acc_fn_args.acc_args.accel)) % "ramp rate";
- auto limit_var = (clipp::required("limit") & clipp::number("scale", modifier_args.acc_fn_args.acc_args.lim_exp)) % "limit";
+ auto accel_var = (clipp::required("accel") & clipp::number("num", args.acc_fn_args.acc_args.accel)) % "ramp rate";
+ auto limit_var = (clipp::required("limit") & clipp::number("scale", args.acc_fn_args.acc_args.limit)) % "limit";
+ auto exp_var = (clipp::required("exponent") & clipp::number("num", args.acc_fn_args.acc_args.exponent)) % "exponent";
// modes
- auto noaccel_mode = "no-accel mode" % (
- clipp::command("off", "noaccel").set(modifier_args.acc_fn_args.accel_mode, accel_implementation_t::id<accel_noaccel>)
- );
+ auto noaccel_mode = "no-accel mode" % make_accel_cmd<accel_noaccel>(args, "off", "noaccel");
+
auto lin_mode = "linear accel mode:" % (
- clipp::command("linear").set(modifier_args.acc_fn_args.accel_mode, accel_implementation_t::id<accel_linear>),
+ make_accel_cmd<accel_linear>(args, "linear"),
accel_var
);
auto classic_mode = "classic accel mode:" % (
- clipp::command("classic").set(modifier_args.acc_fn_args.accel_mode, accel_implementation_t::id<accel_classic>),
+ make_accel_cmd<accel_classic>(args, "classic"),
accel_var,
- (clipp::required("exponent") & clipp::number("num", modifier_args.acc_fn_args.acc_args.lim_exp)) % "exponent"
+ exp_var
);
auto nat_mode = "natural accel mode:" % (
- clipp::command("natural").set(modifier_args.acc_fn_args.accel_mode, accel_implementation_t::id<accel_natural>),
+ make_accel_cmd<accel_natural>(args, "natural"),
accel_var,
limit_var
);
auto log_mode = "logarithmic accel mode:" % (
- clipp::command("logarithmic").set(modifier_args.acc_fn_args.accel_mode, accel_implementation_t::id<accel_logarithmic>),
+ make_accel_cmd<accel_logarithmic>(args, "logarithmic"),
accel_var
);
auto sig_mode = "sigmoid accel mode:" % (
- clipp::command("sigmoid").set(modifier_args.acc_fn_args.accel_mode, accel_implementation_t::id<accel_sigmoid>),
+ make_accel_cmd<accel_sigmoid>(args, "sigmoid"),
accel_var,
limit_var,
- (clipp::required("midpoint") & clipp::number("speed", modifier_args.acc_fn_args.acc_args.midpoint)) % "midpoint"
+ (clipp::required("midpoint") & clipp::number("speed", args.acc_fn_args.acc_args.midpoint)) % "midpoint"
);
auto pow_mode = "power accel mode:" % (
- clipp::command("power").set(modifier_args.acc_fn_args.accel_mode, accel_implementation_t::id<accel_power>) >> [&] { modifier_args.acc_fn_args.acc_args.accel = 1; },
- (clipp::required("exponent") & clipp::number("num", modifier_args.acc_fn_args.acc_args.lim_exp)) % "exponent",
- (clipp::option("scale") & clipp::number("num", modifier_args.acc_fn_args.acc_args.accel)) % "scale factor"
+ make_accel_cmd<accel_power>(args, "power"),
+ exp_var,
+ (clipp::option("scale") & clipp::number("num", args.acc_fn_args.acc_args.power_scale)) % "scale factor"
);
auto accel_mode_exclusive = (lin_mode | classic_mode | nat_mode | log_mode | sig_mode | pow_mode);
@@ -119,7 +122,7 @@ mouse_modifier parse(int argc, char** argv) {
std::exit(0);
}
- return mouse_modifier(modifier_args);
+ return mouse_modifier(args);
}
} // rawaccel
diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp
index b480e87..59a0360 100644
--- a/common/rawaccel.hpp
+++ b/common/rawaccel.hpp
@@ -3,17 +3,16 @@
#define _USE_MATH_DEFINES
#include <math.h>
-#include "vec2.h"
#include "x64-util.hpp"
#include "external/tagged-union-single.h"
-#include "accel_linear.cpp"
-#include "accel_classic.cpp"
-#include "accel_natural.cpp"
-#include "accel_logarithmic.cpp"
-#include "accel_sigmoid.cpp"
-#include "accel_power.cpp"
-#include "accel_noaccel.cpp"
+#include "accel-linear.hpp"
+#include "accel-classic.hpp"
+#include "accel-natural.hpp"
+#include "accel-logarithmic.hpp"
+#include "accel-sigmoid.hpp"
+#include "accel-power.hpp"
+#include "accel-noaccel.hpp"
namespace rawaccel {
@@ -75,13 +74,12 @@ namespace rawaccel {
};
/// <summary> Tagged union to hold all accel implementations and allow "polymorphism" via a visitor call. </summary>
- using accel_implementation_t = tagged_union<accel_linear, accel_classic, accel_natural, accel_logarithmic, accel_sigmoid, accel_power, accel_noaccel>;
+ using accel_impl_t = tagged_union<accel_linear, accel_classic, accel_natural, accel_logarithmic, accel_sigmoid, accel_power, accel_noaccel>;
struct accel_fn_args {
- accel_args acc_args = accel_args{};
- int accel_mode = 0;
+ accel_args acc_args;
+ int accel_mode = accel_impl_t::id<accel_noaccel>;
milliseconds time_min = 0.4;
- vec2d weight = { 1, 1 };
vec2d cap = { 0, 0 };
};
@@ -100,47 +98,25 @@ namespace rawaccel {
double speed_offset = 0;
/// <summary> The acceleration implementation (i.e. curve) </summary>
- accel_implementation_t accel;
-
- /// <summary> The weight of acceleration applied in {x, y} dimensions. </summary>
- vec2d weight = { 1, 1 };
+ accel_impl_t accel;
/// <summary> The object which sets a min and max for the acceleration scale. </summary>
vec2<accel_scale_clamp> clamp;
- accel_function(accel_fn_args args) {
- accel.tag = args.accel_mode;
- accel.visit([&](auto& a){ a = {args.acc_args}; });
+ accel_function(const accel_fn_args& args) {
+ if (args.time_min <= 0) error("min time must be positive");
+ if (args.acc_args.offset < 0) error("offset must not be negative");
- // Verification is performed by the accel_implementation object
- // and therefore must occur after the object has been instantiated
- verify(args.acc_args);
+ accel.tag = args.accel_mode;
+ accel.visit([&](auto& impl){ impl = { args.acc_args }; });
time_min = args.time_min;
speed_offset = args.acc_args.offset;
- weight = args.weight;
clamp.x = accel_scale_clamp(args.cap.x);
clamp.y = accel_scale_clamp(args.cap.y);
}
/// <summary>
- /// Applies mouse acceleration to a given speed, via visitor function to accel_implementation_t
- /// </summary>
- /// <param name="speed">Speed from which to determine acceleration</param>
- /// <returns>Acceleration as a ratio magnitudes, as a double</returns>
- double apply(double speed) const {
- return accel.visit([=](auto accel_t) { return accel_t.accelerate(speed); });
- }
-
- /// <summary>
- /// Verifies acceleration arguments, via visitor function to accel_implementation_t
- /// </summary>
- /// <param name="args">Arguments to be verified</param>
- void verify(accel_args args) const {
- return accel.visit([=](auto accel_t) { accel_t.verify(args); });
- }
-
- /// <summary>
/// Applies weighted acceleration to given input for given time period.
/// </summary>
/// <param name="input">2d vector of {x, y} mouse movement to be accelerated</param>
@@ -151,25 +127,24 @@ namespace rawaccel {
double time_clamped = clampsd(time, time_min, 100);
double speed = maxsd(mag / time_clamped - speed_offset, 0);
- double accel_val = apply(speed);
-
- double scale_x = weight.x * accel_val + 1;
- double scale_y = weight.y * accel_val + 1;
+ vec2d scale = accel.visit([=](auto&& impl) {
+ double accel_val = impl.accelerate(speed);
+ return impl.scale(accel_val);
+ });
return {
- input.x * clamp.x(scale_x),
- input.y * clamp.y(scale_y)
+ input.x * clamp.x(scale.x),
+ input.y * clamp.y(scale.y)
};
}
accel_function() = default;
};
- struct modifier_args
- {
+ struct modifier_args {
double degrees = 0;
vec2d sens = { 1, 1 };
- accel_fn_args acc_fn_args = accel_fn_args{};
+ accel_fn_args acc_fn_args;
};
/// <summary> Struct to hold variables and methods for modifying mouse input </summary>
@@ -180,19 +155,22 @@ namespace rawaccel {
accel_function accel_fn;
vec2d sensitivity = { 1, 1 };
- mouse_modifier(modifier_args args)
+ mouse_modifier(const modifier_args& args)
: accel_fn(args.acc_fn_args)
{
apply_rotate = args.degrees != 0;
+
if (apply_rotate) rotate = rotator(args.degrees);
else rotate = rotator();
- apply_accel = (args.acc_fn_args.accel_mode != 0 &&
- args.acc_fn_args.accel_mode != accel_implementation_t::id<accel_noaccel>);
+ apply_accel = args.acc_fn_args.accel_mode != 0 &&
+ args.acc_fn_args.accel_mode != accel_impl_t::id<accel_noaccel>;
+
+ if (args.sens.x == 0) sensitivity.x = 1;
+ else sensitivity.x = args.sens.x;
- if (args.sens.x == 0) args.sens.x = 1;
- if (args.sens.y == 0) args.sens.y = 1;
- sensitivity = args.sens;
+ if (args.sens.y == 0) sensitivity.y = 1;
+ else sensitivity.y = args.sens.y;
}
/// <summary>
@@ -226,10 +204,7 @@ namespace rawaccel {
input = rotate(input);
}
- if (apply_accel)
- {
- input = accel_fn(input, time);
- }
+ input = accel_fn(input, time);
input.x *= sensitivity.x;
input.y *= sensitivity.y;
diff --git a/common/x64-util.hpp b/common/x64-util.hpp
index 2fb61bb..40bc7c4 100644
--- a/common/x64-util.hpp
+++ b/common/x64-util.hpp
@@ -1,7 +1,13 @@
#pragma once
-#include <emmintrin.h>
+#ifdef _MANAGED
+
+#include <math.h>
+inline double sqrtsd(double val) { return sqrt(val); }
+
+#else
+#include <emmintrin.h>
inline double sqrtsd(double val) {
__m128d src = _mm_load_sd(&val);
__m128d dst = _mm_sqrt_sd(src, src);
@@ -9,6 +15,8 @@ inline double sqrtsd(double val) {
return val;
}
+#endif
+
inline constexpr double minsd(double a, double b) {
return (a < b) ? a : b;
}
diff --git a/grapher/AccelOptions.cs b/grapher/AccelOptions.cs
index 0235bc7..b233552 100644
--- a/grapher/AccelOptions.cs
+++ b/grapher/AccelOptions.cs
@@ -10,7 +10,8 @@ namespace grapher
{
public class AccelOptions
{
- public const int PossibleOptionsCount = 3;
+ public const int PossibleOptionsCount = 4;
+ public const int PossibleOptionsXYCount = 2;
public static readonly Dictionary<string, LayoutBase> AccelerationTypes = new List<LayoutBase>
{
@@ -21,15 +22,18 @@ namespace grapher
new LogLayout(),
new SigmoidLayout(),
new PowerLayout(),
+ new OffLayout()
}.ToDictionary(k => k.Name);
public AccelOptions(
ComboBox accelDropdown,
- Option[] options)
+ Option[] options,
+ OptionXY[] optionsXY,
+ Button writeButton)
{
AccelDropdown = accelDropdown;
AccelDropdown.Items.Clear();
- AccelDropdown.Items.AddRange(AccelerationTypes.Keys.ToArray());
+ AccelDropdown.Items.AddRange(AccelerationTypes.Keys.Skip(1).ToArray());
AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged);
if (options.Length > PossibleOptionsCount)
@@ -37,21 +41,39 @@ namespace grapher
throw new Exception("Layout given too many options.");
}
+ if (optionsXY.Length > PossibleOptionsXYCount)
+ {
+ throw new Exception("Layout given too many options.");
+ }
+
Options = options;
+ OptionsXY = optionsXY;
+ WriteButton = writeButton;
+
+ Layout("Default");
}
+ public Button WriteButton { get; }
+
public ComboBox AccelDropdown { get; }
public int AccelerationIndex { get; private set; }
public Option[] Options { get; }
+ public OptionXY[] OptionsXY { get; }
+
private void OnIndexChanged(object sender, EventArgs e)
{
- var AccelerationTypeString = AccelDropdown.SelectedItem.ToString();
- var AccelerationType = AccelerationTypes[AccelerationTypeString];
- AccelerationIndex = AccelerationType.Index;
- AccelerationType.Layout(Options);
+ var accelerationTypeString = AccelDropdown.SelectedItem.ToString();
+ Layout(accelerationTypeString);
+ }
+
+ private void Layout(string type)
+ {
+ var accelerationType = AccelerationTypes[type];
+ AccelerationIndex = accelerationType.Index;
+ accelerationType.Layout(Options, OptionsXY, WriteButton);
}
}
}
diff --git a/grapher/AccelerationSettings.cs b/grapher/AccelerationSettings.cs
deleted file mode 100644
index dd026e8..0000000
--- a/grapher/AccelerationSettings.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace grapher
-{
- public class AccelerationSettings
- {
- public double SensitivityX { get; }
-
- public double SensitivityY { get; }
-
- public double Rotation { get; }
-
- public double Offset { get; }
-
- public double WeightX { get; }
-
- public double WeightY { get; }
-
- public double CapX { get; }
-
- public double CapY { get; }
-
- public int AccelerationType { get; }
-
- public double Acceleration { get; }
-
- public double LimitOrExponent { get; }
-
- public double Midpoint { get; }
- }
-}
diff --git a/grapher/Form1.cs b/grapher/Form1.cs
index e0953eb..3807d2a 100644
--- a/grapher/Form1.cs
+++ b/grapher/Form1.cs
@@ -8,9 +8,51 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using System.Runtime.InteropServices;
namespace grapher
{
+ public enum accel_mode
+ {
+ linear=1, classic, natural, logarithmic, sigmoid, power, noaccel
+ }
+
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
+ public struct vec2d
+ {
+ public double x;
+ public double y;
+ }
+
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
+ public struct accel_args
+ {
+ public double offset;
+ public double accel;
+ public double limit;
+ public double exponent;
+ public double midpoint;
+ public double power_scale;
+ public vec2d weight;
+ }
+
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
+ public struct accel_fn_args
+ {
+ public accel_args acc_args;
+ public int accel_mode;
+ public double time_min;
+ public vec2d cap;
+ }
+
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
+ public struct modifier_args
+ {
+ public double degrees;
+ public vec2d sens;
+ public accel_fn_args acc_fn_args;
+ }
+
public partial class RawAcceleration : Form
{
public struct MagnitudeData
@@ -27,8 +69,31 @@ namespace grapher
public RawAcceleration()
{
InitializeComponent();
+ modifier_args args;
+
+ args.degrees = 0;
+ args.sens.x = 1;
+ args.sens.y = 1;
+ args.acc_fn_args.acc_args.offset = 0;
+ args.acc_fn_args.acc_args.accel = 0.01;
+ args.acc_fn_args.acc_args.limit = 2;
+ args.acc_fn_args.acc_args.exponent = 1;
+ args.acc_fn_args.acc_args.midpoint = 0;
+ args.acc_fn_args.acc_args.power_scale = 1;
+ args.acc_fn_args.acc_args.weight.x = 1;
+ args.acc_fn_args.acc_args.weight.y = 1;
+ args.acc_fn_args.accel_mode = (int)accel_mode.natural;
+ args.acc_fn_args.time_min = 0.4;
+ args.acc_fn_args.cap.x = 0;
+ args.acc_fn_args.cap.y = 0;
+
+ IntPtr args_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(args));
+ Marshal.StructureToPtr(args, args_ptr, false);
+
+ ManagedAcceleration = new ManagedAccel(args_ptr);
+
+ Marshal.FreeHGlobal(args_ptr);
- ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15);
Sensitivity = new OptionXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1, sensitivityLabel, "Sensitivity");
Rotation = new Option(rotationBox, this, 0, rotationLabel, "Rotation");
Weight = new OptionXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1, weightLabel, "Weight");
@@ -44,10 +109,17 @@ namespace grapher
accelTypeDrop,
new Option[]
{
+ Offset,
Acceleration,
LimitOrExponent,
Midpoint,
- });
+ },
+ new OptionXY[]
+ {
+ Weight,
+ Cap,
+ },
+ writeButton);
UpdateGraph();
diff --git a/grapher/Layouts/ClassicLayout.cs b/grapher/Layouts/ClassicLayout.cs
index a8fc2bd..093f7fa 100644
--- a/grapher/Layouts/ClassicLayout.cs
+++ b/grapher/Layouts/ClassicLayout.cs
@@ -9,11 +9,12 @@ namespace grapher.Layouts
public class ClassicLayout : LayoutBase
{
public ClassicLayout()
+ : base()
{
Name = "Classic";
Index = 2;
- Show = new bool[] { true, true, false };
- OptionNames = new string[] { Acceleration, Exponent, string.Empty };
+ ShowOptions = new bool[] { true, true, true, false };
+ OptionNames = new string[] { Offset, Acceleration, Exponent, string.Empty };
}
}
}
diff --git a/grapher/Layouts/DefaultLayout.cs b/grapher/Layouts/DefaultLayout.cs
index 2ad3c0e..095afdf 100644
--- a/grapher/Layouts/DefaultLayout.cs
+++ b/grapher/Layouts/DefaultLayout.cs
@@ -10,11 +10,13 @@ namespace grapher.Layouts
public class DefaultLayout : LayoutBase
{
public DefaultLayout()
+ : base()
{
- Name = "Off";
+ Name = "Default";
Index = 0;
- Show = new bool[] { true, true, true };
- OptionNames = new string[] { Acceleration, $"{Limit}\\{Exponent}", Midpoint };
+ ShowOptions = new bool[] { true, true, true, true };
+ OptionNames = new string[] { Offset, Acceleration, $"{Limit}\\{Exponent}", Midpoint };
+ ButtonEnabled = false;
}
}
}
diff --git a/grapher/Layouts/LayoutBase.cs b/grapher/Layouts/LayoutBase.cs
index 9c60008..a4d0827 100644
--- a/grapher/Layouts/LayoutBase.cs
+++ b/grapher/Layouts/LayoutBase.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Windows.Forms;
namespace grapher.Layouts
{
@@ -13,11 +14,14 @@ namespace grapher.Layouts
public const string Exponent = "Exponent";
public const string Limit = "Limit";
public const string Midpoint = "Midpoint";
+ public const string Offset = "Offset";
public LayoutBase()
{
- Show = new bool[] { false, false, false };
- OptionNames = new string[] { string.Empty, string.Empty, string.Empty };
+ ShowOptions = new bool[] { false, false, false, false };
+ ShowOptionsXY = new bool[] { true, true };
+ OptionNames = new string[] { string.Empty, string.Empty, string.Empty, string.Empty };
+ ButtonEnabled = true;
}
/// <summary>
@@ -28,16 +32,20 @@ namespace grapher.Layouts
public string Name { get; internal set; }
- internal bool[] Show { get; set; }
+ internal bool[] ShowOptions { get; set; }
+
+ internal bool[] ShowOptionsXY { get; set; }
internal string[] OptionNames { get; set; }
- public void Layout(Option[] options)
+ internal bool ButtonEnabled { get; set; }
+
+ public void Layout(Option[] options, OptionXY[] optionsXY, Button button)
{
// Relies on AccelOptions to keep lengths correct.
for (int i = 0; i< options.Length; i++)
{
- if (Show[i])
+ if (ShowOptions[i])
{
options[i].Show(OptionNames[i]);
}
@@ -47,6 +55,20 @@ namespace grapher.Layouts
}
}
+ // Relies on AccelOptions to keep lengths correct.
+ for (int i = 0; i< optionsXY.Length; i++)
+ {
+ if (ShowOptionsXY[i])
+ {
+ optionsXY[i].Show();
+ }
+ else
+ {
+ optionsXY[i].Hide();
+ }
+ }
+
+ button.Enabled = ButtonEnabled;
}
}
}
diff --git a/grapher/Layouts/LinearLayout.cs b/grapher/Layouts/LinearLayout.cs
index b500b6b..2a0358e 100644
--- a/grapher/Layouts/LinearLayout.cs
+++ b/grapher/Layouts/LinearLayout.cs
@@ -9,11 +9,12 @@ namespace grapher.Layouts
public class LinearLayout : LayoutBase
{
public LinearLayout()
+ : base()
{
Name = "Linear";
Index = 1;
- Show = new bool[] { true, false, false };
- OptionNames = new string[] { Acceleration, string.Empty, string.Empty };
+ ShowOptions = new bool[] { true, true, false, false };
+ OptionNames = new string[] { Offset, Acceleration, string.Empty, string.Empty };
}
}
}
diff --git a/grapher/Layouts/LogLayout.cs b/grapher/Layouts/LogLayout.cs
index 7c7fd9e..ae1a8f5 100644
--- a/grapher/Layouts/LogLayout.cs
+++ b/grapher/Layouts/LogLayout.cs
@@ -9,11 +9,12 @@ namespace grapher.Layouts
public class LogLayout : LayoutBase
{
public LogLayout()
+ : base()
{
Name = "Logarithmic";
Index = 4;
- Show = new bool[] { true, false, false };
- OptionNames = new string[] { Acceleration, string.Empty, string.Empty };
+ ShowOptions = new bool[] { true, true, false, false };
+ OptionNames = new string[] { Offset, Acceleration, string.Empty, string.Empty };
}
}
}
diff --git a/grapher/Layouts/NaturalLayout.cs b/grapher/Layouts/NaturalLayout.cs
index 180a7c0..743135c 100644
--- a/grapher/Layouts/NaturalLayout.cs
+++ b/grapher/Layouts/NaturalLayout.cs
@@ -9,11 +9,12 @@ namespace grapher.Layouts
public class NaturalLayout : LayoutBase
{
public NaturalLayout()
+ : base()
{
Name = "Natural";
Index = 3;
- Show = new bool[] { true, true, false };
- OptionNames = new string[] { Acceleration, Limit, string.Empty };
+ ShowOptions = new bool[] { true, true, true, false };
+ OptionNames = new string[] { Offset, Acceleration, Limit, string.Empty };
}
}
}
diff --git a/grapher/Layouts/OffLayout.cs b/grapher/Layouts/OffLayout.cs
new file mode 100644
index 0000000..cecba05
--- /dev/null
+++ b/grapher/Layouts/OffLayout.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace grapher.Layouts
+{
+ public class OffLayout : LayoutBase
+ {
+ public OffLayout()
+ : base()
+ {
+ Name = "Off";
+ Index = 7;
+ ShowOptions = new bool[] { false, false, false, false };
+ OptionNames = new string[] { string.Empty, string.Empty, string.Empty, string.Empty };
+ ShowOptionsXY = new bool[] { false, false };
+ ButtonEnabled = true;
+ }
+ }
+}
diff --git a/grapher/Layouts/PowerLayout.cs b/grapher/Layouts/PowerLayout.cs
index 6d4f5d7..da02cf5 100644
--- a/grapher/Layouts/PowerLayout.cs
+++ b/grapher/Layouts/PowerLayout.cs
@@ -9,11 +9,12 @@ namespace grapher.Layouts
public class PowerLayout : LayoutBase
{
public PowerLayout()
+ : base()
{
Name = "Power";
Index = 6;
- Show = new bool[] { true, true, false };
- OptionNames = new string[] { Scale, Exponent, string.Empty };
+ ShowOptions = new bool[] { true, true, true, false };
+ OptionNames = new string[] { Offset, Scale, Exponent, string.Empty };
}
}
}
diff --git a/grapher/Layouts/SigmoidLayout.cs b/grapher/Layouts/SigmoidLayout.cs
index 88d6c61..0dec3bf 100644
--- a/grapher/Layouts/SigmoidLayout.cs
+++ b/grapher/Layouts/SigmoidLayout.cs
@@ -9,11 +9,12 @@ namespace grapher.Layouts
public class SigmoidLayout : LayoutBase
{
public SigmoidLayout()
+ : base()
{
Name = "Sigmoid";
Index = 5;
- Show = new bool[] { true, true, true };
- OptionNames = new string[] { Acceleration, Limit, Midpoint };
+ ShowOptions = new bool[] { true, true, true, true };
+ OptionNames = new string[] { Offset, Acceleration, Limit, Midpoint };
}
}
}
diff --git a/grapher/Option.cs b/grapher/Option.cs
index 8e3ecdf..eb5105e 100644
--- a/grapher/Option.cs
+++ b/grapher/Option.cs
@@ -52,8 +52,7 @@ namespace grapher
{
SetName(name);
- Field.Box.Show();
- Label.Show();
+ Show();
}
}
}
diff --git a/grapher/OptionXY.cs b/grapher/OptionXY.cs
index de7fad9..1fdf244 100644
--- a/grapher/OptionXY.cs
+++ b/grapher/OptionXY.cs
@@ -59,6 +59,7 @@ namespace grapher
{
Fields.XField.Box.Hide();
Fields.YField.Box.Hide();
+ Fields.LockCheckBox.Hide();
Label.Hide();
}
@@ -66,6 +67,7 @@ namespace grapher
{
Fields.XField.Box.Show();
Fields.YField.Box.Show();
+ Fields.LockCheckBox.Show();
Label.Show();
}
@@ -73,9 +75,7 @@ namespace grapher
{
SetName(name);
- Fields.XField.Box.Show();
- Fields.YField.Box.Show();
- Label.Show();
+ Show();
}
}
diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj
index 207de79..bd86a0c 100644
--- a/grapher/grapher.csproj
+++ b/grapher/grapher.csproj
@@ -47,7 +47,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="AccelerationSettings.cs" />
<Compile Include="AccelOptions.cs" />
<Compile Include="Field.cs" />
<Compile Include="FieldXY.cs" />
@@ -63,6 +62,7 @@
<Compile Include="Layouts\LinearLayout.cs" />
<Compile Include="Layouts\LogLayout.cs" />
<Compile Include="Layouts\NaturalLayout.cs" />
+ <Compile Include="Layouts\OffLayout.cs" />
<Compile Include="Layouts\PowerLayout.cs" />
<Compile Include="Layouts\SigmoidLayout.cs" />
<Compile Include="Option.cs" />
diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp
index de2916c..ceee1a1 100644
--- a/wrapper/wrapper.cpp
+++ b/wrapper/wrapper.cpp
@@ -6,7 +6,10 @@ using namespace System;
Tuple<double, double>^ ManagedAccel::Accelerate(int x, int y, double time)
{
- vec2d input_vec2d = {x, y};
+ vec2d input_vec2d = {
+ (double)x,
+ (double)y
+ };
vec2d output = (*modifier_instance).modify_with_accel(input_vec2d, (milliseconds)time);
return gcnew Tuple<double, double>(output.x, output.y);
@@ -33,13 +36,14 @@ void ManagedAccel::UpdateAccel(
args.degrees = rotation;
args.sens.x = sensitivityX;
args.sens.y = sensitivityY;
- args.acc_fn_args.weight.x = weightX;
- args.acc_fn_args.weight.y = weightY;
+ args.acc_fn_args.acc_args.weight.x = weightX;
+ args.acc_fn_args.acc_args.weight.y = weightY;
args.acc_fn_args.cap.x = capX;
args.acc_fn_args.cap.y = capY;
args.acc_fn_args.acc_args.offset = offset;
args.acc_fn_args.acc_args.accel = accel;
- args.acc_fn_args.acc_args.lim_exp = lim_exp;
+ args.acc_fn_args.acc_args.limit = lim_exp;
+ args.acc_fn_args.acc_args.exponent = lim_exp;
args.acc_fn_args.acc_args.midpoint = midpoint;
modifier_instance = new mouse_modifier(args);
diff --git a/wrapper/wrapper.hpp b/wrapper/wrapper.hpp
index ff2720c..870aca7 100644
--- a/wrapper/wrapper.hpp
+++ b/wrapper/wrapper.hpp
@@ -1,11 +1,17 @@
#pragma once
-#include "..\common\error.hpp"
#include "wrapper_writer.hpp"
+#include "..\common\rawaccel.hpp";
+#include "..\common\accel-error.hpp";
#include <iostream>
using namespace rawaccel;
using namespace System;
+
+public value struct ArgsWrapper {
+ int a;
+};
+
public ref class ManagedAccel
{
protected:
@@ -15,18 +21,12 @@ public:
ManagedAccel(mouse_modifier* accel)
: modifier_instance(accel)
{
+ driverWriter = new writer();
}
- ManagedAccel(int mode, double offset, double accel, double lim_exp, double midpoint)
+ ManagedAccel(System::IntPtr args)
{
- modifier_args args{};
- args.acc_fn_args.acc_args.accel = accel;
- args.acc_fn_args.acc_args.lim_exp = lim_exp;
- args.acc_fn_args.acc_args.midpoint = midpoint;
- args.acc_fn_args.accel_mode = mode;
- args.acc_fn_args.acc_args.offset = offset;
-
- modifier_instance = new mouse_modifier(args);
+ modifier_instance = new mouse_modifier(*reinterpret_cast<modifier_args*>(args.ToPointer()));
driverWriter = new writer();
}