]> git.saurik.com Git - winterboard.git/commitdiff
Add support for theming iOS4.0+ keyboard via UIKBColors.plist uikbcolors
authorRyan Petrich <rpetrich@gmail.com>
Sat, 5 Feb 2011 20:42:28 +0000 (13:42 -0700)
committerRyan Petrich <rpetrich@gmail.com>
Sat, 5 Feb 2011 20:43:38 +0000 (13:43 -0700)
Library.mm

index a55c7d1c5c8d1c12ccafddb1aa58f20dc42ab358..06394794c2a94f92a68345c0fe4bc1304976ad79 100644 (file)
@@ -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);
+        }
 // }}}
     }