]> git.saurik.com Git - fiveicondock.git/blame - Tweak.mm
Fixed conflict with FiveIRows.
[fiveicondock.git] / Tweak.mm
CommitLineData
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
9MSHook(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 13static int $SBButtonBar$maxIconColumns(SBButtonBar *self, SEL sel) {
b6ceaaff
JF
14 return 5;
15}
16
56a24300
JF
17static 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
JF
27static float $SBButtonBar$topIconPadding(SBButtonBar *self, SEL sel) {
28 return $SBButtonBar$count(self);
b6ceaaff
JF
29}
30
56a24300
JF
31MSHook(void, SBIcon$setOrigin$, SBIcon *self, SEL sel, CGPoint origin) {
32 unsigned count(origin.y);
33 //NSLog(@"C:%u=(%f,%f)", count, origin.x, origin.y);
34
f3ba5d7c 35 if (count < 70 && count > 40)
b6ceaaff 36 origin.x = 256;
56a24300
JF
37 else if (count > 10 || count < 0)
38 goto set;
39 else if (count == 5)
40 origin.x = (origin.x - 4) / 76 * 63 + 4;
41
42 origin.y = 11;
b6ceaaff 43 set:
56a24300 44 _SBIcon$setOrigin$(self, sel, origin);
b6ceaaff
JF
45}
46
56a24300
JF
47MSHook(CGPoint, SBButtonBar$originForIconAtX$Y$, SBButtonBar *self, SEL sel, int x, int y) {
48 CGPoint origin;//(_SBButtonBar$originForIconAtX$Y$(self, sel, x, y));
49 //NSLog(@"f:%u,%u=(%f,%f)", x, y, origin.x, origin.y);
50 origin.y = 11;
51
52 unsigned count($SBButtonBar$count(self)), gap;
53 unsigned space(320 - 60 * count);
54
55 if (count >= 4)
56 gap = space / (count + 1);
57 else // I hate people who love Apple.
58 gap = 16;
59
60 origin.x = (space - gap * (count - 1)) / 2 + (60 + gap) * x;
b6ceaaff 61
56a24300
JF
62 return origin;
63}
64
65extern "C" void TweakInitialize() {
b6ceaaff 66 Class $SBButtonBar(objc_getClass("SBButtonBar"));
56a24300
JF
67 _SBButtonBar$leftMarginForIconRowArray$ = MSHookMessage($SBButtonBar, @selector(leftMarginForIconRowArray:), &$SBButtonBar$leftMarginForIconRowArray$);
68 MSHookMessage($SBButtonBar, @selector(maxIconColumns), &$SBButtonBar$maxIconColumns);
69 MSHookMessage($SBButtonBar, @selector(topIconPadding), &$SBButtonBar$topIconPadding);
70 _SBButtonBar$originForIconAtX$Y$ = MSHookMessage($SBButtonBar, @selector(originForIconAtX:Y:), &$SBButtonBar$originForIconAtX$Y$);
b6ceaaff
JF
71
72 Class $SBIcon(objc_getClass("SBIcon"));
56a24300 73 _SBIcon$setOrigin$ = MSHookMessage($SBIcon, @selector(setOrigin:), &$SBIcon$setOrigin$);
b6ceaaff 74}