From: Ryan Petrich Date: Sat, 5 Feb 2011 20:42:28 +0000 (-0700) Subject: Add support for theming iOS4.0+ keyboard via UIKBColors.plist X-Git-Url: https://git.saurik.com/winterboard.git/commitdiff_plain/refs/heads/uikbcolors Add support for theming iOS4.0+ keyboard via UIKBColors.plist --- diff --git a/Library.mm b/Library.mm index a55c7d1..0639479 100644 --- a/Library.mm +++ b/Library.mm @@ -187,6 +187,7 @@ static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain); static NSBundle *(*_UIKitBundle)(); static bool (*_UIPackedImageTableGetIdentifierForName)(NSString *, int *); static int (*_UISharedImageNameGetIdentifier)(NSString *); +CGColorRef (*UIKBGetNamedColor)(CFStringRef colorName); static NSMutableDictionary *UIImages_; static NSMutableDictionary *PathImages_; @@ -1444,6 +1445,56 @@ MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) { return image == nil ? __UIImageWithNameInDomain(name, domain) : image; } +MSHook(CGColorRef, UIKBGetNamedColor, CFStringRef colorName) +{ + static CFMutableDictionaryRef keyboardColors; + if (!keyboardColors) { + keyboardColors = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + NSString *path = [[NSBundle bundleWithPath:@"/System/Library/Frameworks/UIKit.framework"] pathForResource:@"UIKBColors" ofType:@"plist"]; + NSDictionary *colorSettings = [NSDictionary dictionaryWithContentsOfFile:path]; + if (colorSettings) { + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + for (NSString *settingName in [colorSettings allKeys]) { + NSArray *c = [colorSettings objectForKey:settingName]; + CGFloat components[4]; + switch ([c count]) { + case 1: + components[0] = [[c objectAtIndex:0] floatValue]; + components[1] = components[0]; + components[2] = components[0]; + components[3] = 1.0f; + break; + case 2: + components[0] = [[c objectAtIndex:0] floatValue]; + components[1] = components[0]; + components[2] = components[0]; + components[0] = [[c objectAtIndex:1] floatValue]; + break; + case 3: + components[0] = [[c objectAtIndex:0] floatValue]; + components[1] = [[c objectAtIndex:1] floatValue]; + components[2] = [[c objectAtIndex:2] floatValue]; + components[3] = 1.0f; + break; + case 4: + components[0] = [[c objectAtIndex:0] floatValue]; + components[1] = [[c objectAtIndex:1] floatValue]; + components[2] = [[c objectAtIndex:2] floatValue]; + components[3] = [[c objectAtIndex:3] floatValue]; + break; + default: + continue; + } + CGColorRef color = CGColorCreate(colorSpace, components); + CFDictionarySetValue(keyboardColors, settingName, color); + CFRelease(color); + } + CGColorSpaceRelease(colorSpace); + } + } + return (CGColorRef)CFDictionaryGetValue(keyboardColors, colorName) ?: _UIKBGetNamedColor(colorName); +} + MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) { if (Debug_) NSLog(@"WB:Debug: GSFontCreateWithName(\"%s\", %f)", name, size); @@ -1573,6 +1624,11 @@ extern "C" void WBInitialize() { MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath); MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName); MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain); + + dlset(UIKBGetNamedColor, "UIKBGetNamedColor"); + if (UIKBGetNamedColor != NULL && identifier) { + MSHookFunction(UIKBGetNamedColor, &$UIKBGetNamedColor, &_UIKBGetNamedColor); + } // }}} }