Show
Ignore:
Timestamp:
06/13/2009 03:07:36 PM (15 months ago)
Author:
dunk <dunk@…>
Children:
e16d70dd7f47993875d85b75b8b673c1daa85bc6
Parents:
8d7d83a65de65a32682494df1473805ebb90e4c3
git-committer:
dunk <dunk@inspo.(none)> / 2009-06-13T15:07:36Z+0100
Message:

just depend on yahiko for drawing with sx-background. add (broken) svg support to yahiko styles

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • sx-background/sxbackground.py

    r8d7d83 r6732e9  
    77import ooxcb 
    88 
     9from yahiko.ui import Window 
    910 
    10 # ripped from yahiko 
    11 def default_func(cr, style, width, height): 
    12     x = 0 
    13     y = 0 
    14     if 'background.style' in style:  
    15         cairo.cairo_rectangle(cr, x, y, width, height) 
    1611 
    17         bstyle = style.get('background.style') 
    18         assert bstyle in ('fill', 'gradient', 'image') 
    19         if bstyle == 'fill' and 'background.color' in style: 
    20             cairo.cairo_set_source_rgb(cr, *style['background.color']) 
    21             cairo.cairo_fill(cr) 
    22         elif bstyle == 'gradient' and 'background.fill-line' in style and 'background.fill-stops' in style: 
    23             pat = cairo.cairo_pattern_create_linear(*style['background.fill-line']) 
    24             for stop in style['background.fill-stops']: 
    25                 cairo.cairo_pattern_add_color_stop_rgb(pat, *stop) 
    26             cairo.cairo_set_source(cr, pat) 
    27             cairo.cairo_fill(cr) 
    28         elif bstyle == 'image' and 'background.image' in style and style['background.image']: 
    29             image = cairo.cairo_image_surface_create_from_png(style.get('background.image')) 
    30             w = float(cairo.cairo_image_surface_get_width(image)) 
    31             h = float(cairo.cairo_image_surface_get_height(image)) 
    32  
    33             cairo.cairo_scale(cr, width/w, height/h) 
    34  
    35             cairo.cairo_set_source_surface(cr, image, x, y) 
    36             cairo.cairo_paint(cr) 
    37  
    38     if 'border.color' in style: 
    39         bstyle = style.get('style', 'fill') 
    40         assert bstyle in ('fill', 'gradient') 
    41         if bstyle == 'fill' and 'border.color' in style: 
    42             cairo.cairo_set_source_rgb(cr, *style['border.color']) 
    43         elif bstyle == 'gradient' and 'border.fill-line' in style and 'border.fill-stops' in style: 
    44             pat = cairo.cairo_pattern_create_linear(*style['border.fill-line']) 
    45             for stop in style['border.fill-stops']: 
    46                 cairo.cairo_pattern_add_color_stop_rgb(pat, *stop) 
    47             cairo.cairo_set_source(cr, pat) 
    48         cairo.cairo_set_line_width(cr, style.get('width', 1.0)) 
    49         cairo.cairo_rectangle(cr, x, y, width, height) 
    50         cairo.cairo_stroke(cr) 
     12def yahiko_render(cr, style, width, height): 
     13    win = Window(style=style) 
     14    win.set_render_coords(0, 0, width, height) 
     15    win.render(cr) 
    5116 
    5217 
     
    7035    cr = cairo.cairo_create(surface) 
    7136    if func is None: 
    72         func = default_func 
     37        func = yahiko_render 
    7338    func(cr, style, geom.width, geom.height) 
    7439