 |
 |
Custom Row Highlighting
|
 |
|
 |
|
Senior User
Join Date: Aug 2002
Location: Oxford, England
Status:
Offline
|
|
I'm trying to emulate the functionality of a custom view (tableview) found in Acquistion, whereby the rows are highlighted using a custom, curved shape as shown below.
Except the highlighting occurs when the mouse passes over the row, rather than when a user clicks a row. There is also a fade in/out of the highlight as the mouse moves across the rows (also shown above)
Can any point me in the right direction to adding this functionality to my subclass?
Thanks.
|
|
Luke
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status:
Offline
|
|
take it one step at a time. First make your highlighting have curved edges in the -drawRow:clipRect method (NSBezierPath). Then call that in the -mouseEntered: method. Then add a [self performSelector:@selector(drawLightBlueInRow  withObject:[NSNumber numberWithInt:row] afterDelay:0.5] and one for lighter blue and one for white.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Aug 2002
Location: Oxford, England
Status:
Offline
|
|
Thanks for your help.
Right sorted out my rounded rectange with the following:
Code:
- (void)drawRow:(int)row clipRect:(NSRect)clip
{
if ( [self isRowSelected: row] ) {
[[NSColor redColor] set];
[[NSBezierPath bezierPathWithRoundedRect:[self rectOfRow:row] cornerRadius:50] fill];
[super drawRow:row clipRect:clip];
} else {
[super drawRow:row clipRect:clip];
}
}
But I know need to disable the regular highlighting which is going on over the top of my rounded rec.
I looked at highlightSelectionInClipRect but couldn't find away of elimating the default highlight.
|
|
Luke
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status:
Offline
|
|
|
(Last edited by Uncle Skeleton; Apr 29, 2004 at 08:02 PM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Aug 2002
Location: Oxford, England
Status:
Offline
|
|
Thanks for that,
Now i'm using:
Code:
[[NSBezierPath bezierPathWithRoundedRect:rowRect cornerRadius:50] fill];
and then going through each cell with
Code:
[cell drawWithFrame:cellFrame inView:self];
Problem is that the default highlight still remains over the top of my custom, rounded highlight.
I'd appreciate some more help on this.
(Last edited by sandsl; Apr 30, 2004 at 10:28 AM.
)
|
|
Luke
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status:
Offline
|
|
are you sure you're not still calling super? did you make sure your cells are set to not draw their background color? Maybe if you post your whole method it will reveal something
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Aug 2002
Location: Oxford, England
Status:
Offline
|
|
Code:
- (void) drawRow:(int) row clipRect:(NSRect)r{
NSArray *tcs = [self tableColumns];
NSTableColumn *tc;
id cell;
NSRect cellFrame, rowRect;
id dataSource = [self dataSource];
int i;
NSColor *rowColor;
if ([self isRowSelected:row]) {
rowColor = [NSColor blueColor];
} else {
rowColor = [self backgroundColor];
}
[rowColor set];
rowRect = [self rectOfRow:row];
[[NSBezierPath bezierPathWithRoundedRect:rowRect cornerRadius:50] fill];
for (i=0;i<[tcs count];i++) {
tc = [tcs objectAtIndex:0];
cell = [tc dataCellForRow:row];
cellFrame=[self frameOfCellAtColumn:i row:row];
[cell setObjectValue:[dataSource tableView:self objectValueForTableColumn:tc row:row]];
if ([dataSource respondsToSelector:@selector(tableView:willDisplayCell:forTableColumn:row:)]) {
[dataSource tableView:self willDisplayCell:cell forTableColumn:tc row:row];
}
// Tell the actual cell not to draw a BG so that the row color shows through
if ([cell respondsToSelector:@selector(setDrawsBackground:)]) {
[cell setDrawsBackground:(BOOL)false];
}
// Set text color
if ([self isRowSelected:row]) {
[cell setTextColor:[NSColor whiteColor]];
} else {
[cell setTextColor:[NSColor blackColor]];
}
[cell drawWithFrame:cellFrame inView:self];
}
}
Thats my drawRow method, adapted from your example. Thanks for all your help.
|
|
Luke
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status:
Offline
|
|
can you post a screenshot of what it draws? is your highlight color the default one? try a different color and maybe it will clear up what it is you're drawing and what the rest of it is. And try filling the row with white before drawing.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|