def do_draw(self, context): if not self.discovered: return clipped_rect = Gdk.cairo_get_clip_rectangle(context)[1] num_inpoint_samples = self._get_num_inpoint_samples() drawn_start = self.pixelToNs(clipped_rect.x) drawn_duration = self.pixelToNs(clipped_rect.width) start = int(drawn_start / SAMPLE_DURATION) + num_inpoint_samples end = int((drawn_start + drawn_duration) / SAMPLE_DURATION) + num_inpoint_samples if self._force_redraw or self._surface_x > clipped_rect.x or self._end < end: self._start = start end = int(min(self.n_samples, end + (self.pixelToNs(MARGIN) / SAMPLE_DURATION))) self._end = end self._surface_x = clipped_rect.x surface_width = min(self.props.width_request - clipped_rect.x, clipped_rect.width + MARGIN) surface_height = int(self.get_parent().get_allocation().height) self.surface = renderer.fill_surface(self.samples[start:end], surface_width, surface_height) self._force_redraw = False context.set_operator(cairo.OPERATOR_OVER) context.set_source_surface(self.surface, self._surface_x, 0) context.paint()
def do_draw(self, context): if not self.discovered: return clipped_rect = Gdk.cairo_get_clip_rectangle(context)[1] num_inpoint_samples = self._get_num_inpoint_samples() drawn_start = self.pixelToNs(clipped_rect.x) drawn_duration = self.pixelToNs(clipped_rect.width) start = int(drawn_start / SAMPLE_DURATION) + num_inpoint_samples end = int((drawn_start + drawn_duration) / SAMPLE_DURATION) + num_inpoint_samples if self._force_redraw or self._surface_x > clipped_rect.x or self._end < end: self._start = start end = int( min(self.n_samples, end + (self.pixelToNs(MARGIN) / SAMPLE_DURATION))) self._end = end self._surface_x = clipped_rect.x surface_width = min(self.props.width_request - clipped_rect.x, clipped_rect.width + MARGIN) surface_height = int(self.get_parent().get_allocation().height) self.surface = renderer.fill_surface(self.samples[start:end], surface_width, surface_height) self._force_redraw = False context.set_operator(cairo.OPERATOR_OVER) context.set_source_surface(self.surface, self._surface_x, 0) context.paint()
def do_draw(self, context): if not self.samples: # Nothing to draw. return # The area we have to refresh is determined by the start and end # calculated in the context of the asset duration. rect = Gdk.cairo_get_clip_rectangle(context)[1] inpoint = self.ges_elem.props.in_point max_duration = self.ges_elem.get_asset().get_filesource_asset( ).get_duration() start_ns = min(max(0, self.pixelToNs(rect.x) + inpoint), max_duration) end_ns = min(max(0, self.pixelToNs(rect.x + rect.width) + inpoint), max_duration) zoom = self.getCurrentZoomLevel() height = self.get_allocation().height if not self.surface or \ height != self.surface.get_height() or \ zoom != self._surface_zoom_level or \ start_ns < self._surface_start_ns or \ end_ns > self._surface_end_ns: if self.surface: self.surface.finish() self.surface = None self._surface_zoom_level = zoom # The generated waveform is for an extended range if possible, # so if the user scrolls we don't rebuild the waveform every time. extra = self.pixelToNs(WAVEFORM_SURFACE_EXTRA_PX) self._surface_start_ns = max(0, start_ns - extra) self._surface_end_ns = min(end_ns + extra, max_duration) range_start = min( max(0, int(self._surface_start_ns / SAMPLE_DURATION)), len(self.samples)) range_end = min( max(0, int(self._surface_end_ns / SAMPLE_DURATION)), len(self.samples)) samples = self.samples[range_start:range_end] surface_width = self.nsToPixel(self._surface_end_ns - self._surface_start_ns) self.surface = renderer.fill_surface(samples, surface_width, height) # Paint the surface, ignoring the clipped rect. # We only have to make sure the offset is correct: # 1. + self._start_surface_ns, because that's the position of # the surface in context, if the entire asset would be drawn. # 2. - inpoint, because we're drawing a clip, not the entire asset. context.set_operator(cairo.OPERATOR_OVER) offset = self.nsToPixel(self._surface_start_ns - inpoint) context.set_source_surface(self.surface, offset, 0) context.paint()
def _drawContentCb(self, unused_canvas, cr, unused_surf_w, unused_surf_h): cr.set_operator(cairo.OPERATOR_CLEAR) cr.paint() if not self.discovered: return if self.surface: self.surface.finish() self.surface = renderer.fill_surface(self.samples[self.start:self.end], int(self.width), int(EXPANDED_SIZE)) cr.set_operator(cairo.OPERATOR_OVER) cr.set_source_surface(self.surface, 0, 0) cr.paint()
def _drawContentCb(self, unused_canvas, context, unused_surf_w, unused_surf_h): context.set_operator(cairo.OPERATOR_CLEAR) context.paint() if not self.discovered: return if self.surface: self.surface.finish() self.surface = renderer.fill_surface(self.samples[self.start:self.end], int(self.width), int(EXPANDED_SIZE)) context.set_operator(cairo.OPERATOR_OVER) context.set_source_surface(self.surface, 0, 0) context.paint()