]> git.saurik.com Git - fiveicondock.git/blob - Tweak.mm
302701f82c9aedc5b3680dad77354dfcbaf27a79
[fiveicondock.git] / Tweak.mm
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 #import <SpringBoard/SBIconModel.h>
9
10 MSClassHook(SBButtonBar)
11 MSClassHook(SBIcon)
12 MSClassHook(SBIconModel)
13
14 MSMetaClassHook(SBIconModel)
15
16 MSInstanceMessageHook1(float, SBButtonBar, leftMarginForIconRowArray, NSArray *, row) {
17 return [row indexOfObject:[NSNull null]] == NSNotFound ? 4 : MSOldCall(row);
18 }
19
20 MSInstanceMessageHook0(int, SBButtonBar, maxIconColumns) {
21 return 10;
22 }
23
24 static unsigned $SBButtonBar$count(SBButtonBar *self) {
25 MSIvarHook(NSArray *, _iconMatrix);
26 NSArray *row([_iconMatrix objectAtIndex:0]);
27 unsigned count(0);
28 for (id icon in row)
29 if (icon != [NSNull null])
30 ++count;
31 return count;
32 }
33
34 MSInstanceMessageHook0(float, SBButtonBar, topIconPadding) {
35 return 313370 + $SBButtonBar$count(self);
36 }
37
38 MSInstanceMessageHook1(void, SBIcon, setOrigin, CGPoint, origin) {
39 unsigned count(origin.y);
40 if (count < 313370)
41 goto set;
42 count -= 313370;
43
44 if (count > 40)
45 origin.x = 256;
46 else if (count > 10 || count < 0)
47 goto set;
48 else if (count == 5)
49 origin.x = (origin.x - 4) / 76 * 63 + 4;
50
51 origin.y = 11;
52 set:
53 MSOldCall(origin);
54 }
55
56 MSInstanceMessageHook2(CGPoint, SBButtonBar, originForIconAtX,Y, int, x, int, y) {
57 CGPoint origin;//(MSOldCall(x, y, ));
58 //NSLog(@"f:%u,%u=(%f,%f)", x, y, origin.x, origin.y);
59 origin.y = 11;
60
61 unsigned count($SBButtonBar$count(self)), gap;
62 unsigned space(320 - 60 * count);
63
64 if (count >= 4)
65 gap = space / (count + 1);
66 else // I hate people who love Apple.
67 gap = 16;
68
69 origin.x = (space - gap * (count - 1)) / 2 + (60 + gap) * x;
70
71 return origin;
72 }
73
74 /*MSClassMessageHook0(int, SBIconModel, maxIconListCount) {
75 return 16;
76 }*/