Permalink
Browse files

Fixed segmentedcontrol behavior, added nsbuttoncell customization

  • Loading branch information...
1 parent 1173ab6 commit 7ef2488ebdfd3572a78304c30cfebd1a12af588f @alexzielenski committed Apr 12, 2011
View
BIN .DS_Store
Binary file not shown.
View
29,254 ....xcodeproj/project.xcworkspace/xcuserdata/Alex.xcuserdatad/UserInterfaceState.xcuserstate
15,119 additions, 14,135 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
1 Black Mac OS X/Classes/SIMBL/BMXController.m
@@ -40,6 +40,7 @@ - (void)swizzle {
NSLog(@"Swizzling…");
[NSThemeFrame swizzle];
[NSCell swizzle];
+ [NSButtonCell swizzle];
// [NSSegmentedCell swizzle];
}
@end
View
11 Black Mac OS X/Classes/SIMBL/Categories/BMXCell.h
@@ -11,11 +11,16 @@
@interface NSCell (BMXCell)
- (NSBackgroundStyle)new_backgroundStyle;
-@end
-@interface NSSegmentedCell (BMXSegmentedCell)
- (NSGradient*)titleGradient;
+ (NSGradient*)selectedGradient;
+@end
+
+@interface NSSegmentedCell (BMXSegmentedCell)
+@end
-- (struct CGRect)_rectForSegment:(long long)arg1 inFrame:(struct CGRect)arg2; // IMP=0x00127768
+@interface NSButtonCell (BMXButtonCell)
+- (void)new_drawBezelWithFrame:(NSRect)arg1 inView:(id)arg2;
+- (NSBackgroundStyle)new_interiorBackgroundStyle;
+- (BOOL)shouldHack;
@end
View
144 Black Mac OS X/Classes/SIMBL/Categories/BMXCell.m
@@ -10,9 +10,26 @@
#import "NSThemeFrame.h"
#import "NSBezierPath+MCAdditions.h"
+typedef enum {
+ BMXSegmentNormalState = 1,
+ BMXSegmentDisabledState = 0,
+ BMXSegmentMouseDownState = 3,
+ BMXSegmentSelectedState = 4,
+ BMXSegmentSelectedMouseDownState = 5 // when the selected segment has mousedown
+} BMXSegmentHighlightState;
+
static NSGradient *titleGradient = nil;
static NSGradient *inactiveGradient = nil;
-
+@interface NSCell ()
+- (NSBackgroundStyle)orig_backgroundStyle;
+@end
+@interface NSSegmentedCell ()
+- (struct CGRect)_rectForSegment:(long long)arg1 inFrame:(struct CGRect)arg2; // IMP=0x00127768
+@end
+@interface NSButtonCell ()
+- (void)orig_drawBezelWithFrame:(NSRect)arg1 inView:(NSView*)fp8;
+- (NSBackgroundStyle)orig_interiorBackgroundStyle;
+@end
@implementation NSCell (BMXCell)
+ (void)swizzle {
// backgroundstyle
@@ -38,7 +55,7 @@ - (NSBackgroundStyle)new_backgroundStyle {
if (self.controlView) {
NSThemeFrame *themeFrame = (NSThemeFrame*)[[[self.controlView window] contentView] superview];
if (![themeFrame isKindOfClass:[NSThemeFrame class]])
- themeFrame=[themeFrame superview];
+ themeFrame=(NSThemeFrame*)[themeFrame superview];
if (!themeFrame)
return (NSBackgroundStyle)[self orig_backgroundStyle];
@@ -55,6 +72,29 @@ - (NSBackgroundStyle)new_backgroundStyle {
/*- (NSBackgroundStyle)interiorBackgroundStyle {
return NSBackgroundStyleLowered;
}*/
+- (NSGradient*)titleGradient {
+ if (!titleGradient)
+ titleGradient = [[[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceWhite:0.319 alpha:1.000]
+ endingColor:[NSColor colorWithDeviceWhite:0.160 alpha:1.000]] retain];
+ if (!inactiveGradient)
+ inactiveGradient = [[[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceWhite:0.340 alpha:1.000]
+ endingColor:[NSColor colorWithDeviceWhite:0.240 alpha:1.000]] retain];
+ if (![self.controlView.window isKeyWindow]) {
+ return inactiveGradient;
+ }
+
+
+ return titleGradient;
+
+}
++ (NSGradient*)selectedGradient {
+ static NSGradient *selectedGradient;
+ if (!selectedGradient) {
+ selectedGradient=[[NSGradient alloc] initWithStartingColor:[[NSColor whiteColor]colorWithAlphaComponent:0.45f]
+ endingColor:[NSColor clearColor]];
+ }
+ return selectedGradient;
+}
@end
@implementation NSSegmentedCell (BMXSegmentedCell)
@@ -103,15 +143,15 @@ - (BOOL)_coreUIDrawSegmentBackground:(long long)arg1 withCellFrame:(struct CGRec
[NSGraphicsContext restoreGraphicsState];
[path2 release];
-
NSInteger currentSeg = 0;
while (currentSeg<segmentCount) {
NSRect sepRect = NSRectFromCGRect([self _rectForSegment:currentSeg inFrame:arg2]);
if (currentSeg-segmentCount+1<0) {
[[NSColor blackColor] set];
NSRectFill(NSMakeRect(NSMaxX(sepRect)-1, 0, 1, NSHeight(sepRect)));
}
- if (currentSeg==[self selectedSegment]) {
+ BMXSegmentHighlightState state = [self _segmentHighlightState:currentSeg];
+ if (state==BMXSegmentSelectedState||state==BMXSegmentMouseDownState||state==BMXSegmentSelectedMouseDownState) {
NSShadow *selectedShadow = [[NSShadow alloc] init];
[selectedShadow setShadowColor:[NSColor whiteColor]];
[selectedShadow setShadowBlurRadius:2.0f];
@@ -138,27 +178,89 @@ - (BOOL)_coreUIDrawSegmentBackground:(long long)arg1 withCellFrame:(struct CGRec
return YES;
}
-- (NSGradient*)titleGradient {
- if (!titleGradient)
- titleGradient = [[[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceWhite:0.319 alpha:1.000]
- endingColor:[NSColor colorWithDeviceWhite:0.160 alpha:1.000]] retain];
- if (!inactiveGradient)
- inactiveGradient = [[[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceWhite:0.340 alpha:1.000]
- endingColor:[NSColor colorWithDeviceWhite:0.240 alpha:1.000]] retain];
- if (![self.controlView.window isKeyWindow]) {
- return inactiveGradient;
+
+@end
+
+@implementation NSButtonCell (BMXButtonCell)
++ (void)swizzle {
+ NSError *err = nil;
+ [self jr_aliasMethod:@selector(drawBezelWithFrame:inView:)
+ withSelector:@selector(orig_drawBezelWithFrame:inView:)
+ error:&err];
+ NSLog(@"%@", err);
+ [self jr_swizzleMethod:@selector(drawBezelWithFrame:inView:)
+ withMethod:@selector(new_drawBezelWithFrame:inView:)
+ error:&err];
+ NSLog(@"%@", err);
+
+ [self jr_aliasMethod:@selector(interiorBackgroundStyle)
+ withSelector:@selector(orig_interiorBackgroundStyle)
+ error:&err];
+ NSLog(@"%@", err);
+ [self jr_swizzleMethod:@selector(interiorBackgroundStyle)
+ withMethod:@selector(new_interiorBackgroundStyle)
+ error:&err];
+ NSLog(@"%@", err);
+
+}
+- (BOOL)shouldHack {
+ return (self.bezelStyle==NSTexturedSquareBezelStyle||self.bezelStyle==NSTexturedRoundedBezelStyle); // only hack textured buttons
+}
+- (NSBackgroundStyle)new_interiorBackgroundStyle {
+ if (self.shouldHack)
+ return NSBackgroundStyleLowered;
+ return [self orig_interiorBackgroundStyle];
+}
+- (void)new_drawBezelWithFrame:(NSRect)frame inView:(NSView*)arg2 {
+ if (!self.shouldHack) {
+ [self orig_drawBezelWithFrame:frame inView:arg2];
+ return;
}
+ NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:frame
+ cornerRadius:4.0];
+ [path setLineWidth:2.0f];
+ [path addClip];
- return titleGradient;
+ NSBezierPath *path2 = [path copy];
-}
-+ (NSGradient*)selectedGradient {
- static NSGradient *selectedGradient;
- if (!selectedGradient) {
- selectedGradient=[[NSGradient alloc] initWithStartingColor:[[NSColor whiteColor]colorWithAlphaComponent:0.45f]
- endingColor:[NSColor clearColor]];
+ [self.titleGradient drawInBezierPath:path
+ angle:90];
+
+ [NSGraphicsContext saveGraphicsState];
+ NSAffineTransform *trans = [NSAffineTransform transform];
+ [trans translateXBy:0.0f yBy:1.0f];
+ [path2 transformUsingAffineTransform:trans];
+
+ [[[NSColor whiteColor]colorWithAlphaComponent:0.25] set];
+ [path2 stroke];
+ [path setClip];
+ [NSGraphicsContext restoreGraphicsState];
+
+ [path setLineWidth:2.0f];
+ [NSGraphicsContext saveGraphicsState];
+ [[NSColor blackColor] set];
+
+ [path stroke];
+ [path2 setClip];
+
+ [NSGraphicsContext restoreGraphicsState];
+ [path2 release];
+
+ if (self.isHighlighted) {
+ NSBezierPath *selectionPath = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(path.bounds,
+ 1, 1)
+ cornerRadius:4.0f];
+ NSShadow *selectedShadow = [[NSShadow alloc] init];
+ [selectedShadow setShadowColor:[NSColor whiteColor]];
+ [selectedShadow setShadowBlurRadius:2.0f];
+
+ [selectionPath fillWithInnerShadow:selectedShadow];
+ [self.class.selectedGradient drawInBezierPath:selectionPath angle:-90];
+ [selectedShadow release];
}
- return selectedGradient;
+ [path setClip];
+
}
+
@end
View
4 Black Mac OS X/Classes/SIMBL/Categories/BMXThemeWidgetCell.m
@@ -30,8 +30,8 @@ - (void)coreUIDrawWithFrame:(struct CGRect)arg1 inView:(id)arg2 {
BMXTitlebarButtonStyle style = self.buttonID;
BOOL disabled = ([(NSString*)[self coreUIState] isEqualToString:@"disabled"]);
BOOL shouldRollover = ([(NSString*)[self coreUIState] isEqualToString:@"rollover"]);
- NSLog(@"%@", (NSString*)[self coreUIState]);
- NSLog(@"%@", (NSDictionary*)_coreUIDrawOptions);
+// NSLog(@"%@", (NSString*)[self coreUIState]);
+// NSLog(@"%@", (NSDictionary*)_coreUIDrawOptions);
NSRect frame = NSZeroRect;
if (style==BMXTitlebarToolbar) {
View
2 README.textile
@@ -35,7 +35,7 @@ The layout of the documents should be self-explanatory, if not. Here is a quick
[self orig_overriddenMethod]; // Call the original method (if needed)
[self setColor:[NSColor greenColor]]; // Do what you need to do.
}</pre>
- 4. Don't forget to import the category you create into BMXController and add the JRSwizzle code:
+ 4. Don't forget to import the category you create into BMXController and called -swizzle and add this code into the swizzle method of your category!
<pre>#import "BMXTableView.h"

0 comments on commit 7ef2488

Please sign in to comment.