示例#1
0
 def add_point(self, point, doc_point):
     subpoint = bezier_base_point(point)
     if self.path[0]:
         w = h = config.curve_point_sensitivity_size
         start = self.canvas.point_doc_to_win(self.path[0])
         if self.points:
             p = self.canvas.point_doc_to_win(self.points[-1])
             last = bezier_base_point(p)
             if is_point_in_rect2(subpoint, start, w,
                                  h) and len(self.points) > 1:
                 self.path[2] = sk2const.CURVE_CLOSED
                 if len(point) == 2:
                     self.points.append([] + self.path[0])
                 else:
                     p = doc_point
                     self.points.append(
                         [p[0], p[1], [] + self.path[0], p[3]])
                 if not self.ctrl_mask:
                     self.release_curve()
                 else:
                     self.draw = False
                 self.on_timer()
             elif not is_point_in_rect2(subpoint, last, w, h):
                 self.points.append(doc_point)
                 self.path[1] = self.points
         else:
             if not is_point_in_rect2(subpoint, start, w, h):
                 self.points.append(doc_point)
                 self.path[1] = self.points
     else:
         self.path[0] = doc_point
         self.paths.append(self.path)
示例#2
0
	def add_point(self, point, doc_point):
		subpoint = bezier_base_point(point)
		if self.path[0]:
			w = h = config.curve_point_sensitivity_size
			start = self.canvas.point_doc_to_win(self.path[0])
			if self.points:
				p = self.canvas.point_doc_to_win(self.points[-1])
				last = bezier_base_point(p)
				if is_point_in_rect2(subpoint, start, w, h) and len(self.points) > 1:
					self.path[2] = const.CURVE_CLOSED
					if len(point) == 2:
						self.points.append([] + self.path[0])
					else:
						p = doc_point
						self.points.append([p[0], p[1], [] + self.path[0], p[3]])
					if not self.ctrl_mask:
						self.release_curve()
					else:
						self.draw = False
					self.repaint()
				elif not is_point_in_rect2(subpoint, last, w, h):
					self.points.append(doc_point)
					self.path[1] = self.points
			else:
				if not is_point_in_rect2(subpoint, start, w, h):
					self.points.append(doc_point)
					self.path[1] = self.points
		else:
			self.path[0] = doc_point
			self.paths.append(self.path)
示例#3
0
    def paint_curve(self, paths, cursor=None, trace_path=None, cpoint=None):
        cursor = cursor or []
        trace_path = trace_path or []
        cpoint = cpoint or []
        self.start_soft_repaint()
        if paths:
            for path in paths:
                self.ctx.set_source_rgb(*config.curve_stroke_color)
                self.ctx.set_line_width(config.curve_stroke_width)
                self.ctx.move_to(*path[0])
                points = path[1]
                for point in points:
                    if len(point) == 2:
                        self.ctx.line_to(*point)
                    else:
                        x0, y0 = point[0]
                        x1, y1 = point[1]
                        x2, y2 = point[2]
                        self.ctx.curve_to(x0, y0, x1, y1, x2, y2)
                if path[2]:
                    self.ctx.close_path()
                self.ctx.stroke()

                # Start point rendering
                w = h = config.curve_point_sensitivity_size
                if cursor and libgeom.is_point_in_rect2(cursor, path[0], w, h):
                    self.draw_curve_point(path[0], 'active_point')
                else:
                    self.draw_curve_point(path[0], 'start_point')

                for point in points:
                    self.draw_curve_point(point, 'curve_point')
                if points:
                    self.draw_curve_point(points[-1], 'last_point')
        if cursor:
            self.ctx.set_source_rgb(*config.curve_trace_color)
            self.ctx.set_line_width(config.curve_stroke_width)
            if trace_path:
                self.ctx.move_to(*trace_path[0])
                point = trace_path[1]
                x0, y0 = point[0]
                x1, y1 = point[1]
                x2, y2 = point[2]
                self.ctx.curve_to(x0, y0, x1, y1, x2, y2)
                self.ctx.stroke()
                if cpoint:
                    self.ctx.set_source_rgb(*config.control_line_stroke_color)
                    self.ctx.set_line_width(config.control_line_stroke_width)
                    self.ctx.set_dash(config.control_line_stroke_dash)
                    self.ctx.move_to(*trace_path[0])
                    self.ctx.line_to(x0, y0)
                    self.ctx.stroke()
                    self.ctx.move_to(x2, y2)
                    self.ctx.line_to(x1, y1)
                    self.ctx.stroke()
                    self.ctx.move_to(x2, y2)
                    self.ctx.line_to(*cpoint)
                    self.ctx.stroke()
                    self.ctx.set_dash([])
                    for point in [[x0, y0], [x1, y1], cpoint]:
                        self.draw_curve_point(point, 'control_point')
                    self.draw_curve_point([x2, y2], 'curve_point')
            else:
                if paths[-1][1]:
                    end_point = paths[-1][1][-1]
                    if len(end_point) == 2:
                        self.ctx.move_to(*end_point)
                    else:
                        self.ctx.move_to(*end_point[2])
                else:
                    self.ctx.move_to(*paths[-1][0])
                self.ctx.line_to(*cursor)
                self.ctx.stroke()

        self.end_soft_repaint()