def on_expose(self, widget, cr): if self.frozen: return if not self.row.valid(): self.tw.disconnect(self.sig) self.sig = None return path = self.row.get_path() area = () color = self.stylecontext.get_background_color(0) if not self.columns: columns = self.tw.get_columns() else: columns = self.columns for col in columns: rect = self.tw.get_background_area(path, col) Gdk.cairo_get_clip_rectangle(cr) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.clip() cr.set_source_rgba((1.0/65535)*color.red, (1.0/65535)*color.green, (1.0/65535)*color.blue, 1.0-self.get_state()) cr.set_operator(cairo.OPERATOR_OVER) cr.paint()
def on_expose(self, widget, cr): if self.frozen: return if not self.row.valid(): self.tw.disconnect(self.sig) self.sig = None return path = self.row.get_path() area = () color = self.stylecontext.get_background_color(0) if not self.columns: columns = self.tw.get_columns() else: columns = self.columns for col in columns: rect = self.tw.get_background_area(path, col) Gdk.cairo_get_clip_rectangle(cr) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.clip() cr.set_source_rgba( (1.0 / 65535) * color.red, (1.0 / 65535) * color.green, (1.0 / 65535) * color.blue, 1.0 - self.get_state()) cr.set_operator(cairo.OPERATOR_OVER) cr.paint()
def on_draw(self, view, ctx): window = view.get_window(Gtk.TextWindowType.TEXT) if not Gtk.cairo_should_draw_window(ctx, window): return False # Draw something ctx.set_line_width(1.0) Gtk.cairo_transform_to_window(ctx, view, window) clipped, clip = Gdk.cairo_get_clip_rectangle(ctx) if not clipped: return False for placeholder in self.ordered_placeholders: if not self.placeholder_in_area(placeholder, clip): continue ctx.save() self.draw_placeholder(ctx, placeholder) ctx.restore() return False
def __on_draw(self, widget, cr): style = widget.get_style() x, rect = Gdk.cairo_get_clip_rectangle(cr) Gtk.paint_flat_box(style, cr, Gtk.StateType.NORMAL, Gtk.ShadowType.OUT, widget, "tooltip", rect.x, rect.y, rect.width, rect.height) return False
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 on_draw(self, view, ctx): window = view.get_window(Gtk.TextWindowType.TEXT) if not Gtk.cairo_should_draw_window(ctx, window): return False # Draw something ctx.set_line_width(1.0) Gtk.cairo_transform_to_window(ctx, view, window) clipped, clip = Gdk.cairo_get_clip_rectangle(ctx) if not clipped: return False for placeholder in self.ordered_placeholders: if not self.placeholder_in_area(placeholder, clip): continue ctx.save() self.draw_placeholder(ctx, placeholder) ctx.restore() return False
def redraw_rect(self, widget, cairo_ctx): result, r = Gdk.cairo_get_clip_rectangle(cairo_ctx) if result: x, y, w, h = r.x, r.y, r.width, r.height else: print("Skipping drawing because entire context clipped") return try: buf = self.image.image_buffer(x,y) except MemoryError as err: # suppress these errors return pixbuf = GdkPixbuf.Pixbuf.new_from_bytes( GLib.Bytes(buf), GdkPixbuf.Colorspace.RGB, False, 8, min(self.width-x,w), min(self.height-y,h), self.width*3) Gdk.cairo_set_source_pixbuf(cairo_ctx, pixbuf.copy(), x, y) cairo_ctx.paint() if self.selection_rect: cairo_ctx.set_source_rgb(1.0, 1.0, 1.0) cairo_ctx.set_line_width(T.SELECTION_LINE_WIDTH) cairo_ctx.rectangle(*self.selection_rect) cairo_ctx.stroke()
def redraw_rect(self, widget, cairo_ctx): result, r = Gdk.cairo_get_clip_rectangle(cairo_ctx) if result: x, y, w, h = r.x, r.y, r.width, r.height else: print("Skipping drawing because entire context clipped") return try: buf = self.image.image_buffer(x, y) except MemoryError as err: # suppress these errors return pixbuf = GdkPixbuf.Pixbuf.new_from_bytes( GLib.Bytes(buf), GdkPixbuf.Colorspace.RGB, False, 8, min(self.width - x, w), min(self.height - y, h), self.width * 3) Gdk.cairo_set_source_pixbuf(cairo_ctx, pixbuf.copy(), x, y) cairo_ctx.paint() if self.selection_rect: cairo_ctx.set_source_rgb(1.0, 1.0, 1.0) cairo_ctx.set_line_width(T.SELECTION_LINE_WIDTH) cairo_ctx.rectangle(*self.selection_rect) cairo_ctx.stroke()
def __on_draw(self, widget, cr): style = widget.get_style() x, rect = Gdk.cairo_get_clip_rectangle(cr) Gtk.paint_flat_box(style, cr, Gtk.StateType.NORMAL, Gtk.ShadowType.OUT, widget, "tooltip", rect.x, rect.y, rect.width, rect.height) return False
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 on_draw(self, widget, context): """Draw callback for the drawing area.""" self.update_buffer() ok, r = Gdk.cairo_get_clip_rectangle(context) if not ok: L.error('Failed getting clip rectangle in ZoomableArea.draw') return False self.repaint(context, r.x, r.y, r.width, r.height) self._update_scrollbars() return True
def do_draw(self, context): clipped_rect = Gdk.cairo_get_clip_rectangle(context)[1] if self.__last_rectangle.x != clipped_rect.x or \ self.__last_rectangle.y != clipped_rect.y or \ self.__last_rectangle.width != clipped_rect.width or \ self.__last_rectangle.height != clipped_rect.height: if self._addVisibleThumbnails(clipped_rect): self.__last_rectangle = clipped_rect else: self.__last_rectangle = Gdk.Rectangle() Gtk.Layout.do_draw(self, context)
def redraw_rect(self, widget, cairo_ctx): # draw the color preview bar result, r = Gdk.cairo_get_clip_rectangle(cairo_ctx) wwidth = widget.get_allocated_width() colorband_height = widget.get_allocated_height() - self.grad_handle_height style_ctx = widget.get_style_context() normal_background_color = style_ctx.get_property( "background-color", Gtk.StateFlags.NORMAL) grad = self.f.get_gradient() cairo_ctx.set_line_width(2.0) for i in range(r.x, r.x + r.width): pos_in_gradient = i / wwidth col = grad.get_color_at(pos_in_gradient) cairo_ctx.set_source_rgba(col[0], col[1], col[2]) cairo_ctx.move_to(i, r.y) cairo_ctx.line_to(i, min(r.y + r.height, colorband_height)) cairo_ctx.stroke() # draw the handles cairo_ctx.set_source_rgba(*normal_background_color) cairo_ctx.rectangle( r.x, colorband_height, r.width, self.grad_handle_height) cairo_ctx.fill() for i in range(len(grad.segments)): seg = grad.segments[i] left = seg.left * wwidth mid = seg.mid * wwidth right = seg.right * wwidth if i == self.selected_segment: # draw this chunk selected cairo_ctx.set_line_width(2.0) cairo_ctx.set_source_rgb(0, 1.0, 1.0) cairo_ctx.rectangle( left, colorband_height, right - left, self.grad_handle_height) cairo_ctx.fill() self.draw_handle(widget, cairo_ctx, left, True) self.draw_handle(widget, cairo_ctx, mid, False) # draw last handle on the right self.draw_handle(widget, cairo_ctx, wwidth, True)
def do_draw(self, context): res, rect = Gdk.cairo_get_clip_rectangle(context) assert res if self.__last_rectangle.x != rect.x or \ self.__last_rectangle.y != rect.y or \ self.__last_rectangle.width != rect.width or \ self.__last_rectangle.height != rect.height: if self._addVisibleThumbnails(rect): self.__last_rectangle = rect else: self.__last_rectangle = Gdk.Rectangle() Gtk.Layout.do_draw(self, context)
def _expose(self, widget, event): if not self.driver.is_connected(): return _, clip = Gdk.cairo_get_clip_rectangle(event) cr = widget.get_window().cairo_create() cr.rectangle(clip.x, clip.y, clip.width, clip.height) cr.clip() # Paint if self.buffer: cr.set_source_surface(self.buffer) cr.paint()
def draw_cb(self, darea, context): rect = Gdk.cairo_get_clip_rectangle(context) clipped_rect = rect[1] width = int(darea.get_allocation().width) height = int(darea.get_allocation().height) playhead_index = int(self.position * self.__nb_peaks) self.__surface = renderer.fill_surface(self.__peaks[:], width, height, self.__max_peak, playhead_index) context.set_operator(cairo.OPERATOR_OVER) context.set_source_surface(self.__surface, 0, 0) context.paint() context.set_source_rgb(1.0, 1.0, 1.0) context.set_line_width(0.5) for marker in self.__markers: x = marker * width context.move_to(x, 0) context.line_to(x, height) context.stroke() context.set_source_rgb(1.0, 0.0, 0.0) context.set_line_width(0.5) x = self.position * width context.move_to(x, 0) context.line_to(x, height) context.stroke() if self.selected_section is not None: context.set_source_rgba(0.0, 0.0, 1.0, 0.5) x1 = int(self.selected_section[0] * width) x2 = int(self.selected_section[1] * width) for x in range(x1, x2): context.move_to(x, 0) context.line_to(x, height) context.stroke()
def redraw_rect(self, widget, cairo_ctx): # draw the color preview bar result, r = Gdk.cairo_get_clip_rectangle(cairo_ctx) wwidth = widget.get_allocated_width() colorband_height = widget.get_allocated_height() - self.grad_handle_height style_ctx = widget.get_style_context() normal_background_color = style_ctx.get_property("background-color", Gtk.StateFlags.NORMAL) grad = self.f.get_gradient() cairo_ctx.set_line_width(2.0) for i in range(r.x, r.x + r.width): pos_in_gradient = i / wwidth col = grad.get_color_at(pos_in_gradient) cairo_ctx.set_source_rgba(col[0], col[1], col[2]) cairo_ctx.move_to(i, r.y) cairo_ctx.line_to(i, min(r.y + r.height, colorband_height)) cairo_ctx.stroke() # draw the handles cairo_ctx.set_source_rgba(*normal_background_color) cairo_ctx.rectangle(r.x, colorband_height, r.width, self.grad_handle_height) cairo_ctx.fill() for i in range(len(grad.segments)): seg = grad.segments[i] left = seg.left * wwidth mid = seg.mid * wwidth right = seg.right * wwidth if i == self.selected_segment: # draw this chunk selected cairo_ctx.set_line_width(2.0) cairo_ctx.set_source_rgb(0, 1.0, 1.0) cairo_ctx.rectangle(left, colorband_height, right - left, self.grad_handle_height) cairo_ctx.fill() self.draw_handle(widget, cairo_ctx, left, True) self.draw_handle(widget, cairo_ctx, mid, False) # draw last handle on the right self.draw_handle(widget, cairo_ctx, wwidth, True)
def do_draw_layer(self, layer, context): if layer != Gtk.TextViewLayer.BELOW_TEXT: return GtkSource.Map.do_draw_layer(self, layer, context) # Handle bad view assignments and partial initialisation parent_view = self.props.view if not hasattr(parent_view, 'chunk_iter'): return GtkSource.Map.do_draw_layer(self, layer, context) context.save() context.set_line_width(1.0) _, clip = Gdk.cairo_get_clip_rectangle(context) x = clip.x - 0.5 width = clip.width + 1 bounds = ( self.get_line_num_for_y(clip.y), self.get_line_num_for_y(clip.y + clip.height), ) # Paint chunk backgrounds for change in parent_view.chunk_iter(bounds): if change[1] == change[2]: # We don't have room to paint inserts in this widget continue ypos0 = self.get_y_for_line_num(change[1]) ypos1 = self.get_y_for_line_num(change[2]) height = max(0, ypos1 - ypos0 - 1) context.rectangle(x, ypos0 + 0.5, width, height) context.set_source_rgba(*parent_view.fill_colors[change[0]]) context.fill() context.restore() return GtkSource.Map.do_draw_layer(self, layer, context)
def do_draw_layer(self, layer, context): if layer != Gtk.TextViewLayer.BELOW_TEXT: return GtkSource.Map.do_draw_layer(self, layer, context) # Handle bad view assignments and partial initialisation parent_view = self.props.view if not hasattr(parent_view, 'chunk_iter'): return GtkSource.Map.do_draw_layer(self, layer, context) context.save() context.set_line_width(1.0) _, clip = Gdk.cairo_get_clip_rectangle(context) x = clip.x - 0.5 width = clip.width + 1 bounds = ( self.get_line_num_for_y(clip.y), self.get_line_num_for_y(clip.y + clip.height), ) # Paint chunk backgrounds for change in parent_view.chunk_iter(bounds): if change[1] == change[2]: # We don't have room to paint inserts in this widget continue ypos0 = self.get_y_for_line_num(change[1]) ypos1 = self.get_y_for_line_num(change[2]) height = max(0, ypos1 - ypos0 - 1) context.rectangle(x, ypos0 + 0.5, width, height) context.set_source_rgba(*parent_view.fill_colors[change[0]]) context.fill() context.restore() return GtkSource.Map.do_draw_layer(self, layer, context)
def do_draw_layer(self, layer, context): if layer != Gtk.TextViewLayer.BELOW_TEXT: return GtkSource.View.do_draw_layer(self, layer, context) context.save() context.set_line_width(1.0) _, clip = Gdk.cairo_get_clip_rectangle(context) clip_end = clip.y + clip.height bounds = ( self.get_line_num_for_y(clip.y), self.get_line_num_for_y(clip_end), ) x = clip.x - 0.5 width = clip.width + 1 # Paint chunk backgrounds and outlines for change in self.chunk_iter(bounds): ypos0 = self.get_y_for_line_num(change[1]) ypos1 = self.get_y_for_line_num(change[2]) height = max(0, ypos1 - ypos0 - 1) context.rectangle(x, ypos0 + 0.5, width, height) if change[1] != change[2]: context.set_source_rgba(*self.fill_colors[change[0]]) context.fill_preserve() if self.current_chunk_check(change): highlight = self.fill_colors['current-chunk-highlight'] context.set_source_rgba(*highlight) context.fill_preserve() context.set_source_rgba(*self.line_colors[change[0]]) context.stroke() textbuffer = self.get_buffer() # Check whether we're drawing past the last line in the buffer # (i.e., the overscroll) and draw a custom background if so. end_y, end_height = self.get_line_yrange(textbuffer.get_end_iter()) end_y += end_height visible_bottom_margin = clip_end - end_y if visible_bottom_margin > 0: context.rectangle(x + 1, end_y, width - 1, visible_bottom_margin) context.set_source_rgba(*self.fill_colors['overscroll']) context.fill() # Paint current line highlight if self.props.highlight_current_line_local and self.is_focus(): it = textbuffer.get_iter_at_mark(textbuffer.get_insert()) ypos, line_height = self.get_line_yrange(it) context.rectangle(x, ypos, width, line_height) context.set_source_rgba(*self.highlight_color) context.fill() # Draw syncpoint indicator lines for syncpoint in self.syncpoints: if syncpoint is None: continue syncline = textbuffer.get_iter_at_mark(syncpoint).get_line() if bounds[0] <= syncline <= bounds[1]: ypos = self.get_y_for_line_num(syncline) context.rectangle(x, ypos - 0.5, width, 1) context.set_source_rgba(*self.syncpoint_color) context.stroke() # Overdraw all animated chunks, and update animation states new_anim_chunks = [] for c in self.animating_chunks: current_time = GLib.get_monotonic_time() percent = min(1.0, (current_time - c.start_time) / float(c.duration)) rgba_pairs = zip(c.start_rgba, c.end_rgba) rgba = [s + (e - s) * percent for s, e in rgba_pairs] it = textbuffer.get_iter_at_mark(c.start_mark) ystart, _ = self.get_line_yrange(it) it = textbuffer.get_iter_at_mark(c.end_mark) yend, _ = self.get_line_yrange(it) if ystart == yend: ystart -= 1 context.set_source_rgba(*rgba) context.rectangle(x, ystart, width, yend - ystart) if c.anim_type == TextviewLineAnimationType.stroke: context.stroke() else: context.fill() if current_time <= c.start_time + c.duration: new_anim_chunks.append(c) else: textbuffer.delete_mark(c.start_mark) textbuffer.delete_mark(c.end_mark) self.animating_chunks = new_anim_chunks if self.animating_chunks and self.anim_source_id is None: def anim_cb(): self.queue_draw() return True # Using timeout_add interferes with recalculation of inline # highlighting; this mechanism could be improved. self.anim_source_id = GLib.idle_add(anim_cb) elif not self.animating_chunks and self.anim_source_id: GLib.source_remove(self.anim_source_id) self.anim_source_id = None context.restore() return GtkSource.View.do_draw_layer(self, layer, context)
def _handle_draw(self, cr): should_draw, rectangle = Gdk.cairo_get_clip_rectangle(cr) if should_draw: self._draw(cr, rectangle.width, rectangle.height)
def do_draw_layer(self, layer, context): if layer != Gtk.TextViewLayer.BELOW: return GtkSource.View.do_draw_layer(self, layer, context) context.save() context.set_line_width(1.0) _, clip = Gdk.cairo_get_clip_rectangle(context) _, buffer_y = self.window_to_buffer_coords(Gtk.TextWindowType.WIDGET, 0, clip.y) _, buffer_y_end = self.window_to_buffer_coords( Gtk.TextWindowType.WIDGET, 0, clip.y + clip.height) bounds = (self.get_line_num_for_y(buffer_y), self.get_line_num_for_y(buffer_y_end)) visible = self.get_visible_rect() x = clip.x - 0.5 width = clip.width + 1 # Paint chunk backgrounds and outlines for change in self.chunk_iter(bounds): ypos0 = self.get_y_for_line_num(change[1]) - visible.y ypos1 = self.get_y_for_line_num(change[2]) - visible.y height = max(0, ypos1 - ypos0 - 1) context.rectangle(x, ypos0 + 0.5, width, height) if change[1] != change[2]: context.set_source_rgba(*self.fill_colors[change[0]]) context.fill_preserve() if self.current_chunk_check(change): highlight = self.fill_colors['current-chunk-highlight'] context.set_source_rgba(*highlight) context.fill_preserve() context.set_source_rgba(*self.line_colors[change[0]]) context.stroke() textbuffer = self.get_buffer() # Paint current line highlight if self.props.highlight_current_line_local and self.is_focus(): it = textbuffer.get_iter_at_mark(textbuffer.get_insert()) ypos, line_height = self.get_line_yrange(it) context.save() context.rectangle(x, ypos - visible.y, width, line_height) context.clip() context.set_source_rgba(*self.highlight_color) context.paint_with_alpha(0.25) context.restore() # Draw syncpoint indicator lines for syncpoint in self.syncpoints: if syncpoint is None: continue syncline = textbuffer.get_iter_at_mark(syncpoint).get_line() if bounds[0] <= syncline <= bounds[1]: ypos = self.get_y_for_line_num(syncline) - visible.y context.rectangle(x, ypos - 0.5, width, 1) context.set_source_rgba(*self.syncpoint_color) context.stroke() # Overdraw all animated chunks, and update animation states new_anim_chunks = [] for c in self.animating_chunks: current_time = GLib.get_monotonic_time() percent = min(1.0, (current_time - c.start_time) / float(c.duration)) rgba_pairs = zip(c.start_rgba, c.end_rgba) rgba = [s + (e - s) * percent for s, e in rgba_pairs] it = textbuffer.get_iter_at_mark(c.start_mark) ystart, _ = self.get_line_yrange(it) it = textbuffer.get_iter_at_mark(c.end_mark) yend, _ = self.get_line_yrange(it) if ystart == yend: ystart -= 1 context.set_source_rgba(*rgba) context.rectangle(x, ystart - visible.y, width, yend - ystart) context.fill() if current_time <= c.start_time + c.duration: new_anim_chunks.append(c) else: textbuffer.delete_mark(c.start_mark) textbuffer.delete_mark(c.end_mark) self.animating_chunks = new_anim_chunks if self.animating_chunks and self.anim_source_id is None: def anim_cb(): self.queue_draw() return True # Using timeout_add interferes with recalculation of inline # highlighting; this mechanism could be improved. self.anim_source_id = GLib.idle_add(anim_cb) elif not self.animating_chunks and self.anim_source_id: GLib.source_remove(self.anim_source_id) self.anim_source_id = None context.restore() return GtkSource.View.do_draw_layer(self, layer, context)
def do_draw_layer(self, layer, context): if layer != Gtk.TextViewLayer.BELOW: return GtkSource.View.do_draw_layer(self, layer, context) context.save() context.set_line_width(1.0) _, clip = Gdk.cairo_get_clip_rectangle(context) _, buffer_y = self.window_to_buffer_coords( Gtk.TextWindowType.WIDGET, 0, clip.y) _, buffer_y_end = self.window_to_buffer_coords( Gtk.TextWindowType.WIDGET, 0, clip.y + clip.height) bounds = (self.get_line_num_for_y(buffer_y), self.get_line_num_for_y(buffer_y_end)) visible = self.get_visible_rect() x = clip.x - 0.5 width = clip.width + 1 # Paint chunk backgrounds and outlines for change in self.chunk_iter(bounds): ypos0 = self.get_y_for_line_num(change[1]) - visible.y ypos1 = self.get_y_for_line_num(change[2]) - visible.y height = max(0, ypos1 - ypos0 - 1) context.rectangle(x, ypos0 + 0.5, width, height) if change[1] != change[2]: context.set_source_rgba(*self.fill_colors[change[0]]) context.fill_preserve() if self.current_chunk_check(change): highlight = self.fill_colors['current-chunk-highlight'] context.set_source_rgba(*highlight) context.fill_preserve() context.set_source_rgba(*self.line_colors[change[0]]) context.stroke() textbuffer = self.get_buffer() # Paint current line highlight if self.props.highlight_current_line_local and self.is_focus(): it = textbuffer.get_iter_at_mark(textbuffer.get_insert()) ypos, line_height = self.get_line_yrange(it) context.save() context.rectangle(x, ypos - visible.y, width, line_height) context.clip() context.set_source_rgba(*self.highlight_color) context.paint_with_alpha(0.25) context.restore() # Draw syncpoint indicator lines for syncpoint in self.syncpoints: if syncpoint is None: continue syncline = textbuffer.get_iter_at_mark(syncpoint).get_line() if bounds[0] <= syncline <= bounds[1]: ypos = self.get_y_for_line_num(syncline) - visible.y context.rectangle(x, ypos - 0.5, width, 1) context.set_source_rgba(*self.syncpoint_color) context.stroke() # Overdraw all animated chunks, and update animation states new_anim_chunks = [] for c in self.animating_chunks: current_time = GLib.get_monotonic_time() percent = min( 1.0, (current_time - c.start_time) / float(c.duration)) rgba_pairs = zip(c.start_rgba, c.end_rgba) rgba = [s + (e - s) * percent for s, e in rgba_pairs] it = textbuffer.get_iter_at_mark(c.start_mark) ystart, _ = self.get_line_yrange(it) it = textbuffer.get_iter_at_mark(c.end_mark) yend, _ = self.get_line_yrange(it) if ystart == yend: ystart -= 1 context.set_source_rgba(*rgba) context.rectangle(x, ystart - visible.y, width, yend - ystart) context.fill() if current_time <= c.start_time + c.duration: new_anim_chunks.append(c) else: textbuffer.delete_mark(c.start_mark) textbuffer.delete_mark(c.end_mark) self.animating_chunks = new_anim_chunks if self.animating_chunks and self.anim_source_id is None: def anim_cb(): self.queue_draw() return True # Using timeout_add interferes with recalculation of inline # highlighting; this mechanism could be improved. self.anim_source_id = GLib.idle_add(anim_cb) elif not self.animating_chunks and self.anim_source_id: GLib.source_remove(self.anim_source_id) self.anim_source_id = None context.restore() return GtkSource.View.do_draw_layer(self, layer, context)
def _handle_draw(self, cr): should_draw, rectangle = Gdk.cairo_get_clip_rectangle(cr) if should_draw: self._draw(cr, rectangle.width, rectangle.height)
def do_draw(self, w, cr): (todo, rect) = Gdk.cairo_get_clip_rectangle(cr) if not todo: return self.port.cr = cr self.painter.paint(self.port, rect.x, rect.y, rect.width, rect.height)