From: Matthew Judy Date: Thu, 25 Sep 2003 11:28:51 +0000 (+0000) Subject: w00t. ITButton and ITButtonCell. Also, ITTextField is now correctly implemented... X-Git-Tag: v0.1~35 X-Git-Url: http://git.ithinksw.org/ITKit.git/commitdiff_plain/3e6ffde0979aded206bb6741114253dc0615cc9c w00t. ITButton and ITButtonCell. Also, ITTextField is now correctly implemented, using its cell for all drawing. --- diff --git a/ITButton.h b/ITButton.h new file mode 100755 index 0000000..12f5599 --- /dev/null +++ b/ITButton.h @@ -0,0 +1,8 @@ +#import + + +@interface ITButton : NSButton { + +} + +@end diff --git a/ITButton.m b/ITButton.m new file mode 100755 index 0000000..7a7a242 --- /dev/null +++ b/ITButton.m @@ -0,0 +1,39 @@ +#import "ITButton.h" +#import "ITButtonCell.h" + + +@implementation ITButton + + +/*************************************************************************/ +#pragma mark - +#pragma mark INITIALIZATION METHODS +/*************************************************************************/ + ++ (void)initialize +{ + if ( self == [ITButton class] ) { + [self setCellClass:[ITButtonCell class]]; + } +} + ++ (Class)cellClass +{ + return [ITButtonCell class]; +} + +- (id)initWithCoder:(NSCoder *)coder +{ + if ( ( self = [super initWithCoder:coder] ) ) { + ITButtonCell *cell = [[ITButtonCell alloc] init]; + [self setCell:cell]; + } + return self; +} + +- (BOOL)isOpaque +{ + return NO; +} + +@end diff --git a/ITButtonCell.h b/ITButtonCell.h new file mode 100755 index 0000000..fea3247 --- /dev/null +++ b/ITButtonCell.h @@ -0,0 +1,16 @@ +#import + + +typedef enum _ITBezelStyle { + ITGrayRoundedBezelStyle = 1001 +} ITBezelStyle; + + +@interface ITButtonCell : NSButtonCell { + + ITBezelStyle _subStyle; + +} + + +@end diff --git a/ITButtonCell.m b/ITButtonCell.m new file mode 100755 index 0000000..7885dc3 --- /dev/null +++ b/ITButtonCell.m @@ -0,0 +1,94 @@ +#import "ITButtonCell.h" +#import "ITTextFieldCell.h" + + +#define GRAY_EXTRA_PAD_H 60.0 + + +@interface ITButtonCell (Private) +- (void)drawGrayRoundedBezelWithFrame:(NSRect)rect inView:(NSView *)controlView; +@end + + +@implementation ITButtonCell + +- (id)init +{ + if ( ( self = [super init] ) ) { + _subStyle = 0; + } + + return self; +} + + + +/*************************************************************************/ +#pragma mark - +#pragma mark INSTANCE METHODS +/*************************************************************************/ + +- (void)setBezelStyle:(NSBezelStyle)bezelStyle +{ + if ( bezelStyle == ITGrayRoundedBezelStyle ) { + _subStyle = bezelStyle; + bezelStyle = NSRegularSquareBezelStyle; + } else { + _subStyle = 0; + } + + [super setBezelStyle:bezelStyle]; +} + + +/*************************************************************************/ +#pragma mark - +#pragma mark DRAWING METHODS +/*************************************************************************/ + +- (void)drawWithFrame:(NSRect)rect inView:(NSView *)controlView +{ + if ( _subStyle == ITGrayRoundedBezelStyle ) { + [self drawGrayRoundedBezelWithFrame:rect inView:controlView]; + [super drawInteriorWithFrame:rect inView:controlView]; + } else { + [super drawWithFrame:rect inView:controlView]; + } +} + +- (void)drawGrayRoundedBezelWithFrame:(NSRect)rect inView:(NSView *)controlView +{ + NSBezierPath *path = [NSBezierPath bezierPath]; + float ch = rect.size.height; + float cw = rect.size.width; + float radius = ( ch / 2 ); + NSPoint pointA = NSMakePoint( (ch / 2) , 0.0 ); + NSPoint pointB = NSMakePoint( (cw - (ch / 2)) , 0.0 ); +// NSPoint pointC = NSMakePoint( (cw - (ch / 2)) , ch ); + NSPoint pointD = NSMakePoint( (ch / 2) , ch ); + NSPoint lCtr = NSMakePoint( (ch / 2) , (ch / 2) ); + NSPoint rCtr = NSMakePoint( (cw - (ch / 2)) , (ch / 2) ); + float alpha = 0.35; + + [path moveToPoint:pointA]; + [path lineToPoint:pointB]; + [path appendBezierPathWithArcWithCenter:rCtr + radius:radius + startAngle:270.0 + endAngle:90.0]; + [path lineToPoint:pointD]; + [path appendBezierPathWithArcWithCenter:lCtr + radius:radius + startAngle:90.0 + endAngle:270.0]; + + if ( [self isHighlighted] ) { + alpha = 0.50; + } + + [[NSColor colorWithCalibratedWhite:0.0 alpha:alpha] set]; + [path fill]; +} + + +@end diff --git a/ITHotKey.m b/ITHotKey.m index bf411f9..0e2ddc3 100755 --- a/ITHotKey.m +++ b/ITHotKey.m @@ -14,9 +14,7 @@ - (id)init { - self = [super init]; - - if( self ) + if ( (self = [super init]) ) { [self setKeyCombo: [ITKeyCombo clearKeyCombo]]; } @@ -34,7 +32,9 @@ - (NSString*)description { - return [NSString stringWithFormat: @"<%@: %@>", NSStringFromClass( [self class] ), [self keyCombo]]; + return [NSString stringWithFormat: @"<%@: %@>", + NSStringFromClass( [self class] ), + [self keyCombo]]; } #pragma mark - diff --git a/ITKit.h b/ITKit.h index 8279c53..e76e907 100755 --- a/ITKit.h +++ b/ITKit.h @@ -18,6 +18,8 @@ #import #import #import +#import +#import #import #import #import diff --git a/ITTextField.h b/ITTextField.h index ea3e8f3..0a100ae 100755 --- a/ITTextField.h +++ b/ITTextField.h @@ -18,15 +18,6 @@ @interface ITTextField : NSTextField { - BOOL castsShadow; - - float shadowElevation; - float shadowAzimuth; - float shadowAmbient; - float shadowHeight; - float shadowRadius; - float shadowSaturation; - } - (BOOL)castsShadow; diff --git a/ITTextField.m b/ITTextField.m index 3ab85b7..7c0c92b 100755 --- a/ITTextField.m +++ b/ITTextField.m @@ -1,4 +1,5 @@ #import "ITTextField.h" +#import "ITTextFieldCell.h" #import #import "ITCoreGraphicsHacks.h" @@ -10,81 +11,25 @@ @implementation ITTextField + /*************************************************************************/ #pragma mark - #pragma mark INITIALIZATION METHODS /*************************************************************************/ -- (id)initWithFrame:(NSRect)frameRect ++ (void)initialize { - if ( ( self = [super initWithFrame:frameRect] ) ) { - castsShadow = NO; - shadowElevation = 45.0; - shadowAzimuth = 90.0; - shadowAmbient = 0.15; - shadowHeight = 1.00; - shadowRadius = 4.00; - shadowSaturation = 1.0; + if ( self == [ITTextField class] ) { + [self setCellClass:[ITTextFieldCell class]]; } - - return self; } -- (id)initWithCoder:(NSCoder *)coder ++ (Class)cellClass { - if ( ( self = [super initWithCoder:coder] ) ) { - castsShadow = NO; - shadowElevation = 45.0; - shadowAzimuth = 90.0; - shadowAmbient = 0.15; - shadowHeight = 1.00; - shadowRadius = 4.00; - shadowSaturation = 1.0; - } - - return self; + return [ITTextFieldCell class]; } -/*************************************************************************/ -#pragma mark - -#pragma mark DRAWING METHODS -/*************************************************************************/ - -- (void)drawRect:(NSRect)rect -{ - CGSGenericObj style = nil; - CGShadowStyle shadow; - - if ( castsShadow ) { - // Create the shadow style to use for drawing the string - shadow.version = 0; - shadow.elevation = shadowElevation; - shadow.azimuth = shadowAzimuth; - shadow.ambient = shadowAmbient; - shadow.height = shadowHeight; - shadow.radius = shadowRadius; - shadow.saturation = shadowSaturation; - style = CGStyleCreateShadow(&shadow); - - // Set the context for drawing the string - [NSGraphicsContext saveGraphicsState]; - CGContextSetStyle([[NSGraphicsContext currentContext] graphicsPort], style); - } - - // Draw the string - [super drawRect:rect]; - - - if ( castsShadow ) { - // Restore the old context - [NSGraphicsContext restoreGraphicsState]; - CGStyleRelease(style); - } -} - - - /*************************************************************************/ #pragma mark - #pragma mark ACCESSOR METHODS @@ -92,79 +37,72 @@ - (BOOL)castsShadow; { - return castsShadow; + return [[self cell] castsShadow]; } - (void)setCastsShadow:(BOOL)newSetting; { - castsShadow = newSetting; - [self setNeedsDisplay:YES]; + [[self cell] setCastsShadow:newSetting]; } - (float)shadowElevation; { - return shadowElevation; + return [[self cell] shadowElevation]; } - (void)setShadowElevation:(float)newElevation; { - shadowElevation = newElevation; - [self setNeedsDisplay:YES]; + [[self cell] setShadowElevation:newElevation]; } - (float)shadowAzimuth; { - return shadowAzimuth; + return [[self cell] shadowAzimuth]; } - (void)setShadowAzimuth:(float)newAzimuth; { - shadowAzimuth = newAzimuth; - [self setNeedsDisplay:YES]; + [[self cell] setShadowAzimuth:newAzimuth]; } - (float)shadowAmbient; { - return shadowAmbient; + return [[self cell] shadowAmbient]; } - (void)setShadowAmbient:(float)newAmbient; { - shadowAmbient = newAmbient; - [self setNeedsDisplay:YES]; + [[self cell] setShadowAmbient:newAmbient]; } - (float)shadowHeight; { - return shadowHeight; + return [[self cell] shadowHeight]; } - (void)setShadowHeight:(float)newHeight; { - shadowHeight = newHeight; - [self setNeedsDisplay:YES]; + [[self cell] setShadowHeight:newHeight]; } - (float)shadowRadius; { - return shadowRadius; + return [[self cell] shadowRadius]; } - (void)setShadowRadius:(float)newRadius; { - shadowRadius = newRadius; - [self setNeedsDisplay:YES]; + [[self cell] setShadowRadius:newRadius]; } - (float)shadowSaturation; { - return shadowSaturation; + return [[self cell] shadowSaturation]; } - (void)setShadowSaturation:(float)newSaturation; { - shadowSaturation = newSaturation; - [self setNeedsDisplay:YES]; + [[self cell] setShadowSaturation:newSaturation]; } diff --git a/ITTextFieldCell.m b/ITTextFieldCell.m index 6d2b86a..3d04848 100755 --- a/ITTextFieldCell.m +++ b/ITTextFieldCell.m @@ -15,9 +15,9 @@ #pragma mark INITIALIZATION METHODS /*************************************************************************/ -- (id)init +- (id)initTextCell:(NSString *)string; { - if ( ( self = [super init] ) ) { + if ( ( self = [super initTextCell:string] ) ) { castsShadow = NO; shadowElevation = 45.0; shadowAzimuth = 90.0; @@ -32,7 +32,7 @@ - (id)initWithCoder:(NSCoder *)coder { - if ( ( self = [super initWithCoder:coder] ) ) { + if ( ( self = [super initWithCoder:coder] ) ) { castsShadow = NO; shadowElevation = 45.0; shadowAzimuth = 90.0; @@ -51,13 +51,13 @@ #pragma mark DRAWING METHODS /*************************************************************************/ -- (void)drawInteriorWithFrame:(NSRect)rect inView:(NSView *)controlView +- (void)drawWithFrame:(NSRect)rect inView:(NSView *)controlView { CGSGenericObj style = nil; CGShadowStyle shadow; if ( castsShadow ) { - // Create the shadow style to use for drawing the string +// Create the shadow style to use for drawing the string shadow.version = 0; shadow.elevation = shadowElevation; shadow.azimuth = shadowAzimuth; @@ -73,7 +73,7 @@ } // Draw the string - [super drawInteriorWithFrame:rect inView:controlView]; + [super drawWithFrame:rect inView:controlView]; if ( castsShadow ) { diff --git a/Showcase/Controller.h b/Showcase/Controller.h index 1bd81ea..0cc1118 100755 --- a/Showcase/Controller.h +++ b/Showcase/Controller.h @@ -13,6 +13,9 @@ IBOutlet NSButton *useInvertedCheckBox; IBOutlet NSButton *showTitleCheckBox; + // ITButton Support + IBOutlet ITButton *button; + // ITTabView Support IBOutlet ITTabView *tabView; diff --git a/Showcase/Controller.m b/Showcase/Controller.m index 71463aa..b23d06f 100755 --- a/Showcase/Controller.m +++ b/Showcase/Controller.m @@ -27,6 +27,12 @@ - (void)awakeFromNib { [self createStatusItem]; + [button setBezelStyle:1001]; + [button setFont:[NSFont fontWithName:@"Lucida Grande Bold" size:14]]; + [button setTitle:@"Launch Manually"]; + [button setButtonType:NSMomentaryLight]; + [button sizeToFit]; + [button setFrameSize:NSMakeSize([button frame].size.width + 8, 24)]; [testTextField setCastsShadow:YES]; [tabView setAllowsDragging:YES]; [bevelView setBevelDepth:10]; @@ -332,6 +338,13 @@ [bevelView setBevelDepth:[sender intValue]]; } + +/*************************************************************************/ +#pragma mark - +#pragma mark ITButton SUPPORT +/*************************************************************************/ + + /*************************************************************************/ #pragma mark - #pragma mark NSWindow DELEGATE METHODS diff --git a/Showcase/English.lproj/MainMenu.nib/classes.nib b/Showcase/English.lproj/MainMenu.nib/classes.nib index c1ffceb..37fb827 100755 --- a/Showcase/English.lproj/MainMenu.nib/classes.nib +++ b/Showcase/English.lproj/MainMenu.nib/classes.nib @@ -21,6 +21,7 @@ LANGUAGE = ObjC; OUTLETS = { bevelView = ITBevelView; + button = ITButton; showImageCheckBox = NSButton; showStatusItemCheckBox = NSButton; showTitleCheckBox = NSButton; @@ -40,10 +41,13 @@ }, {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, {CLASS = ITBevelView; LANGUAGE = ObjC; SUPERCLASS = NSView; }, + {CLASS = ITButton; LANGUAGE = ObjC; SUPERCLASS = NSButton; }, + {CLASS = ITButtonCell; LANGUAGE = ObjC; SUPERCLASS = NSButtonCell; }, {CLASS = ITLED; LANGUAGE = ObjC; SUPERCLASS = NSControl; }, {CLASS = ITLEDCell; LANGUAGE = ObjC; SUPERCLASS = NSActionCell; }, {CLASS = ITTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; }, - {CLASS = ITTextField; LANGUAGE = ObjC; SUPERCLASS = NSTextField; } + {CLASS = ITTextField; LANGUAGE = ObjC; SUPERCLASS = NSTextField; }, + {CLASS = ITTextFieldCell; LANGUAGE = ObjC; SUPERCLASS = NSTextFieldCell; } ); IBVersion = 1; } \ No newline at end of file diff --git a/Showcase/English.lproj/MainMenu.nib/info.nib b/Showcase/English.lproj/MainMenu.nib/info.nib index 206ddc1..e3e4173 100755 --- a/Showcase/English.lproj/MainMenu.nib/info.nib +++ b/Showcase/English.lproj/MainMenu.nib/info.nib @@ -15,7 +15,6 @@ 286.0 IBOpenObjects - 29 21 IBSystem Version diff --git a/Showcase/English.lproj/MainMenu.nib/keyedobjects.nib b/Showcase/English.lproj/MainMenu.nib/keyedobjects.nib index e339f7a..944ea80 100755 Binary files a/Showcase/English.lproj/MainMenu.nib/keyedobjects.nib and b/Showcase/English.lproj/MainMenu.nib/keyedobjects.nib differ