comparison mac/dw.m @ 891:3774af45eb0c

Fix for dw_draw_text() not using the background color on the Mac. Also default the background color to transparent instead of black.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 17 Apr 2011 02:45:20 +0000
parents 5a96cc2695b9
children d1d7e5c51860
comparison
equal deleted inserted replaced
890:5a96cc2695b9 891:3774af45eb0c
83 83
84 /* Create a default colors for a thread */ 84 /* Create a default colors for a thread */
85 void _init_colors(void) 85 void _init_colors(void)
86 { 86 {
87 NSColor *fgcolor = [[NSColor grayColor] retain]; 87 NSColor *fgcolor = [[NSColor grayColor] retain];
88 NSColor *bgcolor = [[NSColor blackColor] retain];
89 88
90 pthread_setspecific(_dw_fg_color_key, fgcolor); 89 pthread_setspecific(_dw_fg_color_key, fgcolor);
91 pthread_setspecific(_dw_bg_color_key, bgcolor); 90 pthread_setspecific(_dw_bg_color_key, NULL);
92 } 91 }
93 92
94 typedef struct _sighandler 93 typedef struct _sighandler
95 { 94 {
96 struct _sighandler *next; 95 struct _sighandler *next;
4267 void API dw_color_background_set(unsigned long value) 4266 void API dw_color_background_set(unsigned long value)
4268 { 4267 {
4269 NSColor *oldcolor = pthread_getspecific(_dw_bg_color_key); 4268 NSColor *oldcolor = pthread_getspecific(_dw_bg_color_key);
4270 NSColor *newcolor; 4269 NSColor *newcolor;
4271 4270
4272 _background = _get_color(value); 4271 if(value == DW_CLR_DEFAULT)
4272 {
4273 pthread_setspecific(_dw_bg_color_key, NULL);
4274 }
4275 else
4276 {
4277 _background = _get_color(value);
4273 4278
4274 newcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_background)/255.0 green: 4279 newcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_background)/255.0 green:
4275 DW_GREEN_VALUE(_background)/255.0 blue: 4280 DW_GREEN_VALUE(_background)/255.0 blue:
4276 DW_BLUE_VALUE(_background)/255.0 alpha: 1] retain]; 4281 DW_BLUE_VALUE(_background)/255.0 alpha: 1] retain];
4277 pthread_setspecific(_dw_bg_color_key, newcolor); 4282 pthread_setspecific(_dw_bg_color_key, newcolor);
4283 }
4278 [oldcolor release]; 4284 [oldcolor release];
4279 } 4285 }
4280 4286
4281 /* Allows the user to choose a color using the system's color chooser dialog. 4287 /* Allows the user to choose a color using the system's color chooser dialog.
4282 * Parameters: 4288 * Parameters:
4425 if([image lockFocusIfCanDraw] == NO) 4431 if([image lockFocusIfCanDraw] == NO)
4426 { 4432 {
4427 DW_MUTEX_UNLOCK; 4433 DW_MUTEX_UNLOCK;
4428 return; 4434 return;
4429 } 4435 }
4430 NSColor *color = pthread_getspecific(_dw_fg_color_key); 4436 NSColor *fgcolor = pthread_getspecific(_dw_fg_color_key);
4431 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:color, NSForegroundColorAttributeName, nil]; 4437 NSColor *bgcolor = pthread_getspecific(_dw_bg_color_key);
4438 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:fgcolor, NSForegroundColorAttributeName, nil];
4439 if(bgcolor)
4440 {
4441 [dict setValue:bgcolor forKey:NSBackgroundColorAttributeName];
4442 }
4432 if(font) 4443 if(font)
4433 { 4444 {
4434 [dict setValue:font forKey:NSFontAttributeName]; 4445 [dict setValue:font forKey:NSFontAttributeName];
4435 } 4446 }
4436 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict]; 4447 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict];
4447 { 4458 {
4448 font = [render font]; 4459 font = [render font];
4449 } 4460 }
4450 image = (id)pixmap->image; 4461 image = (id)pixmap->image;
4451 [image lockFocus]; 4462 [image lockFocus];
4452 NSColor *color = pthread_getspecific(_dw_fg_color_key); 4463 NSColor *fgcolor = pthread_getspecific(_dw_fg_color_key);
4453 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:color, NSForegroundColorAttributeName, nil]; 4464 NSColor *bgcolor = pthread_getspecific(_dw_bg_color_key);
4465 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:fgcolor, NSForegroundColorAttributeName, nil];
4466 if(bgcolor)
4467 {
4468 [dict setValue:bgcolor forKey:NSBackgroundColorAttributeName];
4469 }
4454 if(font) 4470 if(font)
4455 { 4471 {
4456 [dict setValue:font forKey:NSFontAttributeName]; 4472 [dict setValue:font forKey:NSFontAttributeName];
4457 } 4473 }
4458 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict]; 4474 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict];