Skip to content
This repository
Newer
Older
100644 126 lines (98 sloc) 3.496 kb
fe8f1733 » pieter
2008-06-17 Add custom cell
1 //
2 // PBGitRevisionCell.m
3 // GitX
4 //
5 // Created by Pieter de Bie on 17-06-08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "PBGitRevisionCell.h"
10
11
12 @implementation PBGitRevisionCell
13
52d94025 » pieter
2008-06-18 First take on graphing
14 @synthesize cellInfo;
bbeedd10 » pieter
2008-08-27 Rewrite the graphing code
15 -(void) setCellInfo: (PBGraphCellInfo*) info
fe8f1733 » pieter
2008-06-17 Add custom cell
16 {
52d94025 » pieter
2008-06-18 First take on graphing
17 isReady = YES;
18 cellInfo = info;
19 }
fe8f1733 » pieter
2008-06-17 Add custom cell
20
52d94025 » pieter
2008-06-18 First take on graphing
21 - (id) initWithCoder: (id) coder
22 {
23 self = [super initWithCoder:coder];
24 if (self != nil) {
25 isReady = NO;
26 }
27 return self;
28 }
fe8f1733 » pieter
2008-06-17 Add custom cell
29
df490103 » pieter
2008-06-18 PBGitGrapher: Improve the grapher
30 - (NSArray*) colors
52d94025 » pieter
2008-06-18 First take on graphing
31 {
ed13cf51 » pieter
2008-08-28 Grapher: use Tango colors for now
32 return [NSArray arrayWithObjects:
33 [NSColor colorWithCalibratedRed: 0X4e/256.0 green:0X9A/256.0 blue: 0X06/256.0 alpha: 1.0],
34 [NSColor colorWithCalibratedRed: 0X20/256.0 green:0X4A/256.0 blue: 0X87/256.0 alpha: 1.0],
35 [NSColor colorWithCalibratedRed: 0XC4/256.0 green:0XA0/256.0 blue: 0 alpha: 1.0],
36 [NSColor colorWithCalibratedRed: 0X5C/256.0 green:0X35/256.0 blue: 0X66/256.0 alpha: 1.0],
37 [NSColor colorWithCalibratedRed: 0XA4/256.0 green:0X00/256.0 blue: 0X00/256.0 alpha: 1.0],
38 [NSColor colorWithCalibratedRed: 0XCE/256.0 green:0X5C/256.0 blue: 0 alpha: 1.0],
39 nil];
df490103 » pieter
2008-06-18 PBGitGrapher: Improve the grapher
40 }
41
a294d911 » pieter
2008-08-28 Grapher: Add colors to lane
42 - (void) drawLineFromColumn: (int) from toColumn: (int) to inRect: (NSRect) r offset: (int) offset color: (int) c
df490103 » pieter
2008-06-18 PBGitGrapher: Improve the grapher
43 {
52d94025 » pieter
2008-06-18 First take on graphing
44
45 int columnWidth = 10;
46 NSPoint origin = r.origin;
47
df490103 » pieter
2008-06-18 PBGitGrapher: Improve the grapher
48 NSPoint source = NSMakePoint(origin.x + columnWidth* from, origin.y + offset);
49 NSPoint center = NSMakePoint( origin.x + columnWidth * to, origin.y + r.size.height * 0.5);
fe8f1733 » pieter
2008-06-17 Add custom cell
50
df490103 » pieter
2008-06-18 PBGitGrapher: Improve the grapher
51 // Just use red for now.
ed13cf51 » pieter
2008-08-28 Grapher: use Tango colors for now
52 NSArray* colors = [self colors];
53 [[colors objectAtIndex: c % [colors count]] set];
df490103 » pieter
2008-06-18 PBGitGrapher: Improve the grapher
54
fe8f1733 » pieter
2008-06-17 Add custom cell
55 NSBezierPath * path = [NSBezierPath bezierPath];
56 [path setLineWidth:2];
52d94025 » pieter
2008-06-18 First take on graphing
57
df490103 » pieter
2008-06-18 PBGitGrapher: Improve the grapher
58 [path moveToPoint: source];
52d94025 » pieter
2008-06-18 First take on graphing
59 [path lineToPoint: center];
fe8f1733 » pieter
2008-06-17 Add custom cell
60 [path stroke];
61
52d94025 » pieter
2008-06-18 First take on graphing
62 }
fe8f1733 » pieter
2008-06-17 Add custom cell
63
52d94025 » pieter
2008-06-18 First take on graphing
64 - (void) drawCircleForColumn: (int) c inRect: (NSRect) r
65 {
b4d7816b » pieter
2008-08-28 Grapher: draw ref names
66 if (!cellInfo.refs)
9bfccb5e » pieter
2008-08-28 Grapher: add first part of displaying refs
67 [[NSColor blackColor] set];
68 else
69 [[NSColor redColor] set];
70
52d94025 » pieter
2008-06-18 First take on graphing
71 int columnWidth = 10;
72 NSPoint origin = r.origin;
73 NSPoint columnOrigin = { origin.x + columnWidth * c, origin.y};
fe8f1733 » pieter
2008-06-17 Add custom cell
74
52d94025 » pieter
2008-06-18 First take on graphing
75 NSRect oval = { columnOrigin.x - 5, columnOrigin.y + r.size.height * 0.5 - 5, 10, 10};
76
77
78 NSBezierPath * path = [NSBezierPath bezierPath];
79 path = [NSBezierPath bezierPathWithOvalInRect:oval];
bbeedd10 » pieter
2008-08-27 Rewrite the graphing code
80 //[[col objectAtIndex:cellInfo.columns[c].color] set];
52d94025 » pieter
2008-06-18 First take on graphing
81 [path fill];
fe8f1733 » pieter
2008-06-17 Add custom cell
82
52d94025 » pieter
2008-06-18 First take on graphing
83 NSRect smallOval = { columnOrigin.x - 3, columnOrigin.y + r.size.height * 0.5 - 3, 6, 6};
fe8f1733 » pieter
2008-06-17 Add custom cell
84 [[NSColor whiteColor] set];
85 path = [NSBezierPath bezierPathWithOvalInRect:smallOval];
52d94025 » pieter
2008-06-18 First take on graphing
86 [path fill];
87 }
88
b4d7816b » pieter
2008-08-28 Grapher: draw ref names
89 - (void) drawRefsInRect: (NSRect*) rect
90 {
91 int pathWidth = 40 * [cellInfo.refs count];
92 NSRect ownRect;
93 NSDivideRect(*rect, &ownRect, rect, pathWidth, NSMinXEdge);
94 for (NSString* ref in cellInfo.refs) {
95 NSString* newRef = [[ref componentsSeparatedByString:@"/"] lastObject];
96 [newRef drawInRect: ownRect withAttributes:nil];
97 }
98 }
99
52d94025 » pieter
2008-06-18 First take on graphing
100 - (void) drawWithFrame: (NSRect) rect inView:(NSView *)view
101 {
102 if (!isReady)
103 return [super drawWithFrame:rect inView:view];
104
105 float pathWidth = 10 + 10 * cellInfo.numColumns;
106
107 NSRect ownRect;
108 NSDivideRect(rect, &ownRect, &rect, pathWidth, NSMinXEdge);
109
727e42fe » pieter
2008-08-27 Refactor and rename graph code
110 for (PBGitGraphLine* line in cellInfo.lines) {
bbeedd10 » pieter
2008-08-27 Rewrite the graphing code
111 if (line.upper == 0)
a294d911 » pieter
2008-08-28 Grapher: Add colors to lane
112 [self drawLineFromColumn: line.from toColumn: line.to inRect:ownRect offset: ownRect.size.height color: line.colorIndex];
bbeedd10 » pieter
2008-08-27 Rewrite the graphing code
113 else
a294d911 » pieter
2008-08-28 Grapher: Add colors to lane
114 [self drawLineFromColumn: line.from toColumn: line.to inRect:ownRect offset: 0 color:line.colorIndex];
52d94025 » pieter
2008-06-18 First take on graphing
115 }
df490103 » pieter
2008-06-18 PBGitGrapher: Improve the grapher
116
52d94025 » pieter
2008-06-18 First take on graphing
117 [self drawCircleForColumn: cellInfo.position inRect: ownRect];
df490103 » pieter
2008-06-18 PBGitGrapher: Improve the grapher
118
b4d7816b » pieter
2008-08-28 Grapher: draw ref names
119 if (cellInfo.refs)
120 [self drawRefsInRect:&rect];
fe8f1733 » pieter
2008-06-17 Add custom cell
121
122 [super drawWithFrame:rect inView:view];
52d94025 » pieter
2008-06-18 First take on graphing
123 isReady = NO;
fe8f1733 » pieter
2008-06-17 Add custom cell
124 }
125
126 @end
Something went wrong with that request. Please try again.