def do_draw(self, context, background_area, cell_area, start, end, state): GtkSource.GutterRendererPixbuf.do_draw(self, context, background_area, cell_area, start, end, state) if self.is_action: if Gtk.get_minor_version() < 20: style_context = get_style(None, "GtkButton.flat.image-button") style_context.add_class(Gtk.STYLE_CLASS_BUTTON) style_context.add_class(Gtk.STYLE_CLASS_FLAT) else: # TODO: Fix padding and min-height in CSS and use # draw_style_common style_context = get_style(None, "button.flat.image-button") style_context.set_state(renderer_to_gtk_state(state)) x = background_area.x + 1 y = background_area.y + 1 width = background_area.width - 2 height = background_area.height - 2 Gtk.render_background(style_context, context, x, y, width, height) Gtk.render_frame(style_context, context, x, y, width, height) pixbuf = self.props.pixbuf pix_width, pix_height = pixbuf.props.width, pixbuf.props.height Gtk.render_icon(style_context, context, pixbuf, x + (width - pix_width) // 2, y + (height - pix_height) // 2) self.draw_chunks(context, background_area, cell_area, start, end, state)
def do_draw(self, context, background_area, cell_area, start, end, state): GtkSource.GutterRendererPixbuf.do_draw( self, context, background_area, cell_area, start, end, state) if self.is_action: if Gtk.get_minor_version() < 20: style_context = get_style(None, "GtkButton.flat.image-button") style_context.add_class(Gtk.STYLE_CLASS_BUTTON) style_context.add_class(Gtk.STYLE_CLASS_FLAT) else: # TODO: Fix padding and min-height in CSS and use # draw_style_common style_context = get_style(None, "button.flat.image-button") style_context.set_state(renderer_to_gtk_state(state)) x = background_area.x + 1 y = background_area.y + 1 width = background_area.width - 2 height = background_area.height - 2 Gtk.render_background(style_context, context, x, y, width, height) Gtk.render_frame(style_context, context, x, y, width, height) pixbuf = self.props.pixbuf pix_width, pix_height = pixbuf.props.width, pixbuf.props.height Gtk.render_icon( style_context, context, pixbuf, x + (width - pix_width) // 2, y + (height - pix_height) // 2) self.draw_chunks( context, background_area, cell_area, start, end, state)
def do_draw(self, context, background_area, cell_area, start, end, state): GtkSource.GutterRendererPixbuf.do_draw(self, context, background_area, cell_area, start, end, state) if self.is_action: if Gtk.get_minor_version() < 20: style_context = get_style(None, "GtkButton.flat.image-button") style_context.add_class(Gtk.STYLE_CLASS_BUTTON) style_context.add_class(Gtk.STYLE_CLASS_FLAT) else: # TODO: Fix padding and min-height in CSS and use # draw_style_common style_context = get_style(None, "button.flat.image-button") style_context.set_state(renderer_to_gtk_state(state)) x = background_area.x + 1 y = background_area.y + 1 width = background_area.width - 2 height = background_area.height - 2 Gtk.render_background(style_context, context, x, y, width, height) Gtk.render_frame(style_context, context, x, y, width, height) pixbuf = self.props.pixbuf pix_width, pix_height = pixbuf.props.width, pixbuf.props.height xalign, yalign = self.get_alignment() align_mode = self.get_alignment_mode() if align_mode == GtkSource.GutterRendererAlignmentMode.CELL: icon_x = x + (width - pix_width) // 2 icon_y = y + (height - pix_height) // 2 else: line_iter = start if align_mode == ALIGN_MODE_FIRST else end textview = self.get_view() loc = textview.get_iter_location(line_iter) line_x, line_y = textview.buffer_to_window_coords( self.get_window_type(), loc.x, loc.y) icon_x = cell_area.x + (cell_area.width - pix_width) * xalign icon_y = line_y + (loc.height - pix_height) * yalign Gtk.render_icon(style_context, context, pixbuf, icon_x, icon_y) self.draw_chunks(context, background_area, cell_area, start, end, state)
def do_draw(self, context, background_area, cell_area, start, end, state): GtkSource.GutterRendererPixbuf.do_draw( self, context, background_area, cell_area, start, end, state) if self.is_action: # TODO: Fix padding and min-height in CSS and use # draw_style_common style_context = get_style(None, "button.flat.image-button") style_context.set_state(renderer_to_gtk_state(state)) x = background_area.x + 1 y = background_area.y + 1 width = background_area.width - 2 height = background_area.height - 2 Gtk.render_background(style_context, context, x, y, width, height) Gtk.render_frame(style_context, context, x, y, width, height) pixbuf = self.props.pixbuf pix_width, pix_height = pixbuf.props.width, pixbuf.props.height xalign, yalign = self.get_alignment() align_mode = self.get_alignment_mode() if align_mode == GtkSource.GutterRendererAlignmentMode.CELL: icon_x = x + (width - pix_width) // 2 icon_y = y + (height - pix_height) // 2 else: line_iter = start if align_mode == ALIGN_MODE_FIRST else end textview = self.get_view() loc = textview.get_iter_location(line_iter) line_x, line_y = textview.buffer_to_window_coords( self.get_window_type(), loc.x, loc.y) icon_x = cell_area.x + (cell_area.width - pix_width) * xalign icon_y = line_y + (loc.height - pix_height) * yalign Gtk.render_icon(style_context, context, pixbuf, icon_x, icon_y) self.draw_chunks( context, background_area, cell_area, start, end, state)
def do_draw(self, context): view = self.source_view if not view or not view.get_realized(): return self.buttons = [] width = self.get_allocated_width() height = self.get_allocated_height() style_context = self.get_style_context() Gtk.render_background(style_context, context, 0, 0, width, height) buf = view.get_buffer() context.save() context.set_line_width(1.0) # Get our linked view's visible offset, get our vertical offset # against our view (e.g., for info bars at the top of the view) # and translate our context to match. view_y_start = view.get_visible_rect().y view_y_offset = view.translate_coordinates(self, 0, 0)[1] gutter_y_translate = view_y_offset - view_y_start context.translate(0, gutter_y_translate) button_x = 1 button_width = width - 2 for chunk in self.get_chunk_range(view_y_start, view_y_start + height): change_type, start_line, end_line, *_unused = chunk rect_y = view.get_y_for_line_num(start_line) rect_height = max( 0, view.get_y_for_line_num(end_line) - rect_y - 1) # Draw our rectangle outside x bounds, so we don't get # vertical lines. Fill first, over-fill with a highlight # if in the focused chunk, and then stroke the border. context.rectangle(-0.5, rect_y + 0.5, width + 1, rect_height) if start_line != end_line: context.set_source_rgba(*self.fill_colors[change_type]) context.fill_preserve() if view.current_chunk_check(chunk): highlight = self.fill_colors['current-chunk-highlight'] context.set_source_rgba(*highlight) context.fill_preserve() context.set_source_rgba(*self.line_colors[change_type]) context.stroke() # Button rendering and tracking action = self._classify_change_actions(chunk) if action is None: continue it = buf.get_iter_at_line(start_line) button_y, button_height = view.get_line_yrange(it) button_y += 1 button_height -= 2 button_style_context = get_style(None, 'button.flat.image-button') if chunk == self.pointer_chunk: button_style_context.set_state(Gtk.StateFlags.PRELIGHT) Gtk.render_background( button_style_context, context, button_x, button_y, button_width, button_height) Gtk.render_frame( button_style_context, context, button_x, button_y, button_width, button_height) # TODO: Ideally we'd do this in a pre-render step of some # kind, but I'm having trouble figuring out what that would # look like. self.buttons.append( ( button_x, button_y + gutter_y_translate, button_x + button_width, button_y + gutter_y_translate + button_height, chunk, ) ) pixbuf = self.action_map.get(action) icon_x = button_x + (button_width - pixbuf.props.width) // 2 icon_y = button_y + (button_height - pixbuf.props.height) // 2 Gtk.render_icon( button_style_context, context, pixbuf, icon_x, icon_y) context.restore()
def do_draw(self, context): view = self.source_view if not view or not view.get_realized(): return self.buttons = [] width = self.get_allocated_width() height = self.get_allocated_height() style_context = self.get_style_context() Gtk.render_background(style_context, context, 0, 0, width, height) buf = view.get_buffer() context.save() context.set_line_width(1.0) # Get our linked view's visible offset, get our vertical offset # against our view (e.g., for info bars at the top of the view) # and translate our context to match. view_y_start = view.get_visible_rect().y view_y_offset = view.translate_coordinates(self, 0, 0)[1] gutter_y_translate = view_y_offset - view_y_start context.translate(0, gutter_y_translate) button_x = 1 button_width = width - 2 for chunk in self.get_chunk_range(view_y_start, view_y_start + height): change_type, start_line, end_line, *_unused = chunk rect_y = view.get_y_for_line_num(start_line) rect_height = max( 0, view.get_y_for_line_num(end_line) - rect_y - 1) # Draw our rectangle outside x bounds, so we don't get # vertical lines. Fill first, over-fill with a highlight # if in the focused chunk, and then stroke the border. context.rectangle(-0.5, rect_y + 0.5, width + 1, rect_height) if start_line != end_line: context.set_source_rgba(*self.fill_colors[change_type]) context.fill_preserve() if view.current_chunk_check(chunk): highlight = self.fill_colors['current-chunk-highlight'] context.set_source_rgba(*highlight) context.fill_preserve() context.set_source_rgba(*self.line_colors[change_type]) context.stroke() # Button rendering and tracking action = self._classify_change_actions(chunk) if action is None: continue it = buf.get_iter_at_line(start_line) button_y, button_height = view.get_line_yrange(it) button_y += 1 button_height -= 2 button_style_context = get_style(None, 'button.flat.image-button') if chunk == self.pointer_chunk: button_style_context.set_state(Gtk.StateFlags.PRELIGHT) Gtk.render_background( button_style_context, context, button_x, button_y, button_width, button_height) Gtk.render_frame( button_style_context, context, button_x, button_y, button_width, button_height) # TODO: Ideally we'd do this in a pre-render step of some # kind, but I'm having trouble figuring out what that would # look like. self.buttons.append( ( button_x, button_y + gutter_y_translate, button_x + button_width, button_y + gutter_y_translate + button_height, chunk, ) ) pixbuf = self.action_map.get(action) icon_x = button_x + (button_width - pixbuf.props.width) // 2 icon_y = button_y + (button_height - pixbuf.props.height) // 2 Gtk.render_icon( button_style_context, context, pixbuf, icon_x, icon_y) context.restore()