def draw_ip(self, cr, rect): x, y, w, h = rect.x, rect.y, rect.width, rect.height ip_segment_distance = self.width / self.segment_number for (ip_segment_index, ip_segment) in enumerate(self.ip.split(self.segment_split_char)): text_color = "#000000" if ip_segment_index == self.highlight_segment_index: (ip_segment_width, ip_segment_height) = get_content_size(ip_segment) if self.grab_focus_flag: background_color = self.select_active_color.get_color_info() else: background_color = self.select_inactive_color.get_color_info() draw_hlinear( cr, x + ip_segment_index * ip_segment_distance + (ip_segment_distance - ip_segment_width) / 2, y + self.cursor_padding_y, ip_segment_width + 1, h - self.cursor_padding_y * 2, background_color, ) text_color = "#FFFFFF" draw_text(cr, ip_segment, x + ip_segment_index * ip_segment_distance, y, ip_segment_distance, h, alignment=pango.ALIGN_CENTER, text_color=text_color, )
def draw_menu_mask(self, cr, x, y, w, h): '''Draw mask.''' # Draw background. cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("menu_mask").get_color_info())) cr.rectangle(x, y, w, h) cr.fill() # Draw left side. draw_hlinear(cr, x + 1, y + 1, 16 + self.padding_x + self.padding_x * 2, h - 2, ui_theme.get_shadow_color("menu_side").get_color_info())
def expose_hseparator(self, widget, event): """Expose separator item.""" # Init. cr = widget.window.cairo_create() rect = widget.allocation # Draw. start_x = rect.x y = rect.y + rect.height / 2 draw_hlinear(cr, start_x, y, rect.width, 1, self.color_infos) return True
def draw_entry_background(self, cr, rect): '''Draw entry background.''' x, y, w, h = rect.x, rect.y, rect.width, rect.height if self.select_start_index != self.select_end_index and self.select_area_visible_flag: select_start_width = self.get_content_width(self.content[0:self.select_start_index]) select_end_width = self.get_content_width(self.content[0:self.select_end_index]) draw_hlinear(cr, x + self.padding_x + max(select_start_width - self.offset_x, 0), y + self.padding_y, min(select_end_width, self.offset_x + w - self.padding_x * 2) - max(select_start_width, self.offset_x), h - self.padding_y * 2, self.background_select_color.get_color_info())
def draw_label_background(self, cr, rect): '''Draw label background.''' if self.select_start_index != self.select_end_index: select_start_width = self.get_content_width(self.text[0:self.select_start_index]) select_end_width = self.get_content_width(self.text[0:self.select_end_index]) draw_hlinear(cr, rect.x + select_start_width, rect.y, select_end_width - select_start_width, rect.height, [(0, (self.text_select_background.get_color(), 0)), (0, (self.text_select_background.get_color(), 1))] )
def expose_hseparator(self, widget, event): ''' Callback for `expose-event` signal. @param widget: HSeparator instance. @param event: Expose event. @return: Return True. ''' # Init. cr = widget.window.cairo_create() rect = widget.allocation # Draw. start_x = rect.x y = rect.y + rect.height / 2 draw_hlinear(cr, start_x, y, rect.width, 1, self.color_infos) return True
def draw_menu_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordinate of draw area. @param y: Y coordinate of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' # Draw background. cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("menu_mask").get_color_info())) cr.rectangle(x, y, w, h) cr.fill() # Draw left side. draw_hlinear(cr, x + 1, y + 1, 16 + self.padding_x + self.padding_x * 2, h - 2, ui_theme.get_shadow_color("menu_side").get_color_info())
def draw_label_background(self, cr, rect): ''' Inernal function to draw label background. @param cr: Cairo context. @param rect: Draw area. @return: Always return True. ''' if self.select_start_index != self.select_end_index: select_start_width = self.get_content_width( self.text[0:self.select_start_index]) select_end_width = self.get_content_width( self.text[0:self.select_end_index]) draw_hlinear(cr, rect.x + select_start_width, rect.y, select_end_width - select_start_width, rect.height, [(0, (self.text_select_background.get_color(), 0)), (0, (self.text_select_background.get_color(), 1))])
def color_test_widget_expose(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation # Draw pixbuf. draw_pixbuf(cr, self.pixbuf, 0, 0) # Draw mask. draw_vlinear(cr, rect.x, rect.y + self.pixbuf.get_height() - SHADOW_SIZE, rect.width, SHADOW_SIZE, [(0, (self.background_color, 0)), (1, (self.background_color, 1))]) draw_hlinear(cr, rect.x + self.pixbuf.get_width() - SHADOW_SIZE, rect.y, SHADOW_SIZE, rect.height, [(0, (self.background_color, 0)), (1, (self.background_color, 1))]) # Draw background. (similar_color_name, similar_color_value) = find_similar_color(self.background_color) print(similar_color_name, self.background_color, similar_color_value) cr.set_source_rgb(*color_hex_to_cairo(similar_color_value)) cr.rectangle(rect.x + self.pixbuf.get_width(), rect.y, rect.width - self.pixbuf.get_width(), rect.height) cr.fill() cr.set_source_rgb(*color_hex_to_cairo(self.background_color)) cr.rectangle(rect.x, rect.y + self.pixbuf.get_height(), rect.width, rect.height - self.pixbuf.get_height()) cr.fill() # cr.set_source_rgb(*color_hex_to_cairo(self.background_color)) # cr.rectangle(rect.x + self.pixbuf.get_width(), rect.y, # rect.width - self.pixbuf.get_width(), rect.height) # cr.rectangle(rect.x, rect.y + self.pixbuf.get_height(), # rect.width, rect.height - self.pixbuf.get_height()) # cr.fill() propagate_expose(widget, event) return True
def draw_label_background(self, cr, rect): ''' Inernal function to draw label background. @param cr: Cairo context. @param rect: Draw area. @return: Always return True. ''' if self.select_start_index != self.select_end_index: select_start_width = self.get_content_width(self.text[0:self.select_start_index]) select_end_width = self.get_content_width(self.text[0:self.select_end_index]) draw_hlinear(cr, rect.x + select_start_width, rect.y, select_end_width - select_start_width, rect.height, [(0, (self.text_select_background.get_color(), 0)), (0, (self.text_select_background.get_color(), 1))] )
def draw_menu_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordinate of draw area. @param y: Y coordinate of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' # Draw background. cr.set_source_rgba(*alpha_color_hex_to_cairo( ui_theme.get_alpha_color("menu_mask").get_color_info())) cr.rectangle(x, y, w, h) cr.fill() # Draw left side. draw_hlinear(cr, x + 1, y + 1, 16 + self.padding_x + self.padding_x * 2, h - 2, ui_theme.get_shadow_color("menu_side").get_color_info())
def color_test_widget_expose(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation # Draw pixbuf. draw_pixbuf(cr, self.pixbuf, 0, 0) # Draw mask. draw_vlinear( cr, rect.x, rect.y + self.pixbuf.get_height() - SHADE_SIZE, rect.width, SHADE_SIZE, [(0, (self.background_color, 0)), (1, (self.background_color, 1))]) draw_hlinear( cr, rect.x + self.pixbuf.get_width() - SHADE_SIZE, rect.y, SHADE_SIZE, rect.height, [(0, (self.background_color, 0)), (1, (self.background_color, 1))]) # Draw background. (similar_color_name, similar_color_value) = find_similar_color(self.background_color) print (similar_color_name, self.background_color, similar_color_value) cr.set_source_rgb(*color_hex_to_cairo(similar_color_value)) cr.rectangle(rect.x + self.pixbuf.get_width(), rect.y, rect.width - self.pixbuf.get_width(), rect.height) cr.fill() cr.set_source_rgb(*color_hex_to_cairo(self.background_color)) cr.rectangle(rect.x, rect.y + self.pixbuf.get_height(), rect.width, rect.height - self.pixbuf.get_height()) cr.fill() # cr.set_source_rgb(*color_hex_to_cairo(self.background_color)) # cr.rectangle(rect.x + self.pixbuf.get_width(), rect.y, # rect.width - self.pixbuf.get_width(), rect.height) # cr.rectangle(rect.x, rect.y + self.pixbuf.get_height(), # rect.width, rect.height - self.pixbuf.get_height()) # cr.fill() propagate_expose(widget, event) return True
def draw_ip(self, cr, rect): x, y, w, h = rect.x, rect.y, rect.width, rect.height ip_segment_distance = self.width / self.segment_number for (ip_segment_index, ip_segment) in enumerate(self.ip.split(self.segment_split_char)): text_color = "#000000" if ip_segment_index == self.highlight_segment_index: (ip_segment_width, ip_segment_height) = get_content_size(ip_segment) if self.grab_focus_flag: background_color = self.select_active_color.get_color_info( ) else: background_color = self.select_inactive_color.get_color_info( ) draw_hlinear( cr, x + ip_segment_index * ip_segment_distance + (ip_segment_distance - ip_segment_width) / 2, y + self.cursor_padding_y, ip_segment_width + 1, h - self.cursor_padding_y * 2, background_color, ) text_color = "#FFFFFF" draw_text( cr, ip_segment, x + ip_segment_index * ip_segment_distance, y, ip_segment_distance, h, alignment=pango.ALIGN_CENTER, text_color=text_color, )
def render_background(self, cr, widget, x, y, translate_width=0, translate_height=0): '''Render background.''' # Init. toplevel_rect = widget.get_toplevel().allocation render_width = toplevel_rect.width + translate_width render_height = toplevel_rect.height + translate_height # Draw background. background_x = int(self.x * self.scale_x) background_y = int(self.y * self.scale_y) background_width = int(self.background_pixbuf.get_width() * self.scale_x) background_height = int(self.background_pixbuf.get_height() * self.scale_y) self.cache_pixbuf.scale(self.background_pixbuf, background_width, background_height, self.vertical_mirror, self.horizontal_mirror) draw_pixbuf( cr, self.cache_pixbuf.get_cache(), x + background_x, y + background_y) # Draw dominant color if necessarily. if ((background_width + background_x) < render_width and (background_height + background_y) < render_height): cr.set_source_rgb(*color_hex_to_cairo(self.dominant_color)) cr.rectangle( x + background_x + background_width, y + background_y + background_height, render_width - (background_width + background_x), render_height - (background_height + background_y)) cr.fill() if (background_width + background_x) < render_width: draw_hlinear( cr, x + (background_width + background_x) - SHADE_SIZE, y, SHADE_SIZE, (background_height + background_y), [(0, (self.dominant_color, 0)), (1, (self.dominant_color, 1))]) cr.set_source_rgb(*color_hex_to_cairo(self.dominant_color)) cr.rectangle( x + (background_width + background_x), y, render_width - (background_width + background_x), (background_height + background_y)) cr.fill() if (background_height + background_y) < render_height: draw_vlinear( cr, x, y + (background_height + background_y) - SHADE_SIZE, (background_width + background_x), SHADE_SIZE, [(0, (self.dominant_color, 0)), (1, (self.dominant_color, 1))]) cr.set_source_rgb(*color_hex_to_cairo(self.dominant_color)) cr.rectangle( x, y + (background_height + background_y), (background_width + background_x), render_height - (background_height + background_y)) cr.fill()
def render_background(self, cr, widget, x, y, translate_width=0, translate_height=0): ''' Internal function to render background. ''' # Init. toplevel_rect = widget.get_toplevel().allocation render_width = toplevel_rect.width + translate_width render_height = toplevel_rect.height + translate_height # Draw background. background_x = int(self.x * self.scale_x) background_y = int(self.y * self.scale_y) background_width = int(self.background_pixbuf.get_width() * self.scale_x) background_height = int(self.background_pixbuf.get_height() * self.scale_y) self.cache_pixbuf.scale(self.background_pixbuf, background_width, background_height, self.vertical_mirror, self.horizontal_mirror) draw_pixbuf( cr, self.cache_pixbuf.get_cache(), x + background_x, y + background_y) # Draw dominant color if necessarily. if ((background_width + background_x) < render_width and (background_height + background_y) < render_height): cr.set_source_rgb(*color_hex_to_cairo(self.dominant_color)) cr.rectangle( x + background_x + background_width, y + background_y + background_height, render_width - (background_width + background_x), render_height - (background_height + background_y)) cr.fill() if (background_width + background_x) < render_width: draw_hlinear( cr, x + (background_width + background_x) - SHADOW_SIZE, y, SHADOW_SIZE, (background_height + background_y), [(0, (self.dominant_color, 0)), (1, (self.dominant_color, 1))]) cr.set_source_rgb(*color_hex_to_cairo(self.dominant_color)) cr.rectangle( x + (background_width + background_x), y, render_width - (background_width + background_x), (background_height + background_y)) cr.fill() if (background_height + background_y) < render_height: draw_vlinear( cr, x, y + (background_height + background_y) - SHADOW_SIZE, (background_width + background_x), SHADOW_SIZE, [(0, (self.dominant_color, 0)), (1, (self.dominant_color, 1))]) cr.set_source_rgb(*color_hex_to_cairo(self.dominant_color)) cr.rectangle( x, y + (background_height + background_y), (background_width + background_x), render_height - (background_height + background_y)) cr.fill()