~ubuntu-branches/ubuntu/karmic/sugar-toolkit/karmic

« back to all changes in this revision

Viewing changes to src/sugar/graphics/roundbox.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-08-07 19:43:09 UTC
  • mfrom: (0.1.2 lenny) (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080807194309-03302c4lj0j0ipze
Tags: 0.82.0-1
* New upstream release.
* Unfuzz patch 2991.
* Add DEB_MAINTAINER_MODE in debian/rules (thanks to Romain Beauxis).
* Update copyright-hints.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006-2007 Red Hat, Inc.
 
2
#
 
3
# This library is free software; you can redistribute it and/or
 
4
# modify it under the terms of the GNU Lesser General Public
 
5
# License as published by the Free Software Foundation; either
 
6
# version 2 of the License, or (at your option) any later version.
 
7
#
 
8
# This library is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
# Lesser General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU Lesser General Public
 
14
# License along with this library; if not, write to the
 
15
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
16
# Boston, MA 02111-1307, USA.
 
17
 
 
18
import math
 
19
 
 
20
import hippo
 
21
 
 
22
from sugar.graphics import style
 
23
 
 
24
class CanvasRoundBox(hippo.CanvasBox, hippo.CanvasItem):
 
25
    __gtype_name__ = 'SugarRoundBox'
 
26
 
 
27
    _BORDER_DEFAULT = style.LINE_WIDTH
 
28
 
 
29
    def __init__(self, **kwargs):
 
30
        hippo.CanvasBox.__init__(self, **kwargs)
 
31
 
 
32
        # TODO: we should calculate radius depending on the height of the box.
 
33
        self._radius = style.zoom(10)
 
34
        
 
35
        self.props.orientation = hippo.ORIENTATION_HORIZONTAL
 
36
        self.props.border = self._BORDER_DEFAULT
 
37
        self.props.border_left = self._radius
 
38
        self.props.border_right = self._radius
 
39
        self.props.border_color = style.COLOR_BLACK.get_int()
 
40
            
 
41
    def do_paint_background(self, cr, damaged_box):
 
42
        [width, height] = self.get_allocation()
 
43
 
 
44
        x = self._BORDER_DEFAULT / 2
 
45
        y = self._BORDER_DEFAULT / 2
 
46
        width -= self._BORDER_DEFAULT
 
47
        height -= self._BORDER_DEFAULT
 
48
 
 
49
        cr.move_to(x + self._radius, y)
 
50
        cr.arc(x + width - self._radius, y + self._radius,
 
51
               self._radius, math.pi * 1.5, math.pi * 2)
 
52
        cr.arc(x + width - self._radius, x + height - self._radius,
 
53
               self._radius, 0, math.pi * 0.5)
 
54
        cr.arc(x + self._radius, y + height - self._radius,
 
55
               self._radius, math.pi * 0.5, math.pi)
 
56
        cr.arc(x + self._radius, y + self._radius, self._radius,
 
57
               math.pi, math.pi * 1.5)
 
58
 
 
59
        hippo.cairo_set_source_rgba32(cr, self.props.background_color)
 
60
        cr.fill_preserve()
 
61
 
 
62
        # TODO: we should be more consistent here with the border properties.
 
63
        if self.props.border_color:
 
64
            hippo.cairo_set_source_rgba32(cr, self.props.border_color)
 
65
            cr.set_line_width(self.props.border_top)
 
66
            cr.stroke()