/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to branchview/graphcell.py

  • Committer: Daniel Schierbeck
  • Date: 2008-01-13 14:15:20 UTC
  • mto: (423.1.2 trunk)
  • mto: This revision was merged to the branch mainline in revision 429.
  • Revision ID: daniel.schierbeck@gmail.com-20080113141520-ol1on2ju8h833rh0
Moved the branch window class to the viz package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
1
# -*- coding: UTF-8 -*-
3
2
"""Cell renderer for directed graph.
4
3
 
31
30
      in_lines          (start, end, colour) tuple list to draw inward lines,
32
31
      out_lines         (start, end, colour) tuple list to draw outward lines.
33
32
    """
 
33
    
 
34
    columns_len = 0
34
35
 
35
36
    __gproperties__ = {
36
37
        "node":         ( gobject.TYPE_PYOBJECT, "node",
46
47
                          gobject.PARAM_WRITABLE
47
48
                        ),
48
49
        }
49
 
 
 
50
    
50
51
    def do_set_property(self, property, value):
51
52
        """Set properties from GObject properties."""
52
53
        if property.name == "node":
72
73
            metrics = pango_ctx.get_metrics(font_desc)
73
74
 
74
75
            ascent = pango.PIXELS(metrics.get_ascent())
75
 
            descent = pango.PIXELS(metrics.get_ascent())
 
76
            descent = pango.PIXELS(metrics.get_descent())
76
77
 
77
 
            self._box_size = ascent + descent
 
78
            self._box_size = ascent + descent + 6
78
79
            return self._box_size
79
80
 
80
81
    def set_colour(self, ctx, colour, bg, fg):
85
86
        colours and the fg parameter provides the multiplier that should be
86
87
        applied to the foreground colours.
87
88
        """
 
89
        mainline_color = ( 0.0, 0.0, 0.0 )
88
90
        colours = [
89
91
            ( 1.0, 0.0, 0.0 ),
90
92
            ( 1.0, 1.0, 0.0 ),
94
96
            ( 1.0, 0.0, 1.0 ),
95
97
            ]
96
98
 
97
 
        colour %= len(colours)
98
 
        red   = (colours[colour][0] * fg) or bg
99
 
        green = (colours[colour][1] * fg) or bg
100
 
        blue  = (colours[colour][2] * fg) or bg
 
99
        if colour == 0:
 
100
            colour_rgb = mainline_color
 
101
        else:
 
102
            colour_rgb = colours[colour % len(colours)]
 
103
 
 
104
        red   = (colour_rgb[0] * fg) or bg
 
105
        green = (colour_rgb[1] * fg) or bg
 
106
        blue  = (colour_rgb[2] * fg) or bg
101
107
 
102
108
        ctx.set_source_rgb(red, green, blue)
103
109
 
108
114
        to be, we let the TreeViewColumn take care of making them all
109
115
        line up.
110
116
        """
111
 
        box_size = self.box_size(widget)
112
 
 
113
 
        cols = self.node[0]
114
 
        for start, end, colour in self.in_lines + self.out_lines:
115
 
            cols = max(cols, start, end)
116
 
 
117
 
        width = box_size * (cols + 1)
 
117
        box_size = self.box_size(widget) + 1
 
118
 
 
119
        width = box_size * (self.columns_len + 1)
118
120
        height = box_size
119
121
 
120
122
        # FIXME I have no idea how to use cell_area properly
138
140
        ctx.rectangle(bg_area.x, bg_area.y, bg_area.width, bg_area.height)
139
141
        ctx.clip()
140
142
 
141
 
        ctx.set_line_width(2)
142
 
        ctx.set_line_cap(cairo.LINE_CAP_SQUARE)
143
 
 
144
143
        box_size = self.box_size(widget)
145
144
 
 
145
        ctx.set_line_width(box_size / 8)
 
146
        ctx.set_line_cap(cairo.LINE_CAP_ROUND)
 
147
 
146
148
        # Draw lines into the cell
147
149
        for start, end, colour in self.in_lines:
148
 
            ctx.move_to(cell_area.x + box_size * start + box_size / 2,
149
 
                        bg_area.y - bg_area.height / 2)
150
 
 
151
 
            if start - end > 1:
152
 
                ctx.line_to(cell_area.x + box_size * start, bg_area.y)
153
 
                ctx.line_to(cell_area.x + box_size * end + box_size, bg_area.y)
154
 
            elif start - end < -1:
155
 
                ctx.line_to(cell_area.x + box_size * start + box_size,
156
 
                            bg_area.y)
157
 
                ctx.line_to(cell_area.x + box_size * end, bg_area.y)
158
 
 
159
 
            ctx.line_to(cell_area.x + box_size * end + box_size / 2,
160
 
                        bg_area.y + bg_area.height / 2)
161
 
 
162
 
            self.set_colour(ctx, colour, 0.0, 0.65)
163
 
            ctx.stroke()
 
150
            self.render_line (ctx, cell_area, box_size,
 
151
                         bg_area.y, bg_area.height,
 
152
                         start, end, colour)
164
153
 
165
154
        # Draw lines out of the cell
166
155
        for start, end, colour in self.out_lines:
167
 
            ctx.move_to(cell_area.x + box_size * start + box_size / 2,
168
 
                        bg_area.y + bg_area.height / 2)
169
 
 
170
 
            if start - end > 1:
171
 
                ctx.line_to(cell_area.x + box_size * start,
172
 
                            bg_area.y + bg_area.height)
173
 
                ctx.line_to(cell_area.x + box_size * end + box_size,
174
 
                            bg_area.y + bg_area.height)
175
 
            elif start - end < -1:
176
 
                ctx.line_to(cell_area.x + box_size * start + box_size,
177
 
                            bg_area.y + bg_area.height)
178
 
                ctx.line_to(cell_area.x + box_size * end,
179
 
                            bg_area.y + bg_area.height)
180
 
 
181
 
            ctx.line_to(cell_area.x + box_size * end + box_size / 2,
182
 
                        bg_area.y + bg_area.height / 2 + bg_area.height)
183
 
 
184
 
            self.set_colour(ctx, colour, 0.0, 0.65)
185
 
            ctx.stroke()
 
156
            self.render_line (ctx, cell_area, box_size,
 
157
                         bg_area.y + bg_area.height, bg_area.height,
 
158
                         start, end, colour)
186
159
 
187
160
        # Draw the revision node in the right column
188
161
        (column, colour) = self.node
189
162
        ctx.arc(cell_area.x + box_size * column + box_size / 2,
190
163
                cell_area.y + cell_area.height / 2,
191
 
                box_size / 5, 0, 2 * math.pi)
 
164
                box_size / 4, 0, 2 * math.pi)
192
165
 
193
166
        self.set_colour(ctx, colour, 0.0, 0.5)
194
167
        ctx.stroke_preserve()
195
168
 
196
169
        self.set_colour(ctx, colour, 0.5, 1.0)
197
170
        ctx.fill()
 
171
    
 
172
    def render_line (self, ctx, cell_area, box_size, mid, height, start, end, colour):
 
173
        if start is None:
 
174
            x = cell_area.x + box_size * end + box_size / 2
 
175
            ctx.move_to(x, mid + height / 3)
 
176
            ctx.line_to(x, mid + height / 3)
 
177
            ctx.move_to(x, mid + height / 6)
 
178
            ctx.line_to(x, mid + height / 6)
 
179
            
 
180
        elif end is None:
 
181
            x = cell_area.x + box_size * start + box_size / 2
 
182
            ctx.move_to(x, mid - height / 3)
 
183
            ctx.line_to(x, mid - height / 3)
 
184
            ctx.move_to(x, mid - height / 6)
 
185
            ctx.line_to(x, mid - height / 6)
 
186
        else:
 
187
            startx = cell_area.x + box_size * start + box_size / 2
 
188
            endx = cell_area.x + box_size * end + box_size / 2
 
189
            
 
190
            ctx.move_to(startx, mid - height / 2)
 
191
            
 
192
            if start - end == 0 :
 
193
                ctx.line_to(endx, mid + height / 2)
 
194
            else:
 
195
                ctx.curve_to(startx, mid - height / 5,
 
196
                             startx, mid - height / 5,
 
197
                             startx + (endx - startx) / 2, mid)
 
198
                
 
199
                ctx.curve_to(endx, mid + height / 5,
 
200
                             endx, mid + height / 5 ,
 
201
                             endx, mid + height / 2)
 
202
                
 
203
        self.set_colour(ctx, colour, 0.0, 0.65)
 
204
        ctx.stroke()
 
205
        
 
 
b'\\ No newline at end of file'