def redo_last_stroke_with_different_brush(self, brush): cmd = self.get_last_command() if not isinstance(cmd, command.Stroke): return cmd = self.undo() assert isinstance(cmd, command.Stroke) new_stroke = cmd.stroke.copy_using_different_brush(brush) snapshot_before = self.layer.save_snapshot() new_stroke.render(self.layer._surface) self.do(command.Stroke(self, new_stroke, snapshot_before))
def split_stroke(self): if not self.stroke: return self.stroke.stop_recording() if not self.stroke.empty: self.command_stack.do(command.Stroke(self, self.stroke, self.snapshot_before_stroke)) del self.snapshot_before_stroke self.unsaved_painting_time += self.stroke.total_painting_time for f in self.stroke_observers: f(self.stroke, self.brush) self.stroke = None
def draw_points(self, layer_number, style, points): # Corrective constants to match characteristics of OpenCanvas 1.1 brushes pressure_correction_weight = 1.0 brush_size_weight = 0.7 brush_velocity = 0.03 print "Drawing on layer ", layer_number self.select_layer(layer_number) layer = self.get_current_layer() brush_style = BrushInfo(brushdata) # Set color rgb = map(lambda c: float(c) / 255.0, style['color']) brush_style.set_color_rgb(rgb) # Set size adjustments and calculate pressure curve size = style['size'] pressure_correct = style['pressure_correct'] x_points = (0.000000, 0.237952, 0.500000, 0.765060, 1.000000) y_points = map( lambda x: (x**pressure_correct) * pressure_correction_weight - pressure_correction_weight / 2.0, x_points) pressure_curve = zip(x_points, y_points) brush_style.set_setting( 'radius_logarithmic', [math.log(size * brush_size_weight), { 'pressure': pressure_curve }]) brush = Brush(brush_style) stroke = Stroke() stroke.start_recording(brush) tdelta = 0 lx, ly, lp = points[0] for point in points: lx = (lx + point[0]) / 2 ly = (ly + point[1]) / 2 lp = float(point[2]) / 1024.0 # Pressure stroke.record_event(tdelta, lx, ly, lp, 0, 0) tdelta += brush_velocity stroke.stop_recording() # Render stroke and save undo information snapshot_before = layer.save_snapshot() stroke.render(layer._surface) self.do(command.Stroke(self, stroke, snapshot_before))
def split_stroke(self): """Splits the current stroke, announcing the newly stacked stroke The stroke being drawn is pushed onto to the command stack and the callbacks in the list `self.stroke_observers` are invoked with two arguments: the newly completed stroke, and the brush used. The brush argument is a temporary read-only convenience object. This is called every so often when drawing a single long brushstroke on input to allow parts of a long line to be undone. """ if not self.stroke: return self.stroke.stop_recording() if not self.stroke.empty: cmd = command.Stroke(self, self.stroke, self.snapshot_before_stroke) self.command_stack.do(cmd) del self.snapshot_before_stroke self.unsaved_painting_time += self.stroke.total_painting_time for f in self.stroke_observers: f(self.stroke, self.brush) self.stroke = None