]> git.saurik.com Git - fiveicondock.git/blob - Tweak.mm
9f492cbb6898477a1f5fdb648ebbc0496d57c213
[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
7 #import <SpringBoard/SBButtonBar.h>
8 #import <SpringBoard/SBIcon.h>
9 #import <SpringBoard/SBIconModel.h>
10
11 @interface SBDockIconListView : NSObject {
12 }
13 - (NSArray *) icons;
14 @end
15
16 MSClassHook(SBButtonBar)
17 MSClassHook(SBDockIconListView)
18 MSClassHook(SBIcon)
19 MSClassHook(SBIconModel)
20
21 MSMetaClassHook(SBDockIconListView)
22 MSMetaClassHook(SBIconModel)
23
24 MSInstanceMessageHook1(float, SBButtonBar, leftMarginForIconRowArray, NSArray *, row) {
25 return [row indexOfObject:[NSNull null]] == NSNotFound ? 4 : MSOldCall(row);
26 }
27
28 MSInstanceMessageHook0(int, SBButtonBar, maxIconColumns) {
29 return 5;
30 }
31
32 MSClassMessageHook1(int, SBDockIconListView, iconColumnsForInterfaceOrientation, int, orientation) {
33 return 5;
34 }
35
36 static unsigned $SBButtonBar$count(SBButtonBar *self) {
37 MSIvarHook(NSArray *, _iconMatrix);
38 NSArray *row([_iconMatrix objectAtIndex:0]);
39 unsigned count(0);
40 for (id icon in row)
41 if (icon != [NSNull null])
42 ++count;
43 return count;
44 }
45
46 MSInstanceMessageHook0(float, SBButtonBar, topIconPadding) {
47 return 313370 + $SBButtonBar$count(self);
48 }
49
50 MSInstanceMessageHook1(void, SBIcon, setOrigin, CGPoint, origin) {
51 unsigned count(origin.y);
52 if (count < 313370)
53 goto set;
54 count -= 313370;
55
56 if (count > 40)
57 origin.x = 256;
58 else if (count > 10 || count < 0)
59 goto set;
60 else if (count == 5)
61 origin.x = (origin.x - 4) / 76 * 63 + 4;
62
63 origin.y = 11;
64 set:
65 MSOldCall(origin);
66 }
67
68 MSInstanceMessageHook2(CGPoint, SBButtonBar, originForIconAtX,Y, int, x, int, y) {
69 CGPoint origin;//(MSOldCall(x, y, ));
70 //NSLog(@"f:%u,%u=(%f,%f)", x, y, origin.x, origin.y);
71 origin.y = 11;
72
73 unsigned count($SBButtonBar$count(self)), gap;
74 unsigned space(320 - 60 * count);
75
76 if (count >= 4)
77 gap = space / (count + 1);
78 else // I hate people who love Apple.
79 gap = 16;
80
81 origin.x = (space - gap * (count - 1)) / 2 + (60 + gap) * x;
82
83 return origin;
84 }
85
86 // XXX: merge with previous function if possible, but not until after iPhone 4
87 MSInstanceMessageHook2(CGPoint, SBDockIconListView, originForIconAtX,Y, int, x, int, y) {
88 CGPoint origin;//(MSOldCall(x, y, ));
89 //NSLog(@"f:%u,%u=(%f,%f)", x, y, origin.x, origin.y);
90 origin.y = 11;
91
92 unsigned count([[self icons] count]), gap;
93 unsigned space(320 - 60 * count);
94
95 if (count >= 4)
96 gap = space / (count + 1);
97 else // I hate people who love Apple.
98 gap = 16;
99
100 origin.x = (space - gap * (count - 1)) / 2 + (60 + gap) * x;
101
102 return origin;
103 }
104
105 /*MSClassMessageHook0(int, SBIconModel, maxIconListCount) {
106 return 16;
107 }*/