Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
1st, my setLineWidth isn't working at all... it will only give me 1 pixel width... don't really know why.

2nd, i wasn't *really* expecting my IF/ELSE statement to work, but i notice that it does change up here and there between black and white strokes... essentially i'm trying to tell the computer that if the fillColor is a light color, to stroke it with black, and if it's a dark color, to stroke it with white.

any thoughts?

Code:
- (void)swatchDragWithStroke:(NSRect)rect
	{
	[fillColor setFill];
	NSRectFill(rect);
	
	NSBezierPath *pathThickness = [NSBezierPath bezierPathWithRect:rect]
	[pathThickness setLineWidth:5];
	
	if (fillColor < [NSColor grayColor])
		{
		[[NSColor whiteColor] setStroke];
		}
		else
		{
		[[NSColor blackColor] setStroke];
		}
		
	[NSBezierPath strokeRect:rect];
	}
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
setLineWidth: is only being applied to the pathThickness object, not to all bezier paths. So instead of
Code:
[NSBezierPath strokeRect:rect];
use
Code:
[pathThickness stroke];

NSColors are just objects - you can't compare them with operators like you can primitive numbers. If you want to determine if a color is lighter than another, compare the individual components via [color redComponent], etc. You may need to convert the color first before accessing the components.
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
thanks...

also, i decided to use a 1px Black + 1px White checkerboard pattern image as my rect's stroke instead... it works well...

Code:
- (void)swatchDragWithStroke:(NSRect)rect
	{
	[fillColor setFill];
	NSRectFill(rect);
	
	NSBezierPath *pathThickness = [NSBezierPath bezierPathWithRect:rect];
	[pathThickness setLineWidth:2];
 
	NSImage *dottedStroke = [NSImage imageNamed:@"DottedStroke.png"];
	NSColor *dottedColor = [NSColor colorWithPatternImage:dottedStroke];

	[dottedColor setStroke];
	[pathThickness stroke];
	}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.