Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame^] | 1 | // |
| 2 | // PreferenceWindowController.m |
| 3 | // Ring |
| 4 | // |
| 5 | // Created by Alexandre Lision on 2015-02-03. |
| 6 | // |
| 7 | // |
| 8 | |
| 9 | #import "PreferencesViewController.h" |
| 10 | #import <QuartzCore/QuartzCore.h> |
| 11 | |
| 12 | #import "GeneralPrefsVC.h" |
| 13 | #import "AudioPrefsVC.h" |
| 14 | #import "VideoPrefsVC.h" |
| 15 | |
| 16 | @interface PreferencesViewController () |
| 17 | |
| 18 | @end |
| 19 | |
| 20 | @implementation PreferencesViewController |
| 21 | |
| 22 | static NSString* const kGeneralPrefsIdentifier = @"GeneralPrefsIdentifier"; |
| 23 | static NSString* const kAudioPrefsIdentifer = @"AudioPrefsIdentifer"; |
| 24 | static NSString* const kAncragePrefsIdentifer = @"AncragePrefsIdentifer"; |
| 25 | static NSString* const kVideoPrefsIdentifer = @"VideoPrefsIdentifer"; |
| 26 | static NSString* const kDonePrefsIdentifer = @"DonePrefsIdentifer"; |
| 27 | |
| 28 | -(void)loadView |
| 29 | { |
| 30 | [super loadView]; |
| 31 | |
| 32 | [self displayGeneral:nil]; |
| 33 | |
| 34 | [self.view setWantsLayer:YES]; |
| 35 | self.view.layer.backgroundColor = [NSColor windowBackgroundColor].CGColor; |
| 36 | |
| 37 | // Set the layer redraw policy. This would be better done in |
| 38 | // the initialization method of a NSView subclass instead of here. |
| 39 | self.view.layerContentsRedrawPolicy = NSViewLayerContentsRedrawDuringViewResize; |
| 40 | |
| 41 | CGRect frame = CGRectOffset(self.view.frame, 0, -self.view.frame.size.height); |
| 42 | |
| 43 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; |
| 44 | animation.fromValue = [NSValue valueWithPoint:frame.origin]; |
| 45 | animation.toValue = [NSValue valueWithPoint:self.view.frame.origin]; |
| 46 | animation.duration = 0.3f; |
| 47 | [animation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:.7 :0.9 :1 :1]]; |
| 48 | |
| 49 | |
| 50 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
| 51 | self.view.layer.position = frame.origin; |
| 52 | } |
| 53 | |
| 54 | - (void) close |
| 55 | { |
| 56 | NSLog(@"closingprefs"); |
| 57 | CGRect frame = CGRectOffset(self.view.frame, 0, -self.view.frame.size.height); |
| 58 | |
| 59 | [CATransaction begin]; |
| 60 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; |
| 61 | animation.fromValue = [NSValue valueWithPoint:self.view.frame.origin]; |
| 62 | animation.toValue = [NSValue valueWithPoint:frame.origin]; |
| 63 | animation.duration = 0.3f; |
| 64 | [animation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:.7 :0.9 :1 :1]]; |
| 65 | |
| 66 | [CATransaction setCompletionBlock:^{ |
| 67 | [self.view removeFromSuperview]; |
| 68 | }]; |
| 69 | |
| 70 | |
| 71 | [self.view.layer addAnimation:animation forKey:animation.keyPath]; |
| 72 | [CATransaction commit]; |
| 73 | } |
| 74 | |
| 75 | - (void)displayGeneral:(NSToolbarItem *)sender { |
| 76 | NSLog(@"GEEENERALL"); |
| 77 | if (self.currentVC != nil) { |
| 78 | [self.currentVC.view removeFromSuperview]; |
| 79 | } |
| 80 | self.generalPrefsVC = [[GeneralPrefsVC alloc] initWithNibName:@"GeneralPrefs" bundle:nil]; |
| 81 | [self.view addSubview:self.generalPrefsVC.view]; |
| 82 | [self.generalPrefsVC.view setFrame:[self.view bounds]]; |
| 83 | self.currentVC = self.generalPrefsVC; |
| 84 | } |
| 85 | |
| 86 | - (void)displayAudio:(NSToolbarItem *)sender { |
| 87 | if (self.currentVC != nil) { |
| 88 | [self.currentVC.view removeFromSuperview]; |
| 89 | } |
| 90 | self.audioPrefsVC = [[AudioPrefsVC alloc] initWithNibName:@"AudioPrefs" bundle:nil]; |
| 91 | [self.view addSubview:self.audioPrefsVC.view]; |
| 92 | [self.audioPrefsVC.view setFrame:[self.view bounds]]; |
| 93 | self.currentVC = self.audioPrefsVC; |
| 94 | } |
| 95 | |
| 96 | - (void)displayAncrage:(NSToolbarItem *)sender { |
| 97 | |
| 98 | } |
| 99 | |
| 100 | - (void)displayVideo:(NSToolbarItem *)sender { |
| 101 | if (self.currentVC != nil) { |
| 102 | [self.currentVC.view removeFromSuperview]; |
| 103 | } |
| 104 | self.videoPrefsVC = [[VideoPrefsVC alloc] initWithNibName:@"VideoPrefs" bundle:nil]; |
| 105 | [self.view addSubview:self.videoPrefsVC.view]; |
| 106 | [self.videoPrefsVC.view setFrame:[self.view bounds]]; |
| 107 | self.currentVC = self.videoPrefsVC; |
| 108 | } |
| 109 | |
| 110 | |
| 111 | #pragma NSToolbar Delegate |
| 112 | |
| 113 | -(NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag |
| 114 | { |
| 115 | NSToolbarItem* item = nil; |
| 116 | |
| 117 | if ([itemIdentifier isEqualToString: kGeneralPrefsIdentifier]) { |
| 118 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kGeneralPrefsIdentifier]; |
| 119 | [item setImage: [NSImage imageNamed: @"general"]]; |
| 120 | [item setLabel: @"General"]; |
| 121 | [item setAction:@selector(displayGeneral:)]; |
| 122 | } |
| 123 | |
| 124 | if ([itemIdentifier isEqualToString: kAudioPrefsIdentifer]) { |
| 125 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kAudioPrefsIdentifer]; |
| 126 | [item setImage: [NSImage imageNamed: @"audio"]]; |
| 127 | [item setLabel: @"Audio"]; |
| 128 | [item setAction:@selector(displayAudio:)]; |
| 129 | } |
| 130 | |
| 131 | if ([itemIdentifier isEqualToString: kAncragePrefsIdentifer]) { |
| 132 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kAncragePrefsIdentifer]; |
| 133 | [item setImage: [NSImage imageNamed: @"ancrage"]]; |
| 134 | [item setLabel: @"Ancrage"]; |
| 135 | [item setAction:@selector(displayAncrage:)]; |
| 136 | } |
| 137 | |
| 138 | if ([itemIdentifier isEqualToString: kDonePrefsIdentifer]) { |
| 139 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kDonePrefsIdentifer]; |
| 140 | [item setImage: [NSImage imageNamed: @"ic_action_cancel"]]; |
| 141 | [item setLabel: @"Done"]; |
| 142 | [item setAction:@selector(closePreferences:)]; |
| 143 | } |
| 144 | |
| 145 | if ([itemIdentifier isEqualToString: kVideoPrefsIdentifer]) { |
| 146 | item = [[NSToolbarItem alloc] initWithItemIdentifier: kVideoPrefsIdentifer]; |
| 147 | [item setImage: [NSImage imageNamed: @"video"]]; |
| 148 | [item setLabel: @"Video"]; |
| 149 | [item setAction:@selector(displayVideo:)]; |
| 150 | } |
| 151 | |
| 152 | return item; |
| 153 | |
| 154 | } |
| 155 | |
| 156 | -(NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar |
| 157 | { |
| 158 | return [NSArray arrayWithObjects: |
| 159 | NSToolbarSpaceItemIdentifier, |
| 160 | NSToolbarFlexibleSpaceItemIdentifier, |
| 161 | kGeneralPrefsIdentifier, |
| 162 | kAudioPrefsIdentifer, |
| 163 | kVideoPrefsIdentifer, |
| 164 | kAncragePrefsIdentifer, |
| 165 | NSToolbarFlexibleSpaceItemIdentifier, |
| 166 | kDonePrefsIdentifer, |
| 167 | nil]; |
| 168 | } |
| 169 | |
| 170 | -(NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar |
| 171 | { |
| 172 | return [NSArray arrayWithObjects: |
| 173 | kGeneralPrefsIdentifier, |
| 174 | kAudioPrefsIdentifer, |
| 175 | kAncragePrefsIdentifer, |
| 176 | kVideoPrefsIdentifer, |
| 177 | nil]; |
| 178 | } |
| 179 | |
| 180 | -(NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar |
| 181 | { |
| 182 | return nil; |
| 183 | } |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | @end |