- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
NSBezierPath* bezier = [NSBezierPath bezierPath];
bezier = [self makeBubble:bezier withBubbleRect:NSMakeRect(10, 0, self.bounds.size.width-10, self.bounds.size.height-10) corner:8 atPostion:1];
[[NSColor greenColor]set];
[bezier fill];
[[NSColor redColor]set];
[bezier stroke];
}
- (NSBezierPath *)makeBubble:(NSBezierPath *) bezierPath
withBubbleRect:(NSRect)rect
corner:(CGFloat)corner
atPostion:(NSInteger)pos
{
CGFloat baseAngle = 40;
CGFloat cornetOffWidth = 10;
CGFloat angle = 10;
BOOL midCorner = NO;
CGFloat rw = CGRectGetWidth(rect);
CGFloat rh = CGRectGetHeight(rect);
CGFloat minDiameter = rw > rh ? rh : rw;
CGFloat radius = 0;
if (corner > 0)
{
radius = corner > minDiameter / 2 ? minDiameter / 2 : corner;
}
CGFloat rate = radius / minDiameter;
NSPoint leftBottom = NSMakePoint(CGRectGetMinX(rect), CGRectGetMinY(rect));
NSPoint leftBottomX = NSMakePoint(leftBottom.x + radius, leftBottom.y);
NSPoint leftBottomY = NSMakePoint(leftBottom.x, leftBottom.y + radius);
NSPoint rightBottom = NSMakePoint(CGRectGetMaxX(rect), CGRectGetMinY(rect));
NSPoint rightBottomX = NSMakePoint(rightBottom.x - radius, rightBottom.y);
NSPoint rightBottomY = NSMakePoint(rightBottom.x, rightBottom.y + radius);
NSPoint rightTop = NSMakePoint(CGRectGetMaxX(rect), CGRectGetMaxY(rect));
NSPoint rightTopX = NSMakePoint(rightTop.x - radius, rightTop.y);
NSPoint rightTopY = NSMakePoint(rightTop.x, rightTop.y - radius);
NSPoint leftTop = NSMakePoint(CGRectGetMinX(rect), CGRectGetMaxY(rect));
NSPoint leftTopX = NSMakePoint(leftTop.x + radius, leftTop.y);
NSPoint leftTopY = NSMakePoint(leftTop.x, leftTop.y - radius);
if (minDiameter < 30 )
{
if (rate > 0.33 && rate <= 0.5)
{
angle = 40;
}
else
{
angle = 0;
midCorner = YES;
}
}
else if (minDiameter >= 30 && minDiameter <= 50)
{
if (rate > 0.2 && rate < 0.4)
{
angle = 40;
}
else if (rate >= 0.4 && rate <= 0.5)
{
angle = 10;
}
else
{
angle = 0;
}
}
else