Permalink
Browse files

Save glossy buttons @2x

  • Loading branch information...
1 parent cf9de38 commit 73d99812781d6d69946f8a344e3220b8d1ee0ef0 @0xced 0xced committed Oct 6, 2010
@@ -10,10 +10,14 @@
#import "AppDelegate.h"
#import <QuartzCore/QuartzCore.h>
+#import "APELite.h"
+#import <mach-o/dyld.h>
#import <dlfcn.h>
@implementation GlossyButtonViewController
+static UIImage*(*GetTintedGlassButtonImage)(UIColor*, UIControlState) = NULL;
+
@synthesize titleTextField;
@synthesize fontSizeSlider, fontSizeLabel;
@synthesize widthSlider, widthLabel;
@@ -24,6 +28,29 @@ @implementation GlossyButtonViewController
@synthesize alphaSlider, alphaLabel;
@synthesize glossyButton;
++ (void) initialize
+{
+ if (self != [GlossyButtonViewController class])
+ return;
+
+ for(uint32_t i = 0; i < _dyld_image_count(); i++)
+ {
+ if (strstr(_dyld_get_image_name(i), "UIKit.framework"))
+ {
+ struct mach_header* header = (struct mach_header*)_dyld_get_image_header(i);
+ GetTintedGlassButtonImage = APEFindSymbol(header, "_GetTintedGlassButtonImage");
+
+ NSMutableDictionary **__images = APEFindSymbol(header, "___images");
+ if (__images && [[UIScreen mainScreen] scale] > 1)
+ {
+ for (NSString *glassButtonImageName in [NSArray arrayWithObjects:/*@"UITintedGlassButtonGradient.png",*/ @"UITintedGlassButtonHighlight.png", @"UITintedGlassButtonMask.png", @"UITintedGlassButtonShadow.png", nil])
+ [*__images setObject:[UIImage imageNamed:glassButtonImageName] forKey:glassButtonImageName];
+ }
+ break;
+ }
+ }
+}
+
- (void) sizeToFit
{
CGSize fitSize = [self.glossyButton sizeThatFits:self.glossyButton.bounds.size];
@@ -109,57 +136,60 @@ - (IBAction) changeFontSize:(UISlider *)slider
self.fontSizeLabel.text = [NSString stringWithFormat:@"%g", fontSize];
}
-- (void) saveButtonInState:(UIControlState)state
+- (void) saveButtonInState:(UIControlState)state scale:(CGFloat)scale
{
- NSString *buttonTitle = [self.glossyButton titleForState:UIControlStateNormal];
- [self.glossyButton setTitle:nil forState:UIControlStateNormal];
-
- // Use dlsym so that it still compiles with the 3.1.3 SDK, could aslo use #if __IPHONE_OS_VERSION_MAX_ALLOWED < 40000
- void (*UIGraphicsBeginImageContextWithOptions)(CGSize, BOOL, CGFloat) = dlsym(RTLD_DEFAULT, "UIGraphicsBeginImageContextWithOptions");
- if (UIGraphicsBeginImageContextWithOptions)
- UIGraphicsBeginImageContextWithOptions(self.glossyButton.frame.size, NO, 0.0);
- else
- UIGraphicsBeginImageContext(self.glossyButton.frame.size);
-
- NSString *buttonName = nil;
-
+ if (!GetTintedGlassButtonImage)
+ {
+ NSLog(@"GetTintedGlassButtonImage function not found");
+ return;
+ }
+
+ NSString *buttonName = @"glossyButton";
+ NSString *xSuffix = scale > 1 ? [NSString stringWithFormat:@"@%gx", scale] : @"";
switch (state)
{
case UIControlStateNormal:
- self.glossyButton.highlighted = NO;
- self.glossyButton.enabled = YES;
- buttonName = @"glossyButton-normal.png";
+ buttonName = [NSString stringWithFormat:@"glossyButton-normal%@.png", xSuffix];
break;
case UIControlStateHighlighted:
- self.glossyButton.highlighted = YES;
- self.glossyButton.enabled = YES;
- buttonName = @"glossyButton-highlighted.png";
+ buttonName = [NSString stringWithFormat:@"glossyButton-highlighted%@.png", xSuffix];
break;
case UIControlStateDisabled:
- self.glossyButton.highlighted = NO;
- self.glossyButton.enabled = NO;
- buttonName = @"glossyButton-disabled.png";
+ buttonName = [NSString stringWithFormat:@"glossyButton-disabled%@.png", xSuffix];
break;
}
-
- CGContextRef theContext = UIGraphicsGetCurrentContext();
- [self.glossyButton.layer renderInContext:theContext];
-
+
+ // Use dlsym so that it still compiles with the 3.1.3 SDK, could aslo use #if __IPHONE_OS_VERSION_MAX_ALLOWED < 40000
+ void (*UIGraphicsBeginImageContextWithOptions)(CGSize, BOOL, CGFloat) = dlsym(RTLD_DEFAULT, "UIGraphicsBeginImageContextWithOptions");
+ if (UIGraphicsBeginImageContextWithOptions)
+ UIGraphicsBeginImageContextWithOptions(self.glossyButton.frame.size, NO, scale);
+ else
+ UIGraphicsBeginImageContext(self.glossyButton.frame.size);
+
+ UIImage *stretchableImage = GetTintedGlassButtonImage([self.glossyButton valueForKey:@"tintColor"], state);
+ CGFloat alpha = state == UIControlStateDisabled ? 0.5 : 1.0;
+ [stretchableImage drawInRect:self.glossyButton.bounds blendMode:kCGBlendModeNormal alpha:alpha];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
NSData *data = UIImagePNGRepresentation(image);
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[data writeToFile:[[appDelegate saveDirectory:@"UIGlassButton"] stringByAppendingPathComponent:buttonName] atomically:YES];
-
+
UIGraphicsEndImageContext();
-
- [self.glossyButton setTitle:buttonTitle forState:UIControlStateNormal];
}
- (IBAction) save
{
- [self saveButtonInState:UIControlStateDisabled];
- [self saveButtonInState:UIControlStateHighlighted];
- [self saveButtonInState:UIControlStateNormal];
+ [self saveButtonInState:UIControlStateDisabled scale:1];
+ [self saveButtonInState:UIControlStateHighlighted scale:1];
+ [self saveButtonInState:UIControlStateNormal scale:1];
+
+ CGFloat scale = [[UIScreen mainScreen] scale];
+ if (scale > 1)
+ {
+ [self saveButtonInState:UIControlStateDisabled scale:scale];
+ [self saveButtonInState:UIControlStateHighlighted scale:scale];
+ [self saveButtonInState:UIControlStateNormal scale:scale];
+ }
}
// MARK: Text Field Delegate
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -27,6 +27,9 @@
DA88C84111FF432300FC6850 /* Icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = DA88C84011FF432300FC6850 /* Icon@2x.png */; };
DA8BF5B9112EAC4E0044106B /* GlossyButtonViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DA8BF5B8112EAC4E0044106B /* GlossyButtonViewController.m */; };
DAC796A011FD71E100A33F28 /* ArtworkDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = DAC7969F11FD71E100A33F28 /* ArtworkDetailViewController.xib */; };
+ DAF387911211AF30003DF2B8 /* UITintedGlassButtonHighlight@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = DAF3878D1211AF30003DF2B8 /* UITintedGlassButtonHighlight@2x.png */; };
+ DAF387921211AF30003DF2B8 /* UITintedGlassButtonMask@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = DAF3878E1211AF30003DF2B8 /* UITintedGlassButtonMask@2x.png */; };
+ DAF387931211AF30003DF2B8 /* UITintedGlassButtonShadow@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = DAF3878F1211AF30003DF2B8 /* UITintedGlassButtonShadow@2x.png */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -58,6 +61,9 @@
DA8BF5B7112EAC4E0044106B /* GlossyButtonViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GlossyButtonViewController.h; sourceTree = "<group>"; };
DA8BF5B8112EAC4E0044106B /* GlossyButtonViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GlossyButtonViewController.m; sourceTree = "<group>"; };
DAC7969F11FD71E100A33F28 /* ArtworkDetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ArtworkDetailViewController.xib; sourceTree = "<group>"; };
+ DAF3878D1211AF30003DF2B8 /* UITintedGlassButtonHighlight@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "UITintedGlassButtonHighlight@2x.png"; sourceTree = "<group>"; };
+ DAF3878E1211AF30003DF2B8 /* UITintedGlassButtonMask@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "UITintedGlassButtonMask@2x.png"; sourceTree = "<group>"; };
+ DAF3878F1211AF30003DF2B8 /* UITintedGlassButtonShadow@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "UITintedGlassButtonShadow@2x.png"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -134,6 +140,7 @@
DA3A6AFE120A9C8E00915B15 /* Checkerboard.png */,
DA4F04CF11E91862009A316E /* Icon.png */,
DA88C84011FF432300FC6850 /* Icon@2x.png */,
+ DAF3878B1211AF30003DF2B8 /* Shared */,
8D1107310486CEB800E47090 /* UIKit_Artwork_Extractor-Info.plist */,
);
name = Resources;
@@ -158,6 +165,17 @@
path = "APE Lite";
sourceTree = "<group>";
};
+ DAF3878B1211AF30003DF2B8 /* Shared */ = {
+ isa = PBXGroup;
+ children = (
+ DAF3878D1211AF30003DF2B8 /* UITintedGlassButtonHighlight@2x.png */,
+ DAF3878E1211AF30003DF2B8 /* UITintedGlassButtonMask@2x.png */,
+ DAF3878F1211AF30003DF2B8 /* UITintedGlassButtonShadow@2x.png */,
+ );
+ name = Shared;
+ path = Resources/Shared;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -211,6 +229,9 @@
DA88C83411FF40E900FC6850 /* GlossyButton@2x.png in Resources */,
DA88C84111FF432300FC6850 /* Icon@2x.png in Resources */,
DA3A6AFF120A9C8E00915B15 /* Checkerboard.png in Resources */,
+ DAF387911211AF30003DF2B8 /* UITintedGlassButtonHighlight@2x.png in Resources */,
+ DAF387921211AF30003DF2B8 /* UITintedGlassButtonMask@2x.png in Resources */,
+ DAF387931211AF30003DF2B8 /* UITintedGlassButtonShadow@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

0 comments on commit 73d9981

Please sign in to comment.