]>
Commit | Line | Data |
---|---|---|
b6ceaaff JF |
1 | #include <substrate.h> |
2 | ||
3 | #import <Foundation/NSArray.h> | |
4 | #import <Foundation/NSNull.h> | |
5 | #import <CoreGraphics/CGGeometry.h> | |
6 | #import <SpringBoard/SBButtonBar.h> | |
7 | #import <SpringBoard/SBIcon.h> | |
8 | ||
56a24300 JF |
9 | MSHook(float, SBButtonBar$leftMarginForIconRowArray$, SBButtonBar *self, SEL sel, NSArray *row) { |
10 | return [row indexOfObject:[NSNull null]] == NSNotFound ? 4 : _SBButtonBar$leftMarginForIconRowArray$(self, sel, row); | |
b6ceaaff JF |
11 | } |
12 | ||
56a24300 | 13 | static int $SBButtonBar$maxIconColumns(SBButtonBar *self, SEL sel) { |
b6ceaaff JF |
14 | return 5; |
15 | } | |
16 | ||
56a24300 JF |
17 | static unsigned $SBButtonBar$count(SBButtonBar *self) { |
18 | NSArray *&_iconMatrix(MSHookIvar<NSArray *>(self, "_iconMatrix")); | |
19 | NSArray *row([_iconMatrix objectAtIndex:0]); | |
20 | unsigned count(0); | |
21 | for (id icon in row) | |
22 | if (icon != [NSNull null]) | |
23 | ++count; | |
24 | return count; | |
b6ceaaff JF |
25 | } |
26 | ||
56a24300 | 27 | static float $SBButtonBar$topIconPadding(SBButtonBar *self, SEL sel) { |
bddf654d | 28 | return 313370 + $SBButtonBar$count(self); |
b6ceaaff JF |
29 | } |
30 | ||
56a24300 JF |
31 | MSHook(void, SBIcon$setOrigin$, SBIcon *self, SEL sel, CGPoint origin) { |
32 | unsigned count(origin.y); | |
bddf654d JF |
33 | if (count < 313370) |
34 | goto set; | |
35 | count -= 313370; | |
56a24300 | 36 | |
bddf654d | 37 | if (count > 40) |
b6ceaaff | 38 | origin.x = 256; |
56a24300 JF |
39 | else if (count > 10 || count < 0) |
40 | goto set; | |
41 | else if (count == 5) | |
42 | origin.x = (origin.x - 4) / 76 * 63 + 4; | |
43 | ||
44 | origin.y = 11; | |
b6ceaaff | 45 | set: |
56a24300 | 46 | _SBIcon$setOrigin$(self, sel, origin); |
b6ceaaff JF |
47 | } |
48 | ||
56a24300 JF |
49 | MSHook(CGPoint, SBButtonBar$originForIconAtX$Y$, SBButtonBar *self, SEL sel, int x, int y) { |
50 | CGPoint origin;//(_SBButtonBar$originForIconAtX$Y$(self, sel, x, y)); | |
51 | //NSLog(@"f:%u,%u=(%f,%f)", x, y, origin.x, origin.y); | |
52 | origin.y = 11; | |
53 | ||
54 | unsigned count($SBButtonBar$count(self)), gap; | |
55 | unsigned space(320 - 60 * count); | |
56 | ||
57 | if (count >= 4) | |
58 | gap = space / (count + 1); | |
59 | else // I hate people who love Apple. | |
60 | gap = 16; | |
61 | ||
62 | origin.x = (space - gap * (count - 1)) / 2 + (60 + gap) * x; | |
b6ceaaff | 63 | |
56a24300 JF |
64 | return origin; |
65 | } | |
66 | ||
67 | extern "C" void TweakInitialize() { | |
b6ceaaff | 68 | Class $SBButtonBar(objc_getClass("SBButtonBar")); |
56a24300 JF |
69 | _SBButtonBar$leftMarginForIconRowArray$ = MSHookMessage($SBButtonBar, @selector(leftMarginForIconRowArray:), &$SBButtonBar$leftMarginForIconRowArray$); |
70 | MSHookMessage($SBButtonBar, @selector(maxIconColumns), &$SBButtonBar$maxIconColumns); | |
71 | MSHookMessage($SBButtonBar, @selector(topIconPadding), &$SBButtonBar$topIconPadding); | |
72 | _SBButtonBar$originForIconAtX$Y$ = MSHookMessage($SBButtonBar, @selector(originForIconAtX:Y:), &$SBButtonBar$originForIconAtX$Y$); | |
b6ceaaff JF |
73 | |
74 | Class $SBIcon(objc_getClass("SBIcon")); | |
56a24300 | 75 | _SBIcon$setOrigin$ = MSHookMessage($SBIcon, @selector(setOrigin:), &$SBIcon$setOrigin$); |
b6ceaaff | 76 | } |