#include <sys/sysctl.h>
+#include "WBMarkup.h"
+
extern "C" void __clear_cache (char *beg, char *end);
@protocol WinterBoard
Class $MPVideoView;
MSClassHook(NSBundle)
+MSClassHook(NSString)
MSClassHook(UIImage)
MSClassHook(UINavigationBar)
return [name hasSuffix:@"@2x"] ? 2 : 1;
}
-static NSString *$getTheme$(NSArray *files, bool rescale = false) {
- if (NSString *path = [Themed_ objectForKey:files])
- return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
+static NSArray *$useScale$(NSArray *files, bool use = true) {
+ if (!use)
+ return files;
- if (rescale && Scale_ == 0) {
+ if (Scale_ == 0) {
UIScreen *screen([UIScreen mainScreen]);
if ([screen respondsToSelector:@selector(scale)])
Scale_ = [screen scale];
Scale_ = 1;
}
+ if (Scale_ == 1)
+ return files;
+
+ NSMutableArray *scaled([NSMutableArray arrayWithCapacity:([files count] * 2)]);
+
+ for (NSString *file in files) {
+ [scaled addObject:[NSString stringWithFormat:@"%@@2x.%@", [file stringByDeletingPathExtension], [file pathExtension]]];
+ [scaled addObject:file];
+ }
+
+ return scaled;
+}
+
+static NSString *$getTheme$(NSArray *files, NSArray *themes = Themes_) {
+ if (NSString *path = [Themed_ objectForKey:files])
+ return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
+
if (Debug_)
NSLog(@"WB:Debug: %@", [files description]);
remapResourceName(Four_ ? @"SBDockBG-old.png" : @"SBDockBG.png", @"Dock")
remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
- if (NSString *path = $getTheme$(names, ui))
+ if (NSString *path = $getTheme$($useScale$(names, ui)))
return path;
return nil;
@implementation NSString (WinterBoard)
- (NSString *) wb$themedPath {
+ if ([self hasPrefix:@"/Library/Themes/"])
+ return self;
+
if (Debug_)
NSLog(@"WB:Debug:Bypass(\"%@\")", self);
if (self == nil)
return nil;
- NSString *paper($getTheme$(Wallpapers_, true));
+ NSString *paper($getTheme$(Wallpapers_));
+ if (paper != nil)
+ paper = [paper stringByDeletingLastPathComponent];
{
size_t size;
_release(WallpaperPage_);
_release(WallpaperURL_);
- if (NSString *path = paper) {
- if ([path hasSuffix:@".mp4"]) {
+ if (paper != nil) {
+ NSArray *themes([NSArray arrayWithObject:paper]);
+
+ if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Wallpaper.mp4"], themes)) {
#if UseAVController
NSError *error;
[indirect addSubview:video];
}
- if ([path hasSuffix:@".png"] || [path hasSuffix:@".jpg"]) {
+ if (NSString *path = $getTheme$($useScale$([NSArray arrayWithObjects:@"Wallpaper.png", @"Wallpaper.jpg", nil]), themes)) {
if (UIImage *image = $getImage$(path)) {
WallpaperFile_ = [path retain];
WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
}
}
- if ([path hasSuffix:@".html"]) {
+ if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Wallpaper.html"], themes)) {
CGRect bounds = [indirect bounds];
UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
}
// }}}
-MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
+MSInstanceMessageHook1(void, SBIconLabel, drawRect, CGRect, rect) {
CGRect bounds = [self bounds];
static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
UIImage *image([UIImages_ objectForKey:key]);
if (image != nil)
return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithName(name) : image;
- if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
- image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
- if (image != nil)
- [image autorelease];
- }
+ if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true))
+ image = $getImage$(path);
[UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
return image == nil ? __UIImageWithName(name) : image;
}
return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithNameInDomain(name, domain) : image;
if (Debug_)
NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
- if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]], true)) {
- image = [[UIImage alloc] initWithContentsOfFile:path];
- if (image != nil)
- [image autorelease];
- }
+ if (NSString *path = $getTheme$($useScale$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])))
+ image = $getImage$(path);
[PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
return image == nil ? __UIImageWithNameInDomain(name, domain) : image;
}
}
// }}}
+extern "C" void WKSetCurrentGraphicsContext(CGContextRef);
+
+static void NSString$drawAtPoint$withStyle$(NSString *self, SEL _cmd, CGPoint point, NSString *style) {
+ WKSetCurrentGraphicsContext(UIGraphicsGetCurrentContext());
+ if (style == nil || [style length] == 0)
+ style = @"font-family: Helvetica; font-size: 12px";
+ return [[WBMarkup sharedMarkup] drawString:self atPoint:point withStyle:style];
+}
+
+static CGSize NSString$sizeWithStyle$forWidth$(NSString *self, SEL _cmd, NSString *style, float width) {
+ if (style == nil || [style length] == 0)
+ style = @"font-family: Helvetica; font-size: 12px";
+ return [[WBMarkup sharedMarkup] sizeOfString:self withStyle:style forWidth:width];
+}
+
static void SBInitialize() {
- _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
+ 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");
- bool olden(dlsym(RTLD_DEFAULT, "GSLibraryCopyGenerationInfoValueForKey") == NULL);
+ _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
if (SummerBoard_) {
WBRename(SBApplication, pathForIcon, pathForIcon);
WBRename(SBDockIconListView, setFrame:, setFrame$);
MSHookMessage(object_getClass($SBDockIconListView), @selector(shouldShowNewDock), &$SBDockIconListView$shouldShowNewDock, &_SBDockIconListView$shouldShowNewDock);
- if (olden)
- WBRename(SBIconLabel, drawRect:, drawRect$);
-
WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
WBRename(SBIconLabel, setInDock:, setInDock$);
// }}}
// SpringBoard {{{
if (SpringBoard_) {
- Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
+ Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper@2x.png", @"Wallpaper@2x.jpg", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
Docked_ = $getTheme$([NSArray arrayWithObjects:@"Dock.png", nil]);
CFNotificationCenterAddObserver(