• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[NSTableView] How should a grid be drawn?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[NSTableView] How should a grid be drawn?


  • Subject: [NSTableView] How should a grid be drawn?
  • From: Iceberg-Dev <email@hidden>
  • Date: Tue, 17 Mar 2009 00:06:32 +0100

I'm trying to draw a custom grid for a table view.

I' using the code at the end of this post.

The problem is that when I scroll the tableview, some of the horizontal lines are not drawn.

I looked at different sample code on the net including the GNUStep source code and found none that was working correctly.

I displayed the clipRect to check out which parts were being refreshed. Still some of the lines are not drawn.

I also tried doing the drawing in highlightSelectionInClipRect: without better results.

What's wrong with the code?

----------8<----------8<-----------8<-----------8<-----------8<--------- --8<-----------8<-----------

/*

	Grid should looks like this:

	--------------------------------------------------------

	        --     --     --     --     --    --     --    -

	--------------------------------------------------------

	        --     --     --     --     --    --     --    -

	--------------------------------------------------------

*/

- (void) drawGridInClipRect:(NSRect) clipRect
{
float rowHeight = [self rowHeight] + [self intercellSpacing].height;
NSRect visibleRect = [self visibleRect];
NSRect highlightRect;
float tColumWidth;
NSBezierPath * tBezierPath;
const float tPattern[2]={2.0,5.0};

highlightRect.origin = NSMakePoint(NSMinX(visibleRect), (int)(NSMinY (clipRect)/rowHeight)*rowHeight);
highlightRect.size = NSMakeSize(NSWidth(visibleRect), rowHeight + [self intercellSpacing].height);

tColumWidth=[[self tableColumnWithIdentifier:ICDOCUMENT_LANGUAGE] width] + [self intercellSpacing].width;

[[self gridColor] set];

tBezierPath=[NSBezierPath bezierPath];

while (NSMinY(highlightRect) < (NSMaxY(visibleRect)/*+[self intercellSpacing].height*/)) /* Extending to the whole visibleRect */
{
NSRect clippedHighlightRect = NSIntersectionRect(highlightRect, visibleRect);
int tRowIndex;

tRowIndex = (int)((NSMinY(highlightRect)+rowHeight*0.5f)/rowHeight);

if ((tRowIndex%2)==0)
{
[tBezierPath setLineDash:tPattern count:0 phase:0];

[tBezierPath moveToPoint:NSMakePoint(NSMinX (clippedHighlightRect),NSMinY(clippedHighlightRect)-0.5f)];

[tBezierPath lineToPoint:NSMakePoint(NSMaxX (clippedHighlightRect),NSMinY(clippedHighlightRect)-0.5f)];
}
else
{
[tBezierPath setLineDash:tPattern count:2 phase:0];

[tBezierPath moveToPoint:NSMakePoint(NSMinX(clippedHighlightRect) +tColumWidth,NSMinY(clippedHighlightRect)-0.5f)];

[tBezierPath lineToPoint:NSMakePoint(NSMaxX (clippedHighlightRect),NSMinY(clippedHighlightRect)-0.5f)];
}

[tBezierPath stroke];

[tBezierPath removeAllPoints];

highlightRect.origin.y += rowHeight;
}
}
_______________________________________________


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


  • Follow-Ups:
    • Re: [NSTableView] How should a grid be drawn?
      • From: Corbin Dunn <email@hidden>
  • Prev by Date: [iPhone] NumberPad with the dot
  • Next by Date: Re: [NSTableView] How should a grid be drawn?
  • Previous by thread: Re: [iPhone] NumberPad with the dot
  • Next by thread: Re: [NSTableView] How should a grid be drawn?
  • Index(es):
    • Date
    • Thread