#
#   Python GUI - Pixmap - Generic
#

from Properties import Properties, overridable_property
from Geometry import rect_sized

class Pixmap(Properties):
    """A Pixmap is an offscreen area that can be used both as a
    destination for drawing and a source of image data for drawing
    in a View or another Pixmap.
    
    Constructor:
        Pixmap(width, height)
    """
    
    width = overridable_property('width', "Width of the drawable area in pixels (read only).")
    height = overridable_property('height', "Height of the drawable area in pixels (read only).")
    size = overridable_property('size', "Size of the drawable area in pixels (read only).")
    bounds = overridable_property('bounds', "Bounding rectangle of the drawable area in pixels (read only).")

    def get_size(self):
        return (self.width, self.height)
    
    def get_bounds(self):
        return rect_sized((0, 0), self.size)
    
    def draw(self, canvas, src_rect, dst_rect):
        """Draw the part of the image specified by src_rect on the given canvas,
        scaled to fit within dst_rect."""
        raise NotImplementedError

    def with_canvas(self, proc):
        """Call the given procedure with a canvas suitable for drawing on
        this Pixmap. The canvas is valid only for the duration of the call,
        and should not be retained beyond it."""
        raise NotImplementedError
