public this repo is viewable by everyone
Description: A Gitk-like application written in RubyCocoa that looks like it belongs on a Mac. See the wiki for downloads and screenshots.
Homepage: http://alternateidea.com
Clone URL: git://github.com/Caged/gitnub.git
gitnub / VisualizationView.rb
100644 82 lines (65 sloc) 2.257 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#
# VisualizationView.rb
# GitNub
#
# Created by Justin Palmer on 4/12/08.
# Copyright (c) 2008 Active Reload, LLC. All rights reserved.
#
 
require 'osx/cocoa'
require 'ostruct'
require 'pp'
 
class VisualizationView < OSX::NSView
  ib_outlet :application_controller
  
  def initWithFrame(frame)
    super_initWithFrame(frame)
    # Initialization code here.
    return self
  end
  
  def awakeFromNib
    @repo ||= @application_controller.repo
  end
  
  def isFlipped
    true
  end
  
  def drawRect(rect)
    nodes = {}
    context = NSGraphicsContext.currentContext
    NSColor.darkGrayColor.set
    NSRectFill(bounds)
    
    path = NSBezierPath.bezierPath
    path.lineWidth = 3
 
    path.moveToPoint([100, 105])
    path.appendBezierPathWithOvalInRect(NSMakeRect(100, 100, 10, 10))
    path.relativeMoveToPoint([0, 3.5])
    
    context.saveGraphicsState
    path.relativeLineToPoint([90, 0])
    context.restoreGraphicsState
    
    path.relativeMoveToPoint([5, 5])
    path.relativeCurveToPoint_controlPoint1_controlPoint2([40, 20], [0, 20], [-5, 20])
    
    path.appendBezierPathWithOvalInRect(NSMakeRect(200, 100, 10, 10))
    path.relativeMoveToPoint([0, 3.5])
    path.relativeLineToPoint([90, 0])
    path.appendBezierPathWithOvalInRect(NSMakeRect(300, 100, 10, 10))
    
    
    
    # commits = @repo.git.rev_list({:topo_order => true, :all => true, :pretty => 'raw', :full_history => true})
    # commits = Grit::Commit.list_from_string(@repo, commits)
    # commits.each_with_index do |commit, index|
    # current_offset = 25 * (index + path_offset)
    # path.moveToPoint([current_offset - ((path_offset * 25) + 40), 105])
    # path.lineToPoint([current_offset, 105])
    # path.appendBezierPathWithOvalInRect(NSMakeRect(current_offset, 100, 10, 10))
    # commit.parents.each do |parent|
    # npath = NSBezierPath.bezierPathWithOvalInRect(NSMakeRect((current_offset + 25), 125, 10, 10))
    # NSColor.blueColor.set
    # npath.fill
    # npath.lineWidth = 3
    # NSColor.whiteColor.set
    # npath.stroke
    # path_offset += 1
    # end if commit.parents.size > 1
    # end
    
    NSColor.blackColor.set
    path.fill
    
    NSColor.whiteColor.set
    path.stroke
  end
 
end