Update of /cvsroot/freevo/freevo/src
In directory sc8-pr-cvs1:/tmp/cvs-serv23312
Modified Files:
osd.py
Log Message:
More cleanups:
o drawstringframed now needs an OSDFont object as font info. This
avoids searching the cache.
o drawstring now uses drawstringframed, removed all the older stuff
Index: osd.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/osd.py,v
retrieving revision 1.63
retrieving revision 1.64
diff -C2 -d -r1.63 -r1.64
*** osd.py 6 Jul 2003 19:39:40 -0000 1.63
--- osd.py 7 Jul 2003 16:24:16 -0000 1.64
***************
*** 10,13 ****
--- 10,19 ----
# -----------------------------------------------------------------------
# $Log$
+ # Revision 1.64 2003/07/07 16:24:16 dischi
+ # More cleanups:
+ # o drawstringframed now needs an OSDFont object as font info. This
+ # avoids searching the cache.
+ # o drawstring now uses drawstringframed, removed all the older stuff
+ #
# Revision 1.63 2003/07/06 19:39:40 dischi
# Return the max_y, int() rounds down
***************
*** 246,252 ****
! class FontInfo:
! def __init__(self, font):
! self.font = font
self.height = max(self.font.size('A')[1], self.font.size('j')[1])
self.chars = {}
--- 252,258 ----
! class OSDFont:
! def __init__(self, name, ptsize):
! self.font = self.__getfont__(name, ptsize)
self.height = max(self.font.size('A')[1], self.font.size('j')[1])
self.chars = {}
***************
*** 266,269 ****
--- 272,310 ----
return w
+ def __getfont__(self, filename, ptsize):
+ ptsize = int(ptsize / 0.7) # XXX pygame multiplies by 0.7 for some reason
+
+ if DEBUG >= 3:
+ print 'OSD: Loading font "%s"' % filename
+ try:
+ font = pygame.font.Font(filename, ptsize)
+ except (RuntimeError, IOError):
+ print 'Couldnt load font "%s"' % filename
+ if DEBUG >= 2:
+ print 'Call stack:'
+ traceback.print_stack()
+
+ # Are there any alternate fonts defined?
+ if not 'OSD_FONT_ALIASES' in dir(config):
+ print 'No font aliases defined!'
+ raise # Nope
+
+ # Ok, see if there is an alternate font to use
+ fontname = os.path.basename(filename).lower()
+ if fontname in config.OSD_FONT_ALIASES:
+ alt_fname = './skins/fonts/' + config.OSD_FONT_ALIASES[fontname]
+ print 'trying alternate: %s' % alt_fname
+ try:
+ font = pygame.font.Font(alt_fname, ptsize)
+ except (RuntimeError, IOError):
+ print 'Couldnt load alternate font "%s"' % alt_fname
+ raise
+ else:
+ print 'No alternate found in the alias list!'
+ raise
+ f = Font(filename, ptsize, font)
+ return f.font
+
+
***************
*** 291,296 ****
self.focused_app = None
- self.fontcache = objectcache.ObjectCache(300, desc='font')
- self.stringcache = objectcache.ObjectCache(100, desc='string')
self.bitmapcache = objectcache.ObjectCache(10, desc='bitmap')
self.font_info_cache = {}
--- 332,335 ----
***************
*** 301,304 ****
--- 340,344 ----
self.width = config.CONF.width
self.height = config.CONF.height
+
if config.CONF.display== 'dxr3':
os.environ['SDL_VIDEODRIVER'] = 'dxr3'
***************
*** 311,319 ****
pygame.font.init()
- #self.depth = pygame.display.mode_ok((self.width, self.height), 1)
- #self.hw = pygame.display.Info().hw
-
self.depth = 32
! self.hw = 0
if config.CONF.display == 'dxr3':
--- 351,356 ----
pygame.font.init()
self.depth = 32
! self.hw = 0
if config.CONF.display == 'dxr3':
***************
*** 591,597 ****
! def getFontInfo(self, font, ptsize):
"""
! return cached font info
"""
key = (font, ptsize)
--- 628,634 ----
! def getfont(self, font, ptsize):
"""
! return cached font
"""
key = (font, ptsize)
***************
*** 599,603 ****
return self.font_info_cache[key]
except:
! fi = FontInfo(self._getfont(font, ptsize))
self.font_info_cache[key] = fi
return fi
--- 636,640 ----
return self.font_info_cache[key]
except:
! fi = OSDFont(font, ptsize)
self.font_info_cache[key] = fi
return fi
***************
*** 679,684 ****
! def drawstringframed(self, string, x, y, width, height, fgcolor=None,
bgcolor=None,
! font=None, ptsize=0, align_h='left', align_v='top',
mode='hard',
layer=None, ellipses='...'):
"""
--- 716,721 ----
! def drawstringframed(self, string, x, y, width, height, font, fgcolor=None,
! bgcolor=None, align_h='left', align_v='top', mode='hard',
layer=None, ellipses='...'):
"""
***************
*** 704,713 ****
return '', (0,0,0,0)
- if font == None:
- font = config.OSD_DEFAULT_FONTNAME
- if not ptsize:
- ptsize = config.OSD_DEFAULT_FONTSIZE
-
- font = self.getFontInfo(font, ptsize)
line_height = font.height * 1.1
--- 741,744 ----
***************
*** 798,802 ****
font=None, ptsize=0, align='left', layer=None):
"""
! draw a string
"""
if not pygame.display.get_init():
--- 829,833 ----
font=None, ptsize=0, align='left', layer=None):
"""
! draw a string. This function is obsolete, please use drawstringframed
"""
if not pygame.display.get_init():
***************
*** 815,870 ****
ptsize = config.OSD_DEFAULT_FONTSIZE
! if DEBUG >= 3:
! print 'FONT: %s %s' % (font, ptsize)
- try:
- ren = self._renderstring(stringproxy(string), font, ptsize, fgcolor,
bgcolor)
- except:
- print "Render failed, skipping..."
- return None
-
- # Handle horizontal alignment
- w, h = ren.get_size()
- tx = x # Left align is default
if align == 'center':
! tx = x - w/2
elif align == 'right':
! tx = x - w
! if layer:
! layer.blit(ren, (tx, y))
! else:
! self.screen.blit(ren, (tx, y))
!
!
! def _renderstring(self, string, font, ptsize, fgcolor, bgcolor):
! """
! Render a string to an SDL surface. Uses a cache for speedup.
! """
! key = (string, font, ptsize, fgcolor, bgcolor)
! surf = self.stringcache[key]
! if surf:
! return surf
!
! f = self._getfont(font, ptsize)
!
! if not f:
! print 'Couldnt get font: "%s", size: %s' % (font, ptsize)
! return
!
! # Render string with anti-aliasing
! if bgcolor == None:
! try:
! surf = f.render(string, 1, self._sdlcol(fgcolor))
! except:
! print 'FAILED: str="%s" col="%s"' % (string, fgcolor)
! raise
! else:
! surf = f.render(string, 1, self._sdlcol(fgcolor), self._sdlcol(bgcolor))
!
! # Store the surface in the FIFO, Even if it's None?
! self.stringcache[key] = surf
!
! return surf
--- 846,860 ----
ptsize = config.OSD_DEFAULT_FONTSIZE
! tx = x
! width = self.width - tx
if align == 'center':
! tx -= width/2
elif align == 'right':
! tx -= width
! self.drawstringframed(string, x, y, width, -1, self.getfont(font, ptsize),
! fgcolor, bgcolor, align_h = align, layer=layer,
! ellipses='')
***************
*** 998,1043 ****
- def _getfont(self, filename, ptsize):
- ptsize = int(ptsize / 0.7) # XXX pygame multiplies by 0.7 for some reason
-
- key = filename+str(ptsize)
- f = self.fontcache[key]
- if f:
- return f.font
-
- if DEBUG >= 3:
- print 'OSD: Loading font "%s"' % filename
- try:
- font = pygame.font.Font(filename, ptsize)
- except (RuntimeError, IOError):
- print 'Couldnt load font "%s"' % filename
- if DEBUG >= 2:
- print 'Call stack:'
- traceback.print_stack()
-
- # Are there any alternate fonts defined?
- if not 'OSD_FONT_ALIASES' in dir(config):
- print 'No font aliases defined!'
- raise # Nope
-
- # Ok, see if there is an alternate font to use
- fontname = os.path.basename(filename).lower()
- if fontname in config.OSD_FONT_ALIASES:
- alt_fname = './skins/fonts/' + config.OSD_FONT_ALIASES[fontname]
- print 'trying alternate: %s' % alt_fname
- try:
- font = pygame.font.Font(alt_fname, ptsize)
- except (RuntimeError, IOError):
- print 'Couldnt load alternate font "%s"' % alt_fname
- raise
- else:
- print 'No alternate found in the alias list!'
- raise
- f = Font(filename, ptsize, font)
- self.fontcache[key] = f
-
- return f.font
-
-
def _getbitmap(self, url):
"""
--- 988,991 ----
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog