X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=OSX%2FSaverListController.m;h=15b3089dffc4575f4e08814f2a9798ea510797ae;hb=8afc01a67be4fbf3f1cc0fce9adf01b5289a21c6;hp=75e8751ba2b59a0f7529e0e5c873ea0b01c37c37;hpb=c70f94f648d51bb4828193124f325fa52b0e57f3;p=xscreensaver diff --git a/OSX/SaverListController.m b/OSX/SaverListController.m index 75e8751b..15b3089d 100644 --- a/OSX/SaverListController.m +++ b/OSX/SaverListController.m @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 2012 Jamie Zawinski +/* xscreensaver, Copyright (c) 2012-2014 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -16,6 +16,7 @@ #import "SaverListController.h" #import "SaverRunner.h" +#import "yarandom.h" #import "version.h" #undef countof @@ -35,6 +36,7 @@ { // Extract the version number and release date from the version string. // Here's an area where I kind of wish I had "Two Problems". + // I guess I could add custom key to the Info.plist for this. NSArray *a = [[NSString stringWithCString: screensaver_id encoding:NSASCIIStringEncoding] @@ -57,14 +59,15 @@ [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent: @"iSaverRunner29t.png"]]; - UIBarButtonItem *button = [[[UIBarButtonItem alloc] - initWithImage: img - style: UIBarButtonItemStylePlain - target: self - action: @selector(titleTapped:)] - autorelease]; - button.width = img.size.width; - self.navigationItem.rightBarButtonItem = button; + UIButton *button = [[UIButton alloc] init]; + [button setFrame: CGRectMake(0, 0, img.size.width, img.size.height)]; + [button setBackgroundImage:img forState:UIControlStateNormal]; + [button addTarget:self + action:@selector(titleTapped:) + forControlEvents:UIControlEventTouchUpInside]; + self.navigationItem.rightBarButtonItem = + [[UIBarButtonItem alloc] initWithCustomView: button]; + [button release]; // The title bar @@ -246,8 +249,7 @@ SaverRunner *s = (SaverRunner *) [[UIApplication sharedApplication] delegate]; if (! s) return; - if (! [s isKindOfClass:[SaverRunner class]]) - abort(); + NSAssert ([s isKindOfClass:[SaverRunner class]], @"not a SaverRunner"); [s loadSaver: cell.textLabel.text]; } @@ -260,8 +262,7 @@ SaverRunner *s = (SaverRunner *) [[UIApplication sharedApplication] delegate]; if (! s) return; - if (! [s isKindOfClass:[SaverRunner class]]) - abort(); + NSAssert ([s isKindOfClass:[SaverRunner class]], @"not a SaverRunner"); [s openPreferences: cell.textLabel.text]; } @@ -296,6 +297,45 @@ } +/* We need this to respond to "shake" gestures + */ +- (BOOL)canBecomeFirstResponder +{ + return YES; +} + +- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event +{ +} + +- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event +{ +} + + +/* Shake means load a random screen saver. + */ +- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event +{ + if (motion != UIEventSubtypeMotionShake) + return; + NSMutableArray *a = [NSMutableArray arrayWithCapacity: 200]; + for (NSArray *sec in letter_sections) + for (NSString *s in sec) + [a addObject: s]; + int n = [a count]; + if (! n) return; + NSString *which = [a objectAtIndex: (random() % n)]; + + SaverRunner *s = + (SaverRunner *) [[UIApplication sharedApplication] delegate]; + if (! s) return; + NSAssert ([s isKindOfClass:[SaverRunner class]], @"not a SaverRunner"); + [self scrollTo: which]; + [s loadSaver: which]; +} + + - (void)dealloc { for (int i = 0; i < countof(list_by_letter); i++)