comparison mac/dw.m @ 1269:9e477efbacca

Added DW_DRAW_DEFAULT, DW_DRAW_FILL and DW_DRAW_FULL drawing flags. Adde some more arc segments and full circle commands to test program.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 30 Oct 2011 00:40:22 +0000
parents c72f5c35e67c
children 0b34e2cf0706
comparison
equal deleted inserted replaced
1268:148daf522080 1269:9e477efbacca
5265 NSBezierPath* aPath = [NSBezierPath bezierPath]; 5265 NSBezierPath* aPath = [NSBezierPath bezierPath];
5266 [aPath setLineWidth: 0.5]; 5266 [aPath setLineWidth: 0.5];
5267 NSColor *color = pthread_getspecific(_dw_fg_color_key); 5267 NSColor *color = pthread_getspecific(_dw_fg_color_key);
5268 [color set]; 5268 [color set];
5269 5269
5270 [aPath moveToPoint:NSMakePoint(x1, y1)]; 5270 /* Special state of a full circle/oval */
5271 /* Calculate the midpoint */ 5271 if(flags & DW_DRAW_FULL)
5272 r = 0.5 * (hypot((double)(y1 - yorigin), (double)(x1 - xorigin)) + 5272 {
5273 hypot((double)(y2 - yorigin), (double)(x2 - xorigin))); 5273 [aPath appendBezierPathWithOvalInRect:NSMakeRect(x1, y1, x2, y2)];
5274 a1 = atan2((double)(y1 - yorigin), (double)(x1 - xorigin)); 5274 }
5275 a2 = atan2((double)(y2 - yorigin), (double)(x2 - xorigin)); 5275 else
5276 if(a2 < a1) 5276 {
5277 a2 += M_PI * 2; 5277 [aPath moveToPoint:NSMakePoint(x1, y1)];
5278 a = (a1 + a2) / 2.; 5278 /* Calculate the midpoint */
5279 /* Prepare to draw */ 5279 r = 0.5 * (hypot((double)(y1 - yorigin), (double)(x1 - xorigin)) +
5280 [aPath appendBezierPathWithArcFromPoint:NSMakePoint((xorigin + r * cos(a)), (yorigin + r * sin(a))) 5280 hypot((double)(y2 - yorigin), (double)(x2 - xorigin)));
5281 toPoint:NSMakePoint(x2, y2) radius:r]; 5281 a1 = atan2((double)(y1 - yorigin), (double)(x1 - xorigin));
5282 a2 = atan2((double)(y2 - yorigin), (double)(x2 - xorigin));
5283 if(a2 < a1)
5284 a2 += M_PI * 2;
5285 a = (a1 + a2) / 2.;
5286 /* Prepare to draw */
5287 [aPath appendBezierPathWithArcFromPoint:NSMakePoint((xorigin + r * cos(a)), (yorigin + r * sin(a)))
5288 toPoint:NSMakePoint(x2, y2) radius:r];
5289 }
5290 /* If the fill flag is passed */
5291 if(flags & DW_DRAW_FILL)
5292 {
5293 [aPath fill];
5294 }
5295 /* Actually do the drawing */
5282 [aPath stroke]; 5296 [aPath stroke];
5283 if(pixmap) 5297 if(pixmap)
5284 { 5298 {
5285 [NSGraphicsContext restoreGraphicsState]; 5299 [NSGraphicsContext restoreGraphicsState];
5286 } 5300 }