Re: Drawing Across NSTableView Columns [solved]
Re: Drawing Across NSTableView Columns [solved]
- Subject: Re: Drawing Across NSTableView Columns [solved]
- From: "K. Darcy Otto" <email@hidden>
- Date: Tue, 28 Apr 2009 10:38:10 -0700
- Resent-date: Wed, 29 Apr 2009 21:53:12 -0700
- Resent-from: "K. Darcy Otto" <email@hidden>
- Resent-message-id: <email@hidden>
- Resent-to: cocoa-dev list <email@hidden>
Thank you for the suggestions. It turns out that I went the second
way, and it works just fine (to tell you the truth, I was a bit
apprehensive at getting into drawing, but it wasn't as difficult as I
had suspected - the -frameOfCellAtColumn:row: really made everything
not too bad at all). Here is my code, added to the NSTableView
subclass, just in case someone else runs into this issue. "slp" is
just an NSArray of 3 integers which represent the beginning row, the
ending row, and the depth (how far indented) each of the lines should
be. If a line isn't meant to have an end, end=0, and then the line is
drawn in blue as opposed to steel.
-(void)drawRect:(NSRect)rect
{
// Draw the table first, by calling drawRect from the superclass
[super drawRect:rect];
// Do nothing if no slp's
NSArray *slp = [mydoc slp];
NSUInteger slpCount = [slp count];
if (slpCount == 0) return;
NSColor *blueish = [NSColor colorWithDeviceRed:0.0 green:.5 blue:1.0
alpha:.75]; // Some sort of blue
NSColor *steelish = [NSColor colorWithDeviceRed:.5797 green:.5797
blue:.5797 alpha:.75]; // Some sort of steel
BOOL endToLine;
for (NSUInteger i=0; i<slpCount; i++)
{
NSBezierPath *thePath = [NSBezierPath bezierPath];
[thePath setLineWidth:2.0];
// Find starting point for line
NSUInteger beginAtRow = [[slp objectAtIndex:i] begin];
NSUInteger endAtRow = [[slp objectAtIndex:i] end];
NSUInteger depth = [[slp objectAtIndex:i] depth];
// If endAtRow is zero, run the line to the bottom of the table
if (endAtRow == 0)
{
endAtRow = [datasource rowCount]-1;
// Set pen colour to blueish
[blueish set];
// Flag no end to line
endToLine = NO;
}
else
{
// Set pen colour to steelish
[steelish set];
// Flag endToLine
endToLine = YES;
}
NSRect beginAtRowRect = [self frameOfCellAtColumn:[self
columnWithIdentifier:@"F"] row:beginAtRow];
NSRect endAtRowRect = [self frameOfCellAtColumn:[self
columnWithIdentifier:@"F"] row:endAtRow];
NSPoint beginPoint, endPoint;
beginPoint.y = beginAtRowRect.origin.y + beginAtRowRect.size.height/
2.0;
beginPoint.x = beginAtRowRect.origin.x + depth*7.0;
endPoint.y = endAtRowRect.origin.y + endAtRowRect.size.height/2.0;
endPoint.x = endAtRowRect.origin.x + depth*7.0;
[thePath setLineCapStyle:NSSquareLineCapStyle];
[thePath setLineJoinStyle:NSRoundLineJoinStyle];
// Move to starting location, and draw the line
[thePath moveToPoint:(NSMakePoint(beginPoint.x+5, beginPoint.y))];
[thePath lineToPoint:beginPoint];
[thePath lineToPoint:endPoint];
if (endToLine) [thePath lineToPoint:(NSMakePoint(endPoint.x+5,
endPoint.y))];
[thePath stroke];
}
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden