コード例 #1
0
    def draw(self, cr: cairo.Context) -> None:
        xc = self._xc
        yc = self._yc
        radius = self._radius
        scale_radius = self._scale_radius
        fill_color = self._fill_color

        if radius == 0.0:
            return

        matrix = cr.get_matrix()
        dx = 1 / matrix.xx
        dy = 1 / matrix.yy

        if scale_radius:
            radius_scale = 1 / (0.5 * (matrix.xx + matrix.yy))
        else:
            radius_scale = 1.0

        cr.arc(xc, yc, radius_scale * radius, 0, 2 * math.pi)
        cr.set_source_rgba(*fill_color)
        cr.fill()

        self._last_drawn_region = circle_region(
            xc, yc, radius_scale * radius + max(dx, dy))
        self._last_drawn_radius_scale = radius_scale
コード例 #2
0
ファイル: _rectangle.py プロジェクト: singh-harshit/opendrop
    def draw(self, cr: cairo.Context) -> None:
        if self._extents is None:
            return

        extents = self._extents
        stroke_color = self._stroke_color
        stroke_width = self._stroke_width

        cr.rectangle(extents.x, extents.y, extents.w, extents.h)

        dx = 1 / cr.get_matrix().xx
        dy = 1 / cr.get_matrix().yy

        cr.save()

        if self._scale_strokes:
            stroke_scale = max(dx, dy)
            cr.identity_matrix()
        else:
            stroke_scale = 1.0

        cr.set_line_width(stroke_width)
        cr.set_source_rgba(*stroke_color)
        cr.stroke()

        cr.restore()

        self._last_drawn_region = rectangle_stroke_region(
            extents, max(stroke_width * stroke_scale, dx, dy))
        self._last_drawn_stroke_scale = stroke_scale
コード例 #3
0
    def draw(self, cr: cairo.Context) -> None:
        polyline = self._polyline
        stroke_width = self._stroke_width
        stroke_color = self._stroke_color

        if polyline is None or len(polyline) == 0:
            self._last_drawn_region = None
            return

        if self._path_cache is not None:
            cr.append_path(self._path_cache)
        else:
            self._show_polyline(cr, polyline)
            self._path_cache = cr.copy_path()
        extents = Rect2(cr.path_extents())

        dx = 1 / cr.get_matrix().xx
        dy = 1 / cr.get_matrix().yy

        cr.save()

        if self._scale_strokes:
            stroke_scale = max(dx, dy)
            cr.identity_matrix()
        else:
            stroke_scale = 1.0

        cr.set_line_width(stroke_width)
        cr.set_source_rgba(*stroke_color)
        cr.stroke()

        cr.restore()

        extents = expand_rect(extents, max(stroke_width * stroke_scale, dx,
                                           dy))
        self._last_drawn_region = cairo.Region(
            cairo.RectangleInt(
                int(math.floor(extents.x)),
                int(math.floor(extents.y)),
                int(math.ceil(extents.w)),
                int(math.ceil(extents.h)),
            ))
コード例 #4
0
ファイル: _angle.py プロジェクト: singh-harshit/opendrop
    def draw(self, cr: cairo.Context) -> None:
        start_angle = self._start_angle
        delta_angle = self._delta_angle
        clockwise = self._clockwise
        arc_radius = self._arc_radius
        start_line_radius = self._start_line_radius
        end_line_radius = self._end_line_radius
        x = self._x
        y = self._y
        stroke_color = self._stroke_color
        stroke_width = self._stroke_width
        text_radius = self._text_radius
        font_size = self._font_size
        text_color = self._text_color
        scale_radii = self._scale_radii
        scale_text = self._scale_text
        scale_strokes = self._scale_strokes

        if not (math.isfinite(start_angle) and math.isfinite(delta_angle)):
            return

        end_angle = start_angle + delta_angle

        matrix = cr.get_matrix()
        if scale_radii:
            radius_scale = 1/(0.5 * (matrix.xx + matrix.yy))
        else:
            radius_scale = 1.0

        self._show_hand(cr, x, y, -start_angle, radius_scale*start_line_radius)
        self._show_hand(cr, x, y, -end_angle, radius_scale*end_line_radius)

        if clockwise:
            cr.arc(x, y, radius_scale*arc_radius, -start_angle, -end_angle)
        else:
            cr.arc_negative(x, y, radius_scale*arc_radius, -start_angle, -end_angle)

        cr.save()
        if scale_strokes:
            cr.identity_matrix()
        cr.set_source_rgba(*stroke_color)
        cr.set_line_width(stroke_width)
        cr.stroke()
        cr.restore()

        half_angle = (start_angle + end_angle) / 2
        cr.move_to(x, y)
        cr.rel_move_to(
            radius_scale*text_radius *  math.cos(half_angle),
            radius_scale*text_radius * -math.sin(half_angle),
        )

        cr.save()

        cr.set_source_rgba(*text_color)
        cr.set_font_size(font_size)

        if scale_text:
            cr.identity_matrix()

        text = '{:.1f}°'.format(math.degrees(math.fabs(delta_angle)))
        text_extents = cr.text_extents(text)

        cr.rel_move_to(-text_extents.x_bearing, -text_extents.y_bearing)
        cr.rel_move_to(-text_extents.width/2, -text_extents.height/2)
        cr.show_text(text)
        cr.fill()

        cr.restore()