Skip to content

Instantly share code, notes, and snippets.

@pkieltyka
Created March 26, 2009 02:35
Show Gist options
  • Save pkieltyka/85829 to your computer and use it in GitHub Desktop.
Save pkieltyka/85829 to your computer and use it in GitHub Desktop.
#import <Cocoa/Cocoa.h>
#define H_QUERY_VIEW_RADIUS 15
@interface HQueryView : NSView {
NSBezierPath *topPath;
NSBezierPath *bottomPath;
NSGradient *topGradient;
NSGradient *bottomGradient;
}
-(void) createViewPaths;
@end
#import "HQueryView.h"
@implementation HQueryView
-(id) initWithFrame:(NSRect)rect
{
NSLog(@"initWithFrame at HQueryView");
if (![super initWithFrame:rect])
return nil;
[self createViewPaths];
return self;
}
-(void) drawRect:(NSRect)rect
{
NSLog(@"drawRect at HQueryView");
[topGradient drawInBezierPath:topPath angle:90.0];
[bottomGradient drawInBezierPath:bottomPath angle:90.0];
}
-(void) dealloc
{
[topPath release];
[bottomPath release];
[topGradient release];
[bottomGradient release];
[super dealloc];
}
-(void) createViewPaths
{
NSRect myRect = [self bounds];
float midPointY = myRect.size.height / 2;
NSRect topRect = NSMakeRect(0, midPointY, myRect.size.width, midPointY);
NSRect topRectBox = NSMakeRect(0, midPointY, myRect.size.width, (midPointY-H_QUERY_VIEW_RADIUS));
NSRect bottomRect = NSMakeRect(0, 0, myRect.size.width, midPointY);
NSRect bottomRectBox = NSMakeRect(0, H_QUERY_VIEW_RADIUS, myRect.size.width, midPointY-H_QUERY_VIEW_RADIUS);
topPath = [NSBezierPath bezierPath];
[topPath appendBezierPathWithRoundedRect:topRect xRadius:H_QUERY_VIEW_RADIUS yRadius:H_QUERY_VIEW_RADIUS];
[topPath appendBezierPathWithRect:topRectBox];
topGradient = [[NSGradient alloc]
initWithStartingColor:[NSColor blackColor]
endingColor:[NSColor redColor]];
bottomPath = [NSBezierPath bezierPath];
[bottomPath appendBezierPathWithRoundedRect:bottomRect xRadius:H_QUERY_VIEW_RADIUS yRadius:H_QUERY_VIEW_RADIUS];
[bottomPath appendBezierPathWithRect:bottomRectBox];
bottomGradient = [[NSGradient alloc]
initWithStartingColor:[NSColor redColor]
endingColor:[NSColor blackColor]];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment