]> git.saurik.com Git - winterboard.git/blobdiff - Library.mm
As reported by thekirbylover, UISounds stack in reverse order.
[winterboard.git] / Library.mm
index d1cf54ed37bcd9a271ec2e37a7b0c2c7ed2cec84..676a2572e1eac05c8e267837bd52b6f7054b380d 100644 (file)
@@ -200,7 +200,7 @@ static BOOL (*_GSFontGetUseLegacyFontMetrics)();
 static bool Debug_ = false;
 static bool UIDebug_ = false;
 static bool Engineer_ = false;
-static bool SummerBoard_ = true;
+static bool SummerBoard_ = false;
 static bool SpringBoard_;
 
 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
@@ -702,7 +702,7 @@ static void $drawLabel$(NSString *label, CGRect rect, NSString *style, NSString
         style = [style stringByAppendingString:custom];
 
     CGSize size = [label sizeWithStyle:style forWidth:rect.size.width];
-    [label drawAtPoint:CGPointMake((rect.size.width - size.width) / 2, 0) withStyle:style];
+    [label drawAtPoint:CGPointMake((rect.size.width - size.width) / 2 + rect.origin.x, rect.origin.y) withStyle:style];
 }
 
 static struct WBStringDrawingState {
@@ -713,6 +713,8 @@ static struct WBStringDrawingState {
 } *stringDrawingState_;
 
 MSInstanceMessageHook6(CGSize, NSString, drawAtPoint,forWidth,withFont,lineBreakMode,letterSpacing,includeEmoji, CGPoint, point, float, width, UIFont *, font, UILineBreakMode, mode, float, spacing, BOOL, emoji) {
+    //NSLog(@"XXX: @\"%@\" %g", self, spacing);
+
     WBStringDrawingState *state(stringDrawingState_);
     if (state == NULL)
         return MSOldCall(point, width, font, mode, spacing, emoji);
@@ -732,7 +734,11 @@ MSInstanceMessageHook6(CGSize, NSString, drawAtPoint,forWidth,withFont,lineBreak
     return CGSizeZero;
 }
 
+extern "C" NSString *NSStringFromCGRect(CGRect rect);
+
 MSInstanceMessageHook7(CGSize, NSString, _drawInRect,withFont,lineBreakMode,alignment,lineSpacing,includeEmoji,truncationRect, CGRect, rect, UIFont *, font, UILineBreakMode, mode, UITextAlignment, alignment, float, spacing, BOOL, emoji, CGRect, truncation) {
+    //NSLog(@"XXX: &\"%@\" %@ \"%@\" %u %u %g %u %@", self, NSStringFromCGRect(rect), font, mode, alignment, spacing, emoji, NSStringFromCGRect(truncation));
+
     WBStringDrawingState *state(stringDrawingState_);
     if (state == NULL)
         return MSOldCall(rect, font, mode, alignment, spacing, emoji, truncation);
@@ -762,11 +768,18 @@ MSInstanceMessageHook7(CGSize, NSString, _drawInRect,withFont,lineBreakMode,alig
 
     NSString *base(state->base_ ?: @"");
     NSString *extra([NSString stringWithFormat:@"text-align: %@", textAlign]);
-    [self drawInRect:rect withStyle:[NSString stringWithFormat:@"%@;%@;%@;%@", [font markupDescription], extra, base, info]];
+
+    if (true)
+        $drawLabel$(self, rect, [NSString stringWithFormat:@"%@;%@", [font markupDescription], base], info);
+    else
+        [self drawInRect:rect withStyle:[NSString stringWithFormat:@"%@;%@;%@;%@", [font markupDescription], extra, base, info]];
+
     return CGSizeZero;
 }
 
 MSInstanceMessageHook4(CGSize, NSString, sizeWithFont,forWidth,lineBreakMode,letterSpacing, UIFont *, font, float, width, UILineBreakMode, mode, float, spacing) {
+    //NSLog(@"XXX: #\"%@\" \"%@\" %g %u %g", self, font, width, mode, spacing);
+
     WBStringDrawingState *state(stringDrawingState_);
     if (state == NULL)
         return MSOldCall(font, width, mode, spacing);
@@ -786,6 +799,8 @@ MSInstanceMessageHook4(CGSize, NSString, sizeWithFont,forWidth,lineBreakMode,let
 }
 
 MSInstanceMessageHook1(CGSize, NSString, sizeWithFont, UIFont *, font) {
+    //NSLog(@"XXX: ?\"%@\"", self);
+
     WBStringDrawingState *state(stringDrawingState_);
     if (state == NULL)
         return MSOldCall(font);
@@ -1598,15 +1613,15 @@ MSInstanceMessage1(void, SBIconLabel, drawRect, CGRect, rect) {
 MSInstanceMessage0(CGImageRef, SBIconLabel, buildLabelImage) {
     bool docked((MSHookIvar<unsigned>(self, "_inDock") & 0x2) != 0);
 
-    WBStringDrawingState labelState = {NULL, 0, [NSString stringWithFormat:@""
-        "color: %@;"
-    ,
-        (docked || !SummerBoard_ ? @"white" : @"#b3b3b3")
-    ], docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle"};
+    WBStringDrawingState labelState = {NULL, 0, @""
+        "color: white;"
+    , docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle"};
 
     stringDrawingState_ = &labelState;
 
+    //NSLog(@"XXX: +");
     CGImageRef image(MSOldCall());
+    //NSLog(@"XXX: -");
 
     stringDrawingState_ = NULL;
     return image;
@@ -1796,7 +1811,7 @@ MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool
                 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
                 if ([Manager_ fileExistsAtPath:path]) {
                     strcpy(a1, [path UTF8String]);
-                    continue;
+                    break;
                 }
             }
         }
@@ -1865,6 +1880,7 @@ static void NSString$drawAtPoint$withStyle$(NSString *self, SEL _cmd, CGPoint po
     WKSetCurrentGraphicsContext(UIGraphicsGetCurrentContext());
     if (style == nil || [style length] == 0)
         style = @"font-family: Helvetica; font-size: 12px";
+    //NSLog(@"XXX:draw(%@)", [style stringByReplacingOccurrencesOfString:@"\n" withString:@" "]);
     return [[WBMarkup sharedMarkup] drawString:self atPoint:point withStyle:style];
 }
 
@@ -1878,6 +1894,7 @@ static void NSString$drawInRect$withStyle$(NSString *self, SEL _cmd, CGRect rect
 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";
+    //NSLog(@"XXX:size(%@)", [style stringByReplacingOccurrencesOfString:@"\n" withString:@" "]);
     return [[WBMarkup sharedMarkup] sizeOfString:self withStyle:style forWidth:width];
 }
 
@@ -1903,7 +1920,7 @@ static void SBInitialize() {
     WBRename(SBDockIconListView, setFrame:, setFrame$);
     MSHookMessage(object_getClass($SBDockIconListView), @selector(shouldShowNewDock), &$SBDockIconListView$shouldShowNewDock, &_SBDockIconListView$shouldShowNewDock);
 
-    if (kCFCoreFoundationVersionNumber < 600)
+    if (kCFCoreFoundationVersionNumber < 600 || SummerBoard_)
         WBRename(SBIconLabel, drawRect:, drawRect$);
     else
         WBRename(SBIconLabel, buildLabelImage, buildLabelImage);
@@ -1953,6 +1970,9 @@ MSInitialize {
     if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
         if (NSNumber *value = [settings objectForKey:@"SummerBoard"])
             SummerBoard_ = [value boolValue];
+        else
+            SummerBoard_ = true;
+
         if (NSNumber *value = [settings objectForKey:@"Debug"])
             Debug_ = [value boolValue];
         if (NSNumber *value = [settings objectForKey:@"RecordUI"])