-
Notifications
You must be signed in to change notification settings - Fork 7
/
LegacyUI.xm
234 lines (210 loc) · 11.2 KB
/
LegacyUI.xm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#import <EmojiLibrary/PSEmojiUtilities.h>
#import <PSHeader/Misc.h>
#import <UIKit/UIApplication+Private.h>
#import <UIKit/UIKeyboardImpl.h>
#import <theos/IOSMacros.h>
#import <version.h>
#import "Global.h"
#import "LegacyUI.h"
extern NSString *UIKBEmojiDivider;
extern NSString *UIKBEmojiDarkDivider;
extern NSString *UIKBEmojiSelectedDivider;
void (*UIKBThemeSetFontSize)(UIKBThemeRef, CGFloat);
void (*UIKBThemeSetSymbolColor)(UIKBThemeRef, CGColorRef);
void (*UIKBThemeSetForegroundGradient)(UIKBThemeRef, CGGradientRef);
void (*UIKBThemeSetEtchColor)(UIKBThemeRef, CGColorRef);
void (*UIKBThemeSetEtchDY)(UIKBThemeRef, CGFloat);
void (*UIKBThemeRelease)(UIKBThemeRef);
void (*UIKBDrawEtchedSymbolString)(CGContextRef, NSString *, UIKBThemeRef, CGRect);
void (*UIKBDrawRoundRectKeyBackground)(CGContextRef, UIKBTree *, UIKBTree *, int, UIKBThemeRef, UIKBRectsRef);
CGContextRef (*UIKBCreateBitmapContextWithScale)(CGSize size, CGFloat scale);
CGFloat (*UIKBKeyboardDefaultLandscapeWidth)();
UIImage *egImage(CGRect frame, NSString *imageName, BOOL pressed) {
return [%c(UIKeyboardEmojiGraphics) imageWithRect:frame name:imageName pressed:pressed];
}
NSMutableArray <UIImage *> *emojiCategoryBarImages(CGRect frame, BOOL pressed) {
NSMutableArray <UIImage *> *array = [NSMutableArray array];
[array addObject:egImage(frame, @"categoryRecents", pressed)];
[array addObject:egImage(frame, @"categoryPeople", pressed)];
[array addObject:egImage(frame, @"categoryNature", pressed)];
[array addObject:egImage(frame, @"categoryFoodAndDrink", pressed)];
[array addObject:egImage(frame, @"categoryActivity", pressed)];
[array addObject:egImage(frame, @"categoryPlaces", pressed)];
[array addObject:egImage(frame, @"categoryObjects", pressed)];
[array addObject:egImage(frame, @"categorySymbols", pressed)];
[array addObject:egImage(frame, @"categoryFlags", pressed)];
return array;
}
%hook UIKeyboardEmojiCategoryBar_iPhone
- (void)layoutSubviews {
%orig;
for (UIImageView *divider in [self valueForKey:@"_dividerViews"])
divider.frame = CGRectMake(divider.frame.origin.x - 1.15, divider.frame.origin.y, divider.frame.size.width, divider.frame.size.height);
for (UIImageView *segment in [self valueForKey:@"_segmentViews"])
segment.frame = CGRectMake(segment.frame.origin.x - 1.15, segment.frame.origin.y, segment.frame.size.width, segment.frame.size.height);
}
- (void)updateSegmentImages {
NSMutableArray <UIView *> *segmentViews([self valueForKey:@"_segmentViews"]);
for (UIView *segment in segmentViews)
[segment removeFromSuperview];
NSMutableArray <UIView *> *dividerViews([self valueForKey:@"_dividerViews"]);
for (UIView *divider in dividerViews)
[divider removeFromSuperview];
[self releaseImagesAndViews];
NSUInteger numberOfCategories = [%c(UIKeyboardEmojiCategory) numberOfCategories];
CGRect barFrame = self.frame;
CGFloat dividerWidth = 1.0;
CGFloat barWidth = barFrame.size.width;
barFrame.size.width = (barWidth - (numberOfCategories + 1) * dividerWidth) / numberOfCategories;
[self setValue:emojiCategoryBarImages(barFrame, NO) forKey:@"_unselectedImages"];
[self setValue:emojiCategoryBarImages(barFrame, YES) forKey:@"_selectedImages"];
NSInteger additionalDivider = 0;
CGFloat barHeight = barFrame.size.height;
CGPoint origin = barFrame.origin;
MSHookIvar<UIImage *>(self, "_plainDivider") = [egImage(CGRectMake(origin.x, origin.y, dividerWidth, barHeight), UIKBEmojiDivider, NO) retain];
MSHookIvar<UIImage *>(self, "_darkDivider") = [egImage(CGRectMake(origin.x, origin.y, dividerWidth, barHeight), UIKBEmojiDarkDivider, NO) retain];
MSHookIvar<UIImage *>(self, "_selectedDivider") = [egImage(CGRectMake(origin.x, origin.y, dividerWidth, barHeight), UIKBEmojiSelectedDivider, NO) retain];
NSInteger orientation = [[UIApplication sharedApplication] _frontMostAppOrientation];
if (!IS_IPAD && ((UIKBKeyboardDefaultLandscapeWidth() > 480.0) || (orientation == 3 || orientation == 4)))
additionalDivider = 1;
NSArray <UIImage *> *currentUnselectedImages = [self valueForKey:@"_unselectedImages"];
NSUInteger unselectedImagesCount = [currentUnselectedImages count];
MSHookIvar<NSInteger>(self, "_total") = unselectedImagesCount;
MSHookIvar<NSInteger>(self, "_dividerTotal") = unselectedImagesCount + additionalDivider;
MSHookIvar<NSMutableArray *>(self, "_segmentViews") = [[NSMutableArray alloc] initWithCapacity:MSHookIvar<NSInteger>(self, "_total")];
MSHookIvar<NSMutableArray *>(self, "_dividerViews") = [[NSMutableArray alloc] initWithCapacity:MSHookIvar<NSInteger>(self, "_dividerTotal") + 1];
int total = [[self valueForKey:@"_total"] intValue];
if (total) {
int i = 0;
do {
UIImageView *unselectedImageView = [[UIImageView alloc] initWithImage:currentUnselectedImages[i]];
[self addSubview:unselectedImageView];
[[self valueForKey:@"_segmentViews"] insertObject:unselectedImageView atIndex:i];
[unselectedImageView release];
} while (++i < total);
}
int dividerCount = [[self valueForKey:@"_dividerTotal"] intValue];
if (dividerCount) {
int j = 0;
do {
UIImage *dividerImage = (j && j < dividerCount) ? MSHookIvar<UIImage *>(self, "_plainDivider") : MSHookIvar<UIImage *>(self, "_darkDivider");
UIImageView *dividerImageView = [[UIImageView alloc] initWithImage:dividerImage];
[self addSubview:dividerImageView];
[[self valueForKey:@"_dividerViews"] insertObject:dividerImageView atIndex:j];
[dividerImageView release];
} while (++j - 1 < dividerCount);
}
[self updateSegmentAndDividers:[[self valueForKey:@"_selected"] intValue]];
}
%end
%hook UIKeyboardEmojiGraphics
- (UIImage *)categoryKeyGenerator:(bool)pressed rect:(CGRect)rect {
UIKBTree *protoKey = [self protoKeyWithDisplayString:@"!"];
UIKBShape *shape = [[[%c(UIKBShape) alloc] initWithGeometry:nil frame:rect paddedFrame:rect] autorelease];
protoKey.shape = shape;
UIKBTree *protoKeyboard = [self protoKeyboard];
int state = pressed ? 8 : 4;
UIKBThemeRef theme = [self createProtoThemeForKey:protoKey keyboard:protoKeyboard state:state];
CGFloat fontSize = [%c(UIKeyboardEmojiGraphics) isLandscape] ? 38.0 : 32.0;
UIKBThemeSetFontSize(theme, fontSize);
CGColorRef color = NULL;
CGGradientRef gradient = NULL;
if (pressed) {
UIKBThemeSetSymbolColor(theme, UIKBGetNamedColor(CFSTR("UIKBColorWhite")));
UIKBThemeSetEtchColor(theme, UIKBGetNamedColor(CFSTR("UIKBColorBlack_Alpha50")));
UIKBThemeSetEtchDY(theme, -1.0);
CGColorRef end = UIKBGetNamedColor(CFSTR("UIKBColorKeyBlueRow1GradientEnd"));
CGColorRef start = UIKBGetNamedColor(CFSTR("UIKBColorKeyBlueRow1GradientStart"));
gradient = UIKBCreateTwoColorLinearGradient(end, start);
UIKBThemeSetForegroundGradient(theme, gradient);
} else {
color = UIKBColorCreate(69, 69, 85, 1.0);
UIKBThemeSetSymbolColor(theme, color);
}
UIKBRectsRef rects = UIKBRectsCreate(protoKeyboard, protoKey);
CGFloat scale = UIKBScale();
CGContextRef ctx = UIKBCreateBitmapContextWithScale(rect.size, scale);
CGContextSaveGState(ctx);
CGContextResetCTM(ctx);
CGAffineTransform t = CGAffineTransformMakeScale(scale, scale);
CGContextConcatCTM(ctx, t);
t.a = 1.0;
t.b = 0.0;
t.c = 0.0;
t.d = -1.0;
t.tx = 0.0;
t.ty = rect.size.height;
CGContextConcatCTM(ctx, t);
CGRect frame = CGRectInset(protoKey.frame, 4.0, 4.0);
UIKBRectsSetFrame(rects, frame);
CGRect displayFrame = CGRectInset(protoKey.frame, 4.0, 4.0);
UIKBRectsSetDisplayFrame(rects, displayFrame);
CGRect paddedFrame = CGRectInset(protoKey.frame, 4.0, 4.0);
UIKBRectsSetPaddedFrame(rects, paddedFrame);
UIKBDrawRoundRectKeyBackground(ctx, protoKeyboard, protoKey, state, theme, rects);
CGRect symbolRect = CGRectInset(rect, 4.0, 4.0);
CGFloat d = symbolRect.size.width / CATEGORIES_COUNT;
symbolRect.origin.x -= 4 * d; // FIXME: We should not need this line
for (NSString *symbol in displaySymbolsAsGlyphs()) {
CGContextSaveGState(ctx);
UIKBDrawEtchedSymbolString(ctx, symbol, theme, symbolRect);
CGContextRestoreGState(ctx);
symbolRect.origin.x += d;
}
CGImageRef cgImage = CGBitmapContextCreateImage(ctx);
UIImage *image = [UIImage imageWithCGImage:cgImage scale:scale orientation:0];
CGContextRelease(ctx);
CGImageRelease(cgImage);
UIKBRectsRelease(rects);
if (color)
CGColorRelease(color);
if (gradient)
CGGradientRelease(gradient);
UIKBThemeRelease(theme);
return image;
}
- (UIImage *)categoryRecentsGenerator:(id)pressed {
return [self categoryWithSymbol:displaySymbolsAsGlyphs()[0] pressed:pressed];
}
- (UIImage *)categoryPeopleGenerator:(id)pressed {
return [self categoryWithSymbol:displaySymbolsAsGlyphs()[1] pressed:pressed];
}
- (UIImage *)categoryNatureGenerator:(id)pressed {
return [self categoryWithSymbol:displaySymbolsAsGlyphs()[2] pressed:pressed];
}
- (UIImage *)categoryPlacesGenerator:(id)pressed {
return [self categoryWithSymbol:displaySymbolsAsGlyphs()[3] pressed:pressed];
}
- (UIImage *)categoryObjectsGenerator:(id)pressed {
return [self categoryWithSymbol:displaySymbolsAsGlyphs()[4] pressed:pressed];
}
- (UIImage *)categorySymbolsGenerator:(id)pressed {
return [self categoryWithSymbol:displaySymbolsAsGlyphs()[5] pressed:pressed];
}
%new
- (UIImage *)categoryActivityGenerator:(id)pressed {
return [self categoryWithSymbol:displaySymbolsAsGlyphs()[6] pressed:pressed];
}
%new
- (UIImage *)categoryFoodAndDrinkGenerator:(id)pressed {
return [self categoryWithSymbol:displaySymbolsAsGlyphs()[7] pressed:pressed];
}
%new
- (UIImage *)categoryFlagsGenerator:(id)pressed {
return [self categoryWithSymbol:displaySymbolsAsGlyphs()[8] pressed:pressed];
}
%end
%ctor {
MSImageRef ref = MSGetImageByName(realPath2(@"/System/Library/Frameworks/UIKit.framework/UIKit"));
UIKBKeyboardDefaultLandscapeWidth = (CGFloat (*)())MSFindSymbol(ref, "_UIKBKeyboardDefaultLandscapeWidth");
UIKBThemeSetFontSize = (void (*)(UIKBThemeRef, CGFloat))MSFindSymbol(ref, "_UIKBThemeSetFontSize");
UIKBThemeSetSymbolColor = (void (*)(UIKBThemeRef, CGColorRef))MSFindSymbol(ref, "_UIKBThemeSetSymbolColor");
UIKBThemeSetForegroundGradient = (void (*)(UIKBThemeRef, CGGradientRef))MSFindSymbol(ref, "_UIKBThemeSetForegroundGradient");
UIKBThemeSetEtchColor = (void (*)(UIKBThemeRef, CGColorRef))MSFindSymbol(ref, "_UIKBThemeSetEtchColor");
UIKBThemeSetEtchDY = (void (*)(UIKBThemeRef, CGFloat))MSFindSymbol(ref, "_UIKBThemeSetEtchDY");
UIKBThemeRelease = (void (*)(UIKBThemeRef))MSFindSymbol(ref, "_UIKBThemeRelease");
UIKBDrawEtchedSymbolString = (void (*)(CGContextRef, NSString *, UIKBThemeRef, CGRect))MSFindSymbol(ref, "_UIKBDrawEtchedSymbolString");
UIKBDrawRoundRectKeyBackground = (void (*)(CGContextRef, UIKBTree *, UIKBTree *, int, UIKBThemeRef, UIKBRectsRef))MSFindSymbol(ref, "_UIKBDrawRoundRectKeyBackground");
UIKBCreateBitmapContextWithScale = (CGContextRef (*)(CGSize, CGFloat))MSFindSymbol(ref, "_UIKBCreateBitmapContextWithScale");
%init;
}