1
# Copyright (C) 2006-2007 Red Hat, Inc.
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.
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.
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.
22
from sugar.graphics import style
24
class CanvasRoundBox(hippo.CanvasBox, hippo.CanvasItem):
25
__gtype_name__ = 'SugarRoundBox'
27
_BORDER_DEFAULT = style.LINE_WIDTH
29
def __init__(self, **kwargs):
30
hippo.CanvasBox.__init__(self, **kwargs)
32
# TODO: we should calculate radius depending on the height of the box.
33
self._radius = style.zoom(10)
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()
41
def do_paint_background(self, cr, damaged_box):
42
[width, height] = self.get_allocation()
44
x = self._BORDER_DEFAULT / 2
45
y = self._BORDER_DEFAULT / 2
46
width -= self._BORDER_DEFAULT
47
height -= self._BORDER_DEFAULT
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)
59
hippo.cairo_set_source_rgba32(cr, self.props.background_color)
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)