comparison mac/dw.m @ 1261:61d0c5f84644

Initial attempt at adding dw_draw_arc() support on all platforms. This code doesn't yet work... will probably require a bunch of fixes... but I wanted to get the code committed while doing research on it.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 25 Oct 2011 10:51:59 +0000
parents 93607596cf85
children c72f5c35e67c
comparison
equal deleted inserted replaced
1260:3cbd8de0b50b 1261:61d0c5f84644
15 #include <sys/socket.h> 15 #include <sys/socket.h>
16 #include <sys/un.h> 16 #include <sys/un.h>
17 #include <sys/mman.h> 17 #include <sys/mman.h>
18 #include <sys/time.h> 18 #include <sys/time.h>
19 #include <sys/stat.h> 19 #include <sys/stat.h>
20 #include <math.h>
20 21
21 /* Create a define to let us know to include Snow Leopard specific features */ 22 /* Create a define to let us know to include Snow Leopard specific features */
22 #if defined(MAC_OS_X_VERSION_10_6) && ((defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6) || !defined(MAC_OS_X_VERSION_MIN_REQUIRED)) 23 #if defined(MAC_OS_X_VERSION_10_6) && ((defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6) || !defined(MAC_OS_X_VERSION_MIN_REQUIRED))
23 #define BUILDING_FOR_SNOW_LEOPARD 24 #define BUILDING_FOR_SNOW_LEOPARD
24 #endif 25 #endif
5212 [aPath lineToPoint:NSMakePoint(x + width, y + height)]; 5213 [aPath lineToPoint:NSMakePoint(x + width, y + height)];
5213 [aPath lineToPoint:NSMakePoint(x + width, y)]; 5214 [aPath lineToPoint:NSMakePoint(x + width, y)];
5214 [aPath closePath]; 5215 [aPath closePath];
5215 if(fill) 5216 if(fill)
5216 [aPath fill]; 5217 [aPath fill];
5218 [aPath stroke];
5219 if(pixmap)
5220 {
5221 [NSGraphicsContext restoreGraphicsState];
5222 }
5223 else
5224 {
5225 [image unlockFocus];
5226 }
5227 DW_MUTEX_UNLOCK;
5228 }
5229
5230 /* Draw an arc on a window (preferably a render window).
5231 * Parameters:
5232 * handle: Handle to the window.
5233 * pixmap: Handle to the pixmap. (choose only one of these)
5234 * flags: For future use.
5235 * xorigin: X coordinate of center of arc.
5236 * yorigin: Y coordinate of center of arc.
5237 * x1: X coordinate of first segment of arc.
5238 * y1: Y coordinate of first segment of arc.
5239 * x2: X coordinate of second segment of arc.
5240 * y2: Y coordinate of second segment of arc.
5241 */
5242 void API dw_draw_arc(HWND handle, HPIXMAP pixmap, int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2)
5243 {
5244 int _locked_by_me = FALSE;
5245 DW_MUTEX_LOCK;
5246 id image = handle;
5247 double r, a1, a2, a;
5248 int x3, y3;
5249
5250 if(pixmap)
5251 {
5252 image = (id)pixmap->image;
5253 [NSGraphicsContext saveGraphicsState];
5254 [NSGraphicsContext setCurrentContext:[NSGraphicsContext
5255 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] flipped:YES]];
5256 }
5257 else
5258 {
5259 if([image lockFocusIfCanDraw] == NO)
5260 {
5261 DW_MUTEX_UNLOCK;
5262 return;
5263 }
5264 _DWLastDrawable = handle;
5265 }
5266 NSBezierPath* aPath = [NSBezierPath bezierPath];
5267 [aPath setLineWidth: 0.5];
5268 NSColor *color = pthread_getspecific(_dw_fg_color_key);
5269 [color set];
5270
5271 [aPath moveToPoint:NSMakePoint(x1, y1)];
5272 /* Calculate the midpoint */
5273 r = 0.5 * (hypot((double)(y1 - yorigin), (double)(x1 - xorigin)) +
5274 hypot((double)(y2 - yorigin), (double)(x2 - xorigin)));
5275 a1 = atan2((double)(y1 - yorigin), (double)(x1 - xorigin));
5276 a2 = atan2((double)(y2 - yorigin), (double)(x2 - xorigin));
5277 if(a2 < a1)
5278 a2 += M_PI * 2;
5279 a = (a1 + a2) / 2.;
5280 /* Prepare to draw */
5281 [aPath appendBezierPathWithArcFromPoint:NSMakePoint((xorigin + r * cos(a)), (yorigin + r * sin(a)))
5282 toPoint:NSMakePoint(x2, y2) radius:r];
5217 [aPath stroke]; 5283 [aPath stroke];
5218 if(pixmap) 5284 if(pixmap)
5219 { 5285 {
5220 [NSGraphicsContext restoreGraphicsState]; 5286 [NSGraphicsContext restoreGraphicsState];
5221 } 5287 }