Skip to content

Commit aaac0e4

Browse files
authored
Merge pull request #66 from a1xd/1.4-tweaks
add angle snapping, update signed/
2 parents 5b64790 + c50b200 commit aaac0e4

File tree

12 files changed

+72
-27
lines changed

12 files changed

+72
-27
lines changed

common/rawaccel-settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace rawaccel {
1919

2020
struct settings {
2121
double degrees_rotation = 0;
22+
double degrees_snap = 0;
2223
bool combine_mags = true;
2324
vec2<accel_mode> modes = { accel_mode::noaccel, accel_mode::noaccel };
2425
vec2<accel_args> argsv;

common/rawaccel-version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#define RA_VER_MINOR 4
55
#define RA_VER_PATCH 0
66

7-
#define RA_MIN_OS "Win7"
7+
#define RA_OS "Win7+"
88

99
#define M_STR_HELPER(x) #x
1010
#define M_STR(x) M_STR_HELPER(x)

common/rawaccel.hpp

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@ namespace rawaccel {
4242
rotator() = default;
4343
};
4444

45+
struct snapper {
46+
double threshold = 0;
47+
48+
inline vec2d apply(const vec2d& input) const {
49+
if (input.x != 0 && input.y != 0) {
50+
double angle = fabs(atan(input.y / input.x));
51+
auto mag = [&] { return sqrtsd(input.x * input.x + input.y * input.y); };
52+
53+
if (angle > M_PI_2 - threshold) return { 0, _copysign(mag(), input.y) };
54+
if (angle < threshold) return { _copysign(mag(), input.x), 0 };
55+
}
56+
57+
return input;
58+
}
59+
60+
snapper(double degrees) : threshold(minsd(fabs(degrees), 45) * M_PI / 180) {}
61+
62+
snapper() = default;
63+
};
64+
4565
/// <summary> Struct to hold clamp (min and max) details for acceleration application </summary>
4666
struct accel_scale_clamp {
4767
double lo = 0;
@@ -232,7 +252,7 @@ namespace rawaccel {
232252
double sigma_x = 1.0;
233253
double sigma_y = 1.0;
234254

235-
weighted_distance(domain_args args)
255+
weighted_distance(const domain_args& args)
236256
{
237257
sigma_x = args.domain_weights.x;
238258
sigma_y = args.domain_weights.y;
@@ -250,19 +270,18 @@ namespace rawaccel {
250270
}
251271
}
252272

253-
double calculate(double x, double y)
273+
inline double calculate(double x, double y)
254274
{
255275
double abs_x = fabs(x);
256276
double abs_y = fabs(y);
257277

258-
if (lp_norm_infinity)
259-
{
260-
return abs_x > abs_y ? abs_x : abs_y;
261-
}
278+
if (lp_norm_infinity) return maxsd(abs_x, abs_y);
262279

263280
double x_scaled = abs_x * sigma_x;
264281
double y_scaled = abs_y * sigma_y;
265-
return pow(pow(x_scaled, p) + pow(y_scaled, p), p_inverse);
282+
283+
if (p == 2) return sqrtsd(x_scaled * x_scaled + y_scaled * y_scaled);
284+
else return pow(pow(x_scaled, p) + pow(y_scaled, p), p_inverse);
266285
}
267286

268287
weighted_distance() = default;
@@ -273,27 +292,20 @@ namespace rawaccel {
273292
double start = 1.0;
274293
bool should_apply = false;
275294

276-
direction_weight(vec2d thetas)
295+
direction_weight(const vec2d& thetas)
277296
{
278297
diff = thetas.y - thetas.x;
279298
start = thetas.x;
280299

281-
if (diff != 0)
282-
{
283-
should_apply = true;
284-
}
285-
else
286-
{
287-
should_apply = false;
288-
}
300+
should_apply = diff != 0;
289301
}
290302

291303
inline double atan_scale(double x, double y)
292304
{
293305
return M_2_PI * atan2(fabs(y), fabs(x));
294306
}
295307

296-
double apply(double x, double y)
308+
inline double apply(double x, double y)
297309
{
298310
return atan_scale(x, y) * diff + start;
299311
}
@@ -304,9 +316,11 @@ namespace rawaccel {
304316
/// <summary> Struct to hold variables and methods for modifying mouse input </summary>
305317
struct mouse_modifier {
306318
bool apply_rotate = false;
319+
bool apply_snap = false;
307320
bool apply_accel = false;
308321
bool combine_magnitudes = true;
309322
rotator rotate;
323+
snapper snap;
310324
weighted_distance distance;
311325
direction_weight directional;
312326
vec2<accelerator> accels;
@@ -321,6 +335,11 @@ namespace rawaccel {
321335
apply_rotate = true;
322336
}
323337

338+
if (args.degrees_snap != 0) {
339+
snap = snapper(args.degrees_snap);
340+
apply_snap = true;
341+
}
342+
324343
if (args.sens.x != 0) sensitivity.x = args.sens.x;
325344
if (args.sens.y != 0) sensitivity.y = args.sens.y;
326345

@@ -344,6 +363,7 @@ namespace rawaccel {
344363

345364
void modify(vec2d& movement, milliseconds time) {
346365
apply_rotation(movement);
366+
apply_angle_snap(movement);
347367
apply_acceleration(movement, [=] { return time; });
348368
apply_sensitivity(movement);
349369
}
@@ -352,6 +372,10 @@ namespace rawaccel {
352372
if (apply_rotate) movement = rotate.apply(movement);
353373
}
354374

375+
inline void apply_angle_snap(vec2d& movement) {
376+
if (apply_snap) movement = snap.apply(movement);
377+
}
378+
355379
template <typename TimeSupplier>
356380
inline void apply_acceleration(vec2d& movement, TimeSupplier time_supp) {
357381
if (apply_accel) {

driver/driver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Routine Description:
7474
};
7575

7676
global.modifier.apply_rotation(input);
77+
global.modifier.apply_angle_snap(input);
7778

7879
if (enable_accel) {
7980
auto time_supplier = [=] {

grapher/Form1.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public RawAcceleration()
160160
DirectionalityRangeLabel,
161161
RangeActiveValueX,
162162
RangeActiveValueY);
163+
164+
ResizeAndCenter();
163165
}
164166

165167
#endregion Constructor
@@ -191,18 +193,25 @@ public void ResetAutoScroll()
191193
chartsPanel.AutoScrollPosition = Constants.Origin;
192194
}
193195

194-
public void DoResize()
196+
public void ResizeAndCenter()
195197
{
196198
ResetAutoScroll();
197199

198-
var workingArea = Screen.PrimaryScreen.WorkingArea;
200+
var workingArea = Screen.FromControl(this).WorkingArea;
199201
var chartsPreferredSize = chartsPanel.GetPreferredSize(Constants.MaxSize);
200202

201203
Size = new Size
202204
{
203-
Width = Math.Min(workingArea.Width - Location.X, optionsPanel.Size.Width + chartsPreferredSize.Width),
204-
Height = Math.Min(workingArea.Height - Location.Y, chartsPreferredSize.Height + 48)
205+
Width = Math.Min(workingArea.Width, optionsPanel.Size.Width + chartsPreferredSize.Width),
206+
Height = Math.Min(workingArea.Height, chartsPreferredSize.Height + 48)
205207
};
208+
209+
Location = new Point
210+
{
211+
X = workingArea.X + (workingArea.Width - Size.Width) / 2,
212+
Y = workingArea.Y + (workingArea.Height - Size.Height) / 2
213+
};
214+
206215
}
207216

208217
#endregion Method

grapher/Models/AccelGUI.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public AccelGUI(
7171
}
7272

7373
SetupButtons();
74-
AccelForm.DoResize();
7574

7675
// TODO: The below removes an overlapping form from the anisotropy panel.
7776
// Figure out why and remove the overlap and below.
@@ -144,6 +143,7 @@ public void UpdateActiveSettingsFromFields()
144143
var settings = new DriverSettings
145144
{
146145
rotation = ApplyOptions.Rotation.Field.Data,
146+
snap = driverSettings.snap,
147147
sensitivity = new Vec2<double>
148148
{
149149
x = ApplyOptions.Sensitivity.Fields.X,
@@ -229,7 +229,7 @@ private void SetButtonDefaults()
229229
ToggleButton.Checked = LastToggleChecked;
230230

231231
ToggleButton.Font = DefaultButtonFont;
232-
ToggleButton.Text = ToggleButton.Checked ? "Enabled" : "Disabled";
232+
ToggleButton.Text = ToggleButton.Checked ? "Disable" : "Enable";
233233
ToggleButton.Update();
234234

235235
WriteButton.Font = DefaultButtonFont;

grapher/Models/Serialized/RawAccelSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public static bool IsDefaultEquivalent(DriverSettings accelSettings)
131131
accelSettings.directionalMultipliers.x <= 0 &&
132132
accelSettings.directionalMultipliers.y <= 0 &&
133133
accelSettings.rotation == 0 &&
134+
accelSettings.snap == 0 &&
134135
accelSettings.modes.x == AccelMode.noaccel &&
135136
wholeOrNoY;
136137
}

installer/installer.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ BEGIN
7070
BEGIN
7171
BLOCK "040904b0"
7272
BEGIN
73-
VALUE "FileDescription", "Raw Accel installer (" RA_MIN_OS ")"
73+
VALUE "FileDescription", "Raw Accel installer (" RA_OS ")"
7474
VALUE "FileVersion", RA_VER_STRING
7575
VALUE "OriginalFilename", "installer.exe"
7676
VALUE "ProductName", "Raw Accel"

signed/driver/rawaccel.sys

8.06 KB
Binary file not shown.

signed/installer.exe

512 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)