comparison mac/dw.m @ 1527:9bab702bd6c1

A bunch of Mac drawing updates to correct issues and improve performance. Switched to using a different (faster) method for drawing rectangles. Fixed subpixel drawing issues related to the fact that drawing occurs centered on the coordinate so adding 0.5 draws at a pixel itself instead of spanning two pixels. And related to that removing the incorrect workaround I had previously used of setting the line width to 0.5. Also added DW_DRAW_NOAA support when drawing to windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 03 Jan 2012 15:59:00 +0000
parents 026c0b4d6ee9
children 5facb5380944
comparison
equal deleted inserted replaced
1526:ff78ae1d7429 1527:9bab702bd6c1
5130 return; 5130 return;
5131 } 5131 }
5132 _DWLastDrawable = handle; 5132 _DWLastDrawable = handle;
5133 } 5133 }
5134 NSBezierPath* aPath = [NSBezierPath bezierPath]; 5134 NSBezierPath* aPath = [NSBezierPath bezierPath];
5135 [aPath setLineWidth: 0.5];
5136 NSColor *color = pthread_getspecific(_dw_fg_color_key); 5135 NSColor *color = pthread_getspecific(_dw_fg_color_key);
5137 [color set]; 5136 [color set];
5138 5137
5139 [aPath moveToPoint:NSMakePoint(x1, y1)]; 5138 [aPath moveToPoint:NSMakePoint(x1 + 0.5, y1 + 0.5)];
5140 [aPath lineToPoint:NSMakePoint(x2, y2)]; 5139 [aPath lineToPoint:NSMakePoint(x2 + 0.5, y2 + 0.5)];
5141 [aPath stroke]; 5140 [aPath stroke];
5142 5141
5143 if(pixmap) 5142 if(pixmap)
5144 { 5143 {
5145 [NSGraphicsContext restoreGraphicsState]; 5144 [NSGraphicsContext restoreGraphicsState];
5307 if([image lockFocusIfCanDraw] == NO) 5306 if([image lockFocusIfCanDraw] == NO)
5308 { 5307 {
5309 DW_MUTEX_UNLOCK; 5308 DW_MUTEX_UNLOCK;
5310 return; 5309 return;
5311 } 5310 }
5311 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)];
5312 _DWLastDrawable = handle; 5312 _DWLastDrawable = handle;
5313 } 5313 }
5314 NSBezierPath* aPath = [NSBezierPath bezierPath]; 5314 NSBezierPath* aPath = [NSBezierPath bezierPath];
5315 [aPath setLineWidth: 0.5];
5316 NSColor *color = pthread_getspecific(_dw_fg_color_key); 5315 NSColor *color = pthread_getspecific(_dw_fg_color_key);
5317 [color set]; 5316 [color set];
5318 5317
5319 [aPath moveToPoint:NSMakePoint(*x, *y)]; 5318 [aPath moveToPoint:NSMakePoint(*x + 0.5, *y + 0.5)];
5320 for(z=1;z<npoints;z++) 5319 for(z=1;z<npoints;z++)
5321 { 5320 {
5322 [aPath lineToPoint:NSMakePoint(x[z], y[z])]; 5321 [aPath lineToPoint:NSMakePoint(x[z] + 0.5, y[z] + 0.5)];
5323 } 5322 }
5324 [aPath closePath]; 5323 [aPath closePath];
5325 if(flags & DW_DRAW_FILL) 5324 if(flags & DW_DRAW_FILL)
5326 { 5325 {
5327 [aPath fill]; 5326 [aPath fill];
5365 if([image lockFocusIfCanDraw] == NO) 5364 if([image lockFocusIfCanDraw] == NO)
5366 { 5365 {
5367 DW_MUTEX_UNLOCK; 5366 DW_MUTEX_UNLOCK;
5368 return; 5367 return;
5369 } 5368 }
5369 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)];
5370 _DWLastDrawable = handle; 5370 _DWLastDrawable = handle;
5371 } 5371 }
5372 NSBezierPath* aPath = [NSBezierPath bezierPath];
5373 [aPath setLineWidth: 0.5];
5374 NSColor *color = pthread_getspecific(_dw_fg_color_key); 5372 NSColor *color = pthread_getspecific(_dw_fg_color_key);
5375 [color set]; 5373 [color set];
5376 5374
5377 [aPath moveToPoint:NSMakePoint(x, y)];
5378 [aPath lineToPoint:NSMakePoint(x, y + height)];
5379 [aPath lineToPoint:NSMakePoint(x + width, y + height)];
5380 [aPath lineToPoint:NSMakePoint(x + width, y)];
5381 [aPath closePath];
5382 if(flags & DW_DRAW_FILL) 5375 if(flags & DW_DRAW_FILL)
5383 [aPath fill]; 5376 [NSBezierPath fillRect:NSMakeRect(x, y, width, height)];
5384 [aPath stroke]; 5377 else
5378 [NSBezierPath strokeRect:NSMakeRect(x, y, width, height)];
5385 if(pixmap) 5379 if(pixmap)
5386 { 5380 {
5387 [NSGraphicsContext restoreGraphicsState]; 5381 [NSGraphicsContext restoreGraphicsState];
5388 } 5382 }
5389 else 5383 else
5425 if([image lockFocusIfCanDraw] == NO) 5419 if([image lockFocusIfCanDraw] == NO)
5426 { 5420 {
5427 DW_MUTEX_UNLOCK; 5421 DW_MUTEX_UNLOCK;
5428 return; 5422 return;
5429 } 5423 }
5424 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)];
5430 _DWLastDrawable = handle; 5425 _DWLastDrawable = handle;
5431 } 5426 }
5432 NSBezierPath* aPath = [NSBezierPath bezierPath]; 5427 NSBezierPath* aPath = [NSBezierPath bezierPath];
5433 [aPath setLineWidth: 0.5];
5434 NSColor *color = pthread_getspecific(_dw_fg_color_key); 5428 NSColor *color = pthread_getspecific(_dw_fg_color_key);
5435 [color set]; 5429 [color set];
5436 5430
5437 /* Special case of a full circle/oval */ 5431 /* Special case of a full circle/oval */
5438 if(flags & DW_DRAW_FULL) 5432 if(flags & DW_DRAW_FULL)