forked from charrea6/freevo1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBorder.py
More file actions
142 lines (114 loc) · 4.74 KB
/
Border.py
File metadata and controls
142 lines (114 loc) · 4.74 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# For drawing borders around rectangular objects.
# -----------------------------------------------------------------------
# $Id$
#
# Todo: o Make a get_thickness set_thickness function pair.
# -----------------------------------------------------------------------
#
# Freevo - A Home Theater PC framework
#
# Copyright (C) 2002 Krister Lagerstrom, et al.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------
"""
For drawing borders around rectangular objects.
Border can only be used when called from other GUI Objects. If no
parent object is passed on creation Border will raise an exception.
All suggestions on improvement are welcome
"""
import logging
logger = logging.getLogger("freevo.gui.Border")
__date__ = "$Date$"
__version__ = "$Revision$"
__author__ = """Thomas Malt <thomas@malt.no>"""
import config
from GUIObject import *
class Border(GUIObject):
"""
Draw borders around objects.
Border can only be used when called from other GUI Objects. If no
parent object is passed on creation Border will raise an exception.
All suggestions on improvement are welcome.
"""
# Define the different borders:
BORDER_FLAT = 'flat'
BORDER_SHADOW = 'shadow'
BORDER_RAISED = 'raised'
BORDER_SUNKEN = 'sunken'
def __init__(self, parent, style=None, color=None, width=None):
"""
Initialise an instance of a Border
@ivar parent: object to draw border of; use this to get geometry and stuff.
@ivar style: border Type. One of 'flat','shadow','raised' or 'sunken'
@ivar color: color of object, Either a Freevo Color object or a color integer.
@ivar width: thickness of border.
"""
if not parent or not isinstance(parent, GUIObject):
raise TypeError, 'You need to set the parent correctly'
self.bd_types = [self.BORDER_FLAT, self.BORDER_SHADOW,
self.BORDER_RAISED, self.BORDER_SUNKEN]
if width and type(width) is IntType:
self.thickness = width
else:
self.thickness = 1
self.style = self.BORDER_FLAT
self.rect = None
self.shadow_ho = 6 # Horisontal offset for dropshadow
self.shadow_vo = 6 # Vertical offset for dropshadow
if style and style in self.bd_types: self.style = style
GUIObject.__init__(self, 0, 0, parent.width,
parent.height)
parent.add_child(self)
self.color = Color(self.osd.default_fg_color)
def get_style(self):
"""
Return the style of the border.
"""
return self.style
def set_style(self, style):
"""
Set the which style to draw the border.
"""
if style in self.bd_types: self.style = style
else: raise TypeError, style
def _draw(self):
"""
Draws the border around the parent.
Todo: Implement what to do for other borders than flat.
"""
logger.log( 9, " Inside Border.draw...")
logger.log( 9, " Border type: %s", self.style)
# XXX Hack to make border draw inside the areas we expect.
if self.style == self.BORDER_FLAT:
c = self.color.get_color_sdl()
w, h = self.parent.surface.get_size()
self.rect = self.osd.drawbox(0, 0, w, h, self.thickness, 0, 0x00000000,
self.parent.surface)
# if self.style == self.BORDER_SHADOW:
# self.rect = pygame.draw.rect(self.osd.screen, color, rect,
# self.thickness)
#
#if self.style == self.BORDER_RAISED:
# self.rect = pygame.draw.rect(self.osd.screen, color, rect,
# self.thickness)
#
#if self.style == self.BORDER_SUNKEN:
# self.rect = pygame.draw.rect(self.osd.screen, color, rect,
# self.thickness)
#