def paint_lines(self, surface, parent_offset): parent_offset = Point(parent_offset) self.line.update() self.draw_rect = draw.lines(surface, self.bg_color, False, [tuple(Point(p) + parent_offset) for p in self.line.current], 2, False) target_widget = self.get_node_widget(self.edge.target) if (self.line.done and target_widget._pos.done and target_widget._size.done and self.cached_parent_offset and self.cached_parent_offset == parent_offset): changed = False else: changed = True self.cached_arrowhead = None if changed or not self.cached_arrowhead: # If we didn't cache the found intersection or some stuff changed.... # TODO: make this a binary search shape = target_widget.shape i = len(self.line.current)/2 while i + 1 < len(self.line.current): a, b = map(Point, (self.line.current[i], self.line.current[i+1])) i += 1 for intersection in shape.intersections(a, b): break else: continue self.cached_arrowhead = paint_arrowhead_by_direction(surface, (200,60,60), a + parent_offset, intersection + parent_offset) self.cached_parent_offset = parent_offset return if self.cached_arrowhead: repaint_arrowhead(surface, *self.cached_arrowhead)
def paint_shape(self, parent_offset, surface, fore_color, back_color): change_stopped_now = False if (self.line.done and self.target_widget.pos.done and self.target_widget.size.done and self.cached_parent_offset and self.cached_parent_offset == parent_offset): if not self.cached_arrowhead: change_stopped_now = True changed = False else: changed = True self.cached_arrowhead = None self.line.update() self.draw_rect = pygame.draw.lines(surface, back_color, False, [tuple(p + parent_offset) for p in self.line.current], 2) if changed or change_stopped_now or not self.cached_arrowhead: # If we didn't cache the found intersection or some stuff changed.... # TODO: make this a binary search shape = self.target_widget.get_shape() i = len(self.line.current)/2 while i + 1 < len(self.line.current): a, b = self.line.current[i], self.line.current[i+1] i += 1 for intersection in shape.intersections(a, b): break else: continue self.cached_arrowhead = paint_arrowhead_by_direction(surface, (200,60,60), a + parent_offset, intersection + parent_offset) self.cached_parent_offset = parent_offset return if self.cached_arrowhead: repaint_arrowhead(surface, *self.cached_arrowhead)