Mercurial > dwindows
comparison mac/dw.m @ 1650:1f35129e4817
Improved arc drawing on the Mac using the same method as GDI+ on Windows.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 07 Apr 2012 18:03:38 +0000 |
parents | 509effb15e35 |
children | 202b1affc706 |
comparison
equal
deleted
inserted
replaced
1649:509effb15e35 | 1650:1f35129e4817 |
---|---|
5675 { | 5675 { |
5676 int _locked_by_me = FALSE; | 5676 int _locked_by_me = FALSE; |
5677 DW_LOCAL_POOL_IN; | 5677 DW_LOCAL_POOL_IN; |
5678 DW_MUTEX_LOCK; | 5678 DW_MUTEX_LOCK; |
5679 id image = handle; | 5679 id image = handle; |
5680 double r, a1, a2, a; | |
5681 | 5680 |
5682 if(pixmap) | 5681 if(pixmap) |
5683 { | 5682 { |
5684 image = (id)pixmap->image; | 5683 image = (id)pixmap->image; |
5685 id gc = _create_gc(image, flags & DW_DRAW_NOAA ? NO : YES); | 5684 id gc = _create_gc(image, flags & DW_DRAW_NOAA ? NO : YES); |
5706 { | 5705 { |
5707 [aPath appendBezierPathWithOvalInRect:NSMakeRect(x1, y1, x2 - x1, y2 - y1)]; | 5706 [aPath appendBezierPathWithOvalInRect:NSMakeRect(x1, y1, x2 - x1, y2 - y1)]; |
5708 } | 5707 } |
5709 else | 5708 else |
5710 { | 5709 { |
5711 [aPath moveToPoint:NSMakePoint(x1, y1)]; | 5710 double a1 = atan2((y1-yorigin), (x1-xorigin)); |
5712 /* Calculate the midpoint */ | 5711 double a2 = atan2((y2-yorigin), (x2-xorigin)); |
5713 r = 0.5 * (hypot((double)(y1 - yorigin), (double)(x1 - xorigin)) + | 5712 double dx = xorigin - x1; |
5714 hypot((double)(y2 - yorigin), (double)(x2 - xorigin))); | 5713 double dy = yorigin - y1; |
5715 a1 = atan2((double)(y1 - yorigin), (double)(x1 - xorigin)); | 5714 double r = sqrt(dx*dx + dy*dy); |
5716 a2 = atan2((double)(y2 - yorigin), (double)(x2 - xorigin)); | 5715 |
5717 if(a2 < a1) | 5716 /* Convert to degrees */ |
5718 a2 += M_PI * 2; | 5717 a1 *= (180.0 / M_PI); |
5719 a = (a1 + a2) / 2.; | 5718 a2 *= (180.0 / M_PI); |
5719 | |
5720 /* Prepare to draw */ | 5720 /* Prepare to draw */ |
5721 [aPath appendBezierPathWithArcFromPoint:NSMakePoint((xorigin + r * cos(a)), (yorigin + r * sin(a))) | 5721 [aPath appendBezierPathWithArcWithCenter:NSMakePoint(xorigin, yorigin) |
5722 toPoint:NSMakePoint(x2, y2) radius:r]; | 5722 radius:r startAngle:a1 endAngle:a2]; |
5723 } | 5723 } |
5724 /* If the fill flag is passed */ | 5724 /* If the fill flag is passed */ |
5725 if(flags & DW_DRAW_FILL) | 5725 if(flags & DW_DRAW_FILL) |
5726 { | 5726 { |
5727 [aPath fill]; | 5727 [aPath fill]; |