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

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2007-05-17 16:12:27 UTC
  • mto: This revision was merged to the branch mainline in revision 201.
  • Revision ID: szilveszter.farkas@gmail.com-20070517161227-9e37lj2rm2t0cwj6
Some small modifications to Branch, Checkout and Info to support remote branches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
      in_lines          (start, end, colour) tuple list to draw inward lines,
31
31
      out_lines         (start, end, colour) tuple list to draw outward lines.
32
32
    """
33
 
    
34
 
    columns_len = 0
35
33
 
36
34
    __gproperties__ = {
37
35
        "node":         ( gobject.TYPE_PYOBJECT, "node",
47
45
                          gobject.PARAM_WRITABLE
48
46
                        ),
49
47
        }
50
 
    
 
48
 
51
49
    def do_set_property(self, property, value):
52
50
        """Set properties from GObject properties."""
53
51
        if property.name == "node":
86
84
        colours and the fg parameter provides the multiplier that should be
87
85
        applied to the foreground colours.
88
86
        """
89
 
        mainline_color = ( 0.0, 0.0, 0.0 )
90
87
        colours = [
91
88
            ( 1.0, 0.0, 0.0 ),
92
89
            ( 1.0, 1.0, 0.0 ),
96
93
            ( 1.0, 0.0, 1.0 ),
97
94
            ]
98
95
 
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
 
96
        colour %= len(colours)
 
97
        red   = (colours[colour][0] * fg) or bg
 
98
        green = (colours[colour][1] * fg) or bg
 
99
        blue  = (colours[colour][2] * fg) or bg
107
100
 
108
101
        ctx.set_source_rgb(red, green, blue)
109
102
 
116
109
        """
117
110
        box_size = self.box_size(widget) + 1
118
111
 
119
 
        width = box_size * (self.columns_len + 1)
 
112
        cols = self.node[0]
 
113
        for start, end, colour in self.in_lines + self.out_lines:
 
114
            cols = max(cols, start, end)
 
115
 
 
116
        width = box_size * (cols + 1)
120
117
        height = box_size
121
118
 
122
119
        # FIXME I have no idea how to use cell_area properly
143
140
        box_size = self.box_size(widget)
144
141
 
145
142
        ctx.set_line_width(box_size / 8)
146
 
        ctx.set_line_cap(cairo.LINE_CAP_ROUND)
 
143
        ctx.set_line_cap(cairo.LINE_CAP_SQUARE)
147
144
 
148
145
        # Draw lines into the cell
149
146
        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)
 
147
            ctx.move_to(cell_area.x + box_size * start + box_size / 2,
 
148
                        bg_area.y - bg_area.height / 2)
 
149
 
 
150
            if start - end > 1:
 
151
                ctx.line_to(cell_area.x + box_size * start, bg_area.y)
 
152
                ctx.line_to(cell_area.x + box_size * end + box_size, bg_area.y)
 
153
            elif start - end < -1:
 
154
                ctx.line_to(cell_area.x + box_size * start + box_size,
 
155
                            bg_area.y)
 
156
                ctx.line_to(cell_area.x + box_size * end, bg_area.y)
 
157
 
 
158
            ctx.line_to(cell_area.x + box_size * end + box_size / 2,
 
159
                        bg_area.y + bg_area.height / 2)
 
160
 
 
161
            self.set_colour(ctx, colour, 0.0, 0.65)
 
162
            ctx.stroke()
153
163
 
154
164
        # Draw lines out of the cell
155
165
        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)
 
166
            ctx.move_to(cell_area.x + box_size * start + box_size / 2,
 
167
                        bg_area.y + bg_area.height / 2)
 
168
 
 
169
            if start - end > 1:
 
170
                ctx.line_to(cell_area.x + box_size * start,
 
171
                            bg_area.y + bg_area.height)
 
172
                ctx.line_to(cell_area.x + box_size * end + box_size,
 
173
                            bg_area.y + bg_area.height)
 
174
            elif start - end < -1:
 
175
                ctx.line_to(cell_area.x + box_size * start + box_size,
 
176
                            bg_area.y + bg_area.height)
 
177
                ctx.line_to(cell_area.x + box_size * end,
 
178
                            bg_area.y + bg_area.height)
 
179
 
 
180
            ctx.line_to(cell_area.x + box_size * end + box_size / 2,
 
181
                        bg_area.y + bg_area.height / 2 + bg_area.height)
 
182
 
 
183
            self.set_colour(ctx, colour, 0.0, 0.65)
 
184
            ctx.stroke()
159
185
 
160
186
        # Draw the revision node in the right column
161
187
        (column, colour) = self.node
168
194
 
169
195
        self.set_colour(ctx, colour, 0.5, 1.0)
170
196
        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'