Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Custom Row Highlighting

Custom Row Highlighting
Thread Tools
Senior User
Join Date: Aug 2002
Location: Oxford, England
Status: Offline
Reply With Quote
Apr 29, 2004, 01:27 PM
 
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
Reply With Quote
Apr 29, 2004, 01:35 PM
 
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.
     
sandsl  (op)
Senior User
Join Date: Aug 2002
Location: Oxford, England
Status: Offline
Reply With Quote
Apr 29, 2004, 03:57 PM
 
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
Reply With Quote
Apr 29, 2004, 04:57 PM
 
you can't call super, you have to instead tell each cell to draw itself over your background

edit: here's a good example that I'm actually using in one of my apps:
http://members.iinet.net.au/~tonyarn...es/000015.html
(Last edited by Uncle Skeleton; Apr 29, 2004 at 08:02 PM. )
     
sandsl  (op)
Senior User
Join Date: Aug 2002
Location: Oxford, England
Status: Offline
Reply With Quote
Apr 30, 2004, 10:23 AM
 
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
Reply With Quote
Apr 30, 2004, 11:32 AM
 
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
     
sandsl  (op)
Senior User
Join Date: Aug 2002
Location: Oxford, England
Status: Offline
Reply With Quote
Apr 30, 2004, 01:02 PM
 
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
Reply With Quote
Apr 30, 2004, 03:37 PM
 
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.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:28 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2