def _draw_transparent_background(self, context, lod): """ fill with the transparent background color """ corner_radius = config.CORNER_RADIUS rect = self.get_keyboard_frame_rect() fill = self.get_background_rgba() fill_gradient = config.theme_settings.background_gradient if lod == LOD.MINIMAL or \ fill_gradient == 0: context.set_source_rgba(*fill) else: fill_gradient /= 100.0 direction = config.theme_settings.key_gradient_direction alpha = -pi/2.0 + pi * direction / 180.0 gline = gradient_line(rect, alpha) pat = cairo.LinearGradient (*gline) rgba = brighten(+fill_gradient*.5, *fill) pat.add_color_stop_rgba(0, *rgba) rgba = brighten(-fill_gradient*.5, *fill) pat.add_color_stop_rgba(1, *rgba) context.set_source (pat) frame = self.can_draw_frame() if frame: roundrect_arc(context, rect, corner_radius) else: context.rectangle(*rect) context.fill() if frame: self.draw_window_frame(context, lod) self.draw_keyboard_frame(context, lod)
def _draw_transparent_background(self, context, lod): """ fill with the transparent background color """ corner_radius = config.CORNER_RADIUS rect = self.get_keyboard_frame_rect() fill = self.get_background_rgba() fill_gradient = config.theme_settings.background_gradient if lod == LOD.MINIMAL or \ fill_gradient == 0: context.set_source_rgba(*fill) else: fill_gradient /= 100.0 direction = config.theme_settings.key_gradient_direction alpha = -pi / 2.0 + pi * direction / 180.0 gline = gradient_line(rect, alpha) pat = cairo.LinearGradient(*gline) rgba = brighten(+fill_gradient * .5, *fill) pat.add_color_stop_rgba(0, *rgba) rgba = brighten(-fill_gradient * .5, *fill) pat.add_color_stop_rgba(1, *rgba) context.set_source(pat) frame = self.can_draw_frame() if frame: roundrect_arc(context, rect, corner_radius) else: context.rectangle(*rect) context.fill() if frame: self.draw_window_frame(context, lod) self.draw_keyboard_frame(context, lod)
def _draw_themed_icon(self, cr, icon_rect, color_scheme): """ draw themed icon """ keys = [RectKey("icon" + str(i)) for i in range(4)] # 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_scheme(key) for key in keys): themed = True # four rounded rectangles rects = Rect(0.0, 0.0, 100.0, 100.0).deflate(5) \ .subdivide(2, 2, 6) cr.save() cr.scale(icon_rect.w / 100., icon_rect.h / 100.0) cr.translate(icon_rect.x, icon_rect.y) 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()
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 _draw_themed_icon(self, cr, icon_rect, color_scheme): """ draw themed icon """ keys = [RectKey("icon" + str(i)) for i in range(4)] # 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_scheme(key) for key in keys): themed = True # four rounded rectangles rects = Rect(0.0, 0.0, 100.0, 100.0).deflate(5).subdivide(2, 2, 6) cr.save() cr.scale(icon_rect.w / 100.0, icon_rect.h / 100.0) cr.translate(icon_rect.x, icon_rect.y) 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()
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 draw_keyboard_frame(self, context, lod): """ draw frame around the (potentially aspect corrected) keyboard """ corner_radius = config.CORNER_RADIUS rect = self.get_keyboard_frame_rect() fill = self.get_background_rgba() # inner decoration line line_rect = rect.deflate(1) roundrect_arc(context, line_rect, corner_radius) context.stroke()
def _on_draw(self, widget, context): if not LabelPopup._pango_layout: LabelPopup._pango_layout = Pango.Layout(context=Gdk.pango_context_get()) rect = Rect(0, 0, self.get_allocated_width(), self.get_allocated_height()) content_rect = Rect(rect.x, rect.y, rect.w, rect.h - rect.h * self.ARROW_HEIGHT) arrow_rect = Rect(rect.x, content_rect.bottom(), rect.w, rect.h * self.ARROW_HEIGHT) \ .deflate((rect.w - rect.w * self.ARROW_WIDTH) / 2.0, 0) label_rect = content_rect.deflate(rect.w * self.LABEL_MARGIN) # background if config.scanner.color_type == "custom_color" and config.scanner.enabled == True: # scan label popup color color_rgba = [] for val in config.scanner.scan_color: color_rgba.append(val) rgb = color_rgba[:3] opacity = color_rgba[3] fill = rgb + [opacity] else: fill = self._key.get_fill_color() context.save() context.set_operator(cairo.OPERATOR_CLEAR) context.paint() context.restore() context.set_source_rgba(*fill) roundrect_arc(context, content_rect, config.CORNER_RADIUS) context.fill() l, t, r, b = arrow_rect.to_extents() t -= 1 context.move_to(l, t) context.line_to(r, t) context.line_to((l+r) / 2, b) context.fill() # draw label/image label_color = self._key.get_label_color() pixbuf = self._key.get_image(label_rect.w, label_rect.h) if pixbuf: self._draw_image(context, pixbuf, label_rect, label_color) else: label = self._key.get_label() if label: if label == " ": label = "␣" self._draw_text(context, label, label_rect, label_color)
def on_draw(self, widget, context): if not LabelPopup._pango_layout: LabelPopup._pango_layout = Pango.Layout( context=Gdk.pango_context_get()) rect = Rect(0, 0, self.get_allocated_width(), self.get_allocated_height()) content_rect = Rect(rect.x, rect.y, rect.w, rect.h - rect.h * self.ARROW_HEIGHT) arrow_rect = Rect(rect.x, content_rect.bottom(), rect.w, rect.h * self.ARROW_HEIGHT) \ .deflate((rect.w - rect.w * self.ARROW_WIDTH) / 2.0, 0) label_rect = content_rect.deflate(rect.w * self.LABEL_MARGIN) # background fill = self._key.get_fill_color() context.save() context.set_operator(cairo.OPERATOR_CLEAR) context.paint() context.restore() context.push_group() context.set_source_rgba(*fill) roundrect_arc(context, content_rect, config.CORNER_RADIUS) context.fill() l, t, r, b = arrow_rect.to_extents() t -= 1 context.move_to(l, t) context.line_to(r, t) context.line_to((l + r) / 2, b) context.fill() # draw label/image label_color = self._key.get_label_color() pixbuf = self._key.get_image(label_rect.w, label_rect.h) if pixbuf: pixbuf.draw(context, label_rect, label_color) else: label = self._key.get_label() if label: if label == " ": label = "␣" self._draw_text(context, label, label_rect, label_color) context.pop_group_to_source() context.paint_with_alpha(self._opacity)
def draw_window_frame(self, context, lod): corner_radius = config.CORNER_RADIUS border_rgba = self.get_popup_window_rgba("border") alpha = border_rgba[3] colors = [ [[0.5, 0.5, 0.5, alpha], 0 , 1], [border_rgba, 1.5, 2.0], ] rect = Rect(0, 0, self.get_allocated_width(), self.get_allocated_height()) for rgba, pos, width in colors: r = rect.deflate(width) roundrect_arc(context, r, corner_radius) context.set_line_width(width) context.set_source_rgba(*rgba) context.stroke()
def draw_window_frame(self, context, lod): corner_radius = config.CORNER_RADIUS border_rgba = self.get_popup_window_rgba("border") alpha = border_rgba[3] colors = [ [[0.5, 0.5, 0.5, alpha], 0, 1], [border_rgba, 1.5, 2.0], ] rect = Rect(0, 0, self.get_allocated_width(), self.get_allocated_height()) for rgba, pos, width in colors: r = rect.deflate(width) roundrect_arc(context, r, corner_radius) context.set_line_width(width) context.set_source_rgba(*rgba) context.stroke()
def draw_transparent_background(self, context, decorated = True): """ fill with the transparent background color """ rgba = self.get_background_rgba() context.set_source_rgba(*rgba) # draw on the potentially aspect-corrected frame around the layout rect = self.layout.get_canvas_border_rect() rect = rect.inflate(config.get_frame_width()) corner_radius = config.CORNER_RADIUS if decorated: roundrect_arc(context, rect, corner_radius) else: context.rectangle(*rect) context.fill() if decorated: # inner decoration line line_rect = rect.deflate(1) roundrect_arc(context, line_rect, corner_radius) context.stroke() self.draw_dish_key_background(context, rgba[3])
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