#
#   PyGUI - Clip Components - Generic
#

from Geometry import add_pt, sub_pt
from Components import Component

class ClipComponent(Component):
    """Abstract base class for components having their own
    coordinate system and clipping region."""

    #
    #		Coordinate transformation
    #

    def local_to_container_offset(self):
        return self.position
    
    def local_to_container(self, p):
        return add_pt(p, self.local_to_container_offset())
    
    def container_to_local(self, p):
        return sub_pt(p, self.local_to_container_offset())

    def invalidate(self):
        """Marks the whole view as needing to be redrawn."""
        self.invalidate_rect(self.viewed_rect())
    
    def viewed_rect(self):
        """Returns the rectangle in local coordinates that is
        currently visible within the component."""
        width, height = self.size
        return (0, 0, width, height)
