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) draw_highlight(context) cr.stroke()
def draw_interaction(box, context, bounding_box): cr = context.cairo cr.rectangle(0, 0, bounding_box.width, bounding_box.height) draw_highlight(context) # draw pentagon w, h = box.sizes[0] h2 = h / 2.0 cr.move_to(0, h) cr.line_to(w - 4, h) cr.line_to(w, h2) cr.line_to(w, 0) cr.stroke()
def draw_initial_node(_box, context, _bounding_box): cr = context.cairo stroke = context.style["color"] if stroke: cr.set_source_rgba(*stroke) r = 10 d = r * 2 path_ellipse(cr, r, r, d, d) draw_highlight(context) cr.set_line_width(0.01) cr.fill()
def draw_initial_pseudostate(box, context, bounding_box): """Draw initial pseudostate symbol.""" cr = context.cairo stroke = context.style["color"] if stroke: cr.set_source_rgba(*stroke) r = 10 d = r * 2 path_ellipse(cr, r, r, d, d) draw_highlight(context) cr.set_line_width(0.01) cr.fill()
def draw_outline(self, bounding_box: Rectangle, context: DrawContext) -> None: """Draw the outline and header of the swimlanes.""" cr = context.cairo cr.move_to(0, bounding_box.height) cr.line_to(0, 0) cr.line_to(bounding_box.width, 0) cr.line_to(bounding_box.width, bounding_box.height) draw_highlight(context) cr.move_to(0, bounding_box.height) cr.line_to(0, HEADER_HEIGHT) cr.line_to(0 + bounding_box.width, HEADER_HEIGHT) cr.line_to(0 + bounding_box.width, bounding_box.height)
def draw_fork_node(self, _box, context, _bounding_box): """ Draw vertical line - symbol of fork and join nodes. Join specification is also drawn above the item. """ cr = context.cairo cr.set_line_width(6) stroke = context.style.get("color") if stroke: cr.set_source_rgba(*stroke) h1, h2 = self._handles cr.move_to(h1.pos.x, h1.pos.y) cr.line_to(h2.pos.x, h2.pos.y) draw_highlight(context) cr.stroke()
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(box.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) cr.stroke() if context.hovered or context.dropzone: cr.save() 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() cr.restore()
def draw_node(box, context, bounding_box): cr = context.cairo d = 10 w = bounding_box.width h = bounding_box.height cr.rectangle(0, 0, w, h) draw_highlight(context) cr.move_to(0, 0) cr.line_to(d, -d) cr.line_to(w + d, -d) cr.line_to(w + d, h - d) cr.line_to(w, h) cr.move_to(w, 0) cr.line_to(w + d, -d) stroke(context)
def draw(self, context): def draw_line_end(end_handle, second_handle, draw): pos, p1 = end_handle.pos, second_handle.pos angle = atan2(p1.y - pos.y, p1.x - pos.x) cr = context.cairo cr.save() try: cr.translate(*pos) cr.rotate(angle) draw(context) finally: cr.restore() style = combined_style(context.style, self.style) context = replace(context, style=style) cr = context.cairo cr.set_line_width(self.line_width) cr.set_dash(style.get("dash-style", ()), 0) stroke = style["color"] if stroke: cr.set_source_rgba(*stroke) handles = self._handles draw_line_end(handles[0], handles[1], self.draw_head) for h in self._handles[1:-1]: cr.line_to(*h.pos) draw_line_end(handles[-1], handles[-2], self.draw_tail) draw_highlight(context) cr.stroke() for shape, rect in ( (self.shape_head, self._shape_head_rect), (self.shape_middle, self._shape_middle_rect), (self.shape_tail, self._shape_tail_rect), ): if shape: shape.draw(context, rect)