예제 #1
0
파일: component.py 프로젝트: rg666/gaphor
def draw_component_icon(box, context, bounding_box):
    with cairo_state(context.cairo) as cr:
        stroke_color = context.style["color"]

        cr.set_line_width(1.0)
        icon_height = 20
        icon_width = 16
        icon_margin_x = 6
        ix = bounding_box.width - icon_margin_x - icon_width
        icon_margin_y = 12

        iy = icon_margin_y

        bar_padding = 4
        bx = ix - bar_padding
        bar_upper_y = iy + bar_padding
        bar_lower_y = iy + bar_padding * 3

        bar_width = 12
        bar_height = 4
        cr.set_source_rgba(*stroke_color)

        cr.rectangle(bx, bar_lower_y, bar_width, bar_height)
        cr.rectangle(bx, bar_upper_y, bar_width, bar_height)

        cr.move_to(ix, iy + bar_padding)
        cr.line_to(ix, iy)
        cr.line_to(ix + icon_width, iy)
        cr.line_to(ix + icon_width, iy + icon_height)
        cr.line_to(ix, iy + icon_height)
        cr.line_to(ix, iy + icon_height - bar_padding)
        cr.move_to(ix, iy + bar_padding * 3)
        cr.line_to(ix, iy + bar_padding * 2)

        cr.stroke()
예제 #2
0
def draw_artifact_icon(box, context, bounding_box):
    cr = context.cairo

    w = 15
    h = 20
    ear = 5
    icon_margin_x = 6
    icon_margin_y = 12

    ix = bounding_box.width - icon_margin_x - w
    iy = icon_margin_y

    with cairo_state(context.cairo) as cr:
        cr.set_line_width(1.0)
        cr.move_to(ix + w - ear, iy)
        for x, y in (
            (ix + w - ear, iy + ear),
            (ix + w, iy + ear),
            (ix + w - ear, iy),
            (ix, iy),
            (ix, iy + h),
            (ix + w, iy + h),
            (ix + w, iy + ear),
        ):
            cr.line_to(x, y)
        stroke_color = context.style["color"] or (0, 0, 0, 1)
        cr.set_source_rgba(*stroke_color)
        cr.stroke()
예제 #3
0
    def _draw_decorating_arrow(self, cr, inverted=False):
        with cairo_state(cr):
            angle: float = self._arrow_angle

            hint = -1

            # rotation hint, keep arrow on the same side as message text
            # elements
            if abs(angle) >= PI_2 and angle != -PI_2:
                hint = 1

            if inverted:
                angle += hint * pi

            x, y = self._arrow_pos

            # move to arrow pos and rotate, below we operate in horizontal
            # mode
            cr.translate(x, y)
            cr.rotate(angle)
            # add some padding
            cr.translate(0, 6 * hint)

            # draw decorating arrow
            d = 15
            dr = d - 4
            r = 3
            cr.set_line_width(1.5)
            cr.move_to(-d, 0)
            cr.line_to(d, 0)
            cr.line_to(dr, r)
            cr.move_to(dr, -r)
            cr.line_to(d, 0)
            cr.stroke()
예제 #4
0
    def draw_lifeline(self, box, context, bounding_box):
        """Draw lifeline.

        We always draw the lifeline's head. We only draw the lifeline's
        lifetime when the lifetime is visible.
        """
        cr = context.cairo
        cr.rectangle(0, 0, self.width, self.height)
        stroke(context, highlight=True)

        if (context.hovered or context.focused or context.dropzone
                or self.lifetime.visible):
            bottom = self.lifetime.bottom
            cr = context.cairo
            with cairo_state(cr):
                cr.set_dash((7.0, 5.0), 0)
                top = self.lifetime.top
                cr.move_to(top.pos.x, top.pos.y)
                cr.line_to(bottom.pos.x, bottom.pos.y)
                stroke(context, highlight=True)

            # draw destruction event
            if self.is_destroyed:
                d1 = 8
                d2 = d1 * 2
                cr.move_to(bottom.pos.x - d1, bottom.pos.y - d2)
                cr.line_to(bottom.pos.x + d1, bottom.pos.y)
                cr.move_to(bottom.pos.x - d1, bottom.pos.y)
                cr.line_to(bottom.pos.x + d1, bottom.pos.y - d2)
                cr.stroke()
예제 #5
0
    def draw_lifeline(self, box, context, bounding_box):
        """
        Draw lifeline.

        Lifeline's head is always drawn.

        Lifeline's lifetime is drawn when lifetime is visible.
        """
        cr = context.cairo
        cr.rectangle(0, 0, self.width, self.height)
        stroke(context)

        if context.hovered or context.focused or self.lifetime.visible:
            top = self.lifetime.top
            bottom = self.lifetime.bottom
            cr = context.cairo
            with cairo_state(cr):
                cr.set_dash((7.0, 5.0), 0)
                cr.move_to(top.pos.x, top.pos.y)
                cr.line_to(bottom.pos.x, bottom.pos.y)
                cr.stroke()

            # draw destruction event
            if self.is_destroyed:
                d1 = 8
                d2 = d1 * 2
                cr.move_to(bottom.pos.x - d1, bottom.pos.y - d2)
                cr.line_to(bottom.pos.x + d1, bottom.pos.y)
                cr.move_to(bottom.pos.x - d1, bottom.pos.y)
                cr.line_to(bottom.pos.x + d1, bottom.pos.y - d2)
                cr.stroke()
예제 #6
0
파일: partition.py 프로젝트: rg666/gaphor
 def draw_hover(self, bounding_box: Rectangle,
                context: DrawContext) -> None:
     """Add dashed line on bottom of swimlanes when hovered."""
     if context.hovered or context.dropzone:
         cr = context.cairo
         with cairo_state(cr):
             cr.set_dash((1.0, 5.0), 0)
             cr.set_line_width(1.0)
             cr.rectangle(0, 0, bounding_box.width, bounding_box.height)
             cr.stroke()
예제 #7
0
 def draw(self, context):
     super().draw(context)
     self._head_end.draw(context)
     self._tail_end.draw(context)
     if self.show_direction:
         with cairo_state(context.cairo) as cr:
             cr.translate(*self._dir_pos)
             cr.rotate(self._dir_angle)
             cr.move_to(0, 0)
             cr.line_to(6, 5)
             cr.line_to(0, 10)
             cr.fill()
예제 #8
0
def draw_package(box, context, bounding_box):
    with cairo_state(context.cairo) as cr:
        o = 0.0
        h = bounding_box.height
        w = bounding_box.width
        x = 50
        y = 20
        cr.move_to(x, y)
        cr.line_to(x, o)
        cr.line_to(o, o)
        cr.line_to(o, h)
        cr.line_to(w, h)
        cr.line_to(w, y)
        cr.line_to(o, y)
        stroke(context)
예제 #9
0
    def draw_partition(self, box, context, bounding_box):
        """
        By default vertical partition is drawn. It is open on the bottom.
        """
        assert self.canvas

        cr = context.cairo
        cr.set_line_width(context.style["line-width"])

        if self.subject and not self.subject.isDimension and self._toplevel:
            cr.move_to(0, 0)
            cr.line_to(bounding_box.width, 0)

        h = self._header_size[1]

        # draw outside lines if this item is toplevel partition
        if self._toplevel:
            cr.move_to(0, bounding_box.height)
            cr.line_to(0, h)
            cr.line_to(bounding_box.width, h)
            cr.line_to(bounding_box.width, bounding_box.height)

        if self._subpart:
            # header line for all subparitions
            hd = h + self._hdmax
            cr.move_to(0, hd)
            cr.line_to(bounding_box.width, hd)

        if self._subpart:
            # draw inside lines for all children but last one
            dp = 0
            for sl in self.canvas.get_children(self)[:-1]:
                dp += sl.width
                cr.move_to(dp, h)
                cr.line_to(dp, bounding_box.height)

        stroke(context)

        if context.hovered or context.dropzone:
            with cairo_state(cr):
                cr.set_dash((1.0, 5.0), 0)
                cr.set_line_width(1.0)
                cr.rectangle(0, 0, bounding_box.width, bounding_box.height)
                draw_highlight(context)
                cr.stroke()
예제 #10
0
def draw_component_icon(box, context, bounding_box):
    bar_width = 12
    bar_height = 4
    bar_padding = 4
    icon_width = 16
    icon_height = 20
    icon_margin_x = 6
    icon_margin_y = 12

    ix = bounding_box.width - icon_margin_x - icon_width
    iy = icon_margin_y

    with cairo_state(context.cairo) as cr:
        fill_color = context.style["background-color"] or (1, 1, 1, 1)
        stroke_color = context.style["color"] or (0, 0, 0, 1)

        cr.set_line_width(1.0)
        cr.rectangle(ix, iy, icon_width, icon_height)
        cr.set_source_rgba(*stroke_color)
        cr.stroke()

        bx = ix - bar_padding
        bar_upper_y = iy + bar_padding
        bar_lower_y = iy + bar_padding * 3

        cr.rectangle(bx, bar_lower_y, bar_width, bar_height)
        cr.set_source_rgba(*fill_color)
        cr.fill_preserve()
        cr.set_source_rgba(*stroke_color)
        cr.stroke()

        cr.rectangle(bx, bar_upper_y, bar_width, bar_height)
        cr.set_source_rgba(*fill_color)
        cr.fill_preserve()
        cr.set_source_rgba(*stroke_color)
        cr.stroke()