def draw_mask_control_points(self, cr, wd, ht): # Draw active and inactive control points on the active shape. if self.__active_shape is None: return cr.save() active_rgb = 1, 1, 1 normal_rgb = 0, 0, 0 delete_rgb = 1, 0, 0 cr.set_line_width(1.0) void = self.colors_to_mask_void(self.__active_shape) # Highlight the objects that would be directly or indirectly affected # if the shape were dragged, and how. min_size = self.get_radius(wd=wd, ht=ht) * self.min_shape_size void_rgb = normal_rgb if self._get_void_size(void) < min_size: # Shape will be deleted void_rgb = delete_rgb elif ((self.__active_ctrlpoint is None) and (self.__tmp_new_ctrlpoint is None)): # The entire shape would be moved void_rgb = active_rgb # Outline the current shape cr.set_source_rgb(*void_rgb) for p_idx, p in enumerate(void): if p_idx == 0: cr.move_to(*p) else: cr.line_to(*p) cr.close_path() cr.stroke() # Control points colors = self.__active_shape for col_idx, col in enumerate(colors): px, py = self.get_pos_for_color(col) if (px, py) not in void: # not in convex hull (is it worth doing this fragile test?) continue point_rgb = void_rgb if col_idx == self.__active_ctrlpoint: point_rgb = active_rgb cr.set_source_rgb(*point_rgb) cr.arc(px, py, self.__ctrlpoint_radius, 0, 2 * math.pi) cr.fill() if self.__tmp_new_ctrlpoint: px, py = self.get_pos_for_color(self.__tmp_new_ctrlpoint) cr.set_source_rgb(*active_rgb) cr.arc(px, py, self.__ctrlpoint_radius, 0, 2 * math.pi) cr.fill() # Centroid cr.set_source_rgb(*void_rgb) cx, cy = geom.poly_centroid(void) cr.save() cr.set_line_cap(cairo.LINE_CAP_SQUARE) cr.set_line_width(0.5) cr.translate(int(cx) + 0.5, int(cy) + 0.5) cr.move_to(-2, 0) cr.line_to(2, 0) cr.stroke() cr.move_to(0, -2) cr.line_to(0, 2) cr.stroke() cr.restore()
def draw_mask_control_points(self, cr, wd, ht): # Draw active and inactive control points on the active shape. if self.__active_shape is None: return cr.save() active_rgb = 1, 1, 1 normal_rgb = 0, 0, 0 delete_rgb = 1, 0, 0 cr.set_line_width(1.0) void = self.colors_to_mask_void(self.__active_shape) # Highlight the objects that would be directly or indirectly affected # if the shape were dragged, and how. min_size = self.get_radius(wd=wd, ht=ht) * self.min_shape_size void_rgb = normal_rgb if self._get_void_size(void) < min_size: # Shape will be deleted void_rgb = delete_rgb elif ((self.__active_ctrlpoint is None) and (self.__tmp_new_ctrlpoint is None)): # The entire shape would be moved void_rgb = active_rgb # Outline the current shape cr.set_source_rgb(*void_rgb) for p_idx, p in enumerate(void): if p_idx == 0: cr.move_to(*p) else: cr.line_to(*p) cr.close_path() cr.stroke() # Control points colors = self.__active_shape for col_idx, col in enumerate(colors): px, py = self.get_pos_for_color(col) if (px, py) not in void: # not in convex hull (is it worth doing this fragile test?) continue point_rgb = void_rgb if col_idx == self.__active_ctrlpoint: point_rgb = active_rgb cr.set_source_rgb(*point_rgb) cr.arc(px, py, self.__ctrlpoint_radius, 0, 2*math.pi) cr.fill() if self.__tmp_new_ctrlpoint: px, py = self.get_pos_for_color(self.__tmp_new_ctrlpoint) cr.set_source_rgb(*active_rgb) cr.arc(px, py, self.__ctrlpoint_radius, 0, 2*math.pi) cr.fill() # Centroid cr.set_source_rgb(*void_rgb) cx, cy = geom.poly_centroid(void) cr.save() cr.set_line_cap(cairo.LINE_CAP_SQUARE) cr.set_line_width(0.5) cr.translate(int(cx)+0.5, int(cy)+0.5) cr.move_to(-2, 0) cr.line_to(2, 0) cr.stroke() cr.move_to(0, -2) cr.line_to(0, 2) cr.stroke() cr.restore()