Add support for horizontal directions to scrolling. Rework UI to make the relationshi...
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Sat, 9 Mar 2013 19:48:40 +0000 (20:48 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Sat, 9 Mar 2013 19:48:40 +0000 (20:48 +0100)
Classes/NJOutputController.h
Classes/NJOutputController.m
Classes/NJOutputMouseScroll.h
Classes/NJOutputMouseScroll.m
Info.plist
Resources/English.lproj/MainMenu.xib

index f8052e786c3d628af0ffa5b646fe2934ad307f19..6f4c8664c3987a74b33be742d304e88c4725fa7e 100644 (file)
@@ -25,6 +25,7 @@
     IBOutlet NSPopUpButton *mappingPopup;
     IBOutlet NJMappingsController *mappingsController;
     IBOutlet NJDeviceController *inputController;
+    IBOutlet NSButton *smoothCheck;
 }
 
 @property (assign) BOOL enabled;
@@ -36,6 +37,7 @@
 - (IBAction)sdirChanged:(id)sender;
 - (IBAction)mouseSpeedChanged:(id)sender;
 - (IBAction)scrollSpeedChanged:(id)sender;
+- (IBAction)scrollTypeChanged:(id)sender;
 
 - (void)focusKey;
 
index d022406fa6e6624210ec0eb8800a7add24c4aaa9..cbb48f7e1cab1a145ef98825de82ecd5ec470cbc 100644 (file)
     if (row != 5) {
         scrollDirSelect.selectedSegment = -1;
         scrollSpeedSlider.floatValue = scrollSpeedSlider.minValue;
+        smoothCheck.state = NSOffState;
         [scrollDirSelect resignIfFirstResponder];
+        [scrollSpeedSlider resignIfFirstResponder];
+        [smoothCheck resignIfFirstResponder];
     } else {
         if (scrollDirSelect.selectedSegment == -1)
             scrollDirSelect.selectedSegment = 0;
-        if (scrollDirSelect.selectedSegment < 2
-            && !scrollSpeedSlider.floatValue)
-            scrollSpeedSlider.floatValue = 15;
-        else if (scrollDirSelect.selectedSegment >= 2
-                 && scrollSpeedSlider.floatValue)
-            scrollSpeedSlider.floatValue = scrollSpeedSlider.minValue;
     }
         
 }
 
 - (void)sdirChanged:(NSView *)sender {
     [radioButtons selectCellAtRow:5 column:0];
-    if (scrollDirSelect.selectedSegment >= 2)
-        scrollSpeedSlider.floatValue = 0;
     [sender.window makeFirstResponder:sender];
     [self commit];
 }
 - (void)scrollSpeedChanged:(NSSlider *)sender {
     [radioButtons selectCellAtRow:5 column:0];
     [sender.window makeFirstResponder:sender];
-    if (!sender.floatValue && scrollDirSelect.selectedSegment < 2)
-        scrollDirSelect.selectedSegment += 2;
-    else if (sender.floatValue && scrollDirSelect.selectedSegment >= 2)
-        scrollDirSelect.selectedSegment -= 2;
+    [self commit];
+}
+
+- (IBAction)scrollTypeChanged:(NSButton *)sender {
+    [radioButtons selectCellAtRow:5 column:0];
+    [sender.window makeFirstResponder:sender];
+    if (sender.state == NSOnState) {
+        scrollSpeedSlider.floatValue = (scrollSpeedSlider.maxValue - scrollSpeedSlider.minValue) / 2;
+        [scrollSpeedSlider setEnabled:YES];
+    } else {
+        scrollSpeedSlider.floatValue = scrollSpeedSlider.minValue;
+        [scrollSpeedSlider setEnabled:NO];
+    }
     [self commit];
 }
 
         }
         case 5: {
             NJOutputMouseScroll *ms = [[NJOutputMouseScroll alloc] init];
-            ms.direction = (scrollDirSelect.selectedSegment & 1) ? 1 : -1;
-            ms.speed = scrollDirSelect.selectedSegment < 2
-                ? scrollSpeedSlider.floatValue
-                : 0.f;
+            ms.direction = [scrollDirSelect.cell tagForSegment:scrollDirSelect.selectedSegment];
+            ms.speed = scrollSpeedSlider.floatValue;
+            ms.smooth = smoothCheck.state == NSOnState;
             return ms;
         }
         default:
     [mouseSpeedSlider setEnabled:enabled];
     [mouseBtnSelect setEnabled:enabled];
     [scrollDirSelect setEnabled:enabled];
-    [scrollSpeedSlider setEnabled:enabled];
+    [smoothCheck setEnabled:enabled];
+    [scrollSpeedSlider setEnabled:enabled && smoothCheck.isEnabled];
 }
 
 - (void)loadOutput:(NJOutput *)output forInput:(NJInput *)input {
         [radioButtons selectCellAtRow:5 column:0];
         int direction = [(NJOutputMouseScroll *)output direction];
         float speed = [(NJOutputMouseScroll *)output speed];
-        scrollDirSelect.selectedSegment = (direction > 0) + !speed * 2;
+        BOOL smooth = [(NJOutputMouseScroll *)output smooth];
+        [scrollDirSelect selectSegmentWithTag:direction];
         scrollSpeedSlider.floatValue = speed;
+        smoothCheck.state = smooth ? NSOnState : NSOffState;
+        [scrollSpeedSlider setEnabled:smooth];
     } else {
         [radioButtons selectCellAtRow:self.enabled ? 0 : -1 column:0];
     }
index dd0444a332975dee66b06c2066b87bfaf902eabd..dac91440715eb17471e54d57b2f9ac5d9cf6823c 100644 (file)
@@ -11,5 +11,6 @@
 
 @property (nonatomic, assign) int direction;
 @property (nonatomic, assign) float speed;
+@property (nonatomic, assign) BOOL smooth;
 
 @end
index 99cec4a2f7724972e3a056b9a3ed97bc0790068f..b97a3e733547320afc7cf3ad3d043058d50a1106 100644 (file)
@@ -16,7 +16,8 @@
 - (NSDictionary *)serialize {
     return @{ @"type": self.class.serializationCode,
               @"direction": @(_direction),
-              @"speed": @(_speed)
+              @"speed": @(_speed),
+              @"smooth": @(_smooth),
               };
 }
 
     NJOutputMouseScroll *output = [[NJOutputMouseScroll alloc] init];
     output.direction = [serialization[@"direction"] intValue];
     output.speed = [serialization[@"speed"] floatValue];
+    output.smooth = [serialization[@"smooth"] boolValue];
     return output;
 }
 
 - (BOOL)isContinuous {
-    return !!self.speed;
+    return _smooth;
+}
+
+- (int)wheel:(int)n {
+    int amount =  abs(_direction) == n ? _direction / n : 0;
+    if (self.smooth)
+        amount *= _speed * self.magnitude;
+    return amount;
 }
 
 - (void)trigger {
-    if (!self.speed) {
+    if (!_smooth) {
         CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL,
                                                           kCGScrollEventUnitLine,
-                                                          1,
-                                                          _direction);
+                                                          2,
+                                                          [self wheel:1],
+                                                          [self wheel:2]);
         CGEventPost(kCGHIDEventTap, scroll);
         CFRelease(scroll);
     }
     if (self.magnitude < 0.05f)
         return NO; // dead zone
     
-    int amount = (int)(_speed * self.magnitude * _direction);
     CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL,
                                                       kCGScrollEventUnitPixel,
-                                                      1,
-                                                      amount);
+                                                      2,
+                                                      [self wheel:1],
+                                                      [self wheel:2]);
     CGEventPost(kCGHIDEventTap, scroll);
     CFRelease(scroll);
 
index 4ad3f4139613b93f7fec765ab5b8e4e744c02109..c38261382b1fa6c0ee83c308cc28cc4793fa16d7 100644 (file)
@@ -46,7 +46,7 @@
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
-       <string>69</string>
+       <string>77</string>
        <key>LSApplicationCategoryType</key>
        <string>public.app-category.utilities</string>
        <key>NSHumanReadableCopyright</key>
index 772132edf41daa28e535f390b6edd2815f8d102e..d6f1307775d9af30327ed861c59e4c85508379ed 100644 (file)
@@ -718,10 +718,42 @@ aW5nLg</string>
                                                                        </object>
                                                                        <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
                                                                </object>
+                                                               <object class="NSButton" id="20704797">
+                                                                       <reference key="NSNextResponder" ref="471332453"/>
+                                                                       <int key="NSvFlags">268</int>
+                                                                       <string key="NSFrame">{{343, 31}, {70, 18}}</string>
+                                                                       <reference key="NSSuperview" ref="471332453"/>
+                                                                       <reference key="NSWindow"/>
+                                                                       <reference key="NSNextKeyView"/>
+                                                                       <string key="NSReuseIdentifierKey">_NS:9</string>
+                                                                       <bool key="NSEnabled">YES</bool>
+                                                                       <object class="NSButtonCell" key="NSCell" id="868379451">
+                                                                               <int key="NSCellFlags">67108864</int>
+                                                                               <int key="NSCellFlags2">268435456</int>
+                                                                               <string key="NSContents">Smooth</string>
+                                                                               <reference key="NSSupport" ref="45863614"/>
+                                                                               <string key="NSCellIdentifier">_NS:9</string>
+                                                                               <reference key="NSControlView" ref="20704797"/>
+                                                                               <int key="NSButtonFlags">1211912448</int>
+                                                                               <int key="NSButtonFlags2">2</int>
+                                                                               <object class="NSCustomResource" key="NSNormalImage">
+                                                                                       <string key="NSClassName">NSImage</string>
+                                                                                       <string key="NSResourceName">NSSwitch</string>
+                                                                               </object>
+                                                                               <object class="NSButtonImageSource" key="NSAlternateImage">
+                                                                                       <string key="NSImageName">NSSwitch</string>
+                                                                               </object>
+                                                                               <string key="NSAlternateContents"/>
+                                                                               <string key="NSKeyEquivalent"/>
+                                                                               <int key="NSPeriodicDelay">200</int>
+                                                                               <int key="NSPeriodicInterval">25</int>
+                                                                       </object>
+                                                                       <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
+                                                               </object>
                                                                <object class="NSSegmentedControl" id="921829691">
                                                                        <reference key="NSNextResponder" ref="471332453"/>
                                                                        <int key="NSvFlags">265</int>
-                                                                       <string key="NSFrame">{{189, 33}, {224, 20}}</string>
+                                                                       <string key="NSFrame">{{189, 33}, {150, 20}}</string>
                                                                        <reference key="NSSuperview" ref="471332453"/>
                                                                        <reference key="NSWindow"/>
                                                                        <reference key="NSNextKeyView" ref="792189805"/>
@@ -735,26 +767,27 @@ aW5nLg</string>
                                                                                <reference key="NSControlView" ref="921829691"/>
                                                                                <array class="NSMutableArray" key="NSSegmentImages">
                                                                                        <object class="NSSegmentItem">
-                                                                                               <double key="NSSegmentItemWidth">86</double>
-                                                                                               <string key="NSSegmentItemLabel">â\86\91</string>
-                                                                                               <string key="NSSegmentItemTooltip">Scroll up continuously</string>
+                                                                                               <double key="NSSegmentItemWidth">36</double>
+                                                                                               <string key="NSSegmentItemLabel">â\86\90</string>
+                                                                                               <int key="NSSegmentItemTag">-2</int>
                                                                                                <int key="NSSegmentItemImageScaling">0</int>
                                                                                        </object>
                                                                                        <object class="NSSegmentItem">
-                                                                                               <double key="NSSegmentItemWidth">85</double>
-                                                                                               <string key="NSSegmentItemLabel">↓</string>
-                                                                                               <string key="NSSegmentItemTooltip">Scroll down continuously</string>
-                                                                                               <int key="NSSegmentItemTag">1</int>
+                                                                                               <double key="NSSegmentItemWidth">35</double>
+                                                                                               <string key="NSSegmentItemLabel">→</string>
+                                                                                               <int key="NSSegmentItemTag">2</int>
                                                                                                <int key="NSSegmentItemImageScaling">0</int>
                                                                                        </object>
                                                                                        <object class="NSSegmentItem">
-                                                                                               <string key="NSSegmentItemLabel">⤒</string>
-                                                                                               <string key="NSSegmentItemTooltip">Scroll up one step</string>
+                                                                                               <double key="NSSegmentItemWidth">35</double>
+                                                                                               <string key="NSSegmentItemLabel">↑</string>
+                                                                                               <int key="NSSegmentItemTag">-1</int>
                                                                                                <int key="NSSegmentItemImageScaling">0</int>
                                                                                        </object>
                                                                                        <object class="NSSegmentItem">
-                                                                                               <string key="NSSegmentItemLabel">⤓</string>
-                                                                                               <string key="NSSegmentItemTooltip">Scroll down one step</string>
+                                                                                               <double key="NSSegmentItemWidth">35</double>
+                                                                                               <string key="NSSegmentItemLabel">↓</string>
+                                                                                               <int key="NSSegmentItemTag">1</int>
                                                                                                <int key="NSSegmentItemImageScaling">0</int>
                                                                                        </object>
                                                                                </array>
@@ -765,10 +798,10 @@ aW5nLg</string>
                                                                <object class="NSSlider" id="792189805">
                                                                        <reference key="NSNextResponder" ref="471332453"/>
                                                                        <int key="NSvFlags">265</int>
-                                                                       <string key="NSFrame">{{191, 24}, {176, 16}}</string>
+                                                                       <string key="NSFrame">{{191, 24}, {146, 16}}</string>
                                                                        <reference key="NSSuperview" ref="471332453"/>
                                                                        <reference key="NSWindow"/>
-                                                                       <reference key="NSNextKeyView"/>
+                                                                       <reference key="NSNextKeyView" ref="20704797"/>
                                                                        <string key="NSReuseIdentifierKey">_NS:9</string>
                                                                        <bool key="NSEnabled">YES</bool>
                                                                        <object class="NSSliderCell" key="NSCell" id="423057230">
@@ -777,11 +810,11 @@ aW5nLg</string>
                                                                                <string key="NSContents"/>
                                                                                <string key="NSCellIdentifier">_NS:9</string>
                                                                                <reference key="NSControlView" ref="792189805"/>
-                                                                               <double key="NSMaxValue">30</double>
-                                                                               <double key="NSMinValue">0.0</double>
+                                                                               <double key="NSMaxValue">29</double>
+                                                                               <double key="NSMinValue">1</double>
                                                                                <double key="NSValue">15</double>
                                                                                <double key="NSAltIncValue">0.0</double>
-                                                                               <int key="NSNumberOfTickMarks">11</int>
+                                                                               <int key="NSNumberOfTickMarks">15</int>
                                                                                <int key="NSTickMarkPosition">1</int>
                                                                                <bool key="NSAllowsTickMarkValuesOnly">YES</bool>
                                                                                <bool key="NSVertical">NO</bool>
@@ -858,10 +891,10 @@ aW5nLg</string>
                                                                                <string key="NSCellIdentifier">_NS:9</string>
                                                                                <reference key="NSControlView" ref="385416822"/>
                                                                                <double key="NSMaxValue">20</double>
-                                                                               <double key="NSMinValue">0.0</double>
+                                                                               <double key="NSMinValue">1</double>
                                                                                <double key="NSValue">10</double>
                                                                                <double key="NSAltIncValue">0.0</double>
-                                                                               <int key="NSNumberOfTickMarks">11</int>
+                                                                               <int key="NSNumberOfTickMarks">20</int>
                                                                                <int key="NSTickMarkPosition">1</int>
                                                                                <bool key="NSAllowsTickMarkValuesOnly">YES</bool>
                                                                                <bool key="NSVertical">NO</bool>
@@ -1934,6 +1967,22 @@ aW5nLg</string>
                                        </object>
                                        <int key="connectionID">709</int>
                                </object>
+                               <object class="IBConnectionRecord">
+                                       <object class="IBActionConnection" key="connection">
+                                               <string key="label">scrollTypeChanged:</string>
+                                               <reference key="source" ref="801536542"/>
+                                               <reference key="destination" ref="20704797"/>
+                                       </object>
+                                       <int key="connectionID">948</int>
+                               </object>
+                               <object class="IBConnectionRecord">
+                                       <object class="IBOutletConnection" key="connection">
+                                               <string key="label">smoothCheck</string>
+                                               <reference key="source" ref="801536542"/>
+                                               <reference key="destination" ref="20704797"/>
+                                       </object>
+                                       <int key="connectionID">949</int>
+                               </object>
                                <object class="IBConnectionRecord">
                                        <object class="IBOutletConnection" key="connection">
                                                <string key="label">keyDelegate</string>
@@ -2485,6 +2534,7 @@ aW5nLg</string>
                                                        <reference ref="875916470"/>
                                                        <reference ref="385416822"/>
                                                        <reference ref="792189805"/>
+                                                       <reference ref="20704797"/>
                                                </array>
                                                <reference key="parent" ref="177223957"/>
                                        </object>
@@ -2765,6 +2815,19 @@ aW5nLg</string>
                                                <reference key="object" ref="466839429"/>
                                                <reference key="parent" ref="110575045"/>
                                        </object>
+                                       <object class="IBObjectRecord">
+                                               <int key="objectID">946</int>
+                                               <reference key="object" ref="20704797"/>
+                                               <array class="NSMutableArray" key="children">
+                                                       <reference ref="868379451"/>
+                                               </array>
+                                               <reference key="parent" ref="471332453"/>
+                                       </object>
+                                       <object class="IBObjectRecord">
+                                               <int key="objectID">947</int>
+                                               <reference key="object" ref="868379451"/>
+                                               <reference key="parent" ref="20704797"/>
+                                       </object>
                                </array>
                        </object>
                        <dictionary class="NSMutableDictionary" key="flattenedProperties">
@@ -2851,10 +2914,10 @@ aW5nLg</string>
                                <integer value="2" key="745.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
                                <string key="745.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="749.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-                               <integer value="0" key="750.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
+                               <integer value="2" key="750.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
                                <string key="750.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="754.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-                               <integer value="0" key="755.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
+                               <integer value="3" key="755.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
                                <string key="755.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="778.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="81.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2949,12 +3012,14 @@ aW5nLg</string>
                                <string key="936.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="938.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string key="940.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+                               <string key="946.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+                               <string key="947.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                        </dictionary>
                        <dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
                        <nil key="activeLocalization"/>
                        <dictionary class="NSMutableDictionary" key="localizations"/>
                        <nil key="sourceID"/>
-                       <int key="maxID">945</int>
+                       <int key="maxID">949</int>
                </object>
                <object class="IBClassDescriber" key="IBDocument.Classes">
                        <array class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -3178,6 +3243,7 @@ aW5nLg</string>
                                                <string key="mouseSpeedChanged:">id</string>
                                                <string key="radioChanged:">id</string>
                                                <string key="scrollSpeedChanged:">id</string>
+                                               <string key="scrollTypeChanged:">id</string>
                                                <string key="sdirChanged:">id</string>
                                        </dictionary>
                                        <dictionary class="NSMutableDictionary" key="actionInfosByName">
@@ -3201,6 +3267,10 @@ aW5nLg</string>
                                                        <string key="name">scrollSpeedChanged:</string>
                                                        <string key="candidateClassName">id</string>
                                                </object>
+                                               <object class="IBActionInfo" key="scrollTypeChanged:">
+                                                       <string key="name">scrollTypeChanged:</string>
+                                                       <string key="candidateClassName">id</string>
+                                               </object>
                                                <object class="IBActionInfo" key="sdirChanged:">
                                                        <string key="name">sdirChanged:</string>
                                                        <string key="candidateClassName">id</string>
@@ -3217,6 +3287,7 @@ aW5nLg</string>
                                                <string key="radioButtons">NSMatrix</string>
                                                <string key="scrollDirSelect">NSSegmentedControl</string>
                                                <string key="scrollSpeedSlider">NSSlider</string>
+                                               <string key="smoothCheck">NSButton</string>
                                                <string key="title">NSTextField</string>
                                        </dictionary>
                                        <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
@@ -3260,6 +3331,10 @@ aW5nLg</string>
                                                        <string key="name">scrollSpeedSlider</string>
                                                        <string key="candidateClassName">NSSlider</string>
                                                </object>
+                                               <object class="IBToOneOutletInfo" key="smoothCheck">
+                                                       <string key="name">smoothCheck</string>
+                                                       <string key="candidateClassName">NSButton</string>
+                                               </object>
                                                <object class="IBToOneOutletInfo" key="title">
                                                        <string key="name">title</string>
                                                        <string key="candidateClassName">NSTextField</string>
@@ -3284,6 +3359,7 @@ aW5nLg</string>
                        <string key="NSRadioButton">{16, 15}</string>
                        <string key="NSRemoveTemplate">{8, 8}</string>
                        <string key="NSRightFacingTriangleTemplate">{9, 9}</string>
+                       <string key="NSSwitch">{15, 15}</string>
                </dictionary>
        </data>
 </archive>