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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to