From: Joe Wreschnig Date: Wed, 6 Mar 2013 10:44:33 +0000 (+0100) Subject: Change NJInputAnalog so magnitudes of subactions are always positive (e.g. -1 magnitu... X-Git-Tag: version-1.0~31 X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=commitdiff_plain;h=4f449987e5296701d1da9963789c4817935ab6c8;hp=35be7b3d4cc4b32ab3488f6585b7dbac3d42b5cc Change NJInputAnalog so magnitudes of subactions are always positive (e.g. -1 magnitude is 1 on low 0 on high, rather than -1 on low and high). Change NSInputs so buttons have a magnitude 1 when pressed, allowing them to also control the mouse. Allow mouse movement speed control. --- diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index 402d345..bd4f12a 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -27,6 +27,8 @@ NSScroller NSSegmentedCell NSSegmentedControl + NSSlider + NSSliderCell NSSplitView NSTableColumn NSTableView @@ -353,12 +355,9 @@ Enabled - + 268 {{7, 14}, {36, 25}} - - - _NS:9 YES @@ -404,12 +403,9 @@ Mapping Selector - + 268 {{0, 14}, {140, 25}} - - - _NS:9 YES @@ -662,38 +658,74 @@ 256 + + + 268 + {{228, 120}, {176, 12}} + + + + _NS:9 + YES + + -2080374784 + 262144 + + _NS:9 + + 20 + 0.0 + 4 + 0.0 + 0 + 1 + NO + NO + + NO + 265 - {{227, 123}, {180, 24}} + {{226, 132}, {179, 15}} - + _NS:9 YES 67108864 - 0 - + 262144 + LucidaGrande - 13 - 16 + 9 + 3614 _NS:9 - 87 - Horizontal + 43 + ← YES 0 - 86 - Vertical + 43 + → 1 0 + + 42 + ↑ + 0 + + + 42 + ↓ + 0 + 1 @@ -702,7 +734,7 @@ 265 - {{227, 55}, {180, 24}} + {{226, 55}, {180, 24}} @@ -711,7 +743,11 @@ 67108864 0 - + + LucidaGrande + 13 + 16 + _NS:9 @@ -735,7 +771,7 @@ 265 - {{227, 89}, {180, 24}} + {{226, 89}, {180, 24}} @@ -768,7 +804,7 @@ 265 - {{229, 190}, {176, 24}} + {{228, 190}, {176, 24}} @@ -778,7 +814,7 @@ 265 - {{226, 156}, {182, 26}} + {{225, 156}, {182, 26}} @@ -811,7 +847,7 @@ 268 - {{20, 16}, {201, 236}} + {{20, 16}, {200, 236}} @@ -925,7 +961,7 @@ 75 - {201, 32} + {200, 32} {4, 2} 1353195520 NSActionCell @@ -1165,11 +1201,7 @@ -2080374784 168034304 - - LucidaGrande - 9 - 3614 - + _NS:22 1221349376 @@ -1650,6 +1682,22 @@ 828 + + + mouseSpeedChanged: + + + + 885 + + + + mouseSpeedSlider + + + + 886 + keyDelegate @@ -2063,6 +2111,7 @@ + Output Editor Pane @@ -2358,6 +2407,19 @@ + + 883 + + + + + + + + 884 + + + @@ -2453,7 +2515,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2493,13 +2555,23 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Maximum mouse speed + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - 880 + 886 @@ -2674,6 +2746,7 @@ id id + id id id @@ -2686,6 +2759,10 @@ mdirChanged: id + + mouseSpeedChanged: + id + radioChanged: id @@ -2702,6 +2779,7 @@ NJMappingsController NSSegmentedControl NSSegmentedControl + NSSlider NSMatrix NSSegmentedControl NSTextField @@ -2731,6 +2809,10 @@ mouseDirSelect NSSegmentedControl + + mouseSpeedSlider + NSSlider + radioButtons NSMatrix diff --git a/NJDeviceController.m b/NJDeviceController.m index 7993842..d553d7d 100644 --- a/NJDeviceController.m +++ b/NJDeviceController.m @@ -64,9 +64,9 @@ NSArray *children = mainInput.children ? mainInput.children : mainInput ? @[mainInput] : @[]; for (NJInput *subInput in children) { NJOutput *output = mappingsController.currentMapping[subInput]; - output.magnitude = mainInput.magnitude; + output.magnitude = subInput.magnitude; output.running = subInput.active; - if (output.running && output.isContinuous) + if ((output.running || output.magnitude) && output.isContinuous) [self addRunningOutput:output]; } } diff --git a/NJInput.h b/NJInput.h index e2c8404..380e858 100644 --- a/NJInput.h +++ b/NJInput.h @@ -15,7 +15,7 @@ @property (nonatomic, weak) id base; @property (nonatomic, copy) NSString *name; @property (nonatomic, assign) BOOL active; -@property (nonatomic, readonly) float magnitude; +@property (nonatomic, assign) float magnitude; @property (readonly) NSString *uid; - (id)initWithName:(NSString *)newName base:(id )newBase; diff --git a/NJInput.m b/NJInput.m index cccda29..077dac8 100644 --- a/NJInput.m +++ b/NJInput.m @@ -29,8 +29,4 @@ [self doesNotRecognizeSelector:_cmd]; } -- (float)magnitude { - return 0.f; -} - @end diff --git a/NJInputAnalog.m b/NJInputAnalog.m index 98ed018..7b4b15a 100644 --- a/NJInputAnalog.m +++ b/NJInputAnalog.m @@ -42,6 +42,8 @@ static float normalize(long p, long min, long max) { - (void)notifyEvent:(IOHIDValueRef)value { magnitude = normalize(IOHIDValueGetIntegerValue(value), rawMin, rawMax); + [self.children[0] setMagnitude:fabsf(MIN(magnitude, 0))]; + [self.children[1] setMagnitude:fabsf(MAX(magnitude, 0))]; [self.children[0] setActive:magnitude < -DEAD_ZONE]; [self.children[1] setActive:magnitude > DEAD_ZONE]; } diff --git a/NJInputButton.m b/NJInputButton.m index c500276..0c3b0ce 100644 --- a/NJInputButton.m +++ b/NJInputButton.m @@ -28,6 +28,7 @@ - (void)notifyEvent:(IOHIDValueRef)value { self.active = IOHIDValueGetIntegerValue(value) == _max; + self.magnitude = IOHIDValueGetIntegerValue(value) / (float)_max; } @end diff --git a/NJInputHat.m b/NJInputHat.m index b7d0161..409ae07 100644 --- a/NJInputHat.m +++ b/NJInputHat.m @@ -89,8 +89,11 @@ static BOOL active_fourway[20] = { size++; } BOOL *activechildren = (size == 8) ? active_eightway : active_fourway; - for (int i = 0; i < 4; i++) - [self.children[i] setActive:activechildren[parsed * 4 + i]]; + for (int i = 0; i < 4; i++) { + BOOL active = activechildren[parsed * 4 + i]; + [self.children[i] setActive:active]; + [self.children[i] setMagnitude:active]; + } } @end diff --git a/NJOutputController.h b/NJOutputController.h index 0c6a859..de8b417 100644 --- a/NJOutputController.h +++ b/NJOutputController.h @@ -17,6 +17,7 @@ IBOutlet NJKeyInputField *keyInput; IBOutlet NSMatrix *radioButtons; IBOutlet NSSegmentedControl *mouseDirSelect; + IBOutlet NSSlider *mouseSpeedSlider; IBOutlet NSSegmentedControl *mouseBtnSelect; IBOutlet NSSegmentedControl *scrollDirSelect; IBOutlet NSTextField *title; @@ -32,6 +33,8 @@ - (IBAction)mdirChanged:(id)sender; - (IBAction)mbtnChanged:(id)sender; - (IBAction)sdirChanged:(id)sender; +- (IBAction)mouseSpeedChanged:(id)sender; + - (void)focusKey; @end diff --git a/NJOutputController.m b/NJOutputController.m index 0c301ff..e60a83e 100644 --- a/NJOutputController.m +++ b/NJOutputController.m @@ -54,9 +54,14 @@ if (row != 3) { mouseDirSelect.selectedSegment = -1; + mouseSpeedSlider.floatValue = mouseSpeedSlider.minValue; [mouseDirSelect resignIfFirstResponder]; - } else if (mouseDirSelect.selectedSegment == -1) - mouseDirSelect.selectedSegment = 0; + } else { + if (mouseDirSelect.selectedSegment == -1) + mouseDirSelect.selectedSegment = 0; + if (!mouseSpeedSlider.floatValue) + mouseSpeedSlider.floatValue = 4; + } if (row != 4) { mouseBtnSelect.selectedSegment = -1; @@ -101,6 +106,12 @@ [self commit]; } +- (void)mouseSpeedChanged:(NSSlider *)sender { + [radioButtons selectCellAtRow:3 column:0]; + [sender.window makeFirstResponder:sender]; + [self commit]; +} + - (void)mbtnChanged:(NSView *)sender { [radioButtons selectCellAtRow:4 column:0]; [sender.window makeFirstResponder:sender]; @@ -138,6 +149,7 @@ case 3: { NJOutputMouseMove *mm = [[NJOutputMouseMove alloc] init]; mm.axis = mouseDirSelect.selectedSegment; + mm.speed = mouseSpeedSlider.floatValue; return mm; } case 4: { @@ -174,6 +186,7 @@ [keyInput setEnabled:enabled]; [mappingPopup setEnabled:enabled]; [mouseDirSelect setEnabled:enabled]; + [mouseSpeedSlider setEnabled:enabled]; [mouseBtnSelect setEnabled:enabled]; [scrollDirSelect setEnabled:enabled]; } @@ -203,7 +216,8 @@ } else if ([output isKindOfClass:NJOutputMouseMove.class]) { [radioButtons selectCellAtRow:3 column:0]; - [mouseDirSelect setSelectedSegment:[(NJOutputMouseMove *)output axis]]; + mouseDirSelect.selectedSegment = [(NJOutputMouseMove *)output axis]; + mouseSpeedSlider.floatValue = [(NJOutputMouseMove *)output speed]; } else if ([output isKindOfClass:NJOutputMouseButton.class]) { [radioButtons selectCellAtRow:4 column:0]; diff --git a/NJOutputMouseMove.h b/NJOutputMouseMove.h index 21db416..428416f 100644 --- a/NJOutputMouseMove.h +++ b/NJOutputMouseMove.h @@ -10,5 +10,6 @@ @interface NJOutputMouseMove : NJOutput @property (nonatomic, assign) int axis; +@property (nonatomic, assign) float speed; @end diff --git a/NJOutputMouseMove.m b/NJOutputMouseMove.m index 8efb8cb..bca5d2d 100644 --- a/NJOutputMouseMove.m +++ b/NJOutputMouseMove.m @@ -9,9 +9,7 @@ #import "NJDeviceController.h" -@implementation NJOutputMouseMove { - int sign; -} +@implementation NJOutputMouseMove -(BOOL) isContinuous { return YES; @@ -22,41 +20,43 @@ } - (NSDictionary *)serialize { - return @{ @"type": self.class.serializationCode, @"axis": @(_axis) }; + return @{ @"type": self.class.serializationCode, + @"axis": @(_axis), + @"speed": @(_speed), + }; } + (NJOutput *)outputDeserialize:(NSDictionary *)serialization withMappings:(NSArray *)mappings { NJOutputMouseMove *output = [[NJOutputMouseMove alloc] init]; output.axis = [serialization[@"axis"] intValue]; + output.speed = [serialization[@"speed"] floatValue]; + if (!output.speed) + output.speed = 4; return output; } - (BOOL)update:(NJDeviceController *)jc { - if (fabsf(self.magnitude) < 0.01) { - sign = 0; + if (self.magnitude < 0.05) return NO; // dead zone - } - - // If the input crossed over High/Low, this output is done. - if (!sign) - sign = self.magnitude < 0 ? -1 : 1; - else if (sign / self.magnitude < 0) { - sign = 0; - return NO; - } CGFloat height = NSScreen.mainScreen.frame.size.height; - // TODO - float speed = 4.f; - if (jc.frontWindowOnly) - speed = 12.f; float dx = 0.f, dy = 0.f; - if (_axis == 0) - dx = self.magnitude * speed; - else - dy = self.magnitude * speed; + switch (_axis) { + case 0: + dx = -self.magnitude * _speed; + break; + case 1: + dx = self.magnitude * _speed; + break; + case 2: + dy = -self.magnitude * _speed; + break; + case 3: + dy = self.magnitude * _speed; + break; + } NSPoint mouseLoc = jc.mouseLoc; mouseLoc.x += dx; mouseLoc.y -= dy;