def on_view_draw(self, view, cr): window = view.get_window(Gtk.TextWindowType.TEXT) if Gtk.cairo_should_draw_window (cr, window): return self._draw_column_mode(cr) window = view.get_window(Gtk.TextWindowType.TOP) if window is None or not Gtk.cairo_should_draw_window (cr, window): return False if not self._in_mode: return False layout = view.create_pango_layout(_('Multi Edit Mode')) extents = layout.get_pixel_extents() w = window.get_width() h = window.get_height() Gtk.cairo_transform_to_window(cr, view, window) cr.translate(0.5, 0.5) cr.set_line_width(1) col = self.get_border_color() Gdk.cairo_set_source_rgba(cr, col) cr.move_to(0, h - 1) cr.rel_line_to(w, 0) cr.stroke() context = self._view.get_style_context() Gdk.cairo_set_source_rgba(cr, context.get_color(Gtk.StateFlags.NORMAL)) cr.move_to(w - extents[1].width - 3, (h - extents[1].height) / 2) PangoCairo.show_layout(cr, layout) if not self._status: status = '' else: status = str(self._status) if status: layout.set_markup(status, -1) cr.move_to(3, (h - extents[1].height) / 2) PangoCairo.show_layout(cr, layout) return False
def on_view_draw(self, view, cr): window = view.get_window(Gtk.TextWindowType.TEXT) if Gtk.cairo_should_draw_window(cr, window): return self._draw_column_mode(cr) window = view.get_window(Gtk.TextWindowType.TOP) if window is None or not Gtk.cairo_should_draw_window(cr, window): return False if not self._in_mode: return False layout = view.create_pango_layout(_('Multi Edit Mode')) extents = layout.get_pixel_extents() w = window.get_width() h = window.get_height() Gtk.cairo_transform_to_window(cr, view, window) cr.translate(0.5, 0.5) cr.set_line_width(1) col = self.get_border_color() Gdk.cairo_set_source_rgba(cr, col) cr.move_to(0, h - 1) cr.rel_line_to(w, 0) cr.stroke() context = self._view.get_style_context() Gdk.cairo_set_source_rgba(cr, context.get_color(Gtk.StateFlags.NORMAL)) cr.move_to(w - extents[1].width - 3, (h - extents[1].height) / 2) PangoCairo.show_layout(cr, layout) if not self._status: status = '' else: status = str(self._status) if status: layout.set_markup(status, -1) cr.move_to(3, (h - extents[1].height) / 2) PangoCairo.show_layout(cr, layout) return False
def draw(self, cairocontext): alloc = self._widget.get_allocation() padding = 5 x = self._area_x - alloc.x + padding y = self._area_y - alloc.y + padding width = max(0, self._area_width - 2 * padding) height = max(0, self._area_height - 2 * padding) if width == 0 or height == 0: return stylecontext = self._widget.get_style_context() state = stylecontext.get_state() if self._widget.is_focus(): state |= Gtk.StateFlags.SELECTED if self._prelit: state |= Gtk.StateFlags.PRELIGHT if Gtk.cairo_should_draw_window(cairocontext, self._window): stylecontext.save() stylecontext.set_state(state) stylecontext.add_class(Gtk.STYLE_CLASS_PANE_SEPARATOR) color = stylecontext.get_background_color(state) if color.alpha > 0.0: Gtk.render_handle(stylecontext, cairocontext, x, y, width, height) else: xcenter = x + width / 2.0 Gtk.render_line(stylecontext, cairocontext, xcenter, y, xcenter, y + height) stylecontext.restore()
def on_view_draw(self, view, cr): window = view.get_window(Gtk.TextWindowType.TEXT) if not window is None and Gtk.cairo_should_draw_window(cr, window): self._draw_column_mode(cr) return False
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 draw(self, cairocontext): alloc = self._widget.get_allocation() padding = 5 x = self._area_x - alloc.x + padding y = self._area_y - alloc.y + padding width = max(0, self._area_width - 2 * padding) height = max(0, self._area_height - 2 * padding) if width == 0 or height == 0: return stylecontext = self._widget.get_style_context() state = self._widget.get_state_flags() if self._widget.is_focus(): state |= Gtk.StateFlags.SELECTED if self._prelit: state |= Gtk.StateFlags.PRELIGHT if Gtk.cairo_should_draw_window(cairocontext, self._window): stylecontext.save() stylecontext.set_state(state) stylecontext.add_class(Gtk.STYLE_CLASS_PANE_SEPARATOR) color = stylecontext.get_background_color(state) if color.alpha > 0.0: Gtk.render_handle(stylecontext, cairocontext, x, y, width, height) else: xcenter = x + width / 2.0 Gtk.render_line(stylecontext, cairocontext, xcenter, y, xcenter, y + height) stylecontext.restore()
def _on_draw(self, widget, cr): """ Draw the onboard icon. """ if not Gtk.cairo_should_draw_window(cr, self.get_window()): return False rect = Rect(0.0, 0.0, float(self.get_allocated_width()), float(self.get_allocated_height())) color_scheme = self.get_color_scheme() # clear background cr.save() cr.set_operator(cairo.OPERATOR_CLEAR) cr.paint() cr.restore() # draw background color background_rgba = list(color_scheme.get_icon_rgba("background")) if Gdk.Screen.get_default().is_composited(): background_rgba[3] *= 0.75 cr.set_source_rgba(*background_rgba) corner_radius = min(rect.w, rect.h) * 0.1 roundrect_arc(cr, rect, corner_radius) cr.fill() # decoration frame line_rect = rect.deflate(2) cr.set_line_width(2) roundrect_arc(cr, line_rect, corner_radius) cr.stroke() else: cr.set_source_rgba(*background_rgba) cr.paint() # draw themed icon self._draw_themed_icon(cr, rect, color_scheme) # draw dwell progress rgba = [0.8, 0.0, 0.0, 0.5] bg_rgba = [0.1, 0.1, 0.1, 0.5] if color_scheme: key = RectKey( "icon0") # take dwell color from the first icon "key" rgba = color_scheme.get_key_rgba(key, "dwell-progress") rgba[3] = min(0.75, rgba[3]) # more transparency key = RectKey("icon1") bg_rgba = color_scheme.get_key_rgba(key, "fill") bg_rgba[3] = min(0.75, rgba[3]) # more transparency dwell_rect = rect.grow(0.5) self._dwell_progress.draw(cr, dwell_rect, rgba, bg_rgba) return True
def _on_draw(self, widget, context): #_logger.debug("Draw: clip_extents=" + str(context.clip_extents())) #self.get_window().set_debug_updates(True) if not Gtk.cairo_should_draw_window(context, self.get_window()): return clip_rect = Rect.from_extents(*context.clip_extents()) # draw background decorated = self.draw_background(context) # On first run quickly overwrite the background only. # This gives a slightly smoother startup with desktop remnants # flashing though for a shorter time. if self._first_draw: self._first_draw = False self.queue_draw() return if not self.layout: return # run through all visible layout items layer_ids = self.layout.get_layer_ids() for item in self.layout.iter_visible_items(): if item.layer_id: # draw layer background layer_index = layer_ids.index(item.layer_id) parent = item.parent if parent and \ layer_index != 0: rect = parent.get_canvas_rect() context.rectangle(*rect.inflate(1)) if self.color_scheme: rgba = self.color_scheme.get_layer_fill_rgba(layer_index) else: rgba = [0.5, 0.5, 0.5, 0.9] context.set_source_rgba(*rgba) context.fill() self.draw_dish_key_background(context, 1.0, item.layer_id) # draw key if item.is_key() and \ clip_rect.intersects(item.get_canvas_rect()): item.draw(context) item.draw_image(context) item.draw_label(context) # draw touch handles (enlarged move and resize handles) if self.touch_handles.active: corner_radius = config.CORNER_RADIUS if decorated else 0 self.touch_handles.set_corner_radius(corner_radius) self.touch_handles.draw(context)
def _on_draw(self, widget, cr): """ Draw the onboard icon. """ if not Gtk.cairo_should_draw_window(cr, self.get_window()): return False rect = Rect(0.0, 0.0, float(self.get_allocated_width()), float(self.get_allocated_height())) color_scheme = self.get_color_scheme() # clear background cr.save() cr.set_operator(cairo.OPERATOR_CLEAR) cr.paint() cr.restore() # draw background color background_rgba = list(color_scheme.get_icon_rgba("background")) if Gdk.Screen.get_default().is_composited(): background_rgba[3] *= 0.75 cr.set_source_rgba(*background_rgba) corner_radius = min(rect.w, rect.h) * 0.1 roundrect_arc(cr, rect, corner_radius) cr.fill() # decoration frame line_rect = rect.deflate(2) cr.set_line_width(2) roundrect_arc(cr, line_rect, corner_radius) cr.stroke() else: cr.set_source_rgba(*background_rgba) cr.paint() # draw themed icon self._draw_themed_icon(cr, rect, color_scheme) # draw dwell progress rgba = [0.8, 0.0, 0.0, 0.5] bg_rgba = [0.1, 0.1, 0.1, 0.5] if color_scheme: key = RectKey("icon0") # take dwell color from the first icon "key" rgba = color_scheme.get_key_rgba(key, "dwell-progress") rgba[3] = min(0.75, rgba[3]) # more transparency key = RectKey("icon1") bg_rgba = color_scheme.get_key_rgba(key, "fill") bg_rgba[3] = min(0.75, rgba[3]) # more transparency dwell_rect = rect.grow(0.5) self._dwell_progress.draw(cr, dwell_rect, rgba, bg_rgba) return True
def on_view_draw_after(self, view, cr): window = view.get_window(Gtk.TextWindowType.TOP) if window is None or not Gtk.cairo_should_draw_window(cr, window): return False if not self._in_mode: return False layout = view.create_pango_layout(_('Multi Edit Mode')) extents = layout.get_pixel_extents() w = window.get_width() h = window.get_height() Gtk.cairo_transform_to_window(cr, view, window) cr.save() cr.translate(0.5, 0.5) cr.set_line_width(1) col = self.get_border_color() Gdk.cairo_set_source_rgba(cr, col) cr.move_to(0, h - 1) cr.rel_line_to(w, 0) cr.stroke() cr.restore() ctx = self.view.get_style_context() ctx.save() ctx.add_class('top') cr.save() Gtk.render_layout(ctx, cr, w - extents[1].width - 3, (h - extents[1].height) / 2, layout) cr.restore() if not self._status: status = '' else: status = str(self._status) if status: layout.set_markup(status, -1) cr.save() Gtk.render_layout(ctx, cr, 3, (h - extents[1].height) / 2, layout) cr.restore() ctx.restore() return False
def _on_draw(self, widget, cr): """ Draw the onboard icon. """ if not Gtk.cairo_should_draw_window(cr, self.get_window()): return False rect = Rect(0.0, 0.0, float(self.get_allocated_width()), float(self.get_allocated_height())) color_scheme = self.get_color_scheme() # clear background cr.save() cr.set_operator(cairo.OPERATOR_CLEAR) cr.paint() cr.restore() # draw background color background_rgba = [0.0, 0.0, 0.7, 0.8] # list(color_scheme.get_icon_rgba("background")) if Gdk.Screen.get_default().is_composited(): background_rgba[3] *= 0.75 cr.set_source_rgba(*background_rgba) corner_radius = min(rect.w, rect.h) * 0.1 roundrect_arc(cr, rect, corner_radius) cr.fill() # decoration frame line_rect = rect.deflate(1) cr.set_line_width(2) roundrect_arc(cr, line_rect, corner_radius) cr.stroke() else: cr.set_source_rgba(*background_rgba) cr.paint() # draw themed icon # self._draw_themed_icon(cr, rect, color_scheme) # FIXME # draw dwell progress rgba = [0.8, 0.0, 0.0, 0.5] bg_rgba = [0.1, 0.1, 0.1, 0.5] if color_scheme: pass # FIXME dwell_rect = rect.grow(0.5) self._dwell_progress.draw(cr, dwell_rect, rgba, bg_rgba) return True
def draw(self, widget, context): if not Gtk.cairo_should_draw_window(context, widget.get_window()): return lod = self._lod draw_cached = self._can_draw_cached(lod) # lazily update font sizes and labels if not self._font_sizes_valid: self.update_labels(lod) draw_rect = self.get_damage_rect(context) # draw background decorated = self._draw_background(context, lod) layout = self.get_layout() if not layout: return # draw layer 0 and None-layer background layer_ids = layout.get_layer_ids() if config.window.transparent_background: alpha = 0.0 elif decorated: alpha = self.get_background_rgba()[3] else: alpha = 1.0 self._draw_layer_key_background(context, alpha, None, None, lod) if layer_ids: self._draw_layer_key_background(context, alpha, None, layer_ids[0], lod) # run through all visible layout items for item in layout.iter_visible_items(): if item.layer_id: self._draw_layer_background(context, item, layer_ids, decorated) # draw key if item.is_key() and \ draw_rect.intersects(item.get_canvas_border_rect()): if draw_cached: item.draw_cached(context) else: item.draw(context, lod) self._starting_up = False return decorated
def draw(self, widget, context): if not Gtk.cairo_should_draw_window(context, self.get_window()): return lod = self._lod draw_cached = self._can_draw_cached(lod) # lazily update font sizes and labels if not self._font_sizes_valid: self.update_labels(lod) draw_rect = self.get_damage_rect(context) # draw background decorated = self._draw_background(context, lod) layout = self.get_layout() if not layout: return # draw layer 0 and None-layer background layer_ids = layout.get_layer_ids() if config.window.transparent_background: alpha = 0.0 elif decorated: alpha = self.get_background_rgba()[3] else: alpha = 1.0 self._draw_layer_key_background(context, alpha, None, None, lod) if layer_ids: self._draw_layer_key_background(context, alpha, None, layer_ids[0], lod) # run through all visible layout items for item in layout.iter_visible_items(): if item.layer_id: self._draw_layer_background(context, item, layer_ids, decorated) # draw key if item.is_key() and \ draw_rect.intersects(item.get_canvas_border_rect()): if draw_cached: item.draw_cached(context) else: item.draw(context, lod) self._starting_up = False return decorated
def on_draw(self, widget, ct): win = widget.get_window(Gtk.TextWindowType.BOTTOM) if not Gtk.cairo_should_draw_window(ct, win): return False Gtk.cairo_transform_to_window(ct, widget, win) color = self.get_border_color() width = win.get_width() ct.set_source_rgba(color.red, color.green, color.blue, color.alpha) ct.move_to(0, 0) ct.line_to(width, 0) ct.stroke() return False
def _on_draw(self, widget, cr): """ Draw the onboard icon. """ if not Gtk.cairo_should_draw_window(cr, self.get_window()): return False width = float(self.get_allocated_width()) height = float(self.get_allocated_height()) # draw themed icon keys = [RectKey("icon" + str(i)) for i in range(4)] color_scheme = self.get_color_scheme() # Default colors for the case when none of the icon keys # are defined in the color scheme. background_rgba = [1.0, 1.0, 1.0, 1.0] fill_rgbas = [[0.9, 0.7, 0.0, 0.75], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [0.0, 0.54, 1.0, 1.0]] stroke_rgba = [0.0, 0.0, 0.0, 1.0] label_rgba = [0.0, 0.0, 0.0, 1.0] themed = False if color_scheme: if any(color_scheme.is_key_in_schema(key) for key in keys): themed = True # clear background cr.save() cr.set_operator(cairo.OPERATOR_CLEAR) cr.paint() cr.restore() # draw background color background_rgba = list(color_scheme.get_icon_rgba("background")) if Gdk.Screen.get_default().is_composited(): background_rgba[3] *= 0.75 cr.set_source_rgba(*background_rgba) rect = Rect(0, 0, width, height) corner_radius = min(width, height) * 0.1 roundrect_arc(cr, rect, corner_radius) cr.fill() # decoration frame line_rect = rect.deflate(2) cr.set_line_width(2) roundrect_arc(cr, line_rect, corner_radius) cr.stroke() else: cr.set_source_rgba(*background_rgba) cr.paint() # four rounded rectangles rects = Rect(0.0, 0.0, 100.0, 100.0).deflate(5) \ .subdivide(2, 2, 6) cr.save() cr.scale(width / 100., height / 100.0) cr.select_font_face ("sans-serif") cr.set_line_width(2) for i, key in enumerate(keys): rect = rects[i] if themed: fill_rgba = color_scheme.get_key_rgba(key, "fill") stroke_rgba = color_scheme.get_key_rgba(key, "stroke") label_rgba = color_scheme.get_key_rgba(key, "label") else: fill_rgba = fill_rgbas[i] roundrect_arc(cr, rect, 5) cr.set_source_rgba(*fill_rgba) cr.fill_preserve() cr.set_source_rgba(*stroke_rgba) cr.stroke() if i == 0 or i == 3: if i == 0: letter = "O" else: letter = "B" cr.set_font_size(25) x_bearing, y_bearing, _width, _height, \ x_advance, y_advance = cr.text_extents(letter) r = rect.align_rect(Rect(0, 0, _width, _height), 0.3, 0.33) cr.move_to(r.x - x_bearing, r.y - y_bearing) cr.set_source_rgba(*label_rgba) cr.show_text(letter) cr.new_path() cr.restore() return True