Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Basil Shkara committed Oct 2, 2010
0 parents commit 7916c74
Show file tree
Hide file tree
Showing 15 changed files with 5,566 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.DS_Store
*.swp
*~.nib

build/

*.pbxuser
*.perspective
*.perspectivev3
*.mode1v3
*.mode2v3
31 changes: 31 additions & 0 deletions AccelerationWindowController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// AccelerationWindowController.h
// Mousy
//
// Created by Basil Shkara on 22/08/09.
// Copyright 2009 Oiled Machine Pty Ltd. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "MouseInterface.h"
#import "AccelerationWindowController.h"


@interface AccelerationWindowController : NSWindowController {
IBOutlet NSSlider *slider_;
IBOutlet NSTextField *textField_;
MouseInterface *mouseInterface_;
CGFloat accelerationValue_;
}

@property (nonatomic, retain) NSSlider *slider;
@property (nonatomic, retain) NSTextField *textField;
@property (nonatomic, retain) MouseInterface *mouseInterface;
@property (nonatomic, assign) CGFloat accelerationValue;

- (IBAction)updateMouseSpeed:(id)sender;
- (IBAction)setMouseSpeedAsDefault:(id)sender;
- (IBAction)incrementMouseSpeed:(id)sender;
- (IBAction)decrementMouseSpeed:(id)sender;

@end
124 changes: 124 additions & 0 deletions AccelerationWindowController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//
// AccelerationWindowController.m
// Mousy
//
// Created by Basil Shkara on 22/08/09.
// Copyright 2009 Oiled Machine Pty Ltd. All rights reserved.
//
// Note: This is basically SetMouseAcclSample from Apple.
// http://developer.apple.com/Samplecode/SetMouseAcclSample/index.html
//

#import "AccelerationWindowController.h"

// Amount divided by 10 as increment/decrement amount
static NSUInteger kStandardIncrement = 1;
// Corresponds to the maximum setting for the slider in the nib file
static NSUInteger kMaxSpeedSetting = 4;


@implementation AccelerationWindowController

@synthesize slider = slider_;
@synthesize textField = textField_;
@synthesize mouseInterface = mouseInterface_;
@synthesize accelerationValue = accelerationValue_;


- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];

[self setSlider:nil];
[self setTextField:nil];
[self setMouseInterface:nil];
[super dealloc];
}

- (void)awakeFromNib {
MouseInterface *mouseInterface = [[MouseInterface alloc] init];
self.mouseInterface = mouseInterface;
[mouseInterface release];

// Store the original value to restore if needed
self.accelerationValue = [self.mouseInterface mouseDefaultSpeed];

// Promote original values into View
[self.slider setFloatValue:self.accelerationValue];
[self.textField setFloatValue:self.accelerationValue];

// Register for notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(windowDidBecomeKey:)
name:NSWindowDidBecomeKeyNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(windowDidResignActive:)
name:NSWindowDidResignMainNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillTerminate:)
name:NSApplicationWillTerminateNotification object:nil];
}

// User wants to set the currently selected acceleration value as the default
- (IBAction)setMouseSpeedAsDefault:(id)sender {
self.accelerationValue = [self.slider floatValue];
}

- (IBAction)updateMouseSpeed:(id)sender {
// Read the current mouse value from the slider
CGFloat value = [self.slider floatValue];

// Set the text value of the mouse setting in the window
[self.textField setFloatValue:value];

// Set this value as the mouse speed
[self.mouseInterface setMouseSpeed:value];
}

- (IBAction)incrementMouseSpeed:(id)sender {
CGFloat value = [self.slider floatValue] * 10 + kStandardIncrement + 0.1;
NSInteger newValue = value;
value = newValue;
value = value / 10; // cannot use value = newValue / 10, since (newValue / 10) will force integer math
if (value > kMaxSpeedSetting) {
value = kMaxSpeedSetting;
}
[self.slider setFloatValue:value];
[self.textField setFloatValue:value];
[self.mouseInterface setMouseSpeed:value];
}

- (IBAction)decrementMouseSpeed:(id)sender {
CGFloat value = [self.slider floatValue] * 10 - kStandardIncrement + 0.1;
NSInteger newValue = value;
if (newValue < 0) {
newValue = 0;
}
value = newValue;
value = value / 10; // cannot use value = newValue / 10, since (newValue / 10) will force integer math
[self.slider setFloatValue:value];
[self.textField setFloatValue:value];
[self.mouseInterface setMouseSpeed:value];
}

#pragma mark -
#pragma mark Observer methods

// Restore the mouse acceleration setting to whatever is in slider
- (void)windowDidBecomeKey:(NSNotification *)aNotification {
CGFloat value = [self.slider floatValue];
[self.textField setFloatValue:value];
[self.mouseInterface setMouseSpeed:value];
}

// Restore the mouse acceleration setting to whatever the original value was
- (void)windowDidResignActive:(NSNotification *)aNotification {
[self.mouseInterface setMouseSpeed:self.accelerationValue];
}

// Restore the mouse acceleration setting to whatever the original value was
- (void)applicationWillTerminate:(NSNotification *)aNotification {
[self.mouseInterface setMouseSpeed:self.accelerationValue];
}


@end
2 changes: 2 additions & 0 deletions English.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Localized versions of Info.plist keys */

Loading

0 comments on commit 7916c74

Please sign in to comment.