def stroke_to(self, dtime, x, y, pressure, xtilt, ytilt): """Painting: forward a stroke position update to the model :param float dtime: Seconds since the last call to this method :param float x: Document X position update :param float y: Document Y position update :param float pressure: Pressure, ranging from 0.0 to 1.0 :param float xtilt: X-axis tilt, ranging from -1.0 to 1.0 :param float ytilt: Y-axis tilt, ranging from -1.0 to 1.0 Stroke data is recorded at this level, but strokes are not autosplit here because that would involve the creation of a new Brushwork command on the CommandStack. Instead, callers should check `split_due` and split appropriately. An example of a mode which does just this can be found in gui/. """ self._check_recording_started() model = self.doc layer = self._stroke_target_layer if layer is None: return # wasn't suitable for painting # Reset initial brush state if requested. brush = model.brush if self._abrupt_start and not self._abrupt_start_done: brush.reset() layer.stroke_to(brush, x, y, 0.0, xtilt, ytilt, 10.0) self._abrupt_start_done = True # Record and paint this position self._stroke_seq.record_event(dtime, x, y, pressure, xtilt, ytilt) self.split_due = layer.stroke_to(brush, x, y, pressure, xtilt, ytilt, dtime)
def stroke_to(self, dtime, x, y, pressure, xtilt, ytilt): """Painting: forward a stroke position update to the model :param float dtime: Seconds since the last call to this method :param float x: Document X position update :param float y: Document Y position update :param float pressure: Pressure, ranging from 0.0 to 1.0 :param float xtilt: X-axis tilt, ranging from -1.0 to 1.0 :param float ytilt: Y-axis tilt, ranging from -1.0 to 1.0 Stroke data is recorded at this level, but strokes are not autosplit here because that would involve the creation of a new Brushwork command on the CommandStack. Instead, callers should check `split_due` and split appropriately. An example of a mode which does just this can be found in gui/. """ self._check_recording_started() model = self.doc layer = self._stroke_target_layer if layer is None: return # wasn't suitable for painting # Reset initial brush state if requested. brush = model.brush if self._abrupt_start and not self._abrupt_start_done: brush.reset() layer.stroke_to(brush, x, y, 0.0, xtilt, ytilt, 10.0) self._abrupt_start_done = True # Record and paint this position self._stroke_seq.record_event( dtime, x, y, pressure, xtilt, ytilt, ) self.split_due = layer.stroke_to( brush, x, y, pressure, xtilt, ytilt, dtime, )
def stroke_to(self, dtime, x, y, pressure, xtilt, ytilt): """Painting: forward a stroke position update to the model :param float dtime: Seconds since the last call to this method :param float x: Document X position update :param float y: Document Y position update :param float pressure: Pressure, ranging from 0.0 to 1.0 :param float xtilt: X-axis tilt, ranging from -1.0 to 1.0 :param float ytilt: Y-axis tilt, ranging from -1.0 to 1.0 Stroke data is recorded at this level, but strokes are not autosplit here because that would involve the creation of a new Brushwork command on the CommandStack. Instead, callers should check `split_due` and split appropriately. An example of a GUI mode which does just this can be found in the complete MyPaint distribution in gui/. """ # Model and layer being painted on. Called frequently during the # painting phase, so use a cache to avoid excessive layers tree # climbing. model = self.doc if self._layer_ref is None: layer = model.layer_stack.deepget(self._layer_path) if not layer.get_paintable(): logger.debug("Skipped non-paintable layer %r", layer) return self._layer_ref = weakref.ref(layer) else: layer = self._layer_ref() if layer is None: logger.error("Layer was deleted while painting was in " "progress: undo stack is probably broken now") self.split_due = True return if not self._stroke_seq: self._stroke_seq = lib.stroke.Stroke() self._time_before = model.unsaved_painting_time self._sshot_before = layer.save_snapshot() self._stroke_seq.start_recording(model.brush) brush = model.brush self._stroke_seq.record_event(dtime, x, y, pressure, xtilt, ytilt) self.split_due = layer.stroke_to(brush, x, y, pressure, xtilt, ytilt, dtime) self._last_pos = (x, y, xtilt, ytilt)