Package ocempgui :: Package access :: Module Magnifier :: Class Magnifier
[show private | hide private]
[frames | no frames]

Type Magnifier

object --+
         |
        Magnifier


Magnifier (size=(20, 20), factor=2) -> Magnifier

A screen magnification class for the pygame screen.

The Magnifier class allows to zoom a certain portion of the screen,
determined by the current mouse position by a specific scaling
factor. It creates a rectangular zoom area that will be blit on the
screen. The zooming area will be placed around the current mouse
position:

##############################################
#                                            #  ###
#               ---------------              #  # # - pygame screen
#               |\           /|              #  ###
#               | \         / |              #
#               |  \ooooooo/  |              #  ooo
#               |   o     o   |              #  o o - Area to zoom (size)
#               |   o  X  o   |              #  ooo
#               |   o     o   |              #
#               |  /ooooooo\  |              #  ---
#               | /         \ |              #  | | - Zoomed area.
#               |/           \|              #  ---
#               ---------------              #
#                                            #   X - Mouse cursor position. 
##############################################

The size of the area to zoom can be adjusted using the 'size'
attribute and set_size() method.

# Zoom a 40x40 px area around the mouse cursor.
magnifier.size = 40, 40
magnifier.set_size (40, 40)

The factor by which the area around the mouse cursor should be
magnified can be set using the 'factor' attribute or set_factor() method.

# Zoom the wanted area by 3 with a result of an area three times as big
# as the original one.
magnifier.factor = 3
magnifier.set_factor (3)

By default the Magnifier uses a simple call to pygame.transform.scale(),
which does not provide optimal results for each surface. The 'zoom_func'
attribute and set_zoom_func() method allow you to provide an own zoom
function, which has to return the zoomed surface. It receives the actual
screen surface, the mouse position the zoomed area will be centered at and
the sizes and scaling factor to use for zooming.

def own_zoom_func (screen, mousepos, resultsize, size, factor):
    ...
    return zoomed_surface

magnifier.zoom_func = own_zoom_func
magnifier.set_zoom_func (own_zoom_func)

The resultsize is a tuple containing the magnifier size multiplied with the
set factor of the magnifier:
resultsize = int (size[0] * factor), int (size[1] * factor)
size and factor contain the currently set values of the respective
attributes of the Magnifier instance. An implementation of the default zoom
functionality of the Magnifier using the 'zoom_func' attribute would look
like the following:

def own_zoom_func (screen, mousepos, resultsize, size, factor):
    offset = mousepos[0] - size[0] / 2, mousepos[1] - size[1] / 2
    # Create zoomable surface.
    surface = pygame.Surface ((size[0], size[1]))
    surface.blit (screen, (0, 0), (offset[0], offset[1], size[0], size[1]))
    # Zoom and blit.
    return pygame.transform.scale (surface, (resultsize[0], resultsize[1]))

Attributes:
factor    - The zoom factor to use for magnification.
size      - The size of the area around the mouse cursor to zoom.
border    - Indicates whether a 1px border around the magnified area should
            be drawn.
zoom_func -

Method Summary
  __init__(self, size, factor)
  enable_border(self, border)
M.enable_border (...) -> None
  notify(self, *events)
M.notify (...) -> bool
  restore(self)
M.restore () -> None
  set_factor(self, factor)
M.set_factor (...) -> None
  set_size(self, width, height)
M.set_size (...) -> None
  set_zoom_func(self, func)
D.set_zoom_func (...) -> None
  _update(self, position)
M._update (...) -> None
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Property Summary
  border: Indicates whether a border should be shown.
  factor: The zoom factor of the magnification area.
  size: The size of the magnification area.
  zoom_func: The zoom function to use.

Method Details

enable_border(self, border)

M.enable_border (...) -> None

Enables or disables the display of a 1px border around the zoom area.

The argument will be interpreted as boolean value.

notify(self, *events)

M.notify (...) -> bool

Notifies the Magnifier about a pygame.event.Event.

The argument must be a pygame.event.Event.

restore(self)

M.restore () -> None

Restores the original screen content.

set_factor(self, factor)

M.set_factor (...) -> None

Sets the zoom factor to use for magnification.

Raises a TypeError, if the argument is not an integer or float. Raises a ValueError, if the argument is smaller than 1.

set_size(self, width, height)

M.set_size (...) -> None

Sets the width and height of the area to zoom.

Raises a TypeError, if the arguments are not integers. Raises a ValueError, if the arguments are smaller than 1.

set_zoom_func(self, func)

D.set_zoom_func (...) -> None

Sets the zoom function to use for the Magnifier..

Raises a TypeError, if func is not callable.

_update(self, position)

M._update (...) -> None

Update the magnification area.

Property Details

border

Indicates whether a border should be shown.
Get Method:
unknown-687689884(...)
Set Method:
unknown-687689940(...)

factor

The zoom factor of the magnification area.
Get Method:
unknown-687689772(...)
Set Method:
unknown-687689828(...)

size

The size of the magnification area.
Get Method:
unknown-687669116(...)
Set Method:
unknown-687669172(...)

zoom_func

The zoom function to use.
Get Method:
unknown-687689996(...)
Set Method:
unknown-687690052(...)

Generated by Epydoc 2.1 on Thu Jan 10 10:18:43 2008 http://epydoc.sf.net