/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 graphcell.py

  • Committer: Scott James Remnant
  • Date: 2005-10-17 01:07:49 UTC
  • Revision ID: scott@netsplit.com-20051017010749-15fa95fc2cf09289
Commit the first version of bzrk.

Show diffs side-by-side

added added

removed removed

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