X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=OSX%2FSaverListController.m;h=484cb1685449bdb50a625d1a7ccfe445c23e27eb;hp=75e8751ba2b59a0f7529e0e5c873ea0b01c37c37;hb=6f5482d73adb0165c0130bb47d852644ab0c4869;hpb=c70f94f648d51bb4828193124f325fa52b0e57f3 diff --git a/OSX/SaverListController.m b/OSX/SaverListController.m index 75e8751b..484cb168 100644 --- a/OSX/SaverListController.m +++ b/OSX/SaverListController.m @@ -16,6 +16,7 @@ #import "SaverListController.h" #import "SaverRunner.h" +#import "yarandom.h" #import "version.h" #undef countof @@ -246,8 +247,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 +260,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 +295,43 @@ } +/* 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 +{ + 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++)