From: Jay Freeman (saurik) Date: Tue, 18 Oct 2011 08:09:20 +0000 (+0000) Subject: Fixed calendars and badges. X-Git-Tag: v0.9.3901~9 X-Git-Url: https://git.saurik.com/winterboard.git/commitdiff_plain/19fe3063189dc6e1f4ab5109e3f2f774ab52a2a8 Fixed calendars and badges. --- diff --git a/Library.mm b/Library.mm index fe01279..3a983c8 100644 --- a/Library.mm +++ b/Library.mm @@ -131,10 +131,12 @@ MSClassHook(SBApplicationIcon) MSClassHook(SBAwayView) MSClassHook(SBBookmarkIcon) MSClassHook(SBButtonBar) +MSClassHook(SBCalendarApplicationIcon) MSClassHook(SBCalendarIconContentsView) MSClassHook(SBDockIconListView) MSClassHook(SBIcon) MSClassHook(SBIconBadge) +MSClassHook(SBIconBadgeFactory) MSClassHook(SBIconController) MSClassHook(SBIconLabel) MSClassHook(SBIconList) @@ -149,6 +151,8 @@ MSClassHook(SBStatusBarTimeView) MSClassHook(SBUIController) MSClassHook(SBWidgetApplicationIcon) +extern "C" void WKSetCurrentGraphicsContext(CGContextRef); + __attribute__((__constructor__)) static void MSFixClass() { if ($SBIcon == nil) @@ -624,6 +628,83 @@ MSInstanceMessageHook2(NSString *, NSBundle, pathForResource,ofType, NSString *, } // }}} +static struct WBStringDrawingState { + WBStringDrawingState *next_; + NSString *extra_; + NSString *key_; +} *stringDrawingState_; + +MSInstanceMessageHook4(CGSize, NSString, drawAtPoint,forWidth,withFont,lineBreakMode, CGPoint, point, float, width, UIFont *, font, int, mode) { + if (stringDrawingState_ == NULL) + return MSOldCall(point, width, font, mode); + + NSString *style([[font markupDescription] stringByAppendingString:@";"]); + + if (NSString *extra = stringDrawingState_->extra_) + style = [style stringByAppendingString:extra]; + + if (stringDrawingState_->key_ != nil) + if (NSString *extra = [Info_ objectForKey:stringDrawingState_->key_]) + style = [style stringByAppendingString:extra]; + + stringDrawingState_ = stringDrawingState_->next_; + + WKSetCurrentGraphicsContext(UIGraphicsGetCurrentContext()); + [[WBMarkup sharedMarkup] drawString:self atPoint:point withStyle:style]; + return CGSizeZero; +} + +MSInstanceMessageHook2(CGSize, NSString, drawAtPoint,withFont, CGPoint, point, UIFont *, font) { + if (stringDrawingState_ == NULL) + return MSOldCall(point, font); + + NSString *style([[font markupDescription] stringByAppendingString:@";"]); + + if (NSString *extra = stringDrawingState_->extra_) + style = [style stringByAppendingString:extra]; + + if (stringDrawingState_->key_ != nil) + if (NSString *extra = [Info_ objectForKey:stringDrawingState_->key_]) + style = [style stringByAppendingString:extra]; + + stringDrawingState_ = stringDrawingState_->next_; + + WKSetCurrentGraphicsContext(UIGraphicsGetCurrentContext()); + [[WBMarkup sharedMarkup] drawString:self atPoint:point withStyle:style]; + return CGSizeZero; +} + +MSInstanceMessageHook1(UIImage *, SBIconBadgeFactory, checkoutBadgeImageForText, NSString *, text) { + WBStringDrawingState badgeState = {NULL, @"" + "color: white;" + , @"BadgeStyle"}; + + stringDrawingState_ = &badgeState; + + UIImage *image(MSOldCall(text)); + + stringDrawingState_ = NULL; + return image; +} + +MSInstanceMessageHook1(UIImage *, SBCalendarApplicationIcon, generateIconImage, int, type) { + WBStringDrawingState dayState = {NULL, @"" + "color: white;" + "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px;" + , @"CalendarIconDayStyle"}; + + WBStringDrawingState dateState = {&dayState, @"" + "color: #333333;" + , @"CalendarIconDateStyle"}; + + stringDrawingState_ = &dateState; + + UIImage *image(MSOldCall(type)); + + stringDrawingState_ = NULL; + return image; +} + MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) { NSBundle *bundle([NSBundle mainBundle]); @@ -1579,8 +1660,6 @@ MSHook(void *, CGImageReadCreateWithFile, NSString *path, int flag) { } // }}} -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)