X-Git-Url: https://git.saurik.com/winterboard.git/blobdiff_plain/603984d918c086e5e72944ba5d278f6eedcd54f0..8e699a8292b89f59ae0d4effd986307e16f2379c:/Library.mm?ds=inline diff --git a/Library.mm b/Library.mm index e97e739..48eca47 100644 --- a/Library.mm +++ b/Library.mm @@ -118,6 +118,7 @@ MSClassHook(NSBundle) MSClassHook(NSString) MSClassHook(UIImage) +MSMetaClassHook(UIImage) MSClassHook(UINavigationBar) MSClassHook(UIToolbar) @@ -145,11 +146,13 @@ MSClassHook(SBIconModel) //MSClassHook(SBImageCache) MSClassHook(SBSearchView) MSClassHook(SBSearchTableViewCell) +MSClassHook(SBSlidingAlertDisplay) MSClassHook(SBStatusBarContentsView) MSClassHook(SBStatusBarController) MSClassHook(SBStatusBarOperatorNameView) MSClassHook(SBStatusBarTimeView) MSClassHook(SBUIController) +MSClassHook(SBWallpaperView) MSClassHook(SBWidgetApplicationIcon) extern "C" void WKSetCurrentGraphicsContext(CGContextRef); @@ -237,9 +240,6 @@ static unsigned $getScale$(NSString *path) { } static NSArray *$useScale$(NSArray *files, bool use = true) { - if (!use) - return files; - if (Scale_ == 0) { UIScreen *screen([UIScreen mainScreen]); if ([screen respondsToSelector:@selector(scale)]) @@ -251,11 +251,40 @@ static NSArray *$useScale$(NSArray *files, bool use = true) { if (Scale_ == 1) return files; - NSMutableArray *scaled([NSMutableArray arrayWithCapacity:([files count] * 2)]); + NSString *idiom(IsWild_ ? @"ipad" : @"iphone"); + + NSMutableArray *scaled([NSMutableArray arrayWithCapacity:([files count] * 4)]); for (NSString *file in files) { - [scaled addObject:[NSString stringWithFormat:@"%@@2x.%@", [file stringByDeletingPathExtension], [file pathExtension]]]; - [scaled addObject:file]; + NSString *base([file stringByDeletingPathExtension]); + NSString *extension([file pathExtension]); + + if (use) { + if (Scale_ == 2) { + [scaled addObject:[NSString stringWithFormat:@"%@@2x~%@.%@", base, idiom, extension]]; + if (!IsWild_) + [scaled addObject:[NSString stringWithFormat:@"%@@2x.%@", base, extension]]; + } + + [scaled addObject:[NSString stringWithFormat:@"%@~%@.%@", base, idiom, extension]]; + + // if (!IsWild_) <- support old themes + [scaled addObject:file]; + } else if ([base hasSuffix: @"@2x"]) { + [scaled addObject:[NSString stringWithFormat:@"%@~iphone.%@", base, extension]]; + [scaled addObject:file]; + + NSString *rest([base substringWithRange:NSMakeRange(0, [base length] - 3)]); + [scaled addObject:[NSString stringWithFormat:@"%@~iphone.%@", rest, extension]]; + [scaled addObject:[rest stringByAppendingPathExtension:extension]]; + } else { + // XXX: this code isn't really complete + + [scaled addObject:file]; + + if ([base hasSuffix:@"~iphone"]) + [scaled addObject:[[base substringWithRange:NSMakeRange(0, [base length] - 7)] stringByAppendingPathExtension:extension]]; + } } return scaled; @@ -632,42 +661,69 @@ MSInstanceMessageHook2(NSString *, NSBundle, pathForResource,ofType, NSString *, static struct WBStringDrawingState { WBStringDrawingState *next_; + unsigned count_; NSString *base_; NSString *info_; } *stringDrawingState_; MSInstanceMessageHook4(CGSize, NSString, drawAtPoint,forWidth,withFont,lineBreakMode, CGPoint, point, float, width, UIFont *, font, int, mode) { - if (stringDrawingState_ == NULL || stringDrawingState_->info_ == nil) + WBStringDrawingState *state(stringDrawingState_); + if (state == NULL) return MSOldCall(point, width, font, mode); - NSString *info([Info_ objectForKey:stringDrawingState_->info_]); - if (info == nil) + if (--state->count_ == 0) + stringDrawingState_ = state->next_; + if (state->info_ == nil) return MSOldCall(point, width, font, mode); - NSString *base(stringDrawingState_->base_ ?: @""); - stringDrawingState_ = stringDrawingState_->next_; + NSString *info([Info_ objectForKey:state->info_]); + if (info == nil) + return MSOldCall(point, width, font, mode); + NSString *base(state->base_ ?: @""); [self drawAtPoint:point withStyle:[NSString stringWithFormat:@"%@;%@;%@", [font markupDescription], base, info]]; return CGSizeZero; } MSInstanceMessageHook2(CGSize, NSString, drawAtPoint,withFont, CGPoint, point, UIFont *, font) { - if (stringDrawingState_ == NULL || stringDrawingState_->info_ == nil) + WBStringDrawingState *state(stringDrawingState_); + if (state == NULL) return MSOldCall(point, font); - NSString *info([Info_ objectForKey:stringDrawingState_->info_]); - if (info == nil) + if (--state->count_ == 0) + stringDrawingState_ = state->next_; + if (state->info_ == nil) return MSOldCall(point, font); - NSString *base(stringDrawingState_->base_ ?: @""); - stringDrawingState_ = stringDrawingState_->next_; + NSString *info([Info_ objectForKey:state->info_]); + if (info == nil) + return MSOldCall(point, font); + NSString *base(state->base_ ?: @""); [self drawAtPoint:point withStyle:[NSString stringWithFormat:@"%@;%@;%@", [font markupDescription], base, info]]; return CGSizeZero; } +MSInstanceMessageHook1(CGSize, NSString, sizeWithFont, UIFont *, font) { + WBStringDrawingState *state(stringDrawingState_); + if (state == NULL) + return MSOldCall(font); + + if (--state->count_ == 0) + stringDrawingState_ = state->next_; + if (state->info_ == nil) + return MSOldCall(font); + + NSString *info([Info_ objectForKey:state->info_]); + if (info == nil) + return MSOldCall(font); + + NSString *base(state->base_ ?: @""); + return [self sizeWithStyle:[NSString stringWithFormat:@"%@;%@;%@", [font markupDescription], base, info] forWidth:65535]; +} + MSInstanceMessageHook1(UIImage *, SBIconBadgeFactory, checkoutBadgeImageForText, NSString *, text) { - WBStringDrawingState badgeState = {NULL, @"" + WBStringDrawingState badgeState = {NULL, 1, @"" "color: white;" , @"BadgeStyle"}; @@ -680,13 +736,15 @@ MSInstanceMessageHook1(UIImage *, SBIconBadgeFactory, checkoutBadgeImageForText, } MSInstanceMessageHook1(UIImage *, SBCalendarApplicationIcon, generateIconImage, int, type) { - WBStringDrawingState dayState = {NULL, @"" + WBStringDrawingState dayState = {NULL, 2, @"" "color: white;" // XXX: this is only correct on an iPod dock "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px;" , @"CalendarIconDayStyle"}; - WBStringDrawingState dateState = {&dayState, @"" + WBStringDrawingState sizeState = {&dayState, 7, nil, nil}; + + WBStringDrawingState dateState = {&sizeState, 2, @"" "color: #333333;" , @"CalendarIconDateStyle"}; @@ -805,14 +863,6 @@ MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) _SBStatusBarContentsView$didMoveToSuperview(self, sel); } -MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) { - if (Debug_) - NSLog(@"WB:Debug:DefaultDesktopImage"); - if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil])) - return [UIImage imageWithContentsOfFile:path]; - return _UIImage$defaultDesktopImage(self, sel); -} - static NSArray *Wallpapers_; static bool Papered_; static bool Docked_; @@ -837,6 +887,34 @@ static UIImage *$getImage$(NSString *path) { return image; } +static UIImage *$getDefaultDesktopImage$() { + if (NSString *path = $getTheme$($useScale$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))) + return $getImage$(path); + return nil; +} + +MSClassMessageHook0(UIImage *, UIImage, defaultDesktopImage) { + return $getDefaultDesktopImage$() ?: MSOldCall(); +} + +MSInstanceMessageHook0(UIImage *, SBSlidingAlertDisplay, _defaultDesktopImage) { + return $getDefaultDesktopImage$() ?: MSOldCall(); +} + +MSInstanceMessageHook0(void, SBWallpaperView, resetCurrentImageToWallpaper) { + for (UIView *parent([self superview]); parent != nil; parent = [parent superview]) + if ([parent isKindOfClass:$SBSlidingAlertDisplay]) { + if (UIImage *image = $getDefaultDesktopImage$()) { + [self setImage:image]; + return; + } + + break; + } + + MSOldCall(); +} + // %hook -[SBUIController init] {{{ MSInstanceMessageHook0(id, SBUIController, init) { self = MSOldCall(); @@ -1340,9 +1418,12 @@ MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) { id &_label(MSHookIvar(self, "_label")); if (![Info_ wb$boolForKey:@"UndockedIconLabels"]) docked = true; + if (_label != nil && [_label respondsToSelector:@selector(setInDock:)]) [_label setInDock:docked]; - return _SBIconLabel$setInDock$(self, sel, docked); + + _SBIconLabel$setInDock$(self, sel, docked); + [self setNeedsDisplay]; } MSHook(BOOL, SBDockIconListView$shouldShowNewDock, id self, SEL sel) { @@ -1691,8 +1772,6 @@ static void SBInitialize() { class_addMethod($NSString, @selector(drawAtPoint:withStyle:), (IMP) &NSString$drawAtPoint$withStyle$, "v20@0:4{CGPoint=ff}8@16"); class_addMethod($NSString, @selector(sizeWithStyle:forWidth:), (IMP) &NSString$sizeWithStyle$forWidth$, "{CGSize=ff}16@0:4@8f12"); - _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage); - if (SummerBoard_) { WBRename(SBApplication, pathForIcon, pathForIcon); WBRename(SBApplicationIcon, icon, icon); @@ -1757,6 +1836,8 @@ MSInitialize { SummerBoard_ = [value boolValue]; if (NSNumber *value = [settings objectForKey:@"Debug"]) Debug_ = [value boolValue]; + if (NSNumber *value = [settings objectForKey:@"RecordUI"]) + UIDebug_ = [value boolValue]; NSArray *themes([settings objectForKey:@"Themes"]); if (themes == nil) @@ -1867,8 +1948,13 @@ MSInitialize { } // }}} - if (Debug_ && [Manager_ fileExistsAtPath:@"/tmp/UIImages"]) - UIDebug_ = true; + if (UIDebug_ && ![Manager_ fileExistsAtPath:@"/tmp/UIImages"]) { + NSError *error(nil); + if (![Manager_ createDirectoryAtPath:@"/tmp/UIImages" withIntermediateDirectories:NO attributes:[NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithShort:0777], NSFilePosixPermissions, + nil] error:&error]) + NSLog(@"WB:Error: cannot create /tmp/UIImages (%@)", error); + } [pool release]; }