Files
gitx/PBGitRevisionCell.m
T
Pieter de Bie bbeedd10ce Rewrite the graphing code
This uses more Cocoa classes to draw the lines, making it easier to
understand and hopefully maintain.

Furthermore, we use less memory now, which is nice, but all the
dynamic arrays probably mean more CPU usage.
2008-08-27 21:51:42 +02:00

110 lines
2.7 KiB
Objective-C

//
// PBGitRevisionCell.m
// GitX
//
// Created by Pieter de Bie on 17-06-08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "PBGitRevisionCell.h"
@implementation PBGitRevisionCell
@synthesize cellInfo;
-(void) setCellInfo: (PBGraphCellInfo*) info
{
isReady = YES;
cellInfo = info;
}
- (id) initWithCoder: (id) coder
{
self = [super initWithCoder:coder];
if (self != nil) {
isReady = NO;
}
return self;
}
- (NSArray*) colors
{
return [NSArray arrayWithObjects:[NSColor redColor], [NSColor blueColor],
[NSColor orangeColor], [NSColor blackColor], [NSColor greenColor], nil];
}
- (void) drawLineFromColumn: (int) from toColumn: (int) to inRect: (NSRect) r offset: (int) offset
{
int columnWidth = 10;
NSPoint origin = r.origin;
NSPoint source = NSMakePoint(origin.x + columnWidth* from, origin.y + offset);
NSPoint center = NSMakePoint( origin.x + columnWidth * to, origin.y + r.size.height * 0.5);
// Just use red for now.
[[[self colors] objectAtIndex:0] set];
NSBezierPath * path = [NSBezierPath bezierPath];
[path setLineWidth:2];
[path moveToPoint: source];
[path lineToPoint: center];
[path stroke];
}
- (void) drawCircleForColumn: (int) c inRect: (NSRect) r
{
NSArray* col = [NSArray arrayWithObjects:[NSColor redColor], [NSColor blueColor],
[NSColor orangeColor], [NSColor blackColor], [NSColor greenColor], nil];
int columnWidth = 10;
NSPoint origin = r.origin;
NSPoint columnOrigin = { origin.x + columnWidth * c, origin.y};
NSRect oval = { columnOrigin.x - 5, columnOrigin.y + r.size.height * 0.5 - 5, 10, 10};
NSBezierPath * path = [NSBezierPath bezierPath];
path = [NSBezierPath bezierPathWithOvalInRect:oval];
//[[col objectAtIndex:cellInfo.columns[c].color] set];
[path fill];
NSRect smallOval = { columnOrigin.x - 3, columnOrigin.y + r.size.height * 0.5 - 3, 6, 6};
[[NSColor whiteColor] set];
path = [NSBezierPath bezierPathWithOvalInRect:smallOval];
[path fill];
}
- (void) drawWithFrame: (NSRect) rect inView:(NSView *)view
{
if (!isReady)
return [super drawWithFrame:rect inView:view];
float pathWidth = 10 + 10 * cellInfo.numColumns;
NSRect ownRect;
NSDivideRect(rect, &ownRect, &rect, pathWidth, NSMinXEdge);
// Adjust by removing the border
ownRect.size.height += 2;
ownRect.origin.y -= 1;
ownRect.origin.x += 0;
for (PBLine* line in cellInfo.lines) {
if (line.upper == 0)
[self drawLineFromColumn: line.from toColumn: line.to inRect:ownRect offset: ownRect.size.height];
else
[self drawLineFromColumn:line.from toColumn: line.to inRect:ownRect offset: 0];
}
[self drawCircleForColumn: cellInfo.position inRect: ownRect];
[super drawWithFrame:rect inView:view];
isReady = NO;
}
@end