Re: Drawing a circle progress meter
Re: Drawing a circle progress meter
- Subject: Re: Drawing a circle progress meter
- From: Scott Ellsworth <email@hidden>
- Date: Mon, 28 Nov 2005 15:23:12 -0800
On Nov 28, 2005, at 2:46 PM, Sherm Pendley wrote:
On Nov 28, 2005, at 5:35 PM, Chad Armstrong wrote:
Drawing the circle itself seems fairly trivial, but I'm not quite
as certain about drawing a sector of the circle.
Shouldn't be too hard - NSBezierPath's
appendBezierPathWithArcWithCenter:radius:startAngle:endAngle:clockwise
: method will help with the "draw a sector" part.
That is what I did when I wanted to draw a filled partial arc with an
inner and outer radius, kind of like a speedometer. Not really
optimized, but it does work.
- (NSBezierPath *)sextantSegmentFrameFrom:(float)startAngle to:(float)
endAngle{
NSBezierPath * sextantPath = [NSBezierPath bezierPath];
float shiftDown = 16.0f;
float innerRadius = 8.0f;
float arcWidth = 8.0f;
float outerRadius = innerRadius + arcWidth;
float centerX = 2.0*hexSz2;
float centerY = hexHt2+shiftDown;
[sextantPath setLineWidth:1.0];
float outerEndX = centerX+outerRadius*cos(M_PI*endAngle/180.0);
float outerEndY = centerY+outerRadius*sin(M_PI*endAngle/180.0);;
[sextantPath appendBezierPathWithArcWithCenter:NSMakePoint(centerX,
centerY) radius:innerRadius startAngle:startAngle endAngle:endAngle
clockwise:NO];
[sextantPath lineToPoint:NSMakePoint(outerEndX, outerEndY)];
[sextantPath appendBezierPathWithArcWithCenter:NSMakePoint(centerX,
centerY) radius:outerRadius startAngle:endAngle endAngle:startAngle
clockwise:YES];
[sextantPath closePath];
return sextantPath;
}
- (void)drawSextantFrame:(HEX_SEXTANT)sextant{
[[NSColor grayColor] set];
switch(sextant){
case SEXTANT_UPPER_RIGHT:
[[self sextantSegmentFrameFrom:300.0 to:360.0] stroke];
break;
case SEXTANT_UP:
[[self sextantSegmentFrameFrom:240.0 to:300.0] stroke];
break;
case SEXTANT_UPPER_LEFT:
[[self sextantSegmentFrameFrom:180.0 to:240.0] stroke];
break;
case SEXTANT_LOWER_LEFT:
[[self sextantSegmentFrameFrom:120.0 to:180.0] stroke];
break;
case SEXTANT_DOWN:
[[self sextantSegmentFrameFrom:60.0 to:120.0] stroke];
break;
case SEXTANT_LOWER_RIGHT:
[[self sextantSegmentFrameFrom:0.0 to:60.0] stroke];
break;
default:
break;
}
}
- (void)drawSextant:(HEX_SEXTANT)sextant withValue:(float)value outOf:
(float)maxValue{
float startAngle = 0.0;
float endAngle = 0.0;
float ratio = value/maxValue;
NSColor * color = [NSColor blackColor];
if (ratio<0.0) ratio=0.0;
if (ratio>1.0) ratio=1.0;
// We are in a flipped view.
switch(sextant){
case SEXTANT_UPPER_RIGHT:
startAngle = 300;
endAngle = startAngle + 60*ratio;
color = [NSColor purpleColor];
break;
case SEXTANT_UP:
startAngle = 240;
endAngle = startAngle + 60*ratio;
color = [NSColor colorWithCalibratedRed:0.0f green:0.0f blue:0.50f
alpha:1.0f];
break;
case SEXTANT_UPPER_LEFT:
startAngle = 180;
endAngle = startAngle + 60*ratio;
color = [NSColor brownColor];
break;
case SEXTANT_LOWER_LEFT:
startAngle = 120;
endAngle = startAngle + 60*ratio;
color = [NSColor colorWithCalibratedRed:0.50f green:0.0f blue:0.0f
alpha:1.0f];
break;
case SEXTANT_DOWN:
startAngle = 60;
endAngle = startAngle + 60*ratio;
color = [NSColor orangeColor];
break;
case SEXTANT_LOWER_RIGHT:
startAngle = 0;
endAngle = startAngle + 60*ratio;
color = [NSColor colorWithCalibratedRed:0.0f green:1.0f blue:0.0f
alpha:1.0f];
break;
default:
break;
}
[color set];
[[self sextantSegmentFrameFrom:startAngle to:endAngle] fill];
[[NSColor blackColor] set];
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden