aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-08-17 13:29:10 +0000
committerBibiko <bibiko@eva.mpg.de>2010-08-17 13:29:10 +0000
commitabee65d8b05aad432a3d37ad498c8bb70341bd5c (patch)
tree8d46ad6458c1236e6572e448f3293d674ebfa628 /Source
parent487cc8e31b4487c5d85817e9ff73d24dbaeedd74 (diff)
downloadsequelpro-abee65d8b05aad432a3d37ad498c8bb70341bd5c.tar.gz
sequelpro-abee65d8b05aad432a3d37ad498c8bb70341bd5c.tar.bz2
sequelpro-abee65d8b05aad432a3d37ad498c8bb70341bd5c.zip
• improved SPColorWellCell
- supports the displaying of colors with alpha values (as triangles) - size is set via parent frame with inset 0.5 - modified the border to match the NSColorWell look (not yet finished)
Diffstat (limited to 'Source')
-rw-r--r--Source/SPColorWellCell.m40
1 files changed, 27 insertions, 13 deletions
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