root/gaphor/tags/gaphor-0.12.0/gaphor/ui/diagrampainters.py

Revision 1679, 1.7 kB (checked in by arj..@yirdis.nl, 1 year ago)

Changed matrix conversion methods to new names.

Line 
1 """
2 Painters for diagrams (canvas').
3
4 """
5
6 from gaphas.painter import Painter, PainterChain
7 from gaphas.painter import ItemPainter, HandlePainter, ToolPainter
8 from gaphas.item import Line
9 from cairo import Matrix, ANTIALIAS_NONE
10
11
12 class LineSegmentPainter(Painter):
13     """
14     This painter draws pseudo-hanldes on gaphas.item.Line objects. Each
15     line can be split by dragging those points, which will result in
16     a new handle.
17
18     ConnectHandleTool take care of performing the user
19     interaction required for this feature.
20     """
21
22     def paint(self, context):
23         view = context.view
24         item = view.hovered_item
25         if item and item is view.focused_item and isinstance(item, Line):
26             cr = context.cairo
27             h = item.handles()
28             for h1, h2 in zip(h[:-1], h[1:]):
29                 cx = (h1.x + h2.x) / 2
30                 cy = (h1.y + h2.y) / 2
31                 cr.save()
32                 cr.identity_matrix()
33                 m = Matrix(*view.get_matrix_i2v(item))
34
35                 cr.set_antialias(ANTIALIAS_NONE)
36                 cr.translate(*m.transform_point(cx, cy))
37                 cr.rectangle(-3, -3, 6, 6)
38                 cr.set_source_rgba(0, 0.5, 0, .4)
39                 cr.fill_preserve()
40                 cr.set_source_rgba(.25, .25, .25, .6)
41                 cr.set_line_width(1)
42                 cr.stroke()
43                 cr.restore()
44
45
46 def DefaultPainter():
47     """
48     Default painter, containing item, handle and tool painters.
49     """
50     chain = PainterChain()
51     chain.append(ItemPainter())
52     chain.append(HandlePainter())
53     chain.append(LineSegmentPainter())
54     chain.append(ToolPainter())
55     return chain
56
57
58 # vim: sw=4:et:ai
Note: See TracBrowser for help on using the browser.