Пример #1
0
 def _draw(self, cr, area, view_area):
     locator_area = self._get_area(area, view_area)
     if locator_area is None:
         return
     locator_x, _, locator_width, locator_height = locator_area
     # Frame
     cr.rectangle(*area)
     cr.clip()
     cr.translate(locator_x, 0)
     cr.set_source_rgba(.6, .6, .6, self.alpha)
     line_width = 1.0
     if vector_based(cr):
         line_width = 0.5
         cr.set_source_rgba(0, 0, 0, self.alpha)
     cr.rectangle(0.5 * line_width, 0.5 * line_width, locator_width - line_width, locator_height - line_width)
     cr.set_line_width(line_width)
     cr.stroke()
     # Miniature
     width = locator_width - 2 * line_width
     height = locator_height - 2 * line_width
     image = self._get_miniature(self.view.renderers, width, height)
     cr.save()
     cr.rectangle(line_width, line_width, width, height)
     cr.clip()
     # A bug in cairo misaligns the paint_with_alpha origin vertically with vector backends. 
     if vector_based(cr):
         cr.set_source_surface(image, line_width, 1)
     else:
         cr.set_source_surface(image, line_width, line_width)
     cr.paint_with_alpha(self.alpha)
     cr.restore()
     # View outline
     vx_first = int(float(view_area.x) / view_area.total_width * width)
     vx_last = int(math.ceil(float(view_area.x + view_area.width) / view_area.total_width * width))
     vx_last = min(vx_last, width)
     v_width = vx_last - vx_first + 1
     vy_first = int(float(view_area.y) / view_area.total_height * height)
     vy_last = int(math.ceil(float(view_area.y + view_area.height) / view_area.total_height * height))
     vy_last = min(vy_last, height)
     v_height = vy_last - vy_first + 1
     cr.rectangle(vx_first + 0.5 * line_width, vy_first + 0.5 * line_width, v_width - line_width, v_height - line_width)
     cr.set_source_rgba(1, 0, 0, self.alpha)
     cr.stroke()
Пример #2
0
 def _draw_dash(self, cr, rectangles, dash, offset, colors=None):
     if colors == None:
         colors = ((0, 0, 0), (1, 1, 1))
     line_width = 1.0
     if vector_based(cr):
         line_width = 0.5
     for r in rectangles:
         x, y, w, h = r
         cr.rectangle(x + 0.5 * line_width, y + 0.5 * line_width, w - line_width, h - line_width)
     cr.set_dash([])
     cr.set_source_rgb(*colors[0])
     cr.set_line_width(line_width)
     cr.stroke_preserve()
     cr.set_source_rgb(*colors[1])
     cr.set_dash(dash, offset)
     cr.stroke()