From abee65d8b05aad432a3d37ad498c8bb70341bd5c Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 17 Aug 2010 13:29:10 +0000 Subject: =?UTF-8?q?=E2=80=A2=20improved=20SPColorWellCell=20-=20supports?= =?UTF-8?q?=20the=20displaying=20of=20colors=20with=20alpha=20values=20(as?= =?UTF-8?q?=20triangles)=20-=20size=20is=20set=20via=20parent=20frame=20wi?= =?UTF-8?q?th=20inset=200.5=20-=20modified=20the=20border=20to=20match=20t?= =?UTF-8?q?he=20NSColorWell=20look=20(not=20yet=20finished)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPColorWellCell.m | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'Source/SPColorWellCell.m') diff --git a/Source/SPColorWellCell.m b/Source/SPColorWellCell.m index d7f50006..18d392b9 100644 --- a/Source/SPColorWellCell.m +++ b/Source/SPColorWellCell.m @@ -29,23 +29,37 @@ - (void) drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { - NSRect square = NSInsetRect (cellFrame, 0.5, 0.5); - - if (square.size.height < square.size.width) { - square.size.width = square.size.height; - square.origin.x = square.origin.x + (cellFrame.size.width - - square.size.width) / 2.0; - } else { - square.size.height = square.size.width; - square.origin.y = square.origin.y + (cellFrame.size.height - - square.size.height) / 2.0; - } + // Set initial inset from cellFrame + NSRect rect = NSInsetRect (cellFrame, 0.5, 0.5); + + // General inset for colored rect shown inside rect + CGFloat insetFactor = 2.0f; + + // Draw border + [[NSColor darkGrayColor] set]; + [NSBezierPath strokeRect: rect]; + [[NSColor grayColor] set]; + [NSBezierPath fillRect: NSInsetRect (rect, 1.0, 1.0)]; + + // The following rectangle and triangle are needed for displaying color with alpha values + // Draw black rectangle [[NSColor blackColor] set]; - [NSBezierPath strokeRect: square]; + [NSBezierPath fillRect: NSInsetRect (rect, insetFactor, insetFactor)]; + // Draw white triangle + [[NSColor whiteColor] set]; + NSBezierPath *path = [NSBezierPath bezierPath]; + [path moveToPoint: NSMakePoint(rect.origin.x - insetFactor + rect.size.width, rect.origin.y + insetFactor)]; + [path lineToPoint: NSMakePoint(rect.origin.x - insetFactor + rect.size.width, rect.origin.y + rect.size.height - insetFactor)]; + [path lineToPoint: NSMakePoint(rect.origin.x + insetFactor, rect.origin.y + rect.size.height - insetFactor)]; + [path closePath]; + [path fill]; + + // Draw the actual color as rect [(NSColor*) [self objectValue] set]; - [NSBezierPath fillRect: NSInsetRect (square, 2.0, 2.0)]; + NSRectFillUsingOperation(NSInsetRect (rect, insetFactor, insetFactor), NSCompositeSourceOver); + } @end -- cgit v1.2.3