Use tabs for indentation

When those Xcode defaults bite you
This commit is contained in:
Conrad Kreyling 2018-04-08 13:29:07 -04:00
parent 3f90c97f39
commit b4e315a839
3 changed files with 209 additions and 209 deletions

View File

@ -18,10 +18,10 @@
- Dots: A bar composed by a line of dots - Dots: A bar composed by a line of dots
*/ */
typedef NS_ENUM(NSInteger, SubtleVolumeStyle) { typedef NS_ENUM(NSInteger, SubtleVolumeStyle) {
SubtleVolumeStylePlain, SubtleVolumeStylePlain,
SubtleVolumeStyleRoundedLine, SubtleVolumeStyleRoundedLine,
SubtleVolumeStyleDashes, SubtleVolumeStyleDashes,
SubtleVolumeStyleDots SubtleVolumeStyleDots
}; };
@ -32,9 +32,9 @@ typedef NS_ENUM(NSInteger, SubtleVolumeStyle) {
- FadeIn: The indicator fades in and out - FadeIn: The indicator fades in and out
*/ */
typedef NS_ENUM(NSInteger, SubtleVolumeAnimation) { typedef NS_ENUM(NSInteger, SubtleVolumeAnimation) {
SubtleVolumeAnimationNone, SubtleVolumeAnimationNone,
SubtleVolumeAnimationSlideDown, SubtleVolumeAnimationSlideDown,
SubtleVolumeAnimationFadeIn SubtleVolumeAnimationFadeIn
}; };
@class SubtleVolume; @class SubtleVolume;

View File

@ -13,10 +13,10 @@ UIView *overlay = [[UIView alloc] init];
CGFloat volumeLevel = 0; CGFloat volumeLevel = 0;
@interface SubtleVolume (){ @interface SubtleVolume (){
BOOL runningShowAnimation; BOOL runningShowAnimation;
BOOL showing; BOOL showing;
BOOL runningHideAnimation; BOOL runningHideAnimation;
BOOL lastAnimated; BOOL lastAnimated;
}; };
@property (nonatomic, strong) NSTimer *timer; @property (nonatomic, strong) NSTimer *timer;
@ -32,207 +32,207 @@ CGFloat volumeLevel = 0;
@implementation SubtleVolume @implementation SubtleVolume
- (instancetype)initWithStyle:(SubtleVolumeStyle)style frame:(CGRect)frame { - (instancetype)initWithStyle:(SubtleVolumeStyle)style frame:(CGRect)frame {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
self.animatedByDefault = YES; self.animatedByDefault = YES;
self.style = style; self.style = style;
[self setup]; [self setup];
} }
return self; return self;
} }
- (instancetype)initWithStyle:(SubtleVolumeStyle)style { - (instancetype)initWithStyle:(SubtleVolumeStyle)style {
return [self initWithStyle:style frame:CGRectZero]; return [self initWithStyle:style frame:CGRectZero];
} }
- (instancetype)initWithCoder:(NSCoder *)aDecoder { - (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder]; self = [super initWithCoder:aDecoder];
if (self) { if (self) {
[self setup]; [self setup];
} }
return self; return self;
} }
- (instancetype)initWithFrame:(CGRect)frame { - (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
[self setup]; [self setup];
} }
return self; return self;
} }
- (instancetype)init { - (instancetype)init {
self = nil; self = nil;
NSAssert(false, @"To init this class please use the designated initializer: initWithStyle or initWithStyle:frame:"); NSAssert(false, @"To init this class please use the designated initializer: initWithStyle or initWithStyle:frame:");
return nil; return nil;
} }
- (void)setup { - (void)setup {
@try { @try {
[[AVAudioSession sharedInstance] setActive:YES error:nil]; [[AVAudioSession sharedInstance] setActive:YES error:nil];
} @catch (NSException *e) { } @catch (NSException *e) {
NSLog(@"Unable to initialize AVAudioSession"); NSLog(@"Unable to initialize AVAudioSession");
} }
volumeLevel = [[AVAudioSession sharedInstance] outputVolume]; volumeLevel = [[AVAudioSession sharedInstance] outputVolume];
[[AVAudioSession sharedInstance] addObserver:self forKeyPath:@"outputVolume" options:NSKeyValueObservingOptionNew context:NULL]; [[AVAudioSession sharedInstance] addObserver:self forKeyPath:@"outputVolume" options:NSKeyValueObservingOptionNew context:NULL];
[volume setVolumeThumbImage:[[UIImage alloc] init] forState:UIControlStateNormal]; [volume setVolumeThumbImage:[[UIImage alloc] init] forState:UIControlStateNormal];
[volume setUserInteractionEnabled:NO]; [volume setUserInteractionEnabled:NO];
[volume setAlpha:0.0001]; [volume setAlpha:0.0001];
[volume setShowsRouteButton:NO]; [volume setShowsRouteButton:NO];
self.alpha = 0.0001; self.alpha = 0.0001;
[self addSubview:volume]; [self addSubview:volume];
[self addSubview:overlay]; [self addSubview:overlay];
} }
- (void)layoutSubviews { - (void)layoutSubviews {
[super layoutSubviews]; [super layoutSubviews];
overlay.frame = CGRectMake( overlay.frame = CGRectMake(
self.padding, self.padding,
self.padding, self.padding,
(self.frame.size.width - (self.padding*2)) * volumeLevel, (self.frame.size.width - (self.padding*2)) * volumeLevel,
self.frame.size.height - (self.padding*2) self.frame.size.height - (self.padding*2)
); );
self.backgroundColor = self.barBackgroundColor; self.backgroundColor = self.barBackgroundColor;
overlay.backgroundColor = self.barTintColor; overlay.backgroundColor = self.barTintColor;
} }
- (void)updateVolume:(CGFloat)value animated:(BOOL)animated { - (void)updateVolume:(CGFloat)value animated:(BOOL)animated {
[self.delegate subtleVolume:self willChange:value]; [self.delegate subtleVolume:self willChange:value];
volumeLevel = value; volumeLevel = value;
lastAnimated = animated; lastAnimated = animated;
[UIView animateWithDuration:(animated ? 0.1 : 0) animations:^{ [UIView animateWithDuration:(animated ? 0.1 : 0) animations:^{
CGRect rectOverlayView = overlay.frame; CGRect rectOverlayView = overlay.frame;
CGFloat overlyWidth = self.frame.size.width * volumeLevel; CGFloat overlyWidth = self.frame.size.width * volumeLevel;
rectOverlayView.size.width = overlyWidth; rectOverlayView.size.width = overlyWidth;
overlay.frame = rectOverlayView; overlay.frame = rectOverlayView;
}]; }];
if(self.timer) { if(self.timer) {
[self.timer invalidate]; [self.timer invalidate];
self.timer = nil; self.timer = nil;
} }
self.timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(timerComplete) userInfo:nil repeats:NO]; self.timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(timerComplete) userInfo:nil repeats:NO];
[self doShow:animated]; [self doShow:animated];
[self.delegate subtleVolume:self didChange:value]; [self.delegate subtleVolume:self didChange:value];
} }
- (void)timerComplete { - (void)timerComplete {
[self doHide:lastAnimated]; [self doHide:lastAnimated];
self.timer = nil; self.timer = nil;
} }
- (void)doHide:(BOOL)animated { - (void)doHide:(BOOL)animated {
if(!showing) { if(!showing) {
return; return;
} }
if(runningHideAnimation && !animated) { if(runningHideAnimation && !animated) {
[self stopAnimations]; [self stopAnimations];
} }
if(runningHideAnimation) { if(runningHideAnimation) {
return; return;
} }
if(animated) { if(animated) {
runningHideAnimation = YES; runningHideAnimation = YES;
[UIView animateWithDuration:0.333 animations:^{ [UIView animateWithDuration:0.333 animations:^{
switch (self.animation) { switch (self.animation) {
case SubtleVolumeAnimationNone: case SubtleVolumeAnimationNone:
break; break;
case SubtleVolumeAnimationFadeIn: case SubtleVolumeAnimationFadeIn:
self.alpha = 0.0001; self.alpha = 0.0001;
break; break;
case SubtleVolumeAnimationSlideDown: case SubtleVolumeAnimationSlideDown:
self.alpha = 0.0001; self.alpha = 0.0001;
self.transform = CGAffineTransformMakeTranslation(0, -self.frame.size.height); self.transform = CGAffineTransformMakeTranslation(0, -self.frame.size.height);
break; break;
default: default:
break; break;
} }
} completion:^(BOOL finished) { } completion:^(BOOL finished) {
showing = NO; showing = NO;
runningHideAnimation = NO; runningHideAnimation = NO;
}]; }];
} else { } else {
showing = NO; showing = NO;
self.alpha = 0.0001; self.alpha = 0.0001;
if(self.animation == SubtleVolumeAnimationSlideDown) { if(self.animation == SubtleVolumeAnimationSlideDown) {
self.transform = CGAffineTransformMakeTranslation(0, -self.frame.size.height); self.transform = CGAffineTransformMakeTranslation(0, -self.frame.size.height);
} }
} }
} }
- (void)doShow:(BOOL)animated { - (void)doShow:(BOOL)animated {
if(showing) { if(showing) {
return; return;
} }
if(runningShowAnimation && !animated) { if(runningShowAnimation && !animated) {
[self stopAnimations]; [self stopAnimations];
} }
if(runningShowAnimation) { if(runningShowAnimation) {
return; return;
} }
if(animated) { if(animated) {
// set up for first run, assuming the animation has changed // set up for first run, assuming the animation has changed
// between instantiation and first showing // between instantiation and first showing
if(self.animation == SubtleVolumeAnimationSlideDown) { if(self.animation == SubtleVolumeAnimationSlideDown) {
self.transform = CGAffineTransformMakeTranslation(0, -self.frame.size.height); self.transform = CGAffineTransformMakeTranslation(0, -self.frame.size.height);
} }
runningShowAnimation = YES; runningShowAnimation = YES;
[UIView animateWithDuration:0.333 animations:^{ [UIView animateWithDuration:0.333 animations:^{
switch (self.animation) { switch (self.animation) {
case SubtleVolumeAnimationNone: case SubtleVolumeAnimationNone:
break; break;
case SubtleVolumeAnimationFadeIn: case SubtleVolumeAnimationFadeIn:
self.alpha = 1; self.alpha = 1;
break; break;
case SubtleVolumeAnimationSlideDown: case SubtleVolumeAnimationSlideDown:
self.alpha = 1; self.alpha = 1;
self.transform = CGAffineTransformIdentity; self.transform = CGAffineTransformIdentity;
break; break;
default: default:
break; break;
} }
} completion:^(BOOL finished) { } completion:^(BOOL finished) {
showing = YES; showing = YES;
runningShowAnimation = NO; runningShowAnimation = NO;
}]; }];
} else { } else {
showing = YES; showing = YES;
self.alpha = 1; self.alpha = 1;
self.transform = CGAffineTransformIdentity; self.transform = CGAffineTransformIdentity;
} }
} }
- (void)stopAnimations { - (void)stopAnimations {
[self.layer removeAllAnimations]; [self.layer removeAllAnimations];
runningHideAnimation = NO; runningHideAnimation = NO;
runningShowAnimation = NO; runningShowAnimation = NO;
} }
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context { - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
if ([keyPath isEqual:@"outputVolume"]) { if ([keyPath isEqual:@"outputVolume"]) {
CGFloat value = [change[@"new"] floatValue]; CGFloat value = [change[@"new"] floatValue];
[self updateVolume:value animated:self.animatedByDefault]; [self updateVolume:value animated:self.animatedByDefault];
} else { } else {
return; return;
} }
} }
@end @end

View File

@ -96,7 +96,7 @@ static GraphicsContext *graphicsContext;
@end @end
@interface ViewController () <SubtleVolumeDelegate> { @interface ViewController () <SubtleVolumeDelegate> {
SubtleVolume *volume; SubtleVolume *volume;
} }
@end @end
@ -208,25 +208,25 @@ static GraphicsContext *graphicsContext;
} }
#endif #endif
CGFloat margin = 0; CGFloat margin = 0;
CGFloat height = 16; CGFloat height = 16;
volume = [[SubtleVolume alloc] volume = [[SubtleVolume alloc]
initWithStyle:SubtleVolumeStylePlain initWithStyle:SubtleVolumeStylePlain
frame:CGRectMake( frame:CGRectMake(
margin, // X margin, // X
0, // Y 0, // Y
self.view.frame.size.width-(margin*2), // width self.view.frame.size.width-(margin*2), // width
height // height height // height
)]; )];
volume.padding = 7; volume.padding = 7;
volume.barTintColor = [UIColor blackColor]; volume.barTintColor = [UIColor blackColor];
volume.barBackgroundColor = [UIColor whiteColor]; volume.barBackgroundColor = [UIColor whiteColor];
volume.animation = SubtleVolumeAnimationSlideDown; volume.animation = SubtleVolumeAnimationSlideDown;
volume.delegate = self; volume.delegate = self;
[self.view addSubview:volume]; [self.view addSubview:volume];
[self.view bringSubviewToFront:volume]; [self.view bringSubviewToFront:volume];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NativeInitGraphics(graphicsContext); NativeInitGraphics(graphicsContext);
@ -263,11 +263,11 @@ static GraphicsContext *graphicsContext;
if (sharedViewController == nil) { if (sharedViewController == nil) {
return; return;
} }
if(volume) { if(volume) {
[volume removeFromSuperview]; [volume removeFromSuperview];
volume = nil; volume = nil;
} }
Audio_Shutdown(); Audio_Shutdown();
@ -418,13 +418,13 @@ static GraphicsContext *graphicsContext;
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{ {
for(UITouch* touch in touches) for(UITouch* touch in touches)
{ {
CGPoint point = [touch locationInView:self.view]; CGPoint point = [touch locationInView:self.view];
NSDictionary* dict = [self touchDictBy:touch]; NSDictionary* dict = [self touchDictBy:touch];
[self touchX:point.x y:point.y code:2 pointerId:[[dict objectForKey:@"index"] intValue]]; [self touchX:point.x y:point.y code:2 pointerId:[[dict objectForKey:@"index"] intValue]];
[self.touches removeObject:dict]; [self.touches removeObject:dict];
} }
} }
- (void)bindDefaultFBO - (void)bindDefaultFBO