当前位置: 首页>>代码示例>>Python>>正文


Python utils.cairo_state函数代码示例

本文整理汇总了Python中utils.cairo_state函数的典型用法代码示例。如果您正苦于以下问题:Python cairo_state函数的具体用法?Python cairo_state怎么用?Python cairo_state使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cairo_state函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: draw_items

 def draw_items(self, cr, rect):
     # Draw items.
     if len(self.items) > 0:
         with cairo_state(cr):
             scrolled_window = get_match_parent(self, ["ScrolledWindow"])
             vadjust_value = int(scrolled_window.get_vadjustment().get_value())
             hadjust_value = int(scrolled_window.get_hadjustment().get_value())
             
             # Draw on drawing area.
             (item_width, item_height, columns, start_index, end_index) = self.get_render_item_info()
             for (index, item) in enumerate(self.items[start_index:end_index]):
                 row = int((start_index + index) / columns)
                 column = (start_index + index) % columns
                 render_x = self.padding_x + column * item_width - hadjust_value
                 render_y = self.padding_y + row * item_height - vadjust_value
                 
                 # Draw row background.
                 self.draw_row_mask(cr, gtk.gdk.Rectangle(render_x, render_y, rect.width, item_height), row)
                 
                 item.row_index = row
                 
                 with cairo_state(cr):
                     # Don't allow draw out of item area.
                     cr.rectangle(render_x, render_y, item_width, item_height)
                     cr.clip()
                     
                     item.render(cr, gtk.gdk.Rectangle(render_x, render_y, item_width, item_height))
开发者ID:Jiarui315,项目名称:deepin-ui,代码行数:27,代码来源:iconview.py

示例2: draw_window_shadow

def draw_window_shadow(cr, x, y, w, h, r, p, color_window_shadow):
    '''Draw window shadow.'''
    color_infos = color_window_shadow.get_color_info()
    with cairo_state(cr):
        # Clip four corner.
        cr.rectangle(x, y, r - 1, r - 1) # top-left
        cr.rectangle(x + r - 1, y, 1, r - 2) # vertical
        cr.rectangle(x, y + r - 1, r - 2, 1) # horizontal
        
        cr.rectangle(x + w - r + 1, y, r - 1, r - 1) # top-right
        cr.rectangle(x + w - r, y, 1, r - 2)         # vertical
        cr.rectangle(x + w - r + 2, y + r - 1, r - 2, 1) # horizontal
        
        cr.rectangle(x, y + h - r + 1, r - 1, r - 1) # bottom-left
        cr.rectangle(x + r - 1, y + h - r + 2, 1, r - 2) # vertical
        cr.rectangle(x, y + h - r, r - 2, 1)     # horizontal
        
        cr.rectangle(x + w - r + 1, y + h - r + 1, r - 1, r - 1) # bottom-right
        cr.rectangle(x + w - r, y + h - r + 2, 1, r - 2)         # vertical
        cr.rectangle(x + w - r + 2, y + h - r, r - 2, 1) # horizontal
        
        cr.clip()
        
        # Draw four round.
        draw_radial_round(cr, x + r, y + r, r, color_infos)
        draw_radial_round(cr, x + r, y + h - r, r, color_infos)
        draw_radial_round(cr, x + w - r, y + r, r, color_infos)
        draw_radial_round(cr, x + w - r, y + h - r, r, color_infos)
    
    with cairo_state(cr):
        # Clip four side.
        cr.rectangle(x, y + r, p, h - r * 2)
        cr.rectangle(x + w - p, y + r, p, h - r * 2)
        cr.rectangle(x + r, y, w - r * 2, p)
        cr.rectangle(x + r, y + h - p, w - r * 2, p)
        cr.clip()
        
        # Draw four side.
        draw_vlinear(
            cr, 
            x + r, y, 
            w - r * 2, r, color_infos)
        draw_vlinear(
            cr, 
            x + r, y + h - r, 
            w - r * 2, r, color_infos, 0, False)
        draw_hlinear(
            cr, 
            x, y + r, 
            r, h - r * 2, color_infos)
        draw_hlinear(
            cr, 
            x + w - r, y + r, 
            r, h - r * 2, color_infos, 0, False)
开发者ID:netphi,项目名称:deepin-ui,代码行数:54,代码来源:draw.py

示例3: draw_shadow

def draw_shadow(cr, x, y, w, h, r, color_window_shadow):
    '''
    Draw window shadow.
    
    @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.
    @param r: Radious of window shadow corner.
    @param color_window_shadow: theme.DyanmicShadowColor.
    '''
    color_infos = color_window_shadow.get_color_info()
    with cairo_state(cr):
        # Clip four corner.
        cr.rectangle(x, y, r, r)
        cr.rectangle(x + w - r, y, r, r)
        cr.rectangle(x, y + h - r, r, r)
        cr.rectangle(x + w - r, y + h - r, r, r)
        
        cr.clip()
        
        # Draw four round.
        draw_radial_round(cr, x + r, y + r, r, color_infos)
        draw_radial_round(cr, x + r, y + h - r, r, color_infos)
        draw_radial_round(cr, x + w - r, y + r, r, color_infos)
        draw_radial_round(cr, x + w - r, y + h - r, r, color_infos)
        
    with cairo_state(cr):
        # Draw four side.
        draw_vlinear(
            cr, 
            x + r, y, 
            w - r * 2, r, color_infos)
        draw_vlinear(
            cr, 
            x + r, y + h - r, 
            w - r * 2, r, color_infos, 0, False)
        draw_hlinear(
            cr, 
            x, y + r, 
            r, h - r * 2, color_infos)
        draw_hlinear(
            cr, 
            x + w - r, y + r, 
            r, h - r * 2, color_infos, 0, False)
        
    # Fill inside.
    cr.set_source_rgba(*alpha_color_hex_to_cairo(color_infos[-1][1]))    
    cr.rectangle(x + r, y + r, w - r * 2, h - r * 2)
    cr.fill()
开发者ID:Jiarui315,项目名称:deepin-ui,代码行数:51,代码来源:draw.py

示例4: render

 def render(self, cr, rect):
     # Init.
     x, y, w, h = rect.x, rect.y, rect.width, rect.height
     
     # Draw background frame.
     with cairo_state(cr):
         cr.rectangle(x, y + 1, w, h - 2)
         cr.rectangle(x + 1, y, w - 2, h)
         cr.clip()
         
         cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("progressbar_background_frame").get_color()))
         cr.rectangle(x, y, w, h)
         cr.set_line_width(1)
         cr.stroke()
         
     # Draw background.
     with cairo_state(cr):
         cr.rectangle(x + 1, y + 1, w - 2, h - 2)
         cr.clip()
         
         draw_vlinear(cr, x + 1, y + 1, w - 2, h - 2,
                      ui_theme.get_shadow_color("progressbar_background").get_color_info(), 
                      )
         
     if self.progress > 0:    
         # Draw foreground frame.
         with cairo_state(cr):
             cr.rectangle(x, y + 1, w, h - 2)
             cr.rectangle(x + 1, y, w - 2, h)
             cr.clip()
         
             cr.set_antialias(cairo.ANTIALIAS_NONE)
             cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("progressbar_foreground_frame").get_color()))
             cr.rectangle(x + 1, y + 1, int(w * self.progress / 100) - 1, h - 1)
             cr.set_line_width(1)
             cr.stroke()
             
         # Draw foreground.
         with cairo_state(cr):
             cr.rectangle(x + 1, y + 1, w - 2, h - 2)
             cr.clip()
             
             draw_vlinear(cr, x + 1, y + 1, int(w * self.progress / 100) - 2, h - 2,
                          ui_theme.get_shadow_color("progressbar_foreground").get_color_info(), 
                          )
         
     # Draw light.
     with cairo_disable_antialias(cr):
         cr.set_source_rgba(1, 1, 1, 0.5)
         cr.rectangle(x + 1, y + 1, w - 2, 1)
         cr.fill()
开发者ID:Jiarui315,项目名称:deepin-ui,代码行数:51,代码来源:progressbar.py

示例5: expose_icon_view

 def expose_icon_view(self, widget, event):
     '''
     Internal callback for `expose-event` signal.
     '''
     # Update vadjustment.
     self.update_vadjustment()    
     
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     
     # Get offset.
     (offset_x, offset_y, viewport) = self.get_offset_coordinate(widget)
         
     # Draw background.
     with cairo_state(cr):
         scrolled_window = get_match_parent(self, ["ScrolledWindow"])
         cr.translate(-scrolled_window.allocation.x, -scrolled_window.allocation.y)
         cr.rectangle(offset_x, offset_y, 
                      scrolled_window.allocation.x + scrolled_window.allocation.width, 
                      scrolled_window.allocation.y + scrolled_window.allocation.height)
         cr.clip()
         
         (shadow_x, shadow_y) = get_window_shadow_size(self.get_toplevel())
         skin_config.render_background(cr, self, offset_x + shadow_x, offset_y + shadow_y)
         
     # Draw mask.
     self.draw_mask(cr, offset_x, offset_y, viewport.allocation.width, viewport.allocation.height)
     
     # Draw items.
     self.draw_items(cr, rect, offset_x, offset_y, viewport)
开发者ID:liuhuan520,项目名称:deepin-ui,代码行数:31,代码来源:iconview.py

示例6: draw_scrolled_window_mask

def draw_scrolled_window_mask(widget, x, y, w, h, render_callback):
    '''
    Draw scrolled window mask with given render method.

    @param widget: Target widget.
    @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.
    @param render_callback: Render callback.
    '''
    # Init.
    cr = widget.window.cairo_create()
    toplevel = widget.get_toplevel()
    (offset_x, offset_y) = widget.translate_coordinates(toplevel, 0, 0)

    with cairo_state(cr):
        cr.rectangle(x, y, w, h)
        cr.clip()

        render_callback(
            cr,
            x - offset_x,
            y - offset_y,
            toplevel.allocation.width,
            toplevel.allocation.height)
开发者ID:chenzhiwei,项目名称:deepin-ui,代码行数:26,代码来源:mask.py

示例7: draw_text

 def draw_text(self, cr, rect):
     x, y, w, h = rect.x, rect.y, rect.width, rect.height
     with cairo_state(cr):
         draw_x = x + self.padding_x
         draw_y = y + self.padding_y
         draw_width = w - self.padding_x * 2
         draw_height = h - self.padding_y * 2
         cr.rectangle(draw_x, draw_y, draw_width, draw_height)
         cr.clip()
         
         # pango context
         context = pangocairo.CairoContext(cr)
         
         # pango layout
         layout = context.create_layout()
         layout.set_font_description(pango.FontDescription("%s %s" % (DEFAULT_FONT, self.font_size)))
         
         text = self.__buffer.get_text()
         layout.set_text(text)
         
         (text_width, text_height) = layout.get_pixel_size()
         cr.move_to(x + self.padding_x , y + self.padding_y)
         
         cr.set_source_rgb(0,0,0)
         context.update_layout(layout)
         context.show_layout(layout)
开发者ID:netphi,项目名称:deepin-ui,代码行数:26,代码来源:textview.py

示例8: draw_icon_view_mask

def draw_icon_view_mask(widget, x, y, w, h, render_callback):
    '''
    Draw icon view mask with given render method.

    @param widget: Target widget.
    @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.
    @param render_callback: Render callback.
    '''
    cr = widget.window.cairo_create()
    viewport = get_match_parent(widget, ["Viewport"])
    toplevel = widget.get_toplevel()
    (offset_x, offset_y) = viewport.translate_coordinates(toplevel, 0, 0)
    (shadow_x, shadow_y) = get_window_shadow_size(toplevel)

    with cairo_state(cr):
        cr.rectangle(x, y, w, h)
        cr.clip()

        render_callback(
            cr,
            x - offset_x + shadow_x,
            y - offset_y + shadow_y,
            toplevel.allocation.width,
            toplevel.allocation.height)
开发者ID:chenzhiwei,项目名称:deepin-ui,代码行数:27,代码来源:mask.py

示例9: draw_title_background

 def draw_title_background(self, cr, widget):
     (offset_x, offset_y) = widget.translate_coordinates(self.get_toplevel(), 0, 0)
     with cairo_state(cr):
         cr.translate(-offset_x, -offset_y)
         
         (shadow_x, shadow_y) = get_window_shadow_size(self.get_toplevel())
         skin_config.render_background(cr, widget, shadow_x, shadow_y)
开发者ID:Jiarui315,项目名称:deepin-ui,代码行数:7,代码来源:tab_window.py

示例10: expose_tab_content_box

    def expose_tab_content_box(self, widget, event):
        '''
        Internal function to `expose-event` signal.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        self.tab_box_width = rect.width

        # Draw background.
        toplevel = widget.get_toplevel()
        coordinate = widget.translate_coordinates(toplevel, 0, 0)
        (offset_x, offset_y) = coordinate

        with cairo_state(cr):
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.clip()
            
            (shadow_x, shadow_y) = get_window_shadow_size(self.get_toplevel())
            skin_config.render_background(cr, self, shadow_x, shadow_y)
        
        # Draw mask.
        cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_select_bg_color.get_color(), 0.93)))
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()
开发者ID:Jiarui315,项目名称:deepin-ui,代码行数:25,代码来源:tab_window.py

示例11: draw_hlinear

def draw_hlinear(cr, x, y, w, h, color_infos, radius=0, left_to_right=True):
    '''
    Draw linear area horticulturally.
    
    @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.
    @param color_infos: A list of ColorInfo, ColorInfo format: (color_stop_position, (color_hex_value, color_alpha))
    @param radius: Rectangle corner radious.
    @param left_to_right: Draw direction, default is from left to right, function will draw from right to left if set option as False.
    '''
    with cairo_state(cr):
        # Translate x coordinate, otherwise x is too big for LinearGradient cause render bug.
        cr.translate(x, 0)
        
        if left_to_right:
            pat = cairo.LinearGradient(0, 0, w, 0)
        else:
            pat = cairo.LinearGradient(w, 0, 0, 0)
        for (pos, color_info) in color_infos:
            add_color_stop_rgba(pat, pos, color_info)
        cr.set_operator(cairo.OPERATOR_OVER)
        cr.set_source(pat)
        draw_round_rectangle(cr, 0, y, w, h, radius)
        cr.fill()
开发者ID:Jiarui315,项目名称:deepin-ui,代码行数:27,代码来源:draw.py

示例12: draw_radial_ring

def draw_radial_ring(cr, x, y, outer_radius, inner_radius, color_infos, clip_corner=None):
    '''
    Draw radial ring.

    @param cr: Cairo context.
    @param x: X coordinate of draw area.
    @param y: Y coordinate of draw area.
    @param outer_radius: Radious for outter ring.
    @param inner_radius: Radious for inner ring.
    @param color_infos: A list of ColorInfo, ColorInfo format as [(color_pos, (color_hex_value, color_alpha))].
    '''
    with cairo_state(cr):
        # Clip corner.
        if clip_corner:
            if clip_corner == "top-left":
                cr.rectangle(x - outer_radius, y - outer_radius, outer_radius, outer_radius)
            elif clip_corner == "top-right":
                cr.rectangle(x, y - outer_radius, outer_radius, outer_radius)
            elif clip_corner == "bottom-left":
                cr.rectangle(x - outer_radius, y, outer_radius, outer_radius)
            elif clip_corner == "bottom-right":
                cr.rectangle(x, y, outer_radius, outer_radius)

            cr.clip()

        # Clip.
        cr.arc(x, y, outer_radius, 0, pi * 2)
        cr.arc(x, y, inner_radius, 0, pi * 2)
        cr.set_fill_rule(cairo.FILL_RULE_EVEN_ODD)
        cr.clip()

        # Draw radial round.
        draw_radial_round(cr, x, y, outer_radius, color_infos)
开发者ID:chenzhiwei,项目名称:deepin-ui,代码行数:33,代码来源:draw.py

示例13: draw_radial_ring

def draw_radial_ring(cr, x, y, outer_radius, inner_radius, color_infos):
    '''Draw radial ring.'''
    with cairo_state(cr):
        # Clip.
        cr.arc(x, y, outer_radius, 0, pi * 2)
        cr.arc(x, y, inner_radius, 0, pi * 2)
        cr.set_fill_rule(cairo.FILL_RULE_EVEN_ODD)
        cr.clip()
        
        # Draw radial round.
        draw_radial_round(cr, x, y, outer_radius, color_infos)
开发者ID:netphi,项目名称:deepin-ui,代码行数:11,代码来源:draw.py

示例14: draw_window_mask

def draw_window_mask(widget, x, y, w, h, render_callback):
    '''Draw window skin mask.'''
    # Init.
    cr = widget.window.cairo_create()

    with cairo_state(cr):
        cr.rectangle(x + 1, y, w - 2, 1)
        cr.rectangle(x, y + 1, w, h - 2)
        cr.rectangle(x + 1, y + h - 1, w - 2, 1)
        cr.clip()
        
        render_callback(cr, x, y, w, h)
开发者ID:netphi,项目名称:deepin-ui,代码行数:12,代码来源:mask.py

示例15: expose_tab_switcher

    def expose_tab_switcher(self, widget, event):
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        
        with cairo_state(cr):
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.clip()

            # Draw tab line.
            cr.set_source_rgb(*color_hex_to_cairo(self.line_dcolor.get_color()))
            cr.rectangle(rect.x + self.padding_x, 
                         rect.y + self.tab_height,
                         rect.width - self.padding_x * 2, 
                         self.tab_line_height)
            cr.fill()
            
            # Draw tab.
            draw_start_x = rect.x + (rect.width - self.tab_width * self.tab_number) / 2
            if self.in_animiation:
                cr.rectangle(self.tab_animation_x,
                             rect.y,
                             self.tab_width,
                             self.tab_height)
            else:
                cr.rectangle(draw_start_x + self.tab_index * self.tab_width,
                             rect.y,
                             self.tab_width,
                             self.tab_height)
            cr.fill()
            
            # Draw tab name.
            for (tab_index, tab_name) in enumerate(self.tab_names):
                if self.in_animiation:
                    tab_name_color = "#000000"
                elif tab_index == self.tab_index:
                    tab_name_color = "#FFFFFF"
                else:
                    tab_name_color = "#000000"
                draw_text(cr,
                          tab_name,
                          draw_start_x + tab_index * self.tab_width,
                          rect.y,
                          self.tab_width,
                          self.tab_height,
                          text_size=self.tab_name_size,
                          text_color=tab_name_color,
                          alignment=pango.ALIGN_CENTER,
                          )
开发者ID:Jiarui315,项目名称:deepin-ui,代码行数:49,代码来源:tab_switcher.py


注:本文中的utils.cairo_state函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。