| |
- __builtin__.object
-
- HUD
- exceptions.BaseException(__builtin__.object)
-
- HUDBadArgs
- HUDNameExists
- HUDNameNotFound
class HUD(__builtin__.object) |
|
HUD class for a basic Heads Up Display
Not supported:
- Per-item details (font, size, style, antialias, color).
Tips and tricks:
Color arguments may be string names, color sequences, or pygame.Color.
Note the difference between set_color(None) and set_background(None). The former is ignored. The latter
has the side effect of making the background transparent.
set_bold() and set_italic() are software rendering effects. If bold and italic fonts exist they give
more pleasing results.
If you want per-item details (font, size, style, antialias, color) or want to use HUD in a more robust
dashboard-like way, you can make multiple HUDs with custom x, y positions. If you want to calculate
their size for positioning, use the hud_size() method, keeping in mind that changing SysFont styles,
font file, etc. will change the rendered size. One can use the same trick with the HUD that is often
done with words: render the longest strings with the widest character (usually "W") and then remember
the size for layout calculations.
The font items are rendered in the order they are added. Order can be rearranged at any time by
modifying the hud.order list, which is simply a list of the item names. When modifying hud.order and/or
hud.items take care to keep the contents one-to-one. |
|
Methods defined here:
- __init__(self, fontname=None, fontsize=24, sysfontname='sans', bold=False, italic=False, underline=False, color='gold', background=None, gcolor=None, ocolor=None, scolor=None, owidth=1, shadow=(1, 1), antialias=True, alpha=1.0)
- create a basic HUD
The defaults are simply sysfont_name='sans', fontsize=16, antialias=True.
Positioning is anchored at topleft. Modify via x and y attribute. The default is 10, 10.
Vertical spacing for items is 3 pixels by default. Modify via space attribute.
:param fontname: the name of a font file
:param fontsize: point size of the font
:param sysfontname: the name of a system font
:param bold: boolean
:param italic: boolean
:param underline: boolean
:param color: text foreground color
:param background: text background color
:param gcolor: text gradient color
:param ocolor: text outline color
:param scolor: text shadow color
:param owidth: int (float?), width in pixels of outline
:param shadow: tuple of int, (x, y) offset for drop shadow
:param antialias: boolean
:param alpha: float, valid values are 0.0 - 1.0
:return: HUD
- add(self, name, text, *args, **kwargs)
- add a HUD item
HUD items are rendered in the order they are added. Order can be rearranged at any time by modifying
hud.order, which is simply a list of the item names.
An item can use varargs or kwargs, not both. The choice is enforced when the item is updated.
:param name: unique ID
:param text: format text compatible with str.format()
:param args: arguments for str.format()
:param kwargs: optional, callback=func
:return: None
- draw(self, surf)
- draw all the items
:param surf: target surface
:return: None
- fps(self)
- get_alpha(self)
- get_antialias(self)
- get_background(self)
- get_bold(self)
- get_color(self)
- get_font(self)
- get the current font object
:return: pygame.font.Font
- get_fontname(self)
- get_fontsize(self)
- get_gcolor(self)
- get_italic(self)
- get_ocolor(self)
- get_owidth(self)
- get_scolor(self)
- get_shadow(self)
- get_sysfontname(self)
- get_underline(self)
- hud_size(self)
- get the total rendered size of the HUD (may change depending on style, etc.)
:return: w, h
- set_alpha(self, alpha)
- change the surface alpha value
Valid values are 0.0 to 1.0.
:param alpha: int, 0 to 255; if None it is disabled
:return: self
- set_antialias(self, boolean)
- render antialiased font
:param boolean
:return: self
- set_background(self, color)
- change background color
If color is None, the background will be transparent.
:param color: a pygame.Color, color sequence, or name string
:return: self
- set_bold(self, boolean)
- change the bold style
:param boolean
:return: self
- set_color(self, color)
- change foreground color
:param color: a pygame.Color, color sequence, or name string
:return: self
- set_font(self, fontname=None, fontsize=None, sysfontname=None, bold=None, italic=None, underline=None)
- change font
If any of the args are not specified the instance variables are used. The instance variables are
updated to reflect the supplied values.
Font creation and re-rendering of items is triggered.
:param fontname: the name of a font file
:param fontsize: point size of the font
:param sysfontname: the name of a sysfont
:param bold: boolean
:param italic: boolean
:param underline: boolean
:return: self
- set_fontname(self, name)
- change the font source to a file font
:param name: the name of a font file or system font
:return: self
- set_fontsize(self, fontsize)
- change the font size
:param fontsize: int
:return: self
- set_gcolor(self, color=None)
- change gradient color
If color is None, the gradient effect will be removed.
:param color: a pygame.Color, color sequence, or name string
:return: self
- set_italic(self, boolean)
- change the italic style
:param boolean
:return: self
- set_ocolor(self, color=None)
- render an outline color
If color is None, the outline effect will be removed.
:param color: a pygame.Color, color sequence, name string, or None
:return: self
- set_owidth(self, width)
- set outline width
:param width: int >= 0
:return: self
- set_scolor(self, color=None)
- render a drop shadow color
If color is None, the shadow effect will be removed.
:param color: a pygame.Color, color sequence, name string, or None
:return: self
- set_shadow(self, shadow)
- set the x, y distance in pixels to project the shadow
:param shadow: tuple of two ints; the offset of the shadow; e.g. (1, 1), (0, 1), (-2, -2)
:return: self
- set_sysfontname(self, name)
- change the font source to a sysfont
:param name: the name of a font file or system font
:return: self
- set_underline(self, boolean)
- change the underline style
:param boolean
:return: None
- update(self, *args)
- update all items, using the callbacks provided with add()
Logic uses the type of the value passed in add() to determine how to update the value.
The order of evaluation is dict, str, sequence, then discrete value.
:param args: not used; for compatibility with timers, etc. that supply args by default
:return: None
- update_item(self, name, *args, **kwargs)
- update the value of an item (does not invoke the callback)
If the item was created with varargs, then the item must be updated with varargs. If item was created with
kwargs, if must be updated with kwargs.
:param name: item's name
:param args: item's new value
:return: None
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
|