~glitter-team/glitter/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# !/usr/bin/python
# -*- coding: utf-8 -*-

# nublo
# a redefinition of senses
        
__authors__ = ["Jan Jokela <janjokela@gmail.com>"]
__licenses__ = ["LICENSE.LGPL"]
__description__ = "Overlay bar base texture"

import math
import clutter
import cairo
from cluttercairo import CairoTexture

class Texture(CairoTexture):

    def __init__(self, width, height):
        
        CairoTexture.__init__(self, width, height)
        
        self.width = width
        self.height = height

        border_offset = self.height * 0.2
        line_width = self.height * 0.005

        if border_offset > self.width / 2.0:
            border_offset = self.width / 2.0
        
        self.context = self.cairo_create()
        
        linpat = cairo.LinearGradient(self.width / 2.0, 0.0, self.width / 2.0, self.height);
        linpat.add_color_stop_rgba (0.0, 0.0, 0.0, 0.0, 0.5);
        linpat.add_color_stop_rgba (1.0, 1.0, 1.0, 1.0, 0.5);
        self._draw_cornered_rect(border_offset, line_width)        
        self.context.close_path()
        self.context.set_source(linpat)
        self.context.fill()

        self.context.set_source_rgba(1.0, 1.0, 1.0, 1.0)
        self._draw_cornered_rect(border_offset, line_width)                 
        self.context.set_line_width(self.height*0.01);
        self.context.stroke()
        
        self.context.stroke()
        del self.context
    
    def _draw_cornered_rect(self, border_offset, line_width):
        """ Draws a cornered rectangle """
        
        self.context.arc(border_offset + line_width, 
                         border_offset + line_width, 
                         border_offset, math.pi, 3.0 * math.pi / 2.0)
        self.context.line_to(self.width - border_offset, line_width)
        self.context.arc(self.width - border_offset,
                         border_offset, 
                         border_offset - line_width, 
                         3.0 * math.pi / 2.0, 
                         0.0)
        self.context.line_to(self.width - line_width, self.height - border_offset)
        self.context.arc(self.width - border_offset - line_width,
                         self.height - border_offset - line_width, 
                         border_offset, 
                         0.0, 
                         math.pi / 2.0)
        self.context.line_to(border_offset + line_width, self.height - line_width)
        self.context.arc(border_offset + line_width,
                         self.height - border_offset - line_width, 
                         border_offset, 
                         math.pi / 2.0, 
                         math.pi)
        self.context.close_path()        
          
    def resize(self, width, height):

        pass